/* ==========================================================================
   K. System — Design System "COMANDO"
   Rail grafite FIXA (nos 2 temas) + conteúdo claro · títulos fortes · rótulos
   em maiúscula · realce por área (--side-accent). Fonte moderna (system-ui).
   Tema light/dark do CONTEÚDO via [data-theme]. A rail é sempre escura.
   Todos os nomes de classe preservados do design anterior.
   ========================================================================== */

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --gap: .9rem;
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --shadow-sm: 0 1px 2px rgba(17,20,24,.05);
  --shadow-md: 0 4px 16px rgba(17,20,24,.09);
  --shadow-lg: 0 16px 42px rgba(17,20,24,.20);
  --trans: .15s ease;

  /* ---- RAIL "Comando" — grafite CONSTANTE (não vira com o tema) ---- */
  --side-bg: #17181b;
  --side-elev: #212328;
  --side-fg: #c6c8c4;
  --side-fg-strong: #f4f3ef;
  --side-muted: #7f817c;
  --side-line: #2b2d32;
  /* realce da rail por área (claro o bastante p/ o grafite). almox = âmbar. */
  --side-accent: #efa93a;
}

/* ---------- Conteúdo — LIGHT ---------- */
[data-theme="light"] {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --surface-3: #eeeeec;
  --border: #e6e6e3;
  --border-strong: #d3d2cf;
  --text: #1b1c1e;
  --text-muted: #6b6d72;
  --text-soft: #9a9ca1;
  --primary: #e08608;
  --primary-hover: #b86e07;
  --primary-ink: #a4590a;
  --primary-soft: #faecd7;
  --primary-text: #2a1e07;
  --accent: #b45309;
  --success: #0f7a4f; --success-soft:#d6f3e4;
  --warning: #b0670a; --warning-soft:#fdeecb;
  --danger: #c8352a;  --danger-soft:#fbe0dd;
  --info: #0e7c94;    --info-soft:#cef1f7;
  --accent-rgb: 224,134,8;
}

/* ---------- Conteúdo — DARK ---------- */
[data-theme="dark"] {
  --bg: #131417;
  --surface: #1b1d21;
  --surface-2: #212429;
  --surface-3: #2c2f35;
  --border: #33363c;
  --border-strong: #474b52;
  --text: #ecedee;
  --text-muted: #a9adb4;
  --text-soft: #7e828a;
  --primary: #f59e0b;
  --primary-hover: #f7af37;
  --primary-ink: #f8b64a;
  --primary-soft: #4d3611;
  --primary-text: #241905;
  --accent: #fbbf24;
  --success: #34d399; --success-soft:#0c3a2b;
  --warning: #fbbf24; --warning-soft:#3f2f0a;
  --danger: #f87171;  --danger-soft:#4a1b18;
  --info: #38bdf8;    --info-soft:#0e3a44;
  --accent-rgb: 245,158,11;
}

