:root {
  --bg: #f7f7f9; --bg-card: #ffffff; --bg-soft: #f1f1f4; --bg-hover: #f4f4f7;
  --text: #17171c; --text-2: #3d3d47; --muted: #75757f; --line: #e7e7ec; --line-2: #d9d9e0;
  --accent: #5b4bff; --accent-soft: rgba(91, 75, 255, .1); --pill: #17171c; --pill-text: #fff;
  --ok: #138a52; --ok-soft: rgba(19, 138, 82, .1); --warn: #a8650a; --warn-soft: rgba(196, 122, 10, .12);
  --err: #c0303a; --err-soft: rgba(192, 48, 58, .1); --info: #2f6fd6; --info-soft: rgba(47, 111, 214, .1);
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 1px 1px rgba(20, 20, 30, .03);
  --shadow-lg: 0 24px 64px rgba(20, 20, 30, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e11; --bg-card: #16161b; --bg-soft: #1d1d23; --bg-hover: #1b1b21;
    --text: #f2f2f5; --text-2: #c9c9d1; --muted: #8b8b96; --line: #26262e; --line-2: #33333d;
    --accent: #8f84ff; --accent-soft: rgba(143, 132, 255, .14); --pill: #f2f2f5; --pill-text: #0e0e11;
    --ok: #3fc58a; --ok-soft: rgba(63, 197, 138, .12); --warn: #e3a54a; --warn-soft: rgba(227, 165, 74, .12);
    --err: #f06470; --err-soft: rgba(240, 100, 112, .12); --info: #6ea2ff; --info-soft: rgba(110, 162, 255, .12);
    --shadow: none; --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e11; --bg-card: #16161b; --bg-soft: #1d1d23; --bg-hover: #1b1b21;
  --text: #f2f2f5; --text-2: #c9c9d1; --muted: #8b8b96; --line: #26262e; --line-2: #33333d;
  --accent: #8f84ff; --accent-soft: rgba(143, 132, 255, .14); --pill: #f2f2f5; --pill-text: #0e0e11;
  --ok: #3fc58a; --ok-soft: rgba(63, 197, 138, .12); --warn: #e3a54a; --warn-soft: rgba(227, 165, 74, .12);
  --err: #f06470; --err-soft: rgba(240, 100, 112, .12); --info: #6ea2ff; --info-soft: rgba(110, 162, 255, .12);
  --shadow: none; --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Figtree, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 24px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
[hidden] { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--bg-card); }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 18px; font-weight: 600; font-size: 16px; }
.brand img { width: 26px; height: auto; }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: auto; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text-2); }
.nav a:hover { background: var(--bg-hover); color: var(--text); }
.nav a.on { background: var(--bg-soft); color: var(--text); font-weight: 500; }
.nav svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; line-height: 18px; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.who { display: flex; flex-direction: column; font-size: 13px; min-width: 0; }
.who span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.side-actions { display: flex; gap: 6px; }
.main { min-width: 0; padding: 28px 36px 64px; max-width: 1240px; }
.topbar { display: none; }

/* Page header */
.ph { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.ph p { margin: 4px 0 0; color: var(--muted); }
.ph .crumbs { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.ph .crumbs a:hover { color: var(--text); }
.ph-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--bg-card); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 13px; white-space: nowrap; box-shadow: var(--shadow); }
.btn:hover { background: var(--bg-hover); }
.btn.dark { background: var(--pill); color: var(--pill-text); border-color: var(--pill); }
.btn.dark:hover { opacity: .9; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--bg-hover); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-card); cursor: pointer; }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* Cards and tiles */
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 14px; }
.card-h .muted { font-size: 12px; }
.card-b { padding: 16px 18px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.g-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.tile { padding: 16px 18px; }
.tile .k { color: var(--muted); font-size: 12.5px; }
.tile .v { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile .s.bad { color: var(--err); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tr.link { cursor: pointer; }
.t tr.link:hover td { background: var(--bg-hover); }
.t .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.t .nowrap { white-space: nowrap; }
.t .sub { color: var(--muted); font-size: 12px; }
.t .actions { text-align: right; white-space: nowrap; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--bg-soft); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.plain::before { display: none; }

/* Toolbar, tabs */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; max-width: 360px; position: relative; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--muted); fill: none; stroke-width: 1.8; }
.seg { display: inline-flex; background: var(--bg-soft); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button.on { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

/* Forms */
input, select, textarea { background: var(--bg-card); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 11px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.form-err { color: var(--err); font-size: 13px; min-height: 0; }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; }

/* Key-value */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 14, .45); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .12s ease-out; }
.modal { background: var(--bg-card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(640px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal.wide { width: min(980px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-b { padding: 18px 20px; overflow-y: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); align-items: center; }
.modal-f .form-err { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--pill); color: var(--pill-text); padding: 9px 18px; border-radius: 999px; font-size: 13px; z-index: 60; box-shadow: var(--shadow-lg); animation: fade .15s; }
.toast.err { background: var(--err); color: #fff; }

/* Lists */
.list { display: flex; flex-direction: column; }
.li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .sub { color: var(--muted); font-size: 12.5px; }
.li.link { cursor: pointer; } .li.link:hover { background: var(--bg-hover); }
.task-done .title { text-decoration: line-through; color: var(--muted); }
.muted { color: var(--muted); }
.bad { color: var(--err); }
.good { color: var(--ok); }
.msg { white-space: pre-wrap; color: var(--text-2); margin-top: 6px; font-size: 13px; }
.note { background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.note.info { background: var(--info-soft); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.bar-row:last-child { border-bottom: 0; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--bg-soft); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Invoice editor */
.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 6px 6px; }
.lines td { padding: 4px 6px; vertical-align: top; }
.lines input, .lines select { padding: 7px 9px; }
.lines .num { width: 90px; } .lines .rate { width: 80px; } .lines .amt { width: 130px; text-align: right; padding-top: 12px; font-variant-numeric: tabular-nums; }
.totals { margin-left: auto; width: 300px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 1px solid var(--line-2); margin-top: 6px; padding-top: 10px; font-weight: 600; font-size: 16px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.login::before { content: ""; position: absolute; width: 900px; height: 600px; left: 50%; top: -260px; transform: translateX(-50%); background: radial-gradient(closest-side, rgba(124, 92, 255, .22), transparent 70%), radial-gradient(closest-side at 70% 60%, rgba(56, 132, 255, .18), transparent 70%); pointer-events: none; }
.login-card { position: relative; width: min(400px, 100%); padding: 32px; text-align: center; }
.login-card img { width: 44px; }
.login-card h1 { margin-top: 14px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 6px 0 24px; }
#g-btn { display: flex; justify-content: center; min-height: 44px; }
.dev-login { margin-top: 18px; display: flex; gap: 8px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: 1fr 1fr; } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  .shell.nav-open .side { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg-card); position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; }
  .main { padding: 20px 16px 48px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .t .hide-sm { display: none; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr 1fr; } .tile .v { font-size: 18px; } .totals { width: 100%; } }
