/* ============ Temas (Dark padrão + Light) ============ */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1420;
  --bg-panel: #1a2130;
  --bg-elev: #222b3d;
  --border: #2c3548;
  --field-border: #5b6a86;   /* borda de controle — contraste ≥3:1 (WCAG 1.4.11) */
  --text: #e6ebf5;
  --muted: #9aa7bd;
  --primary: #4c8dff;        /* acento/texto */
  --primary-d: #3a6fd8;      /* fundo de botão: branco 4.7:1 */
  --primary-d2: #2c5abf;     /* hover de botão */
  --ok: #2ecc71;
  --warn: #f1c40f;
  --err: #e74c3c;
  --tag-blue: #8fb4ff; --tag-green: #5fd394; --tag-purple: #b78be0; --tag-cyan: #5dade2;
  --overlay: rgba(0,0,0,.6);
  --shadow: 0 1px 2px rgba(0,0,0,.25);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.5);
  --radius: 10px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fa;
  --bg-panel: #ffffff;
  --bg-elev: #eef1f6;
  --border: #e3e8f0;
  --field-border: #aab4c4;
  --text: #18202f;
  --muted: #586378;
  --primary: #2563d0;
  --primary-d: #2563d0;      /* fundo de botão: branco 5.5:1 */
  --primary-d2: #1d4fb0;
  --ok: #147a3e;
  --warn: #7d5e00;
  --err: #c62828;
  --tag-blue: #2563d0; --tag-green: #147a3e; --tag-purple: #7c4dbf; --tag-cyan: #1f7fb8;
  --overlay: rgba(16,24,40,.45);
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-lg: 0 18px 50px rgba(16,24,40,.18);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  display: grid; grid-template-columns: 240px 1fr; min-height: 100vh;
}
/* Transição suave ao alternar tema (respeitada pelo prefers-reduced-motion abaixo) */
body, .sidebar, .content, .panel, .card, .table-wrap, table, th, td, tbody tr,
.btn, .btn-limpar, input, select, textarea, .modal-box, .status-box, .nav-item,
.nav-grupo, .icon-btn, code, .feed li, .preview, .tag, .badge, .nat-tag, .tipo-tag,
.theme-toggle, .brand small {
  transition: background-color .25s ease, border-color .25s ease, color .2s ease, box-shadow .25s ease;
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
  min-width: 0; overflow-x: hidden;
}

/* Recolher para faixa de ÍCONES (modo rail) */
body { transition: grid-template-columns .22s ease, background-color .25s ease, color .2s ease; }
body.nav-collapsed { grid-template-columns: 68px 1fr; }
body.nav-collapsed .sidebar { padding: 20px 10px; }
/* header do rail: só o botão de expandir, centralizado */
body.nav-collapsed .brand { justify-content: center; margin-bottom: 16px; }
body.nav-collapsed .brand .logo, body.nav-collapsed .brand-txt { display: none; }
/* itens viram só ícone (font-size:0 esconde o texto; .ic mantém o próprio tamanho) */
body.nav-collapsed .nav-item { justify-content: center; gap: 0; padding: 8px 0; font-size: 0; }
body.nav-collapsed .nav-grupo-fixo { display: none; }
body.nav-collapsed .nav-grupo { justify-content: center; font-size: 0; padding: 6px 0; }
body.nav-collapsed .nav-grupo-lbl { gap: 0; }
body.nav-collapsed .chev { display: none; }
body.nav-collapsed .nav-grupo-itens { display: none; }   /* rail: só nível 1 */
body.nav-collapsed .theme-toggle { justify-content: center; gap: 0; padding: 9px 0; font-size: 0; }
body.nav-collapsed .theme-toggle .ti { font-size: 17px; }
body.nav-collapsed .btn-limpar { font-size: 0; padding: 11px 0; }
body.nav-collapsed .btn-limpar .ti { font-size: 17px; }
body.nav-collapsed .status-box { justify-content: center; font-size: 0; }