/* Esquema nativo por tema: o navegador desenha os controles nativos (popup do <select>,
   barras de rolagem, seletor de data) no tema certo. Sem isso, as opcoes da lista ficam
   ilegiveis no dark. Vale para TODO o sistema. */
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"]  { color-scheme: dark; }
option, optgroup { background: var(--surface); color: var(--text); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.theme-anim, .theme-anim .topbar, .theme-anim .card, .theme-anim .table,
.theme-anim .dropdown__menu, .theme-anim .form-control, .theme-anim .form-select {
  transition: background-color .28s ease, color .28s ease, border-color .28s ease;
}
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5rem; font-weight: 650; line-height: 1.2; letter-spacing: -.011em; text-wrap: balance; color: var(--text); }
h1 { font-size: 1.55rem; } h2 { font-size: 1.22rem; } h3 { font-size: 1.05rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
code { background: var(--surface-3); padding: .1em .35em; border-radius: 5px; font-size: .9em; font-family: var(--mono); }

/* ==========================================================================
   SHELL — rail grafite + submenus (acordeão)
   ========================================================================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--side-bg); border-right: 1px solid var(--side-line);
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.sidebar__brand {
  height: var(--topbar-h); display: flex; align-items: center; gap: .6rem; padding: 0 1.1rem;
  font-weight: 650; font-size: 1.02rem; letter-spacing: -.01em; border-bottom: 1px solid var(--side-line);
  flex: none; color: var(--side-fg-strong);
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--side-accent);
  color: #201603; display: grid; place-items: center; font-weight: 800; font-size: .82rem; flex:none; }
/* Selo BETA ao lado da marca (pilula ambar, le bem no rail escuro e nas telas claras). */
.brand-beta { display: inline-flex; align-items: center; flex: none;
  padding: .1rem .42rem; border-radius: 999px; background: var(--primary); color: var(--primary-text);
  font-size: .58rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; line-height: 1.4; }
.sidebar__scroll { flex: 1; overflow-y: auto; padding: .7rem .6rem 1rem; }
.sidebar__scroll::-webkit-scrollbar { width: 9px; }
.sidebar__scroll::-webkit-scrollbar-thumb { background: #3a3c42; border-radius: 9px; border: 3px solid var(--side-bg); }

.side-base { padding: .35rem .35rem .7rem; border-bottom: 1px solid var(--side-line); margin-bottom: .5rem; }
.side-base .lab { font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--side-muted); display: flex; align-items: center; margin: 0 .25rem .3rem; }

.side-link, .side-head {
  display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .7rem; border-radius: 9px;
  color: var(--side-fg); font-weight: 500; font-size: .875rem; cursor: pointer; background: none; border: 0;
  font-family: inherit; text-align: left; transition: background var(--trans), color var(--trans), box-shadow var(--trans);
}
.side-link:hover, .side-head:hover { background: var(--side-elev); color: var(--side-fg-strong); text-decoration: none; }
.side-link.active { background: var(--side-elev); color: var(--side-accent); font-weight: 600; box-shadow: inset 2px 0 0 var(--side-accent); }
.side-link .i, .side-head .i { width: 18px; text-align: center; flex: none; opacity: .85; }
.side-head { justify-content: space-between; }
.side-head .caret { margin-left: auto; font-size: .58rem; opacity: .6; transition: transform .2s; }
.side-group.open .side-head .caret { transform: rotate(180deg); }
.side-group.open .side-head { color: var(--side-fg-strong); }
.side-sec { font-size: .63rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--side-muted); padding: .85rem .7rem .3rem; }
.side-sub { overflow: hidden; max-height: 0; transition: max-height .28s ease; }
.side-group.open .side-sub { max-height: 520px; }
.side-item {
  display: flex; align-items: center; gap: .55rem; padding: .45rem .7rem .45rem 1.75rem; border-radius: 8px;
  color: var(--side-fg); font-weight: 450; font-size: .84rem; position: relative;
  transition: background var(--trans), color var(--trans);
}
.side-item::before { content: ""; position: absolute; left: 1.05rem; top: 50%; width: 5px; height: 5px;
  border-radius: 50%; background: var(--side-muted); transform: translateY(-50%); opacity: .7; }
.side-item:hover { background: var(--side-elev); color: var(--side-fg-strong); text-decoration: none; }
.side-item.on { color: var(--side-accent); font-weight: 600; }
.side-item.on::before { background: var(--side-accent); opacity: 1; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .7rem; padding: 0 1.1rem; position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-weight: 650; font-size: 1.02rem; letter-spacing: -.01em; display: flex; align-items: center;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__spacer { flex: 1; }
/* Select de CNPJ da topbar: cap no desktop; no mobile o @media reduz para 42vw. */
.topbar select, .topbar .form-select { max-width: 220px; }
.backbtn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .38rem .7rem; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: .82rem; cursor: pointer; font-family: inherit; text-decoration: none;
  transition: all var(--trans); flex: none;
}
.backbtn:hover { background: var(--surface-3); border-color: var(--primary); color: var(--primary-ink); text-decoration: none; }
.backbtn .a { font-size: 1rem; line-height: 1; }
/* overflow-x:clip = guarda contra scroll horizontal (tooltips .help, popups, conteudo largo).
   clip (nao hidden) NAO cria contexto de rolagem, entao a topbar sticky segue funcionando.
   Verificado ao vivo: em html/body o clip nao contem o vazamento; em .content sim (448->375 no cel). */
