/* Faturação — tinta azul de carimbo sobre papel. Sem fontes externas (RGPD, desempenho). */
:root {
  --ink: #1a1f2b;          /* texto */
  --ink-soft: #566074;     /* texto secundário */
  --paper: #ffffff;        /* superfícies (folha) */
  --desk: #eef1f5;         /* fundo (secretária) */
  --rule: #d9dee7;         /* linhas */
  --stamp: #2a3f9d;        /* azul de carimbo: ação principal e navegação */
  --stamp-deep: #1d2c70;
  --stamp-wash: #e7eaf7;
  --ok: #24704f; --ok-wash: #e3f1ea;
  --warn: #8a5a00; --warn-wash: #fbf0d9;
  --void: #b3261e; --void-wash: #fbe6e4;  /* anulado */
  --radius: 6px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --num: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e5e8ef; --ink-soft: #9ba5b8; --paper: #1b2030; --desk: #121624; --rule: #2c3346;
    --stamp: #8fa2ff; --stamp-deep: #b5c2ff; --stamp-wash: #232c4f;
    --ok: #6fcf9f; --ok-wash: #173326; --warn: #f0c063; --warn-wash: #352a12; --void: #ff8a80; --void-wash: #3b1c1b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--desk); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--stamp); }
:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 28px 0 10px; font-weight: 650; }
h3 { font-size: 15px; margin: 18px 0 6px; }
p { margin: 8px 0; max-width: 72ch; }
.muted { color: var(--ink-soft); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
code { background: var(--stamp-wash); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- estrutura ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--stamp-deep); color: #dfe4ff; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
@media (prefers-color-scheme: dark) { .side { background: #0d1120; } }
.side .org { padding: 4px 10px 14px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 10px; }
.side .org strong { display: block; color: #fff; font-size: 15px; line-height: 1.3; }
.side .org span { font-size: 12.5px; color: #aab4e8; }
.side a { color: #dfe4ff; text-decoration: none; padding: 7px 10px; border-radius: var(--radius); font-size: 14.5px; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.on { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.side .issue { background: #fff; color: var(--stamp-deep); font-weight: 650; text-align: center; margin: 4px 0 12px; padding: 10px; }
.side .issue:hover { background: #e9ecff; }
.side .group { font-size: 12.5px; color: #93a0dc; padding: 14px 10px 4px; }
.nav-group { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.nav-group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: var(--radius); color: #c9d0f5; font-size: 13.5px; font-weight: 600; user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s ease; margin-right: 3px; }
.nav-group[open] > summary::after { transform: rotate(45deg); }
.nav-group > summary:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-group > a { padding-left: 20px; }
@media (prefers-reduced-motion: reduce) { .nav-group > summary::after { transition: none; } }
.side .bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; color: #aab4e8; }
.side .bottom form { display: inline; }
.side .bottom button { background: none; border: 0; color: #dfe4ff; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.main { padding: 26px 32px 64px; min-width: 0; max-width: 1180px; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 2px; }
  .side .org { border: 0; margin: 0; padding: 4px 8px; flex: 1 1 100%; }
  .side .group, .side .bottom { display: none; }
  .nav-group { flex-direction: row; flex-wrap: wrap; margin-top: 0; flex: 1 1 100%; }
  .nav-group > summary { padding: 6px 9px; }
  .nav-group > a { padding-left: 9px; }
  .side a { padding: 6px 9px; font-size: 13.5px; }
  .side .issue { margin: 0 6px 0 0; padding: 6px 12px; }
  .main { padding: 18px 16px 48px; }
}

/* ---------- superfícies ---------- */
.card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 0 auto; }
.center-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.figures { display: flex; flex-wrap: wrap; gap: 0; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 18px; }
.figures div { flex: 1 1 180px; padding: 14px 18px; border-right: 1px solid var(--rule); }
.figures div:last-child { border-right: 0; }
.figures b { display: block; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.figures span { font-size: 13px; color: var(--ink-soft); }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { font-size: 13px; font-weight: 600; color: var(--ink-soft); background: var(--desk); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--stamp-wash) 45%, transparent); }
td a.row-link { color: var(--ink); text-decoration: none; font-weight: 600; }
td a.row-link:hover { color: var(--stamp); text-decoration: underline; }
.empty { padding: 28px 20px; text-align: center; color: var(--ink-soft); }
.empty a { font-weight: 600; }

/* ---------- formulários ---------- */
label { display: block; font-weight: 600; font-size: 13.5px; margin: 12px 0 4px; }
label small, .hint { font-weight: 400; color: var(--ink-soft); font-size: 12.5px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); color: var(--ink); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--stamp); outline-offset: 0; border-color: var(--stamp); }
input[readonly] { background: var(--desk); color: var(--ink-soft); }
input[type=checkbox] { width: auto; margin-right: 6px; }
.check { display: flex; align-items: center; font-weight: 500; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--stamp); background: var(--stamp); color: #fff; font: 600 14px/1.3 var(--font); cursor: pointer; text-decoration: none; }
@media (prefers-color-scheme: dark) { .btn { color: #0d1120; } }
.btn:hover { background: var(--stamp-deep); border-color: var(--stamp-deep); }
.btn.ghost { background: transparent; color: var(--stamp); }
.btn.ghost:hover { background: var(--stamp-wash); }
.btn.danger { background: transparent; color: var(--void); border-color: var(--void); }
.btn.danger:hover { background: var(--void-wash); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.search { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search input, .search select { max-width: 280px; }

/* ---------- avisos e estados ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 14px; border: 1px solid; }
.alert.ok { background: var(--ok-wash); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert.info { background: var(--stamp-wash); border-color: color-mix(in srgb, var(--stamp) 30%, transparent); }
.alert.warn { background: var(--warn-wash); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert.error, .alert.danger { background: var(--void-wash); border-color: color-mix(in srgb, var(--void) 35%, transparent); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--desk); color: var(--ink-soft); border: 1px solid var(--rule); white-space: nowrap; }
.badge.ok { background: var(--ok-wash); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-wash); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--void-wash); color: var(--void); border-color: transparent; }

/* O carimbo: marca do documento emitido / anulado na vista do documento */
.stamp { display: inline-block; padding: 4px 12px; border: 2px solid currentColor; border-radius: 4px; font-weight: 700; font-size: 15px; transform: rotate(-3deg); color: var(--stamp); }
.stamp.void { color: var(--void); }

/* ---------- emissão: linhas ---------- */
.lines th, .lines td { padding: 6px 6px; }
.lines input, .lines select { padding: 6px 8px; }
.lines .c-code { width: 22%; } .lines .c-qty { width: 9%; } .lines .c-price { width: 12%; } .lines .c-disc { width: 8%; } .lines .c-tax { width: 15%; } .lines .c-total { width: 11%; }
.lines td.del button { background: none; border: 0; color: var(--void); font-size: 18px; cursor: pointer; padding: 2px 6px; }
.lines .exempt { margin-top: 4px; }
@media (max-width: 860px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border-bottom: 1px solid var(--rule); }
  .lines td, .lines .c-code, .lines .c-desc, .lines .c-qty, .lines .c-price, .lines .c-disc, .lines .c-tax, .lines .c-total { border: 0; padding: 0; width: auto; }
  .lines td.c-total { align-self: center; font-weight: 600; }
  .lines td.del { text-align: right; }
  .lines td.c-desc, .lines td.c-code { grid-column: 1 / -1; }
}
.totals { margin-left: auto; max-width: 340px; }
.totals table td { border: 0; padding: 4px 0; }
.totals .grand td { font-size: 18px; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 8px; }

/* ---------- vista do documento: a folha ---------- */
.sheet { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 26px 28px; box-shadow: 0 1px 0 var(--rule), 0 8px 24px -16px rgba(26, 31, 43, .35); }
.sheet-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.sheet-head .docno { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 14px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }
.qr-box { display: flex; gap: 16px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.qr-box svg { width: 120px; height: 120px; }

/* ---------- login ---------- */
.login-wrap { width: 100%; max-width: 400px; }
.login-wrap .brand { font-size: 20px; font-weight: 700; color: var(--stamp-deep); margin-bottom: 4px; }
@media (prefers-color-scheme: dark) { .login-wrap .brand { color: var(--stamp); } }
.login-wrap .card { padding: 24px; }
.temp-pass { font-size: 20px; font-weight: 700; letter-spacing: .04em; font-variant-numeric: tabular-nums; background: var(--stamp-wash); padding: 8px 12px; border-radius: var(--radius); display: inline-block; user-select: all; }

@media print {
  .side, .topbar .actions, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