.nav-collapse-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 30px; height: 30px; background: none; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 16px;
}
.nav-collapse-btn:hover { color: var(--primary); border-color: var(--primary); }
.nav-open-btn {
  position: fixed; top: 14px; left: 14px; z-index: 60; display: none;
  width: 42px; height: 42px; align-items: center; justify-content: center;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  font-size: 20px; box-shadow: var(--shadow);
}
.nav-open-btn:hover { color: var(--primary); border-color: var(--primary); }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; padding: 0 4px; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-d2));
  color: #fff; font-size: 21px;
  box-shadow: 0 3px 10px rgba(37,99,208,.35);
}
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand small { display: block; color: var(--muted); font-size: 11px; line-height: 1.25; margin-top: 1px; }
.brand .brand-txt { flex: 1; min-width: 0; }
/* Botão de alternância de tema (Sol/Lua) — rodapé da sidebar */
.theme-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 40px; margin: 8px 0 0; padding: 9px 14px;
  background: var(--bg-elev); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 500;
}
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }
.theme-toggle .ti { font-size: 17px; }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; min-height: 40px;
  background: none; border: none; color: var(--muted); text-align: left;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 500; letter-spacing: .1px;
  white-space: nowrap; transition: .15s;
}
/* Foco de teclado visível em todos os controles (WCAG 2.4.7) */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.ic { display: inline-flex; width: 20px; justify-content: center; align-items: center; font-size: 16px; flex-shrink: 0; line-height: 1; }
/* Cabeçalhos de seção (OPERAÇÃO / grupos) — mesmo tratamento tipográfico */
.nav-grupo-fixo, .nav-grupo {
  font-family: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .7px; color: var(--muted);
}
.nav-grupo-fixo { padding: 6px 14px 4px; margin: 6px 0 2px; }
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: var(--primary-d); color: #fff; }

/* Grupos colapsáveis (tipografia herda da regra harmonizada acima) */
.nav-grupo-wrap { margin-top: 6px; }
.nav-grupo {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: none; border: none; cursor: pointer; min-height: 34px;
  padding: 6px 14px 4px; border-radius: 6px; transition: .12s;
}
.nav-grupo:hover { background: var(--bg-elev); color: var(--text); }
.nav-grupo-lbl { display: inline-flex; align-items: center; gap: 10px; }
.nav-grupo-lbl .ic { font-size: 14px; width: 20px; color: var(--muted); }
.nav-grupo .chev { font-size: 14px; opacity: .7; transition: transform .18s; }
.nav-grupo-wrap.collapsed .chev { transform: rotate(-90deg); }
.nav-grupo-itens {
  overflow: hidden; max-height: 600px; transition: max-height .22s ease;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-grupo-wrap.collapsed .nav-grupo-itens { max-height: 0; }
/* Subitens: mesma tipografia dos itens fixos, apenas recuados */
.nav-sub { padding-left: 26px; font-weight: 400; }
.btn-limpar {
  margin: 8px 0; padding: 11px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13px; text-align: center; transition: .15s;
  background: rgba(231,76,60,.12); color: var(--err);
  border: 1px solid rgba(231,76,60,.35);
}
.btn-limpar:hover { background: var(--err); color: #fff; border-color: var(--err); }
.btn-limpar:disabled { opacity: .5; cursor: wait; }
.status-box {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--border);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--err); }

/* Content */
.content { padding: 26px 32px; overflow-y: auto; height: 100vh; }
.view { display: none; animation: fade .2s; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.view-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.view-head h1 { font-size: 22px; font-weight: 600; }

/* Botões / inputs */
.btn {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--field-border);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: .15s;
  min-height: 40px;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary-d); border-color: var(--primary-d); color: #fff; }
