:root {
  --navy: #0d2340; --navy-2: #15325a; --brand: #2a78d6; --brand-ink: #1b5fae;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f9fafb; --line: #e3e6ea; --line-2: #eef0f3;
  --ink: #0b0b0b; --ink-2: #52514e; --ink-3: #85847f;
  --good: #0f7b3e; --good-bg: #e7f5ec; --warn: #9a6200; --warn-bg: #fdf3dc; --bad: #b42318; --bad-bg: #fdeceb; --info-bg: #e8f1fc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--brand-ink); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.muted { color: var(--ink-3); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #cfd8e6; padding: 16px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 20px 18px; color: #fff; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
.brand-name { font-weight: 700; line-height: 1.1; } .brand-sub { font-size: 11px; color: #8fa3c0; }
.nav-group { padding: 10px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f86a8; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 7px 20px; color: #cfd8e6; border-left: 3px solid transparent; }
.nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--navy-2); color: #fff; border-left-color: var(--brand); }
.nav .badge { background: var(--s2); color: #fff; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 24px; position: sticky; top: 0; z-index: 5; }
.topbar .who { display: flex; align-items: center; gap: 12px; color: var(--ink-2); }
.content { padding: 22px 24px 60px; max-width: 1500px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3, .g2 { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .app { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } .g4 { grid-template-columns: 1fr; } }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--ink-2); font-size: 12px; font-weight: 550; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .hint { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 12px; border-radius: 6px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: #f1c2bd; } .btn.danger:hover { background: var(--bad-bg); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid #cfd4db; border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(42,120,214,.35); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 140px; }
.filters label.field { min-width: 150px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 8px 10px; white-space: nowrap; position: sticky; top: 0; }
td { border-bottom: 1px solid var(--line-2); padding: 8px 10px; vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f5f8fd; }
tr.total td { font-weight: 650; border-top: 1px solid var(--line); background: var(--surface-2); }
tr.section td { font-weight: 650; background: #fbfbfc; color: var(--ink-2); text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
tr.grand td { font-weight: 700; border-top: 2px solid var(--ink); }
td.indent { padding-left: 26px; min-width: 250px; }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }
.lines td { padding: 4px; } .lines input, .lines select { padding: 5px 7px; }

/* ---------- status pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-bg); color: var(--good); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); } .pill.info { background: var(--info-bg); color: var(--brand-ink); }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 999px; font-size: 11px; font-weight: 700; text-align: center; }
.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.banner.warn { background: var(--warn-bg); border-color: #f2d48a; color: #6b4600; }
.banner.info { background: var(--info-bg); border-color: #bcd5f5; color: #17457e; }
.banner.bad { background: var(--bad-bg); border-color: #f1c2bd; color: var(--bad); }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(13,35,64,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 10px; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; display: flex; justify-content: space-between; }
.modal .body { padding: 18px 20px; } .modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 60; padding: 11px 16px; border-radius: 8px; background: var(--navy); color: #fff; box-shadow: var(--shadow); max-width: 420px; }
.toast.error { background: var(--bad); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), #1d4677); padding: 20px; }
.login { width: min(400px, 100%); background: #fff; border-radius: 12px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login .brand { color: var(--navy); padding: 0 0 18px; } .login .brand-sub { color: var(--ink-3); }
.login form { display: grid; gap: 12px; }
.error-text { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--ink-3); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.tip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 6px; padding: 7px 9px; font-size: 12px; white-space: nowrap; z-index: 3; }
.hbar { display: grid; grid-template-columns: minmax(130px, 44%) 1fr auto; gap: 8px 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 12px; background: transparent; }
.hbar .fill { height: 12px; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.hbar .lbl { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- invoice print ---------- */
.doc { background: #fff; max-width: 860px; margin: 0 auto; padding: 44px 48px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--navy); padding-bottom: 16px; margin-bottom: 20px; }
.doc-title { font-size: 28px; font-weight: 800; color: var(--navy); letter-spacing: .04em; }
.doc table th { background: var(--navy); color: #fff; }
.doc .meta td { border: 0; padding: 2px 8px 2px 0; }
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .app { display: block; } .content { padding: 0; } body, html { background: #fff; }
  .doc { border: 0; box-shadow: none; padding: 0; }
}