.content { padding: 1.3rem 1.4rem; max-width: 1400px; width: 100%; overflow-x: clip; }

.nav-toggle { display: none; }

/* entrada da página = FADE IN suave */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.content > * { animation: fadeIn .4s ease both; }
.content > *:nth-child(2){ animation-delay:.04s } .content > *:nth-child(3){ animation-delay:.08s }
.content > *:nth-child(n+4){ animation-delay:.12s }

/* ==========================================================================
   AJUDA — tooltip "?"
   ========================================================================== */
.help {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface-3); color: var(--text-muted); font-size: 11px; font-weight: 700; line-height: 1;
  border: 1px solid var(--border-strong); cursor: help; position: relative; vertical-align: middle;
  margin-left: 5px; transition: background var(--trans), color var(--trans), border-color var(--trans);
}
.help:hover, .help:focus-visible { background: var(--primary); color: var(--primary-text); border-color: var(--primary); outline: none; }
.help::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 9px);
  transform: translateX(-50%) translateY(4px); width: max-content; max-width: min(260px, calc(100vw - 1.5rem));
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); border-radius: 10px; padding: .55rem .7rem; font-size: .76rem; font-weight: 450;
  line-height: 1.45; text-align: left; opacity: 0; pointer-events: none; transition: opacity .16s, transform .16s;
  z-index: 200; white-space: normal; letter-spacing: 0; text-transform: none;
}
.help::before {
  content: ""; position: absolute; left: 50%; bottom: calc(100% + 3px); transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--border-strong); opacity: 0; transition: opacity .16s; z-index: 201;
}
.help:hover::after, .help:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.help:hover::before, .help:focus-visible::before { opacity: 1; }
.help.down::after { bottom: auto; top: calc(100% + 9px); transform: translateX(-50%) translateY(-4px); }
.help.down::before { bottom: auto; top: calc(100% + 3px); border-top-color: transparent; border-bottom-color: var(--border-strong); }
.help.down:hover::after, .help.down:focus-visible::after { transform: translateX(-50%) translateY(0); }
.help.left::after { left: auto; right: -6px; transform: translateY(4px); }
.help.left.down::after { transform: translateY(-4px); }
.help.left:hover::after, .help.left:focus-visible::after { transform: translateY(0); }
.help.left::before { left: auto; right: 6px; transform: none; }

/* ==========================================================================
   COMPONENTES
   ========================================================================== */
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  width: 36px; height: 36px; border-radius: var(--radius-sm); cursor: pointer; font-size: 1.02rem;
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  transition: background var(--trans), color var(--trans);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* Ícones de linha (SVG) — monocromáticos, herdam a cor */
.ic { display: inline-block; vertical-align: middle; flex: none; }
.side-link .i, .side-head .i { display: inline-flex; align-items: center; justify-content: center; }

