:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1c2430; --muted: #6b7686; --line: #e3e8ef;
  --brand: #1d5fd1; --brand-ink: #fff; --ok: #14804a; --ok-bg: #e3f5ea; --warn: #a86400; --warn-bg: #fff1d6;
  --danger: #c0392b; --danger-bg: #fde8e6; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161d; --card: #1a212b; --ink: #e6ebf2; --muted: #93a0b2; --line: #2b3542; --brand: #5b97f5; --brand-ink: #0b1220;
    --ok: #4cc58a; --ok-bg: #16352a; --warn: #f0b34d; --warn-bg: #3b2f14; --danger: #f07a6c; --danger-bg: #3e1f1b; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .right { text-align: right; } .nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 14px; } .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.side a.nav { padding: 9px 12px; border-radius: 8px; color: var(--ink); display: block; }
.side a.nav:hover { background: var(--bg); text-decoration: none; } .side a.nav.on { background: var(--brand); color: var(--brand-ink); }
.side .who { margin-top: auto; padding: 10px; font-size: 13px; border-top: 1px solid var(--line); }
.main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 700; } .stat .l { color: var(--muted); font-size: 13px; }
button, .btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); border-color: var(--danger); } button.danger.fill { background: var(--danger); color: #fff; }
button.small { padding: 4px 9px; font-size: 13px; } button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.off { background: var(--danger-bg); color: var(--danger); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; } .tabs button.on { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); margin-bottom: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.scroll { overflow-x: auto; }
table.edit input { padding: 5px 6px; text-align: right; min-width: 84px; width: 96px; }
table.edit td.name { min-width: 190px; position: sticky; left: 0; background: var(--card); }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); padding: 22px; width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
#toast.show { opacity: 1; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .who { margin: 0 0 0 auto; border: 0; } .brand { padding: 4px 10px; } .brand small { display: none; }
  .main { padding: 16px 14px 50px; }
}

/* impressão da folha */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; font-size: 11px; }
  .side, .actions, .no-print, #toast, button { display: none !important; }
  .shell { display: block; } .main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; } .print-only { display: block; }
  table.edit input { border: 0; background: none; padding: 0; width: auto; min-width: 0; color: #000; }
  table.edit td.name { position: static; }
  th, td { padding: 4px 5px; border-color: #999; color: #000; }
}

/* utilitários (a CSP não permite estilos inline) */
.who-actions { margin-top: 8px; display: flex; gap: 6px; }
.flush { margin-top: 0; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; } .mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.wfull { width: 100%; } .w240 { width: 240px; } .wauto { width: auto; } .narrow { max-width: 420px; }
.sign { margin-top: 40px; text-align: center; }
.form .full { grid-column: 1 / -1; }
a.btn { display: inline-block; text-decoration: none; } a.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
a.btn.primary:hover { text-decoration: none; }
