:root {
  color-scheme: light;
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --border: #e2e4df;
  --border-strong: #c9ccc4;
  --text: #17191a;
  --text-2: #4d524f;
  --text-3: #5c615d;
  --accent: #1f6f50;
  --accent-hover: #185a41;
  --accent-soft: #e5f2ec;
  --on-accent: #ffffff;
  --sidebar: #15241e;
  --sidebar-text: #c8d5cf;
  --sidebar-active: #24392f;
  --series-1: #2a78d6;
  --track: #e8ebe6;
  --ok: #11702f; --ok-bg: #e4f4e9;
  --warn: #8a5a00; --warn-bg: #fdf1d6;
  --serious: #b04a0c; --serious-bg: #fde8db;
  --crit: #b42318; --crit-bg: #fde4e2;
  --info: #1d5fa8; --info-bg: #e3eefb;
  --neutral-bg: #eceee9;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 3px rgba(16, 24, 20, .05);
  --radius: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111413; --surface: #1a1d1c; --surface-2: #202423; --border: #2d3230; --border-strong: #3d4441;
    --text: #f1f3f2; --text-2: #c0c6c3; --text-3: #8e9592;
    --accent: #3fa57a; --accent-hover: #4cb789; --accent-soft: #1d3329; --on-accent: #0b130f;
    --sidebar: #0c1210; --sidebar-text: #b7c4be; --sidebar-active: #1b2a24;
    --series-1: #3987e5; --track: #2a2f2d;
    --ok: #5ccb83; --ok-bg: #18301f; --warn: #f0c050; --warn-bg: #3a2f12; --serious: #f2955a; --serious-bg: #3b2414;
    --crit: #f47a72; --crit-bg: #3d1a18; --info: #7fb2f0; --info-bg: #182a40; --neutral-bg: #262b29;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111413; --surface: #1a1d1c; --surface-2: #202423; --border: #2d3230; --border-strong: #3d4441;
  --text: #f1f3f2; --text-2: #c0c6c3; --text-3: #8e9592;
  --accent: #3fa57a; --accent-hover: #4cb789; --accent-soft: #1d3329; --on-accent: #0b130f;
  --sidebar: #0c1210; --sidebar-text: #b7c4be; --sidebar-active: #1b2a24;
  --series-1: #3987e5; --track: #2a2f2d;
  --ok: #5ccb83; --ok-bg: #18301f; --warn: #f0c050; --warn-bg: #3a2f12; --serious: #f2955a; --serious-bg: #3b2414;
  --crit: #f47a72; --crit-bg: #3d1a18; --info: #7fb2f0; --info-bg: #182a40; --neutral-bg: #262b29;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
h1 svg, h2 svg, h3 svg { width: 18px; height: 18px; flex: none; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; }
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand b { display: block; color: #fff; font-size: 15px; letter-spacing: .2px; }
.brand span { font-size: 11.5px; opacity: .75; display: block; margin-top: 2px; }
.nav { padding: 10px 8px; flex: 1; }
.nav .grupo { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .72; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: var(--sidebar-text); font-size: 13.5px; }
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.ativo { background: var(--sidebar-active); color: #fff; font-weight: 560; box-shadow: inset 3px 0 0 #3fa57a; }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.usuario-box { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.06); font-size: 12.5px; }
.usuario-box b { color: #fff; display: block; }
.usuario-box button { margin-top: 8px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.conteudo { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.cab p { margin: 4px 0 0; color: var(--text-3); text-wrap: pretty; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; display: block; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi .rot { color: var(--text-2); font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.kpi .val { font-size: 28px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--text-3); font-size: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 540; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.pri:hover { background: var(--accent-hover); }
.btn.perigo { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.btn.perigo:hover { background: var(--crit-bg); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; height: auto; }
.btn svg { width: 16px; height: 16px; }
.sidebar .btn { background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,.15); }

label.campo { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 520; min-width: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; height: 34px; padding: 0 10px; width: 100%; min-width: 0; }
textarea { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.form { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.form .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); }
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filtros label.campo { min-width: 160px; }
.filtros .busca { flex: 1; min-width: 220px; }

.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr.clicavel { cursor: pointer; }
tfoot td { font-weight: 640; background: var(--surface-2); }
td input { height: 30px; }
.vazio { padding: 32px; text-align: center; color: var(--text-3); text-wrap: pretty; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 560; white-space: nowrap; background: var(--neutral-bg); color: var(--text-2); }
.badge svg { width: 12px; height: 12px; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-serious { background: var(--serious-bg); color: var(--serious); }
.b-crit { background: var(--crit-bg); color: var(--crit); }
.b-info { background: var(--info-bg); color: var(--info); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--info-bg); color: var(--info); margin-left: 4px; font-weight: 560; }

.segmentado { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.segmentado button { border: 0; background: var(--surface); padding: 8px 14px; font: inherit; cursor: pointer; color: var(--text-2); border-right: 1px solid var(--border); }
.segmentado button:last-child { border-right: 0; }
.segmentado button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.alerta { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.alerta svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alerta.info { background: var(--info-bg); color: var(--info); }
.alerta.warn { background: var(--warn-bg); color: var(--warn); }
.alerta.crit { background: var(--crit-bg); color: var(--crit); }

.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.lista li:last-child { border-bottom: 0; }

/* ---------- Interação e acessibilidade ---------- */
.btn, .nav a, .kpi, .segmentado button, input, select, textarea, tbody tr { transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s; }
.btn:active:not(:disabled) { transform: scale(.98); }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible, .segmentado button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.nav a:focus-visible, .sidebar button:focus-visible { outline-color: #8fd3b4; outline-offset: -2px; }
#tela:focus { outline: none; }
.pular { position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.pular:focus { top: 12px; }
.fundo-menu { display: none; }
.passos { margin: 0; padding: 0; list-style: none; counter-reset: passo; display: grid; gap: 10px; }
.passos li { counter-increment: passo; display: flex; gap: 12px; align-items: flex-start; }
.passos li::before { content: counter(passo); flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650; display: grid; place-items: center; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Gráficos ---------- */
.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; }
.grafico .eixo { fill: var(--text-3); font-size: 11px; }
.grafico .grade { stroke: var(--border); stroke-width: 1; }
.grafico .barra { fill: var(--series-1); }
.grafico .alvo { fill: transparent; cursor: default; }
.grafico .alvo:hover + .barra, .grafico g.on .barra { opacity: .8; }
.tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5; }
.medidor { display: grid; grid-template-columns: minmax(120px, 210px) 1fr 64px; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.medidor .trilho { height: 10px; background: var(--track); border-radius: 4px; overflow: hidden; }
.medidor .preench { height: 100%; background: var(--series-1); border-radius: 4px; }
.medidor .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

/* ---------- Modal e toast ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(10, 14, 12, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: min(640px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); border: 1px solid var(--border); }
.modal.largo { width: min(920px, 100%); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 18px 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.fechar { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--text-3); line-height: 1; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.erro { background: var(--crit); color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--sidebar), #1f3a2e); }
.login .card { width: min(400px, 100%); padding: 28px; }
.login h1 { font-size: 20px; }
.login form { display: grid; gap: 14px; margin-top: 18px; }

/* ---------- Impressão (relatórios e comprovantes) ---------- */
@media screen { .so-impressao { display: none !important; } }
.cab-impressao { text-align: center; margin-bottom: 12px; }
.cab-impressao b { display: block; font-size: 13px; }
.assinaturas { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; margin-top: 56px; }
.assinaturas div { border-top: 1px solid #000; padding-top: 6px; text-align: center; font-size: 12px; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; font-size: 11px; }
  .sidebar, .topbar, .nao-imprimir, .filtros, .toasts { display: none !important; }
  .app { display: block; }
  .conteudo { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
  .card-b { padding: 0; }
  th { background: #eee !important; color: #000; position: static; }
  th, td { padding: 4px 6px; border: 1px solid #999; }
  .badge { background: none !important; color: #000 !important; padding: 0; }
  a { color: #000; }
  tr { break-inside: avoid; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
  .g2, .g3 { grid-template-columns: 1fr; }
}
/* Telas de toque: alvos maiores (mínimo recomendado de 44 px) e campos que não dão zoom no iPhone. */
@media (pointer: coarse) {
  .btn { height: 44px; }
  .btn.sm { height: 38px; padding: 0 12px; }
  input, select { height: 44px; font-size: 16px; }
  textarea { font-size: 16px; }
  td input { height: 42px; }
  .nav a { padding: 12px 10px; }
  .segmentado button { padding: 12px 16px; }
  .fechar { width: 44px; height: 44px; }
}
/* Lista de itens da entrada, saída e ajuste: no celular cada item vira um cartão, sem rolar de lado. */
@media (max-width: 700px) {
  .tabela-itens thead { display: none; }
  .tabela-itens, .tabela-itens tbody { display: block; }
  .tabela-itens tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .tabela-itens tbody tr:hover { background: none; }
  .tabela-itens td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; white-space: normal; }
  .tabela-itens td:first-child, .tabela-itens td:has(select) { grid-column: 1 / -1; }
  .tabela-itens td[data-rot]::before { content: attr(data-rot); display: block; font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
  .tabela-itens td:last-child { grid-column: 1 / -1; text-align: right; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar.aberta + .fundo-menu { display: block; position: fixed; inset: 0; background: rgba(10, 14, 12, .5); z-index: 35; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .sidebar.aberta { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; width: 44px; height: 44px; margin-left: -10px; }
  .conteudo { padding: 16px 16px 40px; }
  .medidor { grid-template-columns: 1fr 64px; }
  .medidor .trilho { grid-column: 1 / -1; grid-row: 2; }
}