/* Cards — LIMPOS (sem barra à esquerda), hairline + cantos macios */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); transition: box-shadow .18s ease, border-color .18s ease; min-width: 0; }
.card:hover { box-shadow: var(--shadow-md); }
/* Tooltip do "?" nao pode ficar atras do bloco seguinte: eleva o card que tem um tooltip ativo. */
.card:has(.help:hover), .card:has(.help:focus-within) { position: relative; z-index: 6; }
.card__head { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .6rem; }
.card__head h3 { margin: 0; }
.card__body { padding: 1.1rem; }
.card__foot { padding: .75rem 1.1rem; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius); }
.grid { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
/* grid com coluna lateral fixa (ex.: filtro 320px + tabela) que COLAPSA para 1 coluna no mobile.
   Substitui o grid-template-columns inline que nao respeitava o @media. */
.grid-sidebar { grid-template-columns: 320px minmax(0,1fr); }
@media (max-width: 900px) { .grid-sidebar { grid-template-columns: 1fr; } }

/* Cartão-ação: o card inteiro é clicável (hub do Admin-Master, hub de CNPJ). */
.card-acao { display: flex; flex-direction: column; justify-content: space-between;
  text-decoration: none; color: inherit; }
.card-acao:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.card-acao:hover .btn { filter: brightness(1.06); }
.card-acao .acao-head { display: flex; align-items: center; gap: .55rem; margin-bottom: .45rem; }
.card-acao .acao-head h3 { font-size: 1.02rem; }
.card-acao .acao-head .ic { color: var(--primary); flex: none; }

.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat .label { color: var(--text-muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.025em; }
.stat .hint { color: var(--text-soft); font-size: .78rem; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .5rem .95rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: .875rem; cursor: pointer; transition: all var(--trans);
  background: var(--surface-3); color: var(--text); line-height: 1.2; text-decoration: none;
  position: relative; overflow: hidden; font-family: inherit;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); z-index: 0; }
.btn-ghost::before { content: ""; position: absolute; inset: 0; background: var(--primary); transform: translateY(100%);
  transition: transform .26s ease; z-index: -1; }
.btn-ghost:hover { color: var(--primary-text); border-color: var(--primary); filter: none; }
.btn-ghost:hover::before { transform: translateY(0); }
.btn-sm { padding: .32rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.ripple { position: absolute; border-radius: 50%; transform: scale(0); pointer-events: none;
  background: rgba(255,255,255,.5); animation: ripple .55s ease-out; }
.btn-ghost .ripple, .backbtn .ripple { background: rgba(var(--accent-rgb),.28); }
@keyframes ripple { to { transform: scale(3.4); opacity: 0; } }

/* Forms — input linha (underline) */
.form-group { margin-bottom: 1rem; }
.form-label { display: flex; align-items: center; font-weight: 550; margin-bottom: .35rem; font-size: .85rem; }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-control, .form-select {
  width: 100%; padding: .55rem .35rem; border: 0; border-bottom: 1.5px solid var(--border-strong);
  border-radius: 0; background: transparent; color: var(--text);
  font-size: .9rem; font-family: inherit; transition: border-color var(--trans), box-shadow var(--trans);
}
.form-control:focus, .form-select:focus {
  outline: none; border-bottom-color: var(--primary); box-shadow: 0 1px 0 0 var(--primary);
}
textarea.form-control { border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: .55rem .7rem; background: var(--surface); min-height: 92px; resize: vertical; }
textarea.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-control-sm, .form-select-sm { padding: .32rem .3rem; font-size: .82rem; }
.form-select { appearance: none; background-image:
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23999'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .2rem center; background-size: 13px; padding-right: 1.4rem; }
.form-hint { color: var(--text-soft); font-size: .78rem; margin-top: .3rem; }

/* Campo de arquivo com controle proprio, em portugues (esconde o "Choose File" nativo do navegador). */
.file-field { display: inline-flex; align-items: center; gap: .6rem; flex-wrap: wrap; max-width: 100%; cursor: pointer; }
.file-field__input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.file-field__btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .9rem; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .85rem; white-space: nowrap; transition: border-color var(--trans), background var(--trans), color var(--trans); }
.file-field:hover .file-field__btn { border-color: var(--primary); color: var(--primary-ink); }
.file-field__input:focus-visible + .file-field__btn { outline: 2px solid var(--primary); outline-offset: 2px; border-color: var(--primary); }
.file-field__name { color: var(--text-soft); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.file-field.has-file .file-field__name { color: var(--text); font-weight: 500; }

/* Checkbox como TOGGLE SWITCH */
.form-check { display: flex; align-items: center; gap: .55rem; margin: .5rem 0; }
.form-check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px;
  background: var(--border-strong); position: relative; cursor: pointer; flex: none; transition: background .2s; margin: 0;
}
.form-check input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s;
}
.form-check input[type="checkbox"]:checked { background: var(--primary); }
.form-check input[type="checkbox"]:checked::after { transform: translateX(16px); }
.form-check input[type="checkbox"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.form-check label { cursor: pointer; }

/* ==========================================================================
   FORMULÁRIOS DE PÁGINA — largura de trabalho UNIFORME + grade simétrica
   Todos os forms-card usam a MESMA largura (antes cada um tinha um max-width
   diferente = "fora de esquadro"). Campos em .form-grid preenchem em 2 colunas.
   ========================================================================== */
.form-card { width: 100%; max-width: 860px; }
.form-card--wide { max-width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.2rem; }
.form-grid > .col-2, .form-grid > .form-check, .form-grid > .form-actions { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; align-items: center; margin-top: .3rem; }

/* Lista de itens com edição COLAPSÁVEL (fechada por padrão) — bases, etc.
   Full-width e uniforme; o painel de edição só aparece quando o usuário abre. */
.list-rows { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list-row { border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row > summary { list-style: none; cursor: pointer; }
.list-row > summary::-webkit-details-marker { display: none; }
.list-row > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.list-row__head { display: flex; align-items: center; gap: .8rem; padding: .8rem .95rem; transition: background var(--trans); }
.list-row:hover > summary .list-row__head { background: var(--surface-2); }
.list-row__title { font-weight: 650; }
.list-row__sub { color: var(--text-muted); font-weight: 400; font-size: .85rem; }
.list-row__spacer { margin-left: auto; }
.list-row .chev { color: var(--text-muted); font-size: .8rem; transition: transform .2s; }
.list-row[open] .chev { transform: rotate(180deg); }
.list-row__body { padding: .5rem .95rem 1.1rem; border-top: 1px dashed var(--border); background: var(--surface-2);
  animation: fadeIn .18s ease; }

/* Card colapsável (details): o cabeçalho é o gatilho, sem o triângulo nativo */
details > summary.card__head { cursor: pointer; list-style: none; }
details > summary.card__head::-webkit-details-marker { display: none; }
details[open] > summary.card__head .chev { transform: rotate(180deg); }
summary.card__head .chev { display: inline-block; font-size: .8rem; transition: transform .2s; }

/* Filtros colapsáveis (sanfona) — reutilizável em todas as listas. Oculto por padrão. */
.filters { margin-bottom: 1rem; }
.filters > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; }
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-sm); }
.filters__lbl-hide { display: none; }
.filters[open] .filters__lbl-show { display: none; }
.filters[open] .filters__lbl-hide { display: inline; }
.filters__panel { margin-top: .6rem; width: 100%; animation: fadeIn .16s ease; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
/* tabelas colocadas direto no corpo do card (ex.: dashboard) rolam na horizontal —
   evita o body escapar lateralmente no mobile. table-wrap trata os demais casos. */
.card__body:has(> table.table) { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); }
.table thead th { background: var(--surface-2); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); position: sticky; top: 0; font-weight: 700; }
.table tbody tr { transition: background var(--trans); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.actions { white-space: nowrap; text-align: right; }
.table .muted { color: var(--text-muted); }
td .q, .fw-bold { font-variant-numeric: tabular-nums; }

/* Badges — PILL */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .58rem; border-radius: 999px;
  font-size: .72rem; font-weight: 650; background: var(--surface-3); color: var(--text-muted); }
