:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e3e3df;
  --border-strong: #cfcfc9;
  --text: #1c1c1a;
  --muted: #6d6d66;
  --accent: #1f4fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1f7a46;
  --ok-soft: #e6f4ec;
  --warn: #a15c00;
  --warn-soft: #fdf1df;
  --sidebar: #141413;
  --sidebar-text: #c9c9c2;
  --sidebar-active: #ffffff;
  --bar-a: #c3cde6;
  --bar-b: #1f4fd6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1b1b19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --border-strong: #3b3b37;
    --text: #ececE8;
    --muted: #9b9b93;
    --accent: #7c9cff;
    --accent-ink: #0d1230;
    --accent-soft: #1e2647;
    --danger: #ff8a7d;
    --danger-soft: #3a1714;
    --ok: #6fd39a;
    --ok-soft: #14301f;
    --warn: #f3b562;
    --warn-soft: #36250d;
    --sidebar: #0b0b0a;
    --bar-a: #34405f;
    --bar-b: #7c9cff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-feature-settings: "tnum" 1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin-bottom: 12px; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 20px; }
.pad { padding: 20px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: #fff; text-decoration: none !important; }
.brand-mark { background: #fff; color: #111; font-weight: 800; font-size: 12px; padding: 5px 7px; border-radius: 6px; letter-spacing: .02em; }
.brand-text { font-weight: 650; font-size: 15px; }
.sidebar nav, .sidebar-foot { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .sidebar-foot a, .sidebar-foot .linklike {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none; font-size: 14px; background: none; border: 0; width: 100%; cursor: pointer; font-family: inherit;
}
.sidebar nav a:hover, .sidebar-foot a:hover, .sidebar-foot .linklike:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active, .sidebar-foot a.active { background: rgba(255,255,255,.1); color: var(--sidebar-active); }
.sidebar-actions { display: flex; flex-direction: column; gap: 6px; padding: 0 2px; }
.sidebar-actions .btn:not(.btn-primary) { background: transparent; color: var(--sidebar-text); border-color: #34342f; }
.sidebar-foot { margin-top: auto; }
.sidebar-foot form { margin: 0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-weight: 650; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-search input { width: 240px; }
.menu-toggle { display: none; }
.content { padding: 24px 28px 60px; max-width: 1320px; width: 100%; }

/* ---------- controls ---------- */
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 38px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none !important; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 6px; cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.check-inline { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.check-inline input { margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.fieldset legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.code-input { font-size: 22px; letter-spacing: .3em; text-align: center; font-family: ui-monospace, Consolas, monospace; }

/* ---------- layout pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 40px 20px; }
.card.highlight { border-color: var(--accent); background: var(--accent-soft); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 18px; }
.grid-2 > *, .grid-form > *, .doc-layout > * { min-width: 0; }
.card { overflow-x: auto; }
.grid-form { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; align-items: start; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; align-items: center; }
.page-actions.wrap { flex-wrap: wrap; }
.eyebrow { font-size: 12.5px; margin-bottom: 4px; }
.inline-search { display: flex; gap: 12px; align-items: center; }
.inline-search input[type=search] { width: 260px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tab { padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13.5px; text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: var(--accent-soft); color: var(--accent); }

/* ---------- KPIs and chart ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; color: var(--text); text-decoration: none !important; box-shadow: var(--shadow); }
.kpi:hover { border-color: var(--border-strong); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }
.kpi-warn .kpi-value { color: var(--warn); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.sw-a { background: var(--bar-a); } .sw-b { background: var(--bar-b); }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; height: 180px; align-items: end; padding-top: 8px; }
.bar-group { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-a { background: var(--bar-a); } .bar-b { background: var(--bar-b); }
.bar-label { font-size: 11.5px; color: var(--muted); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; background: var(--surface-2); }
.table th.num { text-align: right; }
.table.compact td { padding: 8px 10px; }
.table.compact th { padding: 8px 10px; }
.card:not(.flush) .table.compact td:first-child, .card:not(.flush) .table.compact th:first-child { padding-left: 0; }
.card:not(.flush) .table.compact td:last-child, .card:not(.flush) .table.compact th:last-child { padding-right: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.check { width: 36px; }
.table-scroll { overflow-x: auto; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-paid, .pill-accepted, .pill-issued { background: var(--ok-soft); color: var(--ok); }
.pill-sent, .pill-invoiced { background: var(--accent-soft); color: var(--accent); }
.pill-partial { background: var(--warn-soft); color: var(--warn); }
.pill-overdue, .pill-declined { background: var(--danger-soft); color: var(--danger); }
.pill-void, .pill-expired { text-decoration: line-through; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
.tag-api { color: var(--accent); }

.bulk-bar { position: sticky; bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.bulk-bar label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.bulk-bar input[type=date], .bulk-bar select { width: auto; min-height: 34px; }

/* ---------- document editor ---------- */
.items-table .col-desc { width: auto; min-width: 260px; }
.items-table .col-qty { width: 80px; }
.items-table .col-unit { width: 140px; }
.items-table .col-disc { width: 80px; display: none; }
.items-table.show-discount .col-disc { display: table-cell; }
.items-table .col-amount { width: 140px; font-weight: 600; }
.items-table .col-rm { width: 40px; }
.items-table td { vertical-align: top; padding: 8px 6px; }
.items-table th { padding: 8px 6px; }
.items-table input { text-align: right; }
.items-table td.col-amount { padding-top: 16px; }
.items-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-top: 12px; }
.totals { margin: 0; min-width: 260px; }
.totals div { display: flex; justify-content: space-between; gap: 20px; padding: 4px 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--border-strong); margin-top: 4px; padding-top: 8px; font-size: 17px; font-weight: 700; }
.totals .grand dt { color: var(--text); }

/* ---------- document view ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.doc-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.paper-frame { width: 100%; min-height: 900px; border: 0; background: #fff; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,.08); display: block; }
.small-preview .paper-frame { min-height: 600px; }
.kv { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv .strong dt, .kv .strong dd { color: var(--text); font-weight: 700; font-size: 16px; }
.kv.stacked div { flex-direction: column; gap: 0; }
.kv.stacked dd { text-align: left; }
.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-list form { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.list li { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.qr { width: 180px; height: 180px; background: #fff; padding: 6px; border-radius: 8px; display: block; margin: 8px 0; }
.copy-row { display: flex; gap: 8px; margin: 10px 0 14px; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

/* ---------- auth pages ---------- */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-wrap { width: 100%; max-width: 380px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.brand-center { justify-content: center; margin-bottom: 18px; color: var(--text); }
.brand-center .brand-mark { background: var(--text); color: var(--surface); }
.auth-title { font-size: 20px; margin-bottom: 14px; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .doc-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar-search { display: none; }
  .content { padding: 16px 16px 60px; }
  .grid-2, .grid-form, .row-3 { grid-template-columns: 1fr; }
  .table th, .table td { padding: 9px 10px; }
  .truncate { max-width: 140px; }
  .card.flush { overflow-x: auto; }
  .inline-search input[type=search] { width: 100%; }
  .page-actions { flex-wrap: wrap; }
  .paper-frame { min-height: 700px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .row-2 { grid-template-columns: 1fr; }
  .bars { gap: 4px; }
  .items-foot { flex-direction: column; }
  .totals { min-width: 0; width: 100%; }
}

/* ---------- personal money ---------- */
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d7d75; padding: 6px 10px 4px; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.dim td, .dim { opacity: .55; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav .icon-btn { font-size: 22px; line-height: 1; padding: 2px 10px; text-decoration: none !important; color: var(--text); }
.month-nav .disabled { opacity: .3; cursor: default; }
.month-label { font-size: 20px; font-weight: 650; min-width: 170px; text-align: center; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; flex: none; }
.cat-chip { display: inline-flex; align-items: center; font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap; text-decoration: none !important; }
.cat-chip.big { font-size: 13px; padding: 5px 12px; gap: 4px; border: 1px solid var(--border); }
.cat-chip.big strong { margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.cat-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.cat-bars a { display: flex; justify-content: space-between; gap: 10px; color: var(--text); text-decoration: none !important; margin-bottom: 4px; font-size: 13.5px; }
.cat-name { display: inline-flex; align-items: center; }
.cat-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-track { display: block; height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.cat-track span { display: block; height: 100%; border-radius: 4px; }
.big-figure { font-size: 26px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.02em; }
.subhead { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 0 6px; }
.sw-in { background: var(--ok); } .sw-out { background: var(--bar-a); }
.bar-in { background: var(--ok); } .bar-out { background: var(--bar-a); }
a.bar-group { text-decoration: none !important; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; }
.filters input[type=search] { width: 240px; }
.filters select { width: auto; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; align-self: flex-start; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 6px 14px; border-radius: 7px; font-weight: 550; font-size: 13.5px; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.progress { display: block; height: 8px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.progress span { display: block; height: 100%; background: var(--ok); border-radius: 5px; }
.progress.tall { height: 12px; }
.goal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.goal-row { display: flex; justify-content: space-between; gap: 10px; color: var(--text); text-decoration: none !important; }
.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.goal-card { display: block; color: var(--text); text-decoration: none !important; margin: 0; }
a.goal-card:hover { border-color: var(--border-strong); }
.goal-name { font-weight: 600; margin-bottom: 6px; }
.goal-balance { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.goal-balance.big { font-size: 32px; }
.new-goal { grid-row: span 2; }
.danger-zone { margin-top: 8px; }
@media (max-width: 860px) {
  .kpis-3 { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
  .month-label { min-width: 0; font-size: 18px; }
}
.cat-table td { padding: 6px 12px; }
.cat-edit { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cat-edit input[type=text] { flex: 1; min-width: 160px; min-height: 34px; }
.cat-edit select { width: auto; min-height: 34px; }
input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }
