:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e6e8ec;
  --line-2: #eef0f3;
  --ink: #0f172a;
  --ink-2: #475467;
  --ink-3: #8a94a6;
  --accent: #2a63d4;
  --accent-soft: #e8effc;
  --side: #0c1424;
  --side-ink: #c5cede;
  --side-ink-2: #7d8aa3;
  --side-active: #1a2740;
  --pos: #0b8a4a;
  --pos-soft: #e6f5ed;
  --neg: #d23a3a;
  --neg-soft: #fcebeb;
  --bar-pos: #16a35f;
  --bar-neg: #e0524f;
  --warn: #b7791f;
  --warn-soft: #fdf3e2;
  --grid: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #161d2d;
  --line: #222b3d;
  --line-2: #1b2334;
  --ink: #e8ecf3;
  --ink-2: #a6b0c2;
  --ink-3: #6b778d;
  --accent: #5b8def;
  --accent-soft: #1a2846;
  --side: #080b12;
  --side-active: #151d2e;
  --pos: #3ccf86;
  --pos-soft: #10291e;
  --neg: #f26d6a;
  --neg-soft: #2e1617;
  --bar-pos: #2fbf75;
  --bar-neg: #ec5f5c;
  --warn: #e7a93b;
  --warn-soft: #2c2312;
  --grid: #1e2638;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.num, td.n, th.n, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 12.5px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b7bf0, #1f4fb8); color: #fff;
  box-shadow: 0 4px 14px rgba(59, 123, 240, .35);
}
.brand-name { color: #fff; font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { color: var(--side-ink-2); font-size: 11.5px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px;
  color: var(--side-ink); text-decoration: none; font-weight: 500; font-size: 13.5px;
}
nav a svg { width: 18px; height: 18px; opacity: .75; }
nav a:hover { background: rgba(255, 255, 255, .04); color: #fff; }
nav a.on { background: var(--side-active); color: #fff; box-shadow: inset 2px 0 0 #4b86f2; }
nav a.on svg { opacity: 1; color: #6ea0ff; }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .06); }
.side-foot .muted { color: var(--side-ink-2); word-break: break-all; margin-top: 4px; }
.sync { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--side-ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #2fbf75; box-shadow: 0 0 0 3px rgba(47, 191, 117, .18); }

main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.015em; }
.crumb { color: var(--ink-3); font-size: 12.5px; margin-top: 1px; }
.filters { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field span { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; height: 34px;
}
textarea { height: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; height: 34px; }
.seg button {
  border: 0; background: none; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  padding: 0 10px; border-radius: 6px; cursor: pointer;
}
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.icon-btn {
  height: 34px; width: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--ink); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  font: inherit; font-weight: 550; font-size: 13px; height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; gap: 7px;
}
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: none; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }

.view { padding: 24px 28px 48px; max-width: 1480px; }

/* ---------- cards & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px 0; }
.card-h h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-h .sub { color: var(--ink-3); font-size: 12px; }
.card-b { padding: 14px 18px 18px; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: 1.35fr repeat(4, 1fr); }
.g-2 { grid-template-columns: 1.6fr 1fr; }
.g-2e { grid-template-columns: 1fr 1fr; }
.mt { margin-top: 16px; }

.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .lbl { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.kpi .val { font-size: 23px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.kpi.hero { background: linear-gradient(140deg, #13213d, #0c1424 70%); border-color: #1e2d4d; color: #fff; }
.kpi.hero .lbl { color: #8fa3c7; }
.kpi.hero .val { font-size: 30px; }
.kpi.hero .foot { color: #8fa3c7; }
.kpi.hero .val.pos { color: #4ade95; }
.kpi.hero .val.neg { color: #ff8a87; }
.kpi.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: radial-gradient(circle, rgba(75, 134, 242, .28), transparent 70%);
}
.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.pill.pos { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.pill.neg { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.blue { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; stroke: none; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: Inter, sans-serif; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .14); min-width: 170px;
}
.tip .t { font-weight: 600; margin-bottom: 5px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .r span:first-child { color: var(--ink-3); }

.hbar { display: grid; grid-template-columns: 96px 1fr 92px; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.hbar .track { height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td.n, th.n { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tr.click { cursor: pointer; }
tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; }
.side-b { font-weight: 650; font-size: 11.5px; padding: 2px 7px; border-radius: 5px; }
.side-b.B { background: var(--pos-soft); color: var(--pos); }
.side-b.S { background: var(--neg-soft); color: var(--neg); }
.sym { font-weight: 550; }
a.mono { color: var(--accent); text-decoration: none; }
a.mono:hover { text-decoration: underline; }
.empty { padding: 48px; text-align: center; color: var(--ink-3); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 16px; justify-content: flex-end; color: var(--ink-3); font-size: 12.5px; }

.stats-row { display: flex; gap: 28px; flex-wrap: wrap; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.stats-row .s .l { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.stats-row .s .v { font-size: 18px; font-weight: 650; margin-top: 3px; font-variant-numeric: tabular-nums; }

/* ---------- modal / contract note ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: start center; overflow: auto; padding: 40px 16px; }
.modal-back { position: fixed; inset: 0; background: rgba(8, 12, 22, .55); backdrop-filter: blur(3px); }
.modal-card { position: relative; width: min(1200px, 100%); }
.doc { background: #fff; color: #111827; border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); overflow: hidden; }
.doc-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 10px; }
.doc-actions .btn { background: rgba(255, 255, 255, .95); color: #111; border-color: transparent; }
.doc-head { display: flex; justify-content: space-between; padding: 26px 32px; background: #0c1424; color: #fff; }
.doc-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.doc-head .meta { text-align: right; font-size: 12.5px; color: #a9b6cf; line-height: 1.7; }
.doc-head .meta b { color: #fff; font-weight: 600; }
.doc-sec { padding: 20px 32px; border-bottom: 1px solid #eceef2; }
.doc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.doc-grid .l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: #6b7280; font-weight: 600; }
.doc-grid .v { font-size: 14px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.doc table th { background: #f6f7f9; color: #6b7280; border-color: #e5e7eb; position: static; }
.doc table td { border-color: #f0f1f4; }
.doc .tbl-wrap th, .doc .tbl-wrap td, .doc > table th, .doc > table td { padding: 8px 9px; font-size: 12.5px; }
.doc .tbl-wrap th:first-child, .doc .tbl-wrap td:first-child { padding-left: 24px; }
.doc .tbl-wrap th:last-child, .doc .tbl-wrap td:last-child { padding-right: 24px; }
.doc tbody tr:hover td { background: #fafbfc; }
.doc tfoot td { background: #f6f7f9; border-color: #e5e7eb; }
.doc .pos { color: #0b8a4a; } .doc .neg { color: #c62f2f; }
.charges { display: grid; grid-template-columns: 1fr 360px; gap: 32px; }
.charges table td { padding: 7px 0; }
.charges table tr.tot td { border-top: 1px solid #d9dce3; font-weight: 700; font-size: 14px; padding-top: 10px; }
.oblig { border-radius: 10px; padding: 16px 18px; background: #f6f7f9; }
.oblig .big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.doc-foot { padding: 16px 32px 22px; font-size: 11.5px; color: #6b7280; line-height: 1.6; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.form-grid .field input, .form-grid .field select { width: 100%; }
.set-sec h4 { margin: 0 0 12px; font-size: 13px; }
.set-sec + .set-sec { border-top: 1px solid var(--line); }
.note { font-size: 12.5px; color: var(--ink-2); background: var(--warn-soft); border-radius: 8px; padding: 10px 12px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.settle-in { width: 96px; height: 28px; text-align: right; }
.skeleton { height: 120px; border-radius: 12px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }

@media (max-width: 1200px) {
  .g-kpi { grid-template-columns: repeat(3, 1fr); }
  .kpi.hero { grid-column: span 3; }
  .g-2, .g-2e { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  nav { flex-direction: row; overflow-x: auto; }
  .side-foot { display: none; }
  .top, .view { padding-left: 16px; padding-right: 16px; }
  .g-kpi { grid-template-columns: 1fr 1fr; }
  .kpi.hero { grid-column: span 2; }
  .doc-grid { grid-template-columns: 1fr 1fr; }
  .charges { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .shell, .doc-actions, .modal-back, .tip, .toast { display: none !important; }
  .modal { position: static; padding: 0; display: block; }
  .doc { box-shadow: none; border-radius: 0; }
  .doc-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
