:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #0b1220;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #b2342a;
  --primary-hover: #c93d32;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }

/* Login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-err { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.4); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; display: none; }

/* Layout */
.app-shell { display: none; min-height: 100vh; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.topbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-tabs { background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; gap: 4px; overflow-x: auto; }
.nav-tab { background: none; border: none; color: var(--muted); padding: 12px 16px; font-size: 13px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: #fff; border-bottom-color: var(--primary); }
.main { padding: 20px; max-width: 1520px; width: 100%; margin: 0 auto; flex: 1; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Controls & Buttons */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; }
input:focus, select:focus { outline: none; border-color: var(--info); }
.btn { border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: opacity .15s, background .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #334155; color: #f8fafc; }
.btn-secondary:hover:not(:disabled) { background: #475569; }
.btn-success { background: #059669; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Cards & Grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi-val { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-val.ok { color: #34d399; }
.kpi-val.warn { color: #fbbf24; }
.kpi-val.danger { color: #f87171; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; margin: 0; }
.check-inline input { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: var(--surface-2); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
tr:hover td { background: rgba(255,255,255,.025); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: 12px; }

/* Grade interativa */
.cell-clickable { cursor: pointer; user-select: none; border-radius: 6px; padding: 3px 8px; display: inline-block; min-width: 34px; text-align: center; font-weight: 700; }
.info-empty { background: #334155; color: #94a3b8; }
.info-1 { background: rgba(16,185,129,.2); color: #34d399; border: 1px solid rgba(16,185,129,.4); }
.info-multi { background: rgba(245,158,11,.22); color: #fcd34d; border: 1px solid rgba(245,158,11,.5); }
.info-9 { background: rgba(239,68,68,.2); color: #fca5a5; border: 1px solid rgba(239,68,68,.4); }
.pcl-badge { background: rgba(56,189,248,.12); color: #7dd3fc; border: 1px dashed rgba(56,189,248,.4); }
.pcl-manual { background: rgba(168,85,247,.2); color: #d8b4fe; border: 1px solid rgba(168,85,247,.5); }
.row-multi td { background: rgba(245,158,11,.10); }
.badge-aviso { display: inline-block; background: rgba(239,68,68,.2); color: #fca5a5; border: 1px solid rgba(239,68,68,.45); padding: 2px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; margin: 1px 2px; }
.badge-ok { display: inline-block; background: rgba(16,185,129,.18); color: #34d399; padding: 2px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; }

/* Relatório / Recibo */
.recibo-sheet { background: #fff; color: #0f172a; border-radius: 10px; padding: 28px; margin-bottom: 24px; }
.recibo-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #0f172a; padding-bottom: 12px; margin-bottom: 16px; gap: 16px; }
.recibo-header h2 { font-size: 18px; }
.recibo-meta { font-size: 12px; color: #334155; }
.recibo-sheet table { color: #0f172a; border: 1px solid #cbd5e1; }
.recibo-sheet th { background: #f1f5f9; color: #0f172a; border-bottom: 1px solid #94a3b8; position: static; }
.recibo-sheet td { border-bottom: 1px solid #e2e8f0; }
.recibo-sheet tr.row-yellow td { background: #fef08a !important; }
.recibo-totais { display: flex; justify-content: flex-end; gap: 24px; margin-top: 14px; font-size: 13px; flex-wrap: wrap; }
.recibo-box { margin-top: 20px; border: 1px solid #94a3b8; border-radius: 6px; padding: 14px; background: #f8fafc; font-size: 13px; }
.recibo-assinatura { margin-top: 32px; display: flex; justify-content: space-between; gap: 32px; font-size: 12px; }
.recibo-assinatura .linha { flex: 1; border-top: 1px solid #0f172a; padding-top: 6px; text-align: center; }
.avisos-panel { background: #450a0a; color: #fecaca; border: 1px solid #dc2626; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-size: 13px; }
.inad-page { margin-top: 24px; padding-top: 18px; border-top: 2px dashed #94a3b8; }

/* Modal & Toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal-backdrop.active { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e293b; color: #fff; border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warn); }

/* Impressão / PDF: esconde UI e avisos fora da área de impressão (coluna N), quebra página na Página 2 */
@media print {
  body { background: #fff; color: #000; }
  .no-print, .topbar, .nav-tabs, .toast-container, .modal-backdrop, .avisos-panel, .col-aviso { display: none !important; }
  .main { padding: 0; max-width: none; }
  .recibo-sheet { box-shadow: none; border: none; padding: 0; margin: 0; page-break-after: always; }
  .inad-page { page-break-before: always; border-top: none; margin-top: 0; padding-top: 0; }
}
