:root {
  /* Layout idea: dark ink rail on the left, calm working surface on the right, one blue for actions, status colours kept separate. */
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --line: #dde2ea;
  --ink: #17202e;
  --ink-2: #485468;
  --ink-3: #738095;
  --accent: #2347c5;
  --accent-ink: #ffffff;
  --accent-soft: #e7ecfb;
  --nav-bg: #121a2a;
  --nav-ink: #c5cedd;
  --nav-active: #24314d;
  --good: #1a7a48;
  --good-soft: #e1f3e8;
  --warn: #8a5d00;
  --warn-soft: #fff1c9;
  --bad: #b93228;
  --bad-soft: #fce6e3;
  --shadow: 0 1px 2px rgba(18, 26, 42, 0.06), 0 4px 14px rgba(18, 26, 42, 0.05);
  --font-display: 'Archivo', 'Segoe UI', Arial, sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e131c; --surface: #171e2b; --surface-2: #1c2433; --line: #2b3548;
    --ink: #e8edf4; --ink-2: #b5bfce; --ink-3: #8794a8;
    --accent: #7d9bf7; --accent-ink: #0e131c; --accent-soft: #1f2b4d;
    --nav-bg: #0a0f17; --nav-ink: #b9c3d3; --nav-active: #1c2740;
    --good: #55c790; --good-soft: #143424; --warn: #e5b84a; --warn-soft: #3a2e0e; --bad: #f2837a; --bad-soft: #41211e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e131c; --surface: #171e2b; --surface-2: #1c2433; --line: #2b3548;
  --ink: #e8edf4; --ink-2: #b5bfce; --ink-3: #8794a8;
  --accent: #7d9bf7; --accent-ink: #0e131c; --accent-soft: #1f2b4d;
  --nav-bg: #0a0f17; --nav-ink: #b9c3d3; --nav-active: #1c2740;
  --good: #55c790; --good-soft: #143424; --warn: #e5b84a; --warn-soft: #3a2e0e; --bad: #f2837a; --bad-soft: #41211e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: 228px 1fr; height: 100%; }
.nav { background: var(--nav-bg); color: var(--nav-ink); display: flex; flex-direction: column; overflow-y: auto; }
.brand { padding: 18px 18px 14px; font-family: var(--font-display); font-weight: 700; font-size: 16px; color: #fff; letter-spacing: 0.01em; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-size: 14px; flex: none; }
.nav-group { padding: 10px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #6f7c93; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: var(--nav-ink); border-left: 3px solid transparent; font-weight: 500; }
.nav a:hover { background: var(--nav-active); text-decoration: none; color: #fff; }
.nav a.on { background: var(--nav-active); color: #fff; border-left-color: #7d9bf7; }
.nav a .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.nav svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #6f7c93; }
.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 22px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.topbar .spacer { flex: 1; }
.btn.burger { display: none; }
.page { padding: 22px; overflow-y: auto; flex: 1; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.demo-bar { background: var(--warn-soft); color: var(--warn); padding: 6px 22px; font-size: 12.5px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; flex: none; }
.demo-bar button { margin-left: auto; }

/* Controls */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
input[type=file] { padding: 6px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
label.f .hint { font-weight: 400; color: var(--ink-3); }
label.check { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; }
.toolbar .search { flex: 1 1 220px; min-width: 180px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: none; border-bottom: 2px solid transparent; padding: 9px 14px; color: var(--ink-3); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi .value { font-family: var(--font-display); font-size: 25px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.kpi .up { color: var(--good); font-weight: 600; }
.kpi .down { color: var(--bad); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td:first-child { min-width: 170px; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl th.num { text-align: right; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 34px 18px; text-align: center; color: var(--ink-3); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; object-fit: cover; flex: none; overflow: hidden; }
.avatar.lg { width: 84px; height: 84px; font-size: 28px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-chip { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; }
.user-chip:hover { text-decoration: none; }
.user-chip .role { font-size: 11.5px; font-weight: 500; color: var(--ink-3); display: block; }
.bell { position: relative; }
.bell .dot { position: absolute; top: -5px; right: -5px; background: var(--bad); color: #fff; border-radius: 10px; font-size: 10.5px; padding: 0 5px; line-height: 16px; }
.level { width: 110px; height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; position: relative; overflow: visible; }
.level i { display: block; height: 100%; border-radius: 4px; background: var(--good); }
.level.low i { background: var(--bad); }
.level b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-3); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.stripe { width: 4px; align-self: stretch; border-radius: 3px; background: var(--warn); flex: none; }
.stripe.bad { background: var(--bad); }
.logo-box { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--line); display: grid; place-items: center; background: #fff; overflow: hidden; font-family: var(--font-display); font-weight: 700; color: #17202e; flex: none; }
.logo-box img { max-width: 100%; max-height: 100%; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.person { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.person .top { display: flex; gap: 12px; align-items: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }

/* Charts */
.chart { width: 100%; display: block; }
.chart text { font-family: var(--font-body); font-size: 11px; fill: var(--ink-3); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover, .chart .bar.hot { filter: brightness(1.2); }
.chart .val { fill: var(--ink); font-weight: 600; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 10px; border-radius: 0 4px 4px 0; background: var(--surface-2); }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.tip { position: fixed; z-index: 60; background: var(--ink); color: var(--surface); padding: 6px 10px; border-radius: 7px; font-size: 12px; pointer-events: none; box-shadow: var(--shadow); }

/* Modal and toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 23, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 40; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 860px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 70; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: var(--surface); padding: 11px 15px; border-radius: 9px; box-shadow: var(--shadow); font-weight: 500; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
.note { background: var(--accent-soft); color: var(--ink); border-radius: 9px; padding: 10px 14px; font-size: 13px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--nav-bg); }
.login .card { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.demo-users { display: flex; flex-direction: column; gap: 8px; }

/* Document editor */
.line-table input, .line-table select { padding: 6px 8px; }
.line-table td { padding: 8px 8px; }
.line-table .qty { width: 78px; }
.line-table .price { width: 98px; }
.line-table .disc { display: flex; gap: 4px; }
.line-table .disc select { width: 58px; }
.line-table .disc input { width: 82px; }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; margin-top: 4px; }
.picker-list button { display: flex; width: 100%; gap: 10px; text-align: left; font: inherit; color: var(--ink); background: none; border: none; border-bottom: 1px solid var(--line); padding: 9px 12px; cursor: pointer; }
.picker-list button:hover { background: var(--surface-2); }
.totals { margin-left: auto; width: min(340px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; }
.totals .grand { font-family: var(--font-display); font-size: 18px; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 8px; }

/* Invoice paper: fixed colours, it is a printed document */
.paper { background: #fff; color: #151b26; border: 1px solid #d9dee6; border-radius: 6px; padding: 38px 40px; max-width: 860px; position: relative; font-size: 13px; overflow: hidden; }
.paper h1 { font-size: 26px; color: #151b26; letter-spacing: 0.02em; }
.paper .p-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.paper .p-logo { max-height: 70px; max-width: 220px; }
.paper .p-mono { font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.paper .p-meta { text-align: right; }
.paper .p-grey { color: #5a6577; }
.paper .p-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 26px 0 18px; }
.paper .p-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #5a6577; font-weight: 700; margin-bottom: 4px; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; text-align: left; padding: 8px 8px; border-bottom: 2px solid #151b26; color: #151b26; }
.paper td { padding: 8px 8px; border-bottom: 1px solid #e3e7ee; vertical-align: top; }
.paper .p-totals { margin-left: auto; width: 290px; max-width: 100%; margin-top: 14px; display: grid; grid-template-columns: 1fr auto; gap: 5px 16px; }
.paper .p-grand { font-weight: 700; font-size: 16px; border-top: 2px solid #151b26; padding-top: 7px; }
.paper .p-foot { margin-top: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.paper .p-sign img { max-height: 90px; border-bottom: 1px solid #151b26; display: block; }
.paper .p-legal { margin-top: 26px; padding-top: 12px; border-top: 1px solid #e3e7ee; font-size: 11px; color: #5a6577; text-align: center; }
.paper .stamp { position: absolute; top: 120px; right: 30px; transform: rotate(-12deg); border: 4px solid #b93228; color: #b93228; font-family: var(--font-display); font-weight: 700; font-size: 34px; padding: 4px 18px; border-radius: 8px; opacity: 0.75; letter-spacing: 0.08em; }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.doc-side { display: flex; flex-direction: column; gap: 14px; }
.doc-side .btn { justify-content: center; }
.sig-pad { width: 100%; height: 220px; background: #fff; border: 2px dashed #9aa5b5; border-radius: 10px; touch-action: none; display: block; cursor: crosshair; }

@media (max-width: 1000px) {
  .grid.two, .grid.side, .doc-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 30; transform: translateX(-100%); transition: transform 0.18s ease; }
  .nav.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 15, 23, 0.5); }
  .btn.burger { display: inline-flex; }
  .demo-bar span { display: none; }
  .page { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
  .paper { padding: 22px 18px; }
  .paper .p-cols, .paper .p-foot { grid-template-columns: 1fr; }
  .user-chip .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  body { background: #fff; }
  .nav, .topbar, .demo-bar, .doc-side, .page-head, .toasts { display: none !important; }
  .shell, .main, .page { display: block; height: auto; overflow: visible; padding: 0; }
  .doc-layout { display: block; }
  .paper { border: none; max-width: none; padding: 0; }
  .paper .p-cols, .paper .p-foot { grid-template-columns: 1fr 1fr; }
  @page { margin: 14mm; }
}
