:root {
  color-scheme: light;
  --page: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --accent: #111;
  --accent-ink: #fff;
  --gold: #a87b1d;
  --good: #006300;
  --bad: #b42323;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #b5b3ab;
  --deduct: #c3c2b7;
  --recoup: #eda100;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255,255,255,0.10); --accent: #f0efec; --accent-ink: #0d0d0d; --gold: #d9a940;
    --good: #0ca30c; --bad: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --other: #5c5b56; --deduct: #4a4a46; --recoup: #c98500;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255,255,255,0.10); --accent: #f0efec; --accent-ink: #0d0d0d; --gold: #d9a940;
  --good: #0ca30c; --bad: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --other: #5c5b56; --deduct: #4a4a46; --recoup: #c98500;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.boot { padding: 80px; text-align: center; color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -2px; }
.topbar .spacer { flex: 1; }
.who { text-align: right; font-size: 13px; color: var(--ink-2); }
.who b { display: block; color: var(--ink); font-size: 14px; }

/* ---------- Layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 28px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 30px; letter-spacing: -.025em; line-height: 1.15; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
select, input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; min-width: 0; outline: none;
}
select:focus, input:focus { border-color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; min-width: 0;
}
.card h2 { margin: 0 0 2px; font-size: 16px; letter-spacing: -.01em; }
.card .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.mt { margin-top: 16px; }

/* ---------- Stat tiles ---------- */
.tile .lbl { font-size: 13px; color: var(--ink-2); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.tile .val { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: 6px; line-height: 1.1; }
.tile .hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.tile.hero { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tile.hero .lbl, .tile.hero .hint { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, #eda100 18%, transparent); color: #8a5d00; }
:root[data-theme="dark"] .pill.warn { color: #eda100; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.warn { color: #eda100; } }
.pill.off { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

/* split bar */
.split { margin-top: 18px; }
.split-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; background: var(--surface); }
.split-bar span { display: block; height: 100%; }
.split-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.split-legend b { color: var(--ink); }

/* balance */
.balance-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.balance-row:last-child { border-bottom: 0; }
.balance-row.total { font-weight: 700; font-size: 16px; padding-top: 12px; }

/* charts */
.chart-box { position: relative; height: 320px; }
.chart-box.sm { height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.strong { font-weight: 600; }
.t-title { font-weight: 600; }
.t-meta { font-size: 12px; color: var(--muted); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.mini-bar { height: 6px; border-radius: 3px; background: var(--s1); }

.note { font-size: 13px; color: var(--muted); margin-top: 18px; line-height: 1.6; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art {
  background: #0d0d0d; color: #f0efec; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art h1 { font-size: 44px; line-height: 1.05; letter-spacing: -.035em; margin: 0 0 16px; max-width: 12ch; }
.auth-art p { color: #c3c2b7; max-width: 42ch; font-size: 16px; }
.auth-art .bars { position: absolute; right: -10px; bottom: 0; display: flex; align-items: flex-end; gap: 6px; height: 60%; opacity: .9; }
.auth-art .bars i { width: 22px; border-radius: 6px 6px 0 0; display: block; }
.auth-art .brand .mark { background: #f0efec; color: #0d0d0d; }
.auth-art .brand small { color: #898781; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--page); }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h2 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 6px; }
.auth-box p.lead { color: var(--ink-2); margin: 0 0 24px; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; }
.auth-box input { width: 100%; padding: 11px 13px; }
.auth-box .btn { width: 100%; padding: 11px; }
.auth-switch { margin-top: 18px; font-size: 14px; color: var(--ink-2); text-align: center; }
.auth-switch a { font-weight: 600; cursor: pointer; text-decoration: underline; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.tabs .count { margin-left: 6px; }
.drop {
  display: block;
  border: 1.5px dashed var(--axis); border-radius: var(--radius); padding: 34px; text-align: center; color: var(--ink-2);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--ink); background: var(--surface-2); }
.drop b { color: var(--ink); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.banner {
  display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  background: color-mix(in srgb, var(--s4) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--s4) 40%, transparent);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; font-size: 14px;
}

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; padding: 24px; border: 1px solid var(--border); }
.modal h3 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.02em; }
.modal .sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.map-row { display: grid; grid-template-columns: 1fr 110px 36px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.map-row input { width: 100%; text-align: right; }
.pct-wrap { display: flex; align-items: center; gap: 4px; }
.suggest { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 8px; }
.suggest div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--border); }
.suggest div:hover { background: var(--surface-2); }
.suggest div:last-child { border-bottom: 0; }
.section-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 18px 0 6px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { flex: 1; min-width: 140px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); padding: 10px 18px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }

/* recoup / contracts */
.contracts-mini { display: grid; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.contracts-mini > div { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.recoup-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.recoup { border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.recoup .table-wrap { margin: 0; padding: 0; }
.contract-card, .grid > * { min-width: 0; }
.recoup-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--recoup); border-radius: 5px; }
table.compact td { padding: 6px 10px; font-size: 13px; }
.kpill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; }
.kpill.pub { background: color-mix(in srgb, var(--s7) 16%, transparent); color: var(--s7); }
.contract-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: grid; gap: 10px; }
.contract-card .row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.item-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 8px; padding: 3px 9px; font-size: 13px; }
.cost-row, .item-row { display: grid; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.item-row { grid-template-columns: minmax(0,1fr) 120px 36px; }
.cost-row { grid-template-columns: 150px minmax(0,1fr) 120px 140px 36px; }
.cost-row input, .cost-row select, .item-row input { width: 100%; }
.map-grid { display: grid; grid-template-columns: 220px minmax(0,1fr); gap: 8px 12px; align-items: center; }
.map-grid label { font-size: 14px; }
.map-grid select { width: 100%; }
.sample { font-size: 12px; }
.sample td, .sample th { padding: 5px 8px; white-space: nowrap; }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); cursor: pointer; font-size: 14px; margin-bottom: 8px; background: none; border: 0; padding: 0; }
.result-list { display: grid; gap: 6px; font-size: 14px; }
.result-list div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .g-3, .g-2 { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: 1fr; }
  .auth-art { min-height: 260px; padding: 28px 16px; }
  .auth-art h1 { font-size: 32px; }
  .auth-art .bars { height: 45%; opacity: .35; }
}
@media (max-width: 560px) {
  .wrap { padding: 18px 16px; }
  .topbar { padding: 12px 16px; }
  .who { display: none; }
  .g-4 { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 24px; }
  .tile .val { font-size: 26px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .filters { width: 100%; }
  .filters .field { flex: 1; min-width: 0; }
  .filters select { width: 100%; }
  .chart-box { height: 280px; }
  .brand small { display: none; }
  .table-wrap table { min-width: 560px; }
  .table-wrap table.compact { min-width: 0; }
  .filters .field:last-child:not(:first-child) { flex-basis: 100%; }
  .filters .btn { width: 100%; }
  .cost-row { grid-template-columns: 1fr 1fr; }
  .map-grid { grid-template-columns: 1fr; }
}
table.compact td.t-meta { white-space: nowrap; }
.ftp-path { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.ftp-path code { font-size: 13px; word-break: break-all; flex: 1; min-width: 0; }
.result-list .progress { height: 6px; }
.lead-row { display: flex; gap: 16px; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.lead-row:last-child { border-bottom: 0; }
.lead-main { flex: 1; min-width: 240px; }
.lead-msg { margin: 6px 0; font-size: 14px; white-space: pre-wrap; }
.lead-side { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.lead-side select { padding: 5px 8px; font-size: 13px; }
.lang-pick { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.lang-pick button { border: 0; background: transparent; padding: 4px 9px; border-radius: 7px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.lang-pick button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.auth-lang { display: flex; justify-content: flex-end; margin-bottom: 26px; }
.svc-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.svc { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.svc p { margin: 0 0 6px; font-size: 13px; color: var(--ink-2); }
.svc .btn { justify-self: start; }
@media (max-width: 980px) { .svc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .svc-grid { grid-template-columns: 1fr; } .topbar .lang-pick button { padding: 4px 6px; } }
.own-auth { font-size: 12.5px !important; color: #898781 !important; max-width: 46ch; margin-top: 28px; line-height: 1.55; }
.own-note { border-top: 1px solid var(--border); padding-top: 14px; }
.split-example { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; font-size: 13.5px; color: var(--ink-2); }
.srow { display: grid; grid-template-columns: minmax(0, 1.6fr) 130px 120px 150px 36px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.srow.shead { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.srow select, .srow input { width: 100%; }
.split-sum { margin-top: 14px; font-size: 14px; color: var(--ink-2); }
.item-row { grid-template-columns: minmax(0,1fr) 150px 120px 36px; }
@media (max-width: 700px) { .srow { grid-template-columns: 1fr 1fr; } .srow.shead { display: none; } .item-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .brand { min-width: 0; flex: 1 1 auto; font-size: 14px; }
  .brand > div:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .spacer { display: none; }
}
