/* ============ Painel BI Estoque — tema ============ */
/* Inter (arquivos locais em lib/fonts — funciona sem internet; licença SIL OFL) */
@font-face {
  font-family: 'Inter'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../lib/fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('../lib/fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  color-scheme: light;
  --page: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --sidebar: #0f1b2d;
  --sidebar-2: #16263d;
  --sidebar-ink: #c9d4e5;
  --sidebar-ink-dim: #7d8ca3;
  --ink: #18212f;
  --ink-2: #5d6879;
  --ink-3: #8a94a4;
  --line: #e4e8ef;
  --line-2: #d3d9e3;
  --grid: #eceff4;
  --axis: #c2c8d2;
  --accent: #257de0;
  --accent-soft: rgba(37, 125, 224, .10);
  --s1: #257de0;
  --s2: #f47230;
  --s3: #00b894;
  --good: #0aac23;
  --good-ink: #00701a;
  --warning: #fbb315;
  --warning-ink: #8a5a00;
  --serious: #f18a59;
  --serious-ink: #a8481a;
  --critical: #dc3c3d;
  --critical-ink: #b3262a;
  --ramp-1: #b6d5f8;
  --ramp-2: #84b9f3;
  --ramp-3: #519ced;
  --ramp-4: #257de0;
  --ramp-5: #1b64be;
  --ramp-6: #0f4a96;
  --ramp-7: #0e3d7e;
  --shadow: none;
  --radius: 6px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0f17;
  --surface: #151a24;
  --surface-2: #1b2130;
  --sidebar: #0a0e15;
  --sidebar-2: #131a26;
  --ink: #e9edf3;
  --ink-2: #a2acbb;
  --ink-3: #737e8f;
  --line: #252c3a;
  --line-2: #323b4c;
  --grid: #232a37;
  --axis: #474f5e;
  --accent: #338ced;
  --accent-soft: rgba(51, 140, 237, .14);
  --s1: #338ced;
  --s2: #e76624;
  --s3: #00a888;
  --good-ink: #53c556;
  --warning-ink: #fbb315;
  --serious-ink: #f18a59;
  --critical-ink: #f06a6b;
  --ramp-1: #0e3d7e;
  --ramp-2: #1757ac;
  --ramp-3: #2370cd;
  --ramp-4: #338ced;
  --ramp-5: #6aabf1;
  --ramp-6: #9dc8f7;
  --ramp-7: #cce3fd;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }

/* ============ layout ============ */
.app { display: flex; flex-direction: column; height: 100vh; }
.appbar {
  display: flex; align-items: center; gap: 22px;
  height: 56px; padding: 0 20px; flex: none;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; margin-right: 20px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #338ced, #1757ac);
  display: grid; place-items: center; color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-title { font-weight: 900; color: #fff; font-size: 20px; line-height: 1; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--sidebar-ink-dim); white-space: nowrap; }
.nav {
  display: flex; align-items: stretch; gap: 2px;
  height: 100%; min-width: 0; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-sep { width: 1px; background: rgba(255, 255, 255, .12); margin: 16px 8px; flex: none; }
.nav button {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  flex: 1 1 auto; /* itens se distribuem pela largura da barra */
  padding: 0 11px; height: 100%;
  border: 0; background: transparent;
  color: var(--sidebar-ink); cursor: pointer; white-space: nowrap;
  font-size: 14px;
}
.nav button svg { width: 15px; height: 15px; opacity: .7; flex: none; }
.nav button:hover { color: #fff; background: var(--sidebar-2); }
.nav button.active { color: #fff; font-weight: 600; }
.nav button.active svg { opacity: 1; color: #6aabf1; }
.nav button.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0;
  height: 3px; border-radius: 3px 3px 0 0; background: #338ced;
}
@media (max-width: 1680px) { .brand-sub { display: none; } }
@media (max-width: 1480px) { .nav button svg { display: none; } .nav button { padding: 0 9px; } }
@media (max-width: 1200px) { .nav button { padding: 0 6px; font-size: 12.5px; } .nav-sep { margin: 16px 4px; } .brand { margin-right: 6px; } .appbar { gap: 14px; padding: 0 14px; } }

.status { font-size: 11.5px; color: var(--ink-2); line-height: 1.45; text-align: right; }
.status b { color: var(--ink); font-weight: 600; }
@media (max-width: 1100px) { .status { display: none; } }

.main { display: flex; flex-direction: column; min-width: 0; flex: 1; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; font-weight: 650; margin: 0; }
.topbar .sub { color: var(--ink-2); font-size: 12px; }
.topbar .spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
  cursor: pointer; font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.icon-btn { width: 32px; padding: 0; justify-content: center; }
select.select {
  height: 32px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); padding: 0 28px 0 10px; cursor: pointer;
}

/* ============ filtros ============ */
.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.fb-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.fb-row #clearAll { flex: none; }
.ms { position: relative; flex: 1 1 auto; min-width: 0; }
.ms:nth-last-child(-n+4) .ms-panel { left: auto; right: 0; }
.ms-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--surface); cursor: pointer; font-size: 12.5px;
  width: 100%; min-width: 0; justify-content: space-between;
}
.ms-btn .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 100%; }
.ms-btn .val { flex: 0 1 auto; min-width: 0; max-width: 140px; text-align: left; }
.ms-btn.on .val + svg { margin-left: auto; }
.ms-btn:not(.on) .lbl { flex: 1 1 auto; text-align: left; }
.ms-btn .ls { display: none; }
@media (max-width: 1700px) { .ms-btn .lf { display: none; } .ms-btn .ls { display: inline; } }
@media (max-width: 1500px) { .ms-btn { padding: 0 7px; gap: 4px; font-size: 12px; } .ms-btn .val { max-width: 90px; } .fb-row { gap: 5px; } .filterbar { padding: 10px 16px; } }
@media (max-width: 1280px) { .fb-row { flex-wrap: wrap; } .ms { flex: 1 1 120px; } }
.ms-btn .lbl { color: var(--ink-2); }
.ms-btn .val { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-btn svg { width: 13px; height: 13px; color: var(--ink-3); flex: none; }
.ms-btn.on { border-color: var(--accent); background: var(--accent-soft); }
.ms-btn.on .val { color: var(--accent); }
.ms-panel {
  position: absolute; top: 36px; left: 0; z-index: 50;
  width: 300px; max-height: 420px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.ms-panel input[type=search] {
  margin: 10px; height: 30px; padding: 0 10px;
  border: 1px solid var(--line-2); border-radius: 7px; background: var(--surface-2);
}
.ms-actions { display: flex; gap: 6px; padding: 0 10px 8px; }
.ms-list { overflow-y: auto; padding: 0 4px 8px; }
.ms-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.ms-opt:hover { background: var(--surface-2); }
.ms-opt .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-opt .c { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12px; }
.ms-opt.zero .t { color: var(--ink-3); }
.ms-opt input { accent-color: var(--accent); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 4px 0 9px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 500;
}
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; }
.chip button:hover { background: rgba(0, 0, 0, .08); }

/* ============ conteúdo ============ */
.content { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
@media (max-width: 1280px) { .span-4, .span-5, .span-7, .span-8 { grid-column: span 12; } .span-3 { grid-column: span 6; } .span-6 { grid-column: span 12; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}
.card-h { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-h h3 { margin: 0; font-size: 13.5px; font-weight: 650; }
.card-h .hint { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.card-h .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.chart { width: 100%; height: 300px; overflow: hidden; }
.chart.tall { height: 420px; }
.chart.xtall { height: 560px; }
.chart.short { height: 220px; }

/* KPI */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); grid-column: span 12; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .k { color: var(--ink-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 24px; font-weight: 650; margin-top: 6px; letter-spacing: -.01em; }
.kpi .d { color: var(--ink-3); font-size: 11.5px; margin-top: 4px; }
.kpi .d b { color: var(--ink-2); font-weight: 600; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ruptura { color: var(--serious-ink); background: color-mix(in srgb, var(--serious) 16%, transparent); }
.st-ideal { color: var(--good-ink); background: color-mix(in srgb, var(--good) 14%, transparent); }
.st-atencao { color: var(--warning-ink); background: color-mix(in srgb, var(--warning) 18%, transparent); }
.st-excesso { color: var(--critical-ink); background: color-mix(in srgb, var(--critical) 14%, transparent); }
.st-semvenda { color: var(--ink-2); background: var(--surface-2); }

/* insights */
.insights { list-style: none; margin: 0; padding: 0; }
.insights li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.insights li:last-child { border-bottom: 0; }
.insights .ico, .stale-banner .ico { flex: none; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.insights .ico.i-info { background: var(--accent-soft); color: var(--accent); }
.insights .ico.i-warn, .stale-banner .ico.i-warn { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning-ink); }
.insights .ico.i-bad { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical-ink); }
.insights .ico.i-good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good-ink); }
.insights b { font-weight: 650; }

/* tabelas */
.tbl-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--line); border-radius: 8px; }
table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
.tbl th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 600; text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line-2); white-space: nowrap; cursor: pointer; user-select: none;
}
.tbl th.n, .tbl td.n { text-align: right; }
.tbl th .arr { color: var(--accent); }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 650; border-top: 1px solid var(--line-2); }
.tbl td.first, .tbl th.first { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.tbl th.first { z-index: 3; background: var(--surface-2); }
.tbl tfoot td.first { background: var(--surface-2); z-index: 3; }
.tbl tr.click { cursor: pointer; }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-cell .b { height: 6px; border-radius: 3px; background: var(--s1); opacity: .85; }
.muted { color: var(--ink-3); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding-top: 10px; color: var(--ink-2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar label { color: var(--ink-2); font-size: 12px; }
.toolbar input[type=search], .top-slot input[type=search], .toolbar input[type=number], .toolbar input[type=date] {
  height: 32px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface);
}
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 12px; height: 30px; cursor: pointer; color: var(--ink-2); font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* empty / upload */
.empty {
  max-width: 640px; margin: 60px auto; text-align: center;
}
.empty h2 { font-size: 20px; margin: 0 0 8px; }
.empty p { color: var(--ink-2); line-height: 1.6; }
.drop {
  border: 2px dashed var(--line-2); border-radius: 14px;
  padding: 34px 20px; margin: 20px 0; cursor: pointer;
  background: var(--surface); transition: .15s;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 36px; height: 36px; color: var(--accent); }
.drop .t { font-weight: 600; margin-top: 8px; }
.drop .s { color: var(--ink-2); font-size: 12px; margin-top: 4px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 12, 20, .5); z-index: 100; display: grid; place-items: center; }
.modal { width: min(560px, 94vw); background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); padding: 22px; }
.modal { position: relative; }
.modal h3 { margin: 0 0 6px; font-size: 16px; padding-right: 36px; }
.modal-x { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.modal-x:hover { background: var(--line); color: var(--ink); }
.modal p { color: var(--ink-2); margin: 0 0 14px; line-height: 1.55; }
.modal .row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.modal .row label { width: 170px; color: var(--ink-2); }
.modal .row input, .modal .row select { flex: 1; height: 32px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; background: var(--surface); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 12.5px; background: var(--surface-2); border-radius: 8px; padding: 12px; }
.kv span:nth-child(odd) { color: var(--ink-2); }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-size: 13px; max-width: 420px;
}
.legend-inline { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }
.legend-inline i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.note { font-size: 12px; color: var(--ink-2); line-height: 1.55; }
.note code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.params { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 20px; }
.params label { display: flex; flex-direction: column; gap: 5px; color: var(--ink-2); font-size: 12px; }
.params input, .params select { height: 32px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; background: var(--surface); color: var(--ink); }
.hidden { display: none !important; }

/* ============ faixas de dias em estoque (padrão do sistema) ============ */
:root { --age-0: #111111; --age-1: #7a7a7a; --age-2: #0a7d1e; --age-3: #1f3fd6; --age-4: #f59a9a; --age-5: #e0191c; --age-6: #7d0b10; }
:root[data-theme="dark"] { --age-0: #e9edf3; --age-1: #9aa3b0; --age-2: #4fc464; --age-3: #7f9bff; --age-4: #ffb8b8; --age-5: #ff5c5c; --age-6: #b51d1d; }
.tbl tr.age-0 td { color: var(--age-0); }
.tbl tr.age-1 td { color: var(--age-1); }
.tbl tr.age-2 td { color: var(--age-2); }
.tbl tr.age-3 td { color: var(--age-3); }
.tbl tr.age-4 td { color: var(--age-5); } /* lista: > 90 dias em vermelho */
.tbl tr[class*="age-"] td:first-child { box-shadow: inset 4px 0 0 var(--row-age, transparent); }
.tbl tr.age-0 { --row-age: var(--age-0); } .tbl tr.age-1 { --row-age: var(--age-1); } .tbl tr.age-2 { --row-age: var(--age-2); }
.tbl tr.age-3 { --row-age: var(--age-3); } .tbl tr.age-4 { --row-age: var(--age-5); }
.tbl tr[class*="age-"] .badge { color: inherit; background: color-mix(in srgb, currentColor 12%, transparent); }
.age-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 26px; padding: 14px 0 2px; font-size: 14px; }
.age-legend span { display: inline-flex; align-items: center; gap: 6px; }
.age-legend i { width: 14px; height: 14px; display: inline-block; background: currentColor; }
.age-legend b { font-weight: 600; font-size: 12.5px; opacity: .85; }
.age-legend .age-0 { color: var(--age-0); } .age-legend .age-1 { color: var(--age-1); } .age-legend .age-2 { color: var(--age-2); }
.age-legend .age-3 { color: var(--age-3); } .age-legend .age-4 { color: var(--age-5); }
.age-legend.sm { font-size: 12px; gap: 6px 14px; padding-top: 8px; }
.age-legend.sm i { width: 11px; height: 11px; }

/* lista solta na página (uma rolagem só): cabeçalho fixo no topo da página */
.tbl-wrap.flat { max-height: none; overflow: visible; background: var(--surface); }
.tbl-wrap.flat .tbl th { top: -20px; box-shadow: 0 1px 0 var(--line-2); }
.tbl td.wrap { white-space: normal; min-width: 150px; }
.tbl-wrap.flat .tbl { font-size: 12px; }
.tbl-wrap.flat .tbl th, .tbl-wrap.flat .tbl td { padding-left: 8px; padding-right: 8px; }
.tbl-wrap.flat .tbl tfoot td { bottom: -40px; }

/* aviso de carga antiga */
.stale-banner { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); color: var(--ink); font-size: 13px; line-height: 1.5; }
.stale-banner > div { flex: 1; }
.stale-banner .ico { flex: none; }

/* rodapé fixo das listas de veículos: legenda + contagem, barra fina */
.pager.sticky-foot {
  position: sticky; bottom: -40px; z-index: 3;
  justify-content: flex-start; gap: 10px;
  margin-top: 0; padding: 4px 12px;
  background: var(--surface); border: 1px solid var(--line); border-top-color: var(--line-2);
  border-radius: 0 0 8px 8px; box-shadow: 0 -2px 6px rgba(0, 0, 0, .04);
  font-size: 11px; line-height: 1.3; color: var(--ink-2);
}
.pager.sticky-foot .age-legend { flex: 1; justify-content: flex-start; gap: 2px 14px; padding: 0; font-size: 11px; }
.pager.sticky-foot .age-legend i { width: 9px; height: 9px; }
.pager.sticky-foot .age-legend b { font-size: 10.5px; }
.pager.sticky-foot .cnt { white-space: nowrap; }
.pager.sticky-foot .btn { height: 22px; padding: 0 8px; font-size: 11px; }

/* espaço no topo da página para controles da página (ex.: busca de Veículos) */
.top-slot { display: flex; align-items: center; gap: 10px; margin-left: 24px; min-width: 0; }
.top-slot:empty { display: none; }
.top-slot input[type=search] { width: 380px; max-width: 32vw; }
.top-slot .note { white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions:empty { display: none; }
/* tabelas soltas na página: cantos retos */
.tbl-wrap.flat { border-radius: 0; }
.pager.sticky-foot { border-radius: 0; }
/* lupa no campo de busca do topo */
.top-slot input[type=search] {
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23737e8f' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 11px center; background-size: 15px 15px;
}
[data-theme="dark"] .top-slot input[type=search] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a4' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}

/* ---------- modo online: login e usuário ---------- */
.auth-pending .app { visibility: hidden; }
.login {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px;
  background: var(--sidebar);
}
.login-card {
  width: min(340px, 100%); background: transparent; color: #e8edf5;
  padding: 0; display: flex; flex-direction: column; gap: 14px;
}
.login-box { width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; gap: 28px; }
.login-logo { width: min(256px, 69%); height: auto; display: block; }
.login-sub { font-size: 14px; font-weight: 600; color: var(--ink); }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: #b7c2d3; }
.login-card input {
  height: 40px; border: 1px solid rgba(255, 255, 255, .16); border-radius: 8px; padding: 0 12px;
  background: rgba(255, 255, 255, .06); color: #fff; font: inherit; font-size: 14px; font-weight: 400;
}
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 42px; }
.pw-eye { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: #8794a8; cursor: pointer; }
.pw-eye:hover, .pw-eye[aria-pressed="true"] { color: #e8edf5; }
.modal .pw-wrap { flex: 1; }
.users-tbl { max-height: none; background: var(--surface); }
.users-tbl .tbl td { padding-top: 11px; padding-bottom: 11px; }
.users-tbl .tbl th { padding-top: 10px; padding-bottom: 10px; }
.u-name { display: inline-flex; align-items: center; gap: 10px; }
.u-name .av { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.modal .pw-eye { color: var(--ink-3); }
.modal .pw-eye:hover, .modal .pw-eye[aria-pressed="true"] { color: var(--ink); background: var(--line); }
.login-card input:focus { outline: 2px solid rgba(43, 127, 230, .35); border-color: #2b7fe6; }
.login-card input:-webkit-autofill { -webkit-text-fill-color: #fff; box-shadow: 0 0 0 40px #1a2638 inset; caret-color: #fff; }
.login .login-err { color: #ff9b9b; }
.login .login-note { color: #8794a8; }
.login-card .btn.primary { height: 40px; margin-top: 4px; justify-content: center; font-size: 14px; }
.login-err { min-height: 0; color: var(--critical-ink); font-size: 12.5px; }
.login-err:empty { display: none; }
.modal .login-err { margin: 6px 0 0; }
.login-note { margin: 0; font-size: 12px; color: var(--ink-3); text-align: center; line-height: 1.5; }

.user-box { position: relative; }
.user-box:empty { display: none; }
.user-btn {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px 0 4px;
  border: 1px solid var(--line-2); border-radius: 16px; background: var(--surface); color: var(--ink);
  cursor: pointer; font: inherit; font-size: 13px;
}
.user-btn:hover { background: var(--surface-2); }
.user-btn .av {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700;
}
.user-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 230px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18); padding: 6px;
}
.um-h { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 12px; color: var(--ink-2); }
.um-h b { color: var(--ink); font-size: 13px; }
.user-menu > button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--ink); cursor: pointer; font: inherit; font-size: 13px;
}
.user-menu > button:hover { background: var(--surface-2); }

/* ---------- abertura sem piscar ---------- */
html.booting .app { visibility: hidden; }
.splash { display: none; }
html.booting-online, html.booting-online body { background: var(--sidebar); }
html.booting-online .splash {
  position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; background: var(--sidebar);
}
.splash-brand { font-weight: 900; font-size: 26px; color: #fff; letter-spacing: .5px; }
.splash-sub { font-size: 13px; color: var(--sidebar-ink-dim); }

/* ======================================================================
   Celular (até 760px): menu em gaveta, topo em duas linhas, filtros recolhíveis
   ====================================================================== */
.menu-btn, .fb-toggle { display: none; }
@media (max-width: 760px) {
  /* barra superior + gaveta do menu */
  .appbar { height: calc(52px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); gap: 10px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); position: relative; }
  .brand { margin-right: 0; }
  .brand-title { font-size: 18px; }
  .menu-btn {
    display: flex; align-items: center; gap: 8px; margin-left: auto; height: 36px; padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, .16); border-radius: 8px; background: transparent;
    color: #fff; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; min-width: 0;
  }
  .menu-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
  .menu-btn svg { width: 20px; height: 20px; flex: none; }
  .nav { display: none; }
  body.nav-open .nav {
    display: flex; flex-direction: column; position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 0; right: 0; bottom: 0; z-index: 150;
    height: auto; gap: 0; padding: 8px 0 24px; overflow-y: auto; background: var(--sidebar);
  }
  body.nav-open .nav button { flex: none; justify-content: flex-start; height: 48px; padding: 0 22px; font-size: 15px; gap: 12px; }
  body.nav-open .nav button svg { display: inline; width: 18px; height: 18px; }
  body.nav-open .nav button.active { background: var(--sidebar-2); }
  body.nav-open .nav button.active::after { left: 0; right: auto; top: 10px; bottom: 10px; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  body.nav-open .nav-sep { width: auto; height: 1px; margin: 8px 22px; }

  /* topo: título numa linha, controles na outra, busca embaixo */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar > div:first-child { flex: 1 1 100%; min-width: 0; }
  .topbar h1 { font-size: 16px; }
  .topbar .sub { font-size: 11.5px; }
  .topbar .spacer { display: none; }
  #snapSel { flex: 1 1 auto; min-width: 0; height: 36px; }
  .top-slot { order: 10; flex: 1 1 100%; margin-left: 0; }
  .top-slot input[type=search] { width: 100%; max-width: none; height: 38px; font-size: 16px; }
  .top-actions .btn:has(svg) { font-size: 0; gap: 0; width: 36px; height: 36px; padding: 0; justify-content: center; }
  .top-actions .btn:has(svg) svg { width: 17px; height: 17px; }
  #btnTheme { width: 36px; height: 36px; }
  .user-btn { height: 36px; padding: 0 4px; border-radius: 18px; }
  .user-btn .nm { display: none; }
  .user-btn .av { width: 28px; height: 28px; font-size: 11px; }

  /* filtros: botão que abre/fecha a grade */
  .filterbar { padding: 8px 12px; gap: 0; }
  .fb-toggle {
    display: flex; align-items: center; gap: 8px; width: 100%; height: 38px; padding: 0 12px;
    border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); color: var(--ink);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .fb-toggle > svg { width: 16px; height: 16px; color: var(--ink-2); }
  .fb-toggle b { background: var(--accent); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
  .fb-toggle .fb-chev { margin-left: auto; display: flex; transition: transform .15s; }
  .fb-toggle .fb-chev svg { width: 16px; height: 16px; color: var(--ink-3); }
  .filterbar.fb-open .fb-toggle .fb-chev { transform: rotate(180deg); }
  .filterbar:not(.fb-open) .fb-row { display: none; }
  .filterbar.fb-open .fb-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
  .fb-row #clearAll { grid-column: span 2; height: 34px; }
  .ms-btn { height: 38px; font-size: 13px; padding: 0 10px; }
  .ms-btn .val { max-width: none; }
  /* lista de opções do filtro: painel na parte de baixo da tela */
  .ms-panel, .ms:nth-last-child(-n+4) .ms-panel {
    position: fixed; left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 72vh; z-index: 160;
  }
  .ms-opt { padding: 10px 8px; }
  .ms-panel input[type=search] { height: 38px; font-size: 16px; }

  /* conteúdo */
  .content { padding: 12px 12px 40px; }
  .grid { gap: 12px; }
  .span-3 { grid-column: span 12; }
  .card { padding: 12px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .v { font-size: 20px; }
  .kpi .d { font-size: 11px; }
  .chart.tall { height: 340px; }
  .chart.xtall { height: 440px; }
  .age-legend { gap: 6px 14px; font-size: 12px; }

  /* tabelas: rolagem lateral dentro da própria tabela */
  .tbl-wrap.flat { overflow: auto; max-height: 68vh; }
  .tbl-wrap.flat .tbl th { top: 0; }
  .tbl-wrap.flat .tbl tfoot td { bottom: 0; }
  .pager.sticky-foot { bottom: -40px; flex-wrap: wrap; gap: 4px 10px; }
  .pager.sticky-foot .age-legend { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: 12px; }
  .pager.sticky-foot .age-legend span { white-space: nowrap; }

  /* janelas */
  .modal-bg { padding: 10px; }
  .modal { width: 100%; max-height: 92dvh; overflow-y: auto; padding: 16px; border-radius: 12px; }
  .modal .row { flex-direction: column; align-items: stretch; gap: 4px; }
  .modal .row label { width: auto; }
  .modal .row input, .modal .row select { height: 38px; font-size: 16px; }
  .modal .foot { flex-wrap: wrap; }
  .toast { left: 12px; right: 12px; max-width: none; }
}

/* celular: avatar e tema na barra escura, menu sem borda e sem o nome da página */
.appbar-actions { display: none; }
@media (max-width: 760px) {
  .appbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
  .menu-btn { margin-left: 0; border: 0; padding: 0 4px; height: 40px; }
  .menu-btn span { display: none; }
  .menu-btn svg { width: 24px; height: 24px; }
  .appbar #btnTheme { width: 36px; height: 36px; background: transparent; border-color: transparent; color: #fff; }
  .appbar #btnTheme:hover { background: var(--sidebar-2); }
  .appbar .user-btn { background: transparent; border: 0; padding: 0 2px; }
  .appbar .user-btn:hover { background: var(--sidebar-2); }
}
@media (max-width: 760px) {
  .appbar #btnInstall { width: 36px; height: 36px; background: transparent; border-color: transparent; color: #fff; }
  .appbar #btnInstall:hover { background: var(--sidebar-2); }
}
@media (max-width: 760px) { #btnTheme { display: none; } } /* celular: sem o botão de tema */

.btn.danger { background: var(--critical-ink); border-color: var(--critical-ink); color: #fff; }
.btn.danger:disabled { opacity: .45; cursor: not-allowed; }
.w-ack { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; color: var(--ink-2); line-height: 1.45; cursor: pointer; }
.w-ack input { margin-top: 3px; }

/* skeleton de carregamento */
.sk { display: block; max-width: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 45%, var(--line) 65%); background-size: 300% 100%; animation: sk-shine 1.3s ease-in-out infinite; }
.u-name .sk, .sk-fb .sk { display: inline-block; }
.sk-fb { display: flex; flex-wrap: wrap; gap: 8px; }
.sk-page .card .sk + .sk { margin-top: 0; }
@keyframes sk-shine { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* filtro ativo: botão Limpar em vermelho */
#clearAll { color: var(--critical-ink); font-weight: 600; }
#clearAll:hover { background: var(--critical-soft, rgba(179, 38, 42, .08)); color: var(--critical-ink); }

/* app instalado (iPhone): a barra de status fica sobre o topo azul-marinho; área do gesto inferior respeitada */
@media (display-mode: standalone) {
  .appbar { height: calc(56px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .content { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) and (max-width: 760px) {
  .appbar { height: calc(52px + env(safe-area-inset-top)); }
}
