:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --brand-soft: #e8efff;
  --teal: #0ea5a4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --sidebar: #0b1220;
  --sidebar-2: #111b30;
  --sidebar-ink: #cbd5e1;
  --radius: 12px;
  --shadow: 0 12px 32px rgba(15, 23, 42, .10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14.5px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.erro { color: var(--danger); font-size: 13px; }
.quebra { word-break: break-all; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand {
  background: radial-gradient(1200px 600px at 10% 10%, #1e3a8a 0%, #0b1220 55%);
  color: #e2e8f0; padding: 64px; display: flex; flex-direction: column; justify-content: center; gap: 18px;
}
.login-brand h1 { font-size: 40px; color: #fff; }
.login-brand p { max-width: 420px; color: #94a3b8; font-size: 16px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--brand)); color: #fff; font-weight: 800; letter-spacing: -.02em;
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 12px; }
.login-card { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-card > .stack { width: 100%; max-width: 400px; background: var(--surface); padding: 32px; border-radius: 18px; box-shadow: var(--shadow); }
.login-card h2 { font-size: 24px; }

/* Shell */
#app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(148,163,184,.16); }
.nav { display: flex; flex-direction: column; gap: 3px; padding: 14px 0; flex: 1; overflow: auto; }
.nav a { color: var(--sidebar-ink); padding: 9px 12px; border-radius: 9px; display: flex; gap: 10px; align-items: center; font-size: 14px; cursor: pointer; }
.nav a:hover { background: rgba(148,163,184,.10); color: #fff; }
.nav a.ativo { background: rgba(29,78,216,.28); color: #fff; }
.nav a .icone { width: 18px; text-align: center; opacity: .9; }
.sidebar-user { border-top: 1px solid rgba(148,163,184,.16); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-user div { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user strong { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar > div { display: flex; align-items: center; gap: 12px; }
.conteudo { padding: 24px 28px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; }

/* Components */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.fim { justify-content: flex-end; }
.grid { display: grid; gap: 16px; }
.grid.duas { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.tres { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h3 { margin-bottom: 10px; }
.card + .card { margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; outline: none; width: 100%;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.field .dica { font-size: 11.5px; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: #cbd5e1; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #1e40af; border-color: #1e40af; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small, .btn.small { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.erro { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.neutro { background: #f1f5f9; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.tabela { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tabela th, .tabela td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabela th { background: #f8fafc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.tabela tr:last-child td { border-bottom: 0; }
.tabela tbody tr:hover { background: #fbfcff; }
.tabela .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela .acoes-linha { display: flex; gap: 6px; flex-wrap: wrap; }
.vazio { padding: 32px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { font: inherit; padding: 8px 13px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; font-weight: 600; }
.tabs button.ativo { background: var(--brand); border-color: var(--brand); color: #fff; }
.codigo-box { background: #0b1220; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; font-family: var(--mono); letter-spacing: .08em; word-break: break-all; }
.recovery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; list-style: none; padding: 0; margin: 0; }
.recovery li { background: #f1f5f9; border-radius: 8px; padding: 7px 10px; font-family: var(--mono); font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi strong { display: block; font-size: 22px; margin-top: 4px; }
.kpi span { color: var(--muted); font-size: 12.5px; }
.atalhos { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.atalho { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; }
.atalho:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.atalho strong { display: block; margin-bottom: 4px; }
.atalho span { color: var(--muted); font-size: 12.5px; }
.secao-titulo { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.linha-itens { display: grid; grid-template-columns: 1.4fr 2fr .9fr .6fr .7fr .8fr .7fr .7fr 32px; gap: 6px; align-items: end; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.linha-itens:last-child { border-bottom: 0; }
.linha-itens .field { font-size: 11.5px; gap: 3px; }
.linha-itens .field input, .linha-itens .field select { padding: 6px 8px; }
.remover { align-self: end; }
.detalhe-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.detalhe-grid div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding: 6px 0; }
.detalhe-grid span:first-child { color: var(--muted); }
.detalhe-grid .num { font-variant-numeric: tabular-nums; text-align: right; }
.total-linha { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.total-linha.forte { font-weight: 700; border-bottom: 0; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 18px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 680px; }
.modal.grande { max-width: 980px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-corpo { padding: 20px; max-height: 74vh; overflow: auto; }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #0b1220; color: #fff; padding: 11px 15px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; }
.toast.erro { background: var(--danger); }
.toast.ok { background: var(--ok); }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .grid.duas, .grid.tres, .kpis, .detalhe-grid { grid-template-columns: 1fr; }
  .conteudo { padding: 18px 16px 48px; }
  .topbar { padding: 16px; }
  .linha-itens { grid-template-columns: 1fr 1fr; }
  .linha-itens .remover { grid-column: span 2; }
}

.qr { width: 220px; height: 220px; margin: 4px auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; padding: 8px; }
.qr svg { width: 196px; height: 196px; }