.badge-primary { background: var(--primary-soft); color: var(--primary-ink); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
/* Cargo Admin-Master: tag dourada de diferenciacao (vale em todo o sistema). */
.badge-master { background: linear-gradient(180deg, #f7d774 0%, #d9a520 100%); color: #3a2b00; border: 1px solid #c6951a; font-weight: 700; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Alerts / flash */
.alert { padding: .7rem .9rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  margin-bottom: .7rem; display: flex; align-items: center; gap: .5rem; font-size: .88rem; animation: fadeIn .35s ease both; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger); }
.alert-info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info); }
.alert .close { margin-left: auto; cursor: pointer; opacity: .7; background: none; border: 0; color: inherit; font-size: 1.1rem; }
.alert-success::before { content: ""; width: 18px; height: 18px; flex: none;
  background: no-repeat center/100% url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath fill='none' stroke='%230f7a4f' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M6 14.5l5 5 11-12'/%3E%3C/svg%3E");
  animation: checkDraw .5s ease; }
@keyframes checkDraw { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* Loader dual-ring */
.ld-dual { display: inline-block; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid transparent; border-top-color: var(--primary); border-bottom-color: var(--accent);
  animation: spin .9s linear infinite; }
.ld-dual.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: grid; place-items: center; padding: 2rem; gap: .6rem; color: var(--text-muted); }

