:root {
  --brand: #1f8fe0;
  --brand-strong: #1673bd;
  --brand-soft: #e8f3fc;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1c2430;
  --muted: #64748b;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --warn: #d97706;
  --warn-soft: #fdf3e2;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --info-soft: #eef2ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4aa8f0;
    --brand-strong: #7cc0f5;
    --brand-soft: #14304a;
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1b2430;
    --border: #273241;
    --text: #e6ebf2;
    --muted: #93a1b5;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #33270f;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --info-soft: #1d2340;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 12px; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 15px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--brand-soft); color: var(--brand-strong); }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 10px 0; font-size: 13px; }
.sidebar-foot .who { font-weight: 600; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

main { padding: 24px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.topbar-mobile { display: none; }

/* ── Componentes ────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: 2fr 1fr; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.lg { height: 48px; padding: 0 22px; font-size: 16px; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field .help { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); outline: none; width: 100%;
}
textarea.input { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px;
}
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.b-AGUARDANDO { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.b-EM_CONFERENCIA { background: var(--brand-soft); color: var(--brand-strong); }
.b-DIVERGENTE { background: var(--warn-soft); color: var(--warn); }
.b-AGUARDANDO_APROVACAO { background: var(--danger-soft); color: var(--danger); }
.b-CONCLUIDO, .b-OK, .b-GRAVADO { background: var(--ok-soft); color: var(--ok); }
.b-CANCELADO { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.b-FALTA, .b-ERRO { background: var(--danger-soft); color: var(--danger); }
.b-SOBRA { background: var(--warn-soft); color: var(--warn); }
.b-PENDENTE { background: var(--info-soft); color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input { max-width: 280px; }

.alert-box { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.alert-box.warn { background: var(--warn-soft); color: var(--warn); }
.alert-box.danger { background: var(--danger-soft); color: var(--danger); }
.alert-box.ok { background: var(--ok-soft); color: var(--ok); }
.alert-box.info { background: var(--brand-soft); color: var(--brand-strong); }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px 20px; }
.meta-grid .k { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.meta-grid .v { margin-top: 3px; font-weight: 500; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth h1 { font-size: 20px; margin: 14px 0 4px; }
.auth .sub { color: var(--muted); margin-bottom: 20px; }

/* ── Conferência ───────────────────────────────────────────────────────── */
.conf { display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
.scan-box { padding: 20px; }
.scan-input { height: 64px; font-size: 26px; font-weight: 600; letter-spacing: .03em; text-align: center; }
.scan-row { display: grid; grid-template-columns: 1fr 120px; gap: 10px; }
.qty-input { height: 64px; font-size: 24px; text-align: center; }
.last-scan { margin-top: 16px; padding: 16px; border-radius: 10px; background: var(--surface-2); min-height: 76px; }
.last-scan.ok { background: var(--ok-soft); }
.last-scan.err { background: var(--danger-soft); color: var(--danger); }
.last-scan .desc { font-size: 17px; font-weight: 600; }
.count-list { max-height: 60vh; overflow-y: auto; }
.count-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.count-item.recount { background: var(--warn-soft); }
.count-item .q { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ── Modal e toast ─────────────────────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 27, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { padding: 18px 22px 0; font-size: 17px; font-weight: 700; }
.modal .body { padding: 16px 22px; }
.modal footer { padding: 0 22px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.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: 12px 16px; border-radius: 10px; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-weight: 500; }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 1100px) {
  .grid.two, .conf { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar-mobile { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  main { padding: 16px; }
  .toolbar .input { max-width: none; }
}
