/* Cedrivo — ledger-desk layout: fixed navigation rail, wide working surface,
   figures set in tabular numerals. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #0e1a2b;
  --muted: #5a697c;
  --line: #dbe1e8;
  --brand: #12315c;
  --brand-ink: #ffffff;
  --accent: #0b6f6a;
  --accent-soft: #dff2f0;
  --pos: #0a7a47;
  --neg: #b42318;
  --warn: #9a5b00;
  --warn-soft: #fdf0d8;
  --neg-soft: #fde8e6;
  --focus: #2a6fdb;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --rail: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141f; --surface: #121d2c; --surface-2: #172538; --ink: #e8eef6;
    --muted: #93a3b8; --line: #243449; --brand: #1c4a86; --brand-ink: #ffffff;
    --accent: #38b2aa; --accent-soft: #123a3a; --pos: #4cc38a; --neg: #ff8a80;
    --warn: #f2b45a; --warn-soft: #3a2b10; --neg-soft: #3b1a18; --focus: #6aa5ff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; letter-spacing: .02em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.boot { padding: 24px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.code { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.sr { position: absolute; left: -9999px; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100%; }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 600; font-size: 17px; }
.mark { width: 30px; height: 30px; border-radius: 6px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 600; }
.nav-group { margin-top: 6px; }
.nav-group > h3 { padding: 10px 10px 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.nav-link { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; text-decoration: none; color: var(--ink); }
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-link[disabled], .nav-link.soon { color: var(--muted); cursor: default; }
.nav-link.soon:hover { background: none; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar { flex-wrap: wrap; }
.topbar select { max-width: 100%; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.main { min-width: 0; }
.page { padding: 24px 28px 64px; max-width: 1280px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--neg); border-color: var(--neg); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, select.input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
tfoot td { font-weight: 600; background: var(--surface-2); }
tr.group td { background: var(--surface-2); font-weight: 600; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); }
.pill.POSTED, .pill.PAID, .pill.ACTIVE { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.DRAFT, .pill.UNPAID, .pill.PARTIAL, .pill.PARTIALLY_PAID { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.REVERSED, .pill.CANCELLED, .pill.VOID { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 2px; color: var(--muted); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--neg-soft); color: var(--neg); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.drawer-back { position: fixed; inset: 0; background: rgba(10, 20, 35, .45); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { width: min(760px, 100%); background: var(--surface); height: 100%; overflow-y: auto; padding: 22px 24px 48px; }
.drawer header { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 16px; }
.toast-host { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 40; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 6px; max-width: 360px; }
.toast.error { background: var(--neg); color: #fff; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login .card { width: min(380px, 100%); display: grid; gap: 14px; }
.login .brand { padding: 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 30; left: 0; top: 0; width: min(82vw, 300px); transform: translateX(-102%); transition: transform .18s ease; }
  .rail.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 20, 35, .45); }
  .btn.menu-btn { display: inline-flex; }
  .hide-sm { display: none; }
  .topbar { padding: 10px 16px; }
  .page { padding: 18px 16px 56px; }
}
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }

.field input, .field select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Document view / PDF */
.pd-back { position: fixed; inset: 0; z-index: 150; background: #e9edf2; overflow: auto; }
.pd-bar { position: sticky; top: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 2; }
.pd-sheet { box-sizing: border-box; background: #fff; color: #111; width: min(210mm, 100%); margin: 16px auto; padding: 16mm 14mm; box-shadow: 0 2px 14px rgba(0,0,0,.15); font-size: 13px; line-height: 1.45; }
.pd-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111; padding-bottom: 12px; }
.pd-co { font-size: 18px; font-weight: 700; }
.pd-title { text-align: right; }
.pd-h { font-size: 22px; font-weight: 700; letter-spacing: .08em; }
.pd-num { font-family: ui-monospace, monospace; font-size: 15px; }
.pd-draft { display: inline-block; margin-top: 4px; padding: 2px 8px; border: 1px solid #b00; color: #b00; font-weight: 700; }
.pd-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 14px 0; }
.pd-lab { font-size: 11px; text-transform: uppercase; color: #666; letter-spacing: .06em; }
.pd-bold { font-weight: 700; }
.pd-kv { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dotted #ccc; padding: 2px 0; }
.pd-lines { width: 100%; border-collapse: collapse; margin-top: 8px; }
.pd-lines th { text-align: left; border-bottom: 1.5px solid #111; padding: 6px 4px; font-size: 11px; text-transform: uppercase; }
.pd-lines td { padding: 6px 4px; border-bottom: 1px solid #ddd; vertical-align: top; }
.pd-lines .num { text-align: right; white-space: nowrap; }
.pd-totals { width: min(320px, 100%); margin: 14px 0 0 auto; }
.pd-tot { display: flex; justify-content: space-between; padding: 3px 0; }
.pd-tot.strong { font-weight: 700; border-top: 1.5px solid #111; border-bottom: 1.5px solid #111; margin: 4px 0; padding: 6px 0; font-size: 15px; }
.pd-notes, .pd-desc { margin-top: 12px; white-space: pre-wrap; }
@media print {
  body.printing-doc > *:not(.pd-back) { display: none !important; }
  .pd-back { position: static; background: #fff; overflow: visible; }
  .pd-bar { display: none !important; }
  .pd-sheet { box-shadow: none; margin: 0; width: 100%; padding: 0; }
  @page { size: A4; margin: 14mm; }
}
@media print {
  .rail, .topbar, .toolbar, .page-head .btn { display: none !important; }
  .shell { display: block !important; }
  .main { margin: 0 !important; padding: 0 !important; }
}