.btn.primary:hover { background: var(--primary-d2); border-color: var(--primary-d2); }
input, select {
  background: var(--bg); color: var(--text); border: 1px solid var(--field-border);
  padding: 9px 11px; border-radius: 8px; font-size: 13px; min-height: 40px;
}
input:focus, select:focus { border-color: var(--primary); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card .val { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.card.ok .val { color: var(--ok); } .card.warn .val { color: var(--warn); } .card.err .val { color: var(--err); }
.card.money .val { color: var(--primary); }

/* KPI cards (dashboard) */
.card.kpi { display: flex; flex-direction: column; gap: 6px; }
.card.kpi .val { font-size: 24px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-ic { width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 20px; background: var(--bg-elev); color: var(--primary); }
.kpi-delta { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--bg-elev); color: var(--muted); }
.kpi-delta.up { color: var(--ok); background: rgba(34,197,94,.14); }
.kpi-delta.down { color: var(--err); background: rgba(239,68,68,.14); }

/* Gráficos (SVG puro) */
.dash-charts .panel { display: flex; flex-direction: column; }
#dash-pie { flex: 1; display: flex; align-items: center; justify-content: center; }
#dash-line { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pie-wrap { display: flex; align-items: center; justify-content: center; gap: 34px; flex-wrap: wrap; width: 100%; }
.pie { width: 352px; height: 352px; flex: 0 0 auto; }
.pie text { text-anchor: middle; fill: var(--text); }
.pie-c1 { font-size: 5px; font-weight: 700; }
.pie-c2 { font-size: 2.4px; fill: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.legenda { display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.leg { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.leg strong { margin-left: auto; }
.leg .muted { min-width: 46px; text-align: right; }
.leg-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex: 0 0 auto; }
.linechart { width: 100%; height: auto; }
.linechart .ch-grid { stroke: var(--border); stroke-width: 1; }
.linechart .ch-yl { fill: var(--muted); font-size: 10px; text-anchor: end; }
.linechart .ch-xl { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.legenda-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin-top: 8px; justify-content: center; }
@media (max-width: 720px) { .pie-wrap { justify-content: center; } }

/* Cabeçalho azul dos grids do dashboard (fornecedores/clientes) */
#dash-forn thead th, #dash-cli thead th { background: var(--primary); color: #fff; }

/* Acompanhamento da importação */
#imp-mon-badge.EM_ANDAMENTO { background: rgba(79,124,255,.16); color: var(--primary); }
#imp-mon-badge.CONCLUIDA { background: rgba(34,197,94,.16); color: var(--ok); }
#imp-mon-badge.PENDENTE { background: rgba(245,158,11,.18); color: var(--warn); }
.imp-classif { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 16px; }
.imp-classif h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 0 0 8px; }
.imp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.imp-chip { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 13px; color: var(--text); }
.imp-chip b { color: var(--primary); }
.imp-chip.ent b { color: var(--ok); }
.imp-chip.sai b { color: var(--primary); }

/* Abas da tela Empresa */
.emp-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.emp-tab { background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; padding: 10px 16px; cursor: pointer; border-radius: 6px 6px 0 0; }
.emp-tab:hover { background: var(--bg-elev); color: var(--text); }
.emp-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Panels / grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel h2 { font-size: 15px; margin-bottom: 14px; font-weight: 600; }

/* Feed */
.feed { list-style: none; max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.feed li { padding: 9px 12px; border-radius: 7px; background: var(--bg-elev); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.feed li.muted { background: none; color: var(--muted); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.tag.IMPORTADO { background: rgba(46,204,113,.18); color: var(--ok); }
.tag.DUPLICADO { background: rgba(241,196,15,.18); color: var(--warn); }
.tag.ERRO { background: rgba(231,76,60,.18); color: var(--err); }

/* Totalização (tela de consulta) */
.totais { display: flex; gap: 26px; }
.tot-item { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.tot-val { font-size: 22px; font-weight: 700; line-height: 1.1; }
.tot-val.money { color: var(--primary); }
.tot-lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }

/* Filtros */
.filtros { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }

/* Tabelas */
.table-wrap { overflow-x: auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
tbody tr { cursor: pointer; transition: .1s; }
tbody tr:hover { background: var(--bg-elev); }
.nat-tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.nat-tag.emitida { background: rgba(155,89,182,.18); color: var(--tag-purple); }
.nat-tag.recebida { background: rgba(52,152,219,.16); color: var(--tag-cyan); }
.nat-tag.desconhecida { color: var(--muted); }
.tipo-tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }
.tipo-tag.entrada { background: rgba(76,141,255,.16); color: var(--tag-blue); }
.tipo-tag.saida { background: rgba(46,204,113,.16); color: var(--tag-green); }
.acoes { white-space: nowrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px;
  background: var(--bg-elev); border: 1px solid var(--field-border); border-radius: 7px;
  cursor: pointer; font-size: 15px; padding: 5px 8px; margin-right: 4px; line-height: 1;
  transition: .12s;
}
.icon-btn.ver:hover { border-color: var(--primary); background: rgba(76,141,255,.15); }
.icon-btn.del:hover { border-color: var(--err); background: rgba(231,76,60,.18); }
.badge { padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.AUTORIZADA { background: rgba(46,204,113,.18); color: var(--ok); }
.badge.CANCELADA { background: rgba(231,76,60,.18); color: var(--err); }
.lvl-INFO { color: var(--ok); } .lvl-WARN { color: var(--warn); } .lvl-ERROR { color: var(--err); }
.muted { color: var(--muted); }
code { background: var(--bg-elev); padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* Config */
.config-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 12px 16px; margin: 16px 0; align-items: center; }
.config-grid label { color: var(--muted); font-size: 13px; }

/* Form em grade (empresa) */
.form-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 10px 14px; margin: 16px 0; align-items: center; }
.form-grid label { color: var(--muted); font-size: 12px; text-align: right; }
.form-grid input, .form-grid select { width: 100%; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr; } .form-grid label { text-align: left; } }

/* Prévia SPED */
.preview { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-family: 'Consolas', monospace; font-size: 11px; line-height: 1.5; color: var(--text);
  overflow-x: auto; max-height: 340px; white-space: pre; }
.feed .tag.ERRO { background: rgba(231,76,60,.18); color: var(--err); }

/* Login */
.login-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(1100px 520px at 50% -8%, rgba(79,124,255,.16), transparent 62%),
    radial-gradient(900px 500px at 100% 110%, rgba(79,124,255,.10), transparent 60%),
    var(--bg);
}
body.nao-autenticado .login-overlay { display: flex; }
.login-card {
  width: 100%; max-width: 400px; background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: 18px; padding: 34px 32px 30px;
  box-shadow: var(--shadow-lg);
}
.login-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; margin-bottom: 24px; }
.login-ic {
  width: 66px; height: 66px; border-radius: 20px; margin-bottom: 10px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 32px; color: #fff;
  background: linear-gradient(135deg, var(--primary), #3a5bd0);
  box-shadow: 0 10px 22px rgba(79,124,255,.38);
}
.login-hero strong { font-size: 21px; letter-spacing: .3px; }
.login-hero small { color: var(--muted); font-size: 12px; }
.login-title { text-align: center; font-size: 15px; font-weight: 600; color: var(--text); margin: 0 0 10px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.login-card input { width: 100%; }
.login-field { position: relative; }
.login-field > i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; pointer-events: none; }
.login-field input { padding-left: 40px; }
.login-msg { font-size: 13px; margin: 10px 0 0; min-height: 18px; text-align: center; }
.login-msg.erro { color: var(--err); }
.login-msg.ok { color: var(--ok); }
.login-link { display: block; width: 100%; text-align: center; background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; margin-top: 14px; padding: 0; }
.login-link:hover { text-decoration: underline; }

/* Rodapé de usuário */
.user-box {
  display: flex; align-items: center; gap: 8px; padding: 10px 6px 6px;
  border-top: 1px solid var(--border); margin-top: 6px;
}
.user-ic { font-size: 26px; color: var(--muted); flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-info strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info small { color: var(--muted); font-size: 11px; }
.user-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0; background: none; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 16px;
}
.user-btn:hover { color: var(--primary); border-color: var(--primary); }
body.nav-collapsed .user-box { flex-direction: column; padding: 8px 0; }
body.nav-collapsed .user-info { display: none; }

/* Matriz de permissões */
.matriz { width: 100%; border-collapse: collapse; font-size: 13px; }
.matriz th, .matriz td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.matriz th:first-child, .matriz td:first-child { text-align: left; white-space: nowrap; }
.matriz thead th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.matriz input[type=checkbox] { width: 16px; height: 16px; min-height: 0; cursor: pointer; accent-color: var(--primary); }

/* Modal */
.modal { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 50; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-box { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px; padding: 26px; max-width: 820px; width: 92%; max-height: 86vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-lg); }
.modal-close {
  position: absolute; top: 10px; right: 10px; background: none; border: none;
  color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 8px; transition: .12s;
}
.modal-close:hover { background: var(--bg-elev); color: var(--text); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; margin: 14px 0; }
.kv span:nth-child(odd) { color: var(--muted); font-size: 13px; }

/* ============ Responsividade / UX (dispositivos e resoluções) ============ */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, svg { max-width: 100%; }
#nav-backdrop { display: none; }
.view-head > div { flex-wrap: wrap; }          /* grupos de filtros/ações quebram linha */
.totais { flex-wrap: wrap; }
#cad-paginacao { flex-wrap: wrap; }
.table-wrap { -webkit-overflow-scrolling: touch; }
.pie { max-width: 100%; height: auto; aspect-ratio: 1 / 1; }  /* pizza nunca ultrapassa o painel */

@media (max-width: 1200px) {
  body { grid-template-columns: 210px 1fr; }
  .content { padding: 22px 22px; }
}

/* Tablet / celular: a sidebar vira DRAWER sobreposto (não empurra o conteúdo) */
@media (max-width: 900px) {
  body, body.nav-collapsed { grid-template-columns: 1fr; }
  .content { height: 100vh; padding: 18px 16px 40px; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 95;
    width: 274px; max-width: 86vw; padding: 18px 14px;
    border-right: 1px solid var(--border); border-bottom: none;
    transform: translateX(-100%); transition: transform .24s ease;
    box-shadow: var(--shadow-lg); overflow-y: auto;
  }
  body:not(.nav-collapsed) .sidebar { transform: translateX(0); }   /* drawer aberto */
  body.nav-collapsed .sidebar { display: flex; }                     /* fica no DOM, fora da tela */

  body:not(.nav-collapsed) #nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 90; background: var(--overlay);
  }
  .nav-open-btn { display: none; }
  body.nav-collapsed .nav-open-btn { display: inline-flex; }
  body.nav-collapsed .view-head { padding-left: 46px; }   /* título não fica sob o hamburguer */

  .grid-2, .dash-charts { grid-template-columns: 1fr; }
  .view-head { flex-wrap: wrap; gap: 12px; }
  .view-head h1 { font-size: 19px; }
  .totais { gap: 14px 22px; }
  .config-grid { grid-template-columns: 1fr; gap: 6px 0; }
}

/* Celular pequeno (≤600px — cobre 320/375/390/414) */
@media (max-width: 600px) {
  .content { padding: 16px 12px 36px; }
  .cards { gap: 10px; }
  .card { padding: 14px 16px; }
  .card .val { font-size: 22px; }
  .panel { padding: 16px 14px; }
  th, td { padding: 9px 10px; }
  .modal-box { padding: 20px 16px; border-radius: 12px; }
  .modal-box input, .modal-box select { max-width: 100%; }
  .view-head h1 { font-size: 18px; }
  .pie-wrap { gap: 16px; }
  .legenda { min-width: 0; width: 100%; }
  .filtros .field { flex: 1 1 140px; }
  .filtros .field input, .filtros .field select { width: 100%; }
}

/* Impressão: remove navegação/cromo e imprime o conteúdo ativo limpo */
@media print {
  .sidebar, .nav-open-btn, #nav-backdrop, .theme-toggle, .btn-limpar, .status-box,
  .nav-collapse-btn, .view-head > div, .icon-btn { display: none !important; }
  body { display: block; overflow: visible; }
  .content { height: auto; overflow: visible; padding: 0; }
  .panel, .card, .table-wrap { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  th, td { white-space: normal; }
}

/* Respeita "reduzir movimento" do sistema (acessibilidade vestibular) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}