/* checkmark inline */
.fx-check { width: 22px; height: 22px; vertical-align: middle; }
.fx-check circle { stroke: var(--success); stroke-width: 3; fill: none; stroke-dasharray: 76; stroke-dashoffset: 76; animation: draw .5s ease forwards; }
.fx-check path { stroke: var(--success); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; stroke-dashoffset: 24; animation: draw .35s .4s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Toast */
#toast-wrap { position: fixed; top: 1rem; right: 1rem; z-index: 1200; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); padding: .7rem .9rem; min-width: 240px;
  max-width: min(360px, calc(100vw - 2rem)); animation: fadeIn .2s ease; }
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(12,14,18,.55); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 1rem; animation: fadeIn .16s ease; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; animation: fadeIn .2s ease; }
.modal__head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); font-weight: 650; font-size: 1.05rem; }
.modal__body { padding: 1.2rem; }
.modal__foot { padding: .9rem 1.2rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .6rem; }

/* Dropdown (sino / usuário) */
.dropdown { position: relative; }
.dropdown__menu { position: absolute; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 232px; z-index: 70; overflow: hidden; padding: .3rem; }
.dropdown__menu.right { right: 0; }
.dropdown__menu.left { left: 0; }
.dropdown__menu[hidden] { display: none; }
.dropdown__item { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; color: var(--text);
  cursor: pointer; font-size: .87rem; border-radius: 8px; text-decoration: none; }
.dropdown__item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown__item.on { color: var(--primary-ink); background: var(--primary-soft); font-weight: 650; }
.dropdown__item .i { width: 18px; text-align: center; opacity: .85; }
.dropdown__head { padding: .55rem .7rem; color: var(--text-soft); font-weight: 700; font-size: .66rem;
  text-transform: uppercase; letter-spacing: .07em; }
.dropdown__sep { height: 1px; background: var(--border); margin: .3rem 0; }
/* v0.5: a lista do sino ROLA. Sem isto, o .dropdown__menu (overflow:hidden) cortava os
   itens e não havia como ver o fim da lista nem alcançar as ações do rodapé. */
#notif-list { max-height: min(60vh, 420px); overflow-y: auto; overscroll-behavior: contain; }
.notif-item { padding: .6rem .7rem; border-radius: 8px; font-size: .85rem; }
.notif-item.unread { background: var(--primary-soft); }
.notif-empty { padding: 1.2rem .7rem; text-align: center; color: var(--text-soft); font-size: .85rem; }

.badge-count { position: absolute; top: 3px; right: 3px; background: var(--danger); color: #fff;
  font-size: .6rem; font-weight: 700; min-width: 15px; height: 15px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 3px; }
.badge-count[hidden] { display: none; }

