/**
 * Design system do painel (dashboard, editor e resultados).
 *
 * Identidade própria: superfícies neutras quentes, um azul-violeta como cor de
 * ação, cantos generosos e sombras discretas. Independente do tema que o criador
 * escolhe para o formulário dele — aquele vive nas variáveis --f-*.
 */

:root {
  color-scheme: light;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --surface-3: #f1f1f4;
  --border: #e6e6ea;
  --border-strong: #d3d3da;
  --text: #16161c;
  --text-2: #55555f;
  --text-3: #85858f;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef0fe;
  --brand-text: #4338ca;
  --on-brand: #ffffff;
  --ok: #12784c;
  --ok-soft: #e6f4ec;
  --warn: #9a5b00;
  --warn-soft: #fdf3e3;
  --danger: #c0362f;
  --danger-hover: #a52c26;
  --danger-soft: #fbeceb;
  --serie-1: #4f46e5;
  --serie-2: #eb6834;
  --grid: #ebebef;
  --shadow-1: 0 1px 2px rgba(16, 16, 28, 0.05);
  --shadow-2: 0 1px 2px rgba(16, 16, 28, 0.05), 0 8px 24px rgba(16, 16, 28, 0.06);
  --shadow-3: 0 8px 16px rgba(16, 16, 28, 0.08), 0 24px 56px rgba(16, 16, 28, 0.12);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --topo: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --bg: #101014;
    --surface: #18181d;
    --surface-2: #1e1e24;
    --surface-3: #26262d;
    --border: #2c2c34;
    --border-strong: #3d3d47;
    --text: #f4f4f6;
    --text-2: #b4b4bf;
    --text-3: #8a8a95;
    --brand: #7c74f0;
    --brand-hover: #8f88f3;
    --brand-soft: #232140;
    --brand-text: #a49df5;
    --on-brand: #12101f;
    --ok: #4bbd80;
    --ok-soft: #14261c;
    --warn: #d8a252;
    --warn-soft: #2a2113;
    --danger: #ef7b76;
    --danger-hover: #f59491;
    --danger-soft: #2c1717;
    --serie-1: #7c74f0;
    --serie-2: #e07a4f;
    --grid: #2a2a32;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-3: 0 10px 20px rgba(0, 0, 0, 0.5), 0 30px 60px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
p { margin: 0; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { flex: none; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* =============================================================== botões */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}
.btn:hover { background: var(--brand-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-2 { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-2:hover { background: var(--surface-2); border-color: var(--text-3); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-perigo { background: transparent; color: var(--danger); }
.btn-perigo:hover { background: var(--danger-soft); }

.btn-solido-perigo { background: var(--danger); color: #fff; }
.btn-solido-perigo:hover { background: var(--danger-hover); }

.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 7px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-bloco { width: 100%; }
.btn-icone { padding: 7px; border-radius: 7px; }

/* ================================================================ campos */

.campo { display: block; margin-bottom: 15px; }
.campo:last-child { margin-bottom: 0; }

.rotulo {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}
.rotulo .req { color: var(--danger); }

.ajuda { margin-top: 5px; font-size: 12.5px; color: var(--text-3); }

.inp {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}
.inp::placeholder { color: var(--text-3); }
.inp:hover { border-color: var(--text-3); }
.inp:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.inp:disabled { background: var(--surface-3); cursor: not-allowed; opacity: 0.75; }
.inp[aria-invalid='true'] { border-color: var(--danger); }
textarea.inp { resize: vertical; min-height: 72px; }

select.inp {
  appearance: none; cursor: pointer; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 53%, calc(100% - 12px) 53%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.erro-campo { margin-top: 5px; font-size: 12.5px; color: var(--danger); font-weight: 500; }
.erro-campo:empty { display: none; }

.linha { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.linha > * { flex: 1; min-width: 0; }
.linha > .fixo { flex: none; }

/* interruptor */

.switch { display: flex; align-items: flex-start; gap: 11px; cursor: pointer; padding: 3px 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-trilha {
  flex: none;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.18s ease;
  margin-top: 1px;
}
.switch-trilha::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}
.switch input:checked + .switch-trilha { background: var(--brand); }
.switch input:checked + .switch-trilha::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-trilha { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch-texto { font-size: 14px; }
.switch-texto small { display: block; color: var(--text-3); font-size: 12.5px; line-height: 1.4; }

/* segmentado */

.segmentos {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 9px;
  gap: 2px;
}
.segmento {
  padding: 6px 13px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmento:hover { color: var(--text); }
.segmento[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ================================================================= card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
}
.card-p { padding: 18px 20px; }

.painel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-1); padding: 18px 20px; margin-bottom: 16px; }
.painel-cabeca { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.painel-titulo { font-size: 15px; font-weight: 650; }
.painel-sub { font-size: 12.5px; color: var(--text-3); }

/* ================================================================ chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-off { background: var(--surface-3); color: var(--text-3); }
.chip-brand { background: var(--brand-soft); color: var(--brand-text); }
.chip-ponto { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ================================================================ topo */

.topo {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topo);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topo-inner {
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.topo.largo .topo-inner { max-width: none; }

.marca { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; }
.marca:hover { text-decoration: none; }
.marca-simbolo {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--brand), #7c3aed);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: var(--shadow-1);
}
.marca-nome { font-size: 14.5px; font-weight: 680; letter-spacing: -0.02em; }
.marca-sub { font-size: 11.5px; color: var(--text-3); line-height: 1.2; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700;
  border: 1px solid var(--border);
  cursor: pointer;
}

/* ============================================================== layout */

.pagina { max-width: 1280px; margin: 0 auto; padding: 26px 20px 72px; }
.pagina-estreita { max-width: 900px; }

.pagina-cabeca {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.pagina-cabeca h1 { font-size: 24px; }
.pagina-cabeca .sub { margin-top: 4px; color: var(--text-2); font-size: 14px; }
.acoes-cabeca { display: flex; gap: 8px; flex-wrap: wrap; }

/* =============================================================== menus */

.menu-wrap { position: relative; }
/* Posição vem do JS (coordenadas do botão), por isso `fixed` e sem top/right. */
.menu {
  position: fixed;
  min-width: 200px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-3);
  padding: 5px;
  z-index: 50;
  animation: menu-entra 0.14s ease both;
}
@keyframes menu-entra { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-3); text-decoration: none; }
.menu-item.perigo { color: var(--danger); }
.menu-item.perigo:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 2px; }
.menu-titulo { padding: 7px 10px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }

/* ============================================================== modal */

.modal-fundo {
  position: fixed; inset: 0;
  background: rgba(16, 16, 28, 0.45);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fade 0.16s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 520px;
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  animation: modal-entra 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.modal.largo { max-width: 720px; }
@keyframes modal-entra { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

.modal-cabeca {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-cabeca h2 { font-size: 16.5px; }
.modal-corpo { padding: 18px 20px; overflow-y: auto; }
.modal-pe {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ============================================================== toast */

.toasts {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  display: grid; gap: 8px;
  z-index: 200;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  animation: toast-entra 0.2s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.toast.saindo { animation: toast-sai 0.18s ease both; }
.toast.erro { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-entra { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-sai { to { opacity: 0; transform: translateY(6px); } }

/* ============================================================ estados */

.vazio {
  text-align: center;
  padding: 56px 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}
.vazio-icone {
  width: 52px; height: 52px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand-text);
  display: grid; place-items: center;
}
.vazio h3 { font-size: 16.5px; }
.vazio p { margin: 8px auto 0; max-width: 40ch; color: var(--text-2); font-size: 14px; }
.vazio .btn { margin-top: 18px; }

.esqueleto {
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-3) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: brilho 1.4s ease infinite;
}
@keyframes brilho { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.spinner, .fx-spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: 0.9;
  animation: girar 0.7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.carregando-tela {
  min-height: 60vh;
  display: grid;
  place-items: center;
  color: var(--text-3);
  gap: 12px;
}

/* ============================================================= tabela */

.tabela-rolagem {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  max-height: 70vh;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left;
  padding: 10px 13px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 13px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

/* ============================================================== alerta */

.alerta {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  border: 1px solid;
  margin-bottom: 14px;
}
.alerta .ic { margin-top: 2px; }
.alerta-erro { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alerta-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.alerta-info { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); }
.alerta-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