/* Medição — diff de serial (DIGITADO no WFM × CORRETO no app), um embaixo do outro, char a char. */
.sdiff { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.3; display: inline-block; }
.sdiff-row { display: flex; align-items: center; gap: 1px; white-space: nowrap; }
.sdiff-lbl { flex: 0 0 auto; width: 2.6em; color: var(--text-soft); font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.sdiff-c { display: inline-block; min-width: 1.05ch; padding: 0 1px; text-align: center; border-radius: 3px; }
.sdiff-ok  { color: var(--success); }                                             /* certo, na posição */
.sdiff-bad { color: var(--danger); font-weight: 700; background: var(--danger-soft); }   /* errado / a mais */
.sdiff-ref { color: var(--success); font-weight: 700; background: var(--success-soft); } /* o correto (trocado / a menos) */
.sdiff-gap { color: var(--text-soft); opacity: .55; }                             /* lacuna (·) */

/* Técnicos — resumo da carga por técnico (números alinhados, cores sutis por situação) */
.tec-carga { display: flex; flex-direction: column; gap: 2px; font-size: .82rem; align-items: flex-start; }
.tec-carga .tc-row { display: inline-flex; gap: .4rem; align-items: baseline; color: var(--text); text-decoration: none; white-space: nowrap; }
.tec-carga .tc-row b { min-width: 1.7em; text-align: right; font-weight: 700; }
.tec-carga a.tc-row:hover { color: var(--primary-ink); text-decoration: underline; }
.tec-carga .tc-uso { color: var(--primary-ink); }
.tec-carga .tc-aceite { color: var(--warning); }
.tec-carga .tc-extravio { color: var(--danger); }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; flex-wrap: wrap; }
.tab { padding: .55rem 1rem; color: var(--text-muted); font-weight: 550; border-bottom: 2px solid transparent; cursor: pointer; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary-ink); border-bottom-color: var(--primary); }

/* Auth (login) — limpo, sem gradiente de supermercado */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.1rem; animation: fadeIn .3s ease; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: .6rem; text-align: center; font-weight: 700; font-size: 1.4rem; margin-bottom: .3rem; letter-spacing: -.02em; }
.auth-sub { text-align: center; color: var(--text-muted); margin-bottom: 1.6rem; font-size: .9rem; }
.auth-card .form-control {
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: .66rem .75rem;
}
.auth-card .form-control:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.auth-card .btn-block { margin-top: .7rem; }
.auth-theme {
  position: fixed; top: 1rem; right: 1rem; z-index: 20;
  background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-sm);
}
.auth-theme:hover { background: var(--surface-3); color: var(--text); }

/* Cartões de sistema (tela de escolha) */
.sys-card { text-decoration: none; display: block; transition: border-color .15s, box-shadow .18s, transform .12s; }
.sys-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.sys-ic { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px;
  border-radius: 11px; background: var(--surface-3); color: var(--primary); margin-bottom: .85rem; }
.sys-nome { font-weight: 600; font-size: 1.05rem; margin-bottom: .25rem; color: var(--text); letter-spacing: -.01em; }

/* Utilities */
/* flex-wrap: em telas estreitas, grupos de botoes/campos quebram em vez de vazar a pagina.
   So quebra quando NAO cabe — no desktop nada muda. */
.flex { display: flex; flex-wrap: wrap; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.flex-nowrap { flex-wrap: nowrap; }
.gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.mt-1{margin-top:.5rem}.mt-2{margin-top:1rem}.mt-3{margin-top:1.5rem}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:.5rem}.mb-2{margin-bottom:1rem}.mb-3{margin-bottom:1.5rem}
.text-muted{color:var(--text-muted)} .text-soft{color:var(--text-soft)} .text-danger{color:var(--danger)}
.text-center{text-align:center} .text-right{text-align:right}
.fw-bold{font-weight:700} .small{font-size:.8rem}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.empty-state { text-align: center; padding: 2.6rem 1rem; color: var(--text-soft); }
.empty-state .ico { font-size: 2.4rem; opacity: .4; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; }
  /* topbar cabe em telas estreitas: menos padding/gap, título trunca, botão Voltar só ícone */
  .topbar { padding: 0 .55rem; gap: .35rem; }
  .topbar__title { font-size: .95rem; }
  .content { padding: 1rem .8rem; }
  .backbtn { padding: .38rem .5rem; font-size: 0; gap: 0; }
  .backbtn .a { font-size: 1rem; }
  /* Alvos de toque >= 44px no celular (topbar/menu/botoes) */
  .icon-btn { width: 44px; height: 44px; }
  .btn, .backbtn { min-height: 44px; }
  /* Inputs com fonte >= 16px: evita o ZOOM automatico do iOS/Safari ao focar um campo */
  .form-control, .form-select, input, select, textarea { font-size: 16px; }
  /* Select de CNPJ na topbar nao empurra titulo/icones em telas estreitas */
  .topbar select, .topbar .form-select { max-width: 42vw; }
}
