/* ---------- Tokens ---------- */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f4;
  --text: #0a0a0a;
  --muted: #6b6b6b;
  --border: #e7e7e7;
  --border-strong: #d4d4d4;
  --accent: #0a0a0a;
  --accent-fg: #ffffff;
  --hover: #f1f1f1;
  --ok: #15803d;     --ok-bg: #ecf7ef;
  --warn: #a15c07;   --warn-bg: #fdf4e3;
  --bad: #b91c1c;    --bad-bg: #fcebeb;
  --info: #404040;   --info-bg: #efefef;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0a0a; --surface: #141414; --surface-2: #1b1b1b;
    --text: #f2f2f2; --muted: #9a9a9a; --border: #262626; --border-strong: #333;
    --accent: #f2f2f2; --accent-fg: #0a0a0a; --hover: #1e1e1e;
    --ok: #5fcf86; --ok-bg: #11251a; --warn: #e7b25a; --warn-bg: #2a2010;
    --bad: #f07a7a; --bad-bg: #2c1414; --info: #c8c8c8; --info-bg: #222;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0a0a; --surface: #141414; --surface-2: #1b1b1b;
  --text: #f2f2f2; --muted: #9a9a9a; --border: #262626; --border-strong: #333;
  --accent: #f2f2f2; --accent-fg: #0a0a0a; --hover: #1e1e1e;
  --ok: #5fcf86; --ok-bg: #11251a; --warn: #e7b25a; --warn-bg: #2a2010;
  --bad: #f07a7a; --bad-bg: #2c1414; --info: #c8c8c8; --info-bg: #222;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.4);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; padding: 4px 8px 16px; }
.brand img { border-radius: 7px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500;
}
.side-nav a:hover { background: var(--hover); color: var(--text); }
.side-nav a.active { background: var(--accent); color: var(--accent-fg); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.demo-banner {
  font-size: 12.5px; color: var(--muted); text-align: center;
  padding: 6px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
#view { width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 32px 48px; outline: none; }
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0; font-size: 16px; }
  .topbar-actions { display: flex; gap: 4px; }
  #view { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--border);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 0; font-size: 11px; font-weight: 500; color: var(--muted); border-radius: 10px;
  }
  .bottom-nav a svg.i { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--text); }
  .bottom-nav a.active svg.i { stroke-width: 2.3; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.back:hover { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); opacity: .86; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); justify-content: flex-start; }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-solid:hover { background: var(--bad); opacity: .88; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-head a { font-size: 13px; color: var(--muted); }
.card-head a:hover { color: var(--text); }
.card-body { padding: 16px 18px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 420px) { .stat .value { font-size: 22px; } .stat { padding: 14px; } }

/* ---------- Badges, chips, progress ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--info-bg); color: var(--info);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.plain { background: transparent; border: 1px solid var(--border-strong); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 550; cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip .count { opacity: .6; margin-left: 4px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 80px; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--text); border-radius: 99px; }
.avatars { display: flex; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 650; background: var(--surface-2); color: var(--text);
  border: 2px solid var(--surface); margin-left: -6px;
}
.avatars .avatar:first-child { margin-left: 0; }
.avatar.lg { width: 38px; height: 38px; font-size: 13px; margin: 0; border: 1px solid var(--border); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; flex: 0 1 280px; }
.search svg.i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 34px; }
@media (max-width: 640px) { .search { flex: 1 1 100%; } }

/* ---------- Lists (tables that collapse on mobile) ---------- */
.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 18px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.list td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr[data-href], .list tbody tr[data-action] { cursor: pointer; }
.list tbody tr[data-href]:hover, .list tbody tr[data-action]:hover { background: var(--hover); }
.list .t { font-weight: 550; }
.list .s { font-size: 13px; color: var(--muted); }
.list .end { text-align: right; }
.list .shrink { width: 1%; white-space: nowrap; }
@media (max-width: 720px) {
  .list thead { display: none; }
  .list, .list tbody { display: block; width: 100%; }
  .list tr { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .list tr:last-child { border-bottom: 0; }
  .list td { padding: 0; border: 0; width: auto !important; flex: none; }
  .list td:first-child { flex: 1 1 auto; min-width: 0; }
  .list .sm-hide { display: none; }
  .list .t, .list .s { overflow: hidden; text-overflow: ellipsis; }
}
@media (min-width: 721px) { .list .sm-only { display: none; } }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg.i { width: 32px; height: 32px; margin-bottom: 8px; stroke-width: 1.4; }
.empty p { margin: 0 0 14px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 550; }
.field > small { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); outline: none;
}
textarea.input { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 12%, transparent); }
.req::after { content: " *"; color: var(--muted); }
.check-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; pointer-events: none; }
.check-pill span {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px 0 4px; border-radius: 999px;
  border: 1px solid var(--border-strong); cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.check-pill span .avatar { width: 26px; height: 26px; margin: 0; border: 0; }
.check-pill input:checked + span { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.check-pill input:checked + span .avatar { background: var(--accent-fg); color: var(--accent); }
.check-pill input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button { border: 0; background: transparent; height: 32px; padding: 0 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 550; font-size: 13.5px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Tasks ---------- */
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.task label { display: flex; align-items: center; gap: 12px; flex: 1; cursor: pointer; min-width: 0; }
.task input[type=checkbox] { appearance: none; width: 20px; height: 20px; flex: none; border-radius: 6px; border: 1.5px solid var(--border-strong); display: grid; place-items: center; cursor: pointer; margin: 0; }
.task input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.task input[type=checkbox]:checked::after { content: ""; width: 10px; height: 5px; border: 2px solid var(--accent-fg); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.task.done .task-text { color: var(--muted); text-decoration: line-through; }
.task .icon-btn { width: 30px; height: 30px; opacity: 0; }
.task:hover .icon-btn, .task .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .task .icon-btn { opacity: 1; } }
.add-task { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

/* ---------- Key/value details ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13.5px; }
.kv dd { margin: 0; text-align: right; font-weight: 500; }

/* ---------- Ready-to-invoice callout ---------- */
.callout { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.callout:last-child { border-bottom: 0; }
.callout .grow { flex: 1; min-width: 0; }
.callout .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Invoice editor ---------- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 0 6px 8px; }
.items-table td { padding: 4px 6px; vertical-align: top; }
.items-table .qty { width: 80px; }
.items-table .rate { width: 140px; }
.items-table .amt { width: 130px; text-align: right; padding-top: 12px; font-variant-numeric: tabular-nums; font-weight: 550; }
.items-table .rm { width: 40px; }
@media (max-width: 640px) {
  .items-table thead { display: none; }
  .items-table tr { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .items-table td { padding: 0; width: auto !important; }
  .items-table td.desc { grid-column: 1 / -1; }
  .items-table td.amt { grid-column: 1 / 3; text-align: left; padding: 0; }
  .items-table td.rm { grid-column: 3; grid-row: 3; }
  .items-table td.qty { grid-column: 1; }
  .items-table td.rate { grid-column: 2 / 4; }
}
.totals { margin-left: auto; width: min(340px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 18px; font-weight: 650; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }

/* ---------- Invoice document (screen + print) ---------- */
.doc {
  background: #fff; color: #111; border-radius: var(--radius); border: 1px solid var(--border);
  padding: 44px 48px; font-size: 13.5px; line-height: 1.5; position: relative; overflow: hidden;
}
.doc .muted { color: #666; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 2px solid #111; }
.doc-firm { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 22px; letter-spacing: .08em; font-weight: 700; }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin-top: 8px; justify-content: end; }
.doc-meta dt { color: #666; }
.doc-meta dd { margin: 0; font-weight: 600; text-align: right; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 22px 0; }
.doc-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #666; margin-bottom: 4px; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th { background: #f3f3f3; text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 9px 10px; border-bottom: 1px solid #ddd; }
.doc td { padding: 10px; border-bottom: 1px solid #eee; vertical-align: top; }
.doc .r { text-align: right; font-variant-numeric: tabular-nums; }
.doc-sum { display: grid; grid-template-columns: 1fr 300px; gap: 24px; margin-top: 18px; }
.doc-sum .totals { width: 100%; }
.doc-sum .grand { border-top: 2px solid #111; }
.doc-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 30px; padding-top: 18px; border-top: 1px solid #ddd; }
.doc-sign { text-align: right; align-self: end; }
.doc-sign .line { margin-top: 48px; border-top: 1px solid #999; display: inline-block; padding-top: 6px; min-width: 200px; text-align: center; }
.stamp {
  position: absolute; top: 110px; right: 40px; transform: rotate(-12deg);
  border: 3px solid #15803d; color: #15803d; padding: 4px 16px; border-radius: 8px;
  font-size: 26px; font-weight: 800; letter-spacing: .15em; opacity: .55;
}
@media (max-width: 720px) {
  .doc { padding: 22px 18px; font-size: 12.5px; border-radius: 10px; }
  .doc-head, .doc-parties, .doc-sum, .doc-foot { grid-template-columns: 1fr; display: grid; }
  .doc-title { text-align: left; }
  .doc-meta { justify-content: start; }
  .doc-meta dd { text-align: left; }
  .doc-sign { text-align: left; }
  .doc .hide-xs { display: none; }
  .stamp { top: 18px; right: 14px; font-size: 18px; }
}

/* ---------- Modal ---------- */
.modal {
  width: min(620px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
.modal[open] { display: flex; flex-direction: column; animation: pop .16s ease-out; }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body p { margin: 0; color: var(--muted); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-foot .spacer { flex: 1; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (max-width: 640px) {
  .modal:not(.modal-sm) {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh;
    border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .modal:not(.modal-sm)[open] { animation: sheet .22s ease-out; }
  .modal-foot .btn { flex: 1; }
  .modal-foot .spacer { display: none; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .4; } }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 960px) { #toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }

/* ---------- Print: only the invoice ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .sidebar, .topbar, .bottom-nav, .demo-banner, .no-print, #toast { display: none !important; }
  .app { display: block; }
  #view { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; border-radius: 0; font-size: 12px; }
  .doc-head, .doc-parties, .doc-sum, .doc-foot { display: grid; }
  .doc-head { display: flex; }
  .doc-parties, .doc-foot { grid-template-columns: 1fr 1fr; }
  .doc-sum { grid-template-columns: 1fr 300px; }
  .doc-title, .doc-meta dd, .doc-sign { text-align: right; }
  .doc-meta { justify-content: end; }
  .doc .hide-xs { display: table-cell; }
  .stamp { top: 90px; right: 20px; font-size: 26px; }
}
@media (max-width: 1100px) and (min-width: 721px) { .list .md-hide { display: none; } }

/* ---------- Users ---------- */
.user-chip {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 4px 8px 8px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.user-chip .icon-btn { width: 32px; height: 32px; }
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar svg.i { width: 18px; height: 18px; }
.top-user .avatar { width: 30px; height: 30px; font-size: 11px; }
.narrow { max-width: 620px; }

/* ---------- Powered by ---------- */
.powered {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  text-decoration: none; white-space: nowrap;
}
.powered b { font-weight: 600; color: var(--text); }
.powered img { display: block; object-fit: contain; }
.powered:hover b { text-decoration: underline; text-underline-offset: 2px; }
.powered-side { justify-content: center; padding: 10px 4px 0; margin-top: 6px; border-top: 1px solid var(--border); font-size: 11.5px; }
.powered-card { justify-content: center; padding: 8px 0; }

/* ---------- Login ---------- */
#login { display: none; }
body.logged-out .app, body.logged-out .bottom-nav { display: none; }
body.logged-out #login { display: block; }
.login { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr); min-height: 100vh; min-height: 100dvh; }
.login-hero {
  display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
  padding: 40px 48px; background: var(--text); color: var(--bg);
}
.login-hero .brand { padding: 0; font-size: 18px; }
.login-hero .brand img { border-radius: 8px; outline: 1px solid color-mix(in srgb, var(--bg) 25%, transparent); }
.login-hero-copy { max-width: 440px; }
.login-hero h1 { font-size: 36px; line-height: 1.15; letter-spacing: -.03em; font-weight: 700; }
.login-hero p { margin: 16px 0 28px; font-size: 16px; opacity: .72; }
.login-hero ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.login-hero li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; opacity: .9; }
.login-hero li svg.i { margin-top: 2px; width: 18px; height: 18px; stroke-width: 2.2; }
.login-hero-foot { font-size: 12.5px; opacity: .55; }
.login-panel {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px;
  padding: 40px 24px; background: var(--bg);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-card > p.muted { margin: 4px 0 28px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; }
.login-card .input { height: 46px; font-size: 15px; }
.login-brand-sm { display: none; padding: 0 0 28px; }
.login-brand-sm img { border-radius: 9px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 46px; }
.pw-wrap .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.login-error {
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500;
  background: var(--bad-bg); color: var(--bad);
}
.btn-lg { height: 46px; font-size: 15px; margin-top: 4px; }
.login-help { margin: 20px 0 0; text-align: center; }
.login-panel .powered { font-size: 12.5px; }
.login-panel .powered img { width: 20px; height: 20px; }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-panel { justify-content: space-between; padding: calc(env(safe-area-inset-top) + 56px) 20px calc(env(safe-area-inset-bottom) + 24px); }
  .login-card { margin: auto 0; }
  .login-brand-sm { display: flex; }
}

/* Firm names can be long: keep the brand on one line. */
.brand { min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-help a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; display: inline-block; margin-top: 8px; }

/* Login panel: illustration + one line */
.login-hero { justify-content: center; align-items: center; text-align: center; gap: 28px; }
.login-art { width: min(400px, 82%); height: auto; color: var(--bg); }
.login-hero-line { margin: 0; font-size: 17px; font-weight: 500; opacity: .75; letter-spacing: -.01em; }
.login-mark { display: block; border-radius: 11px; margin-bottom: 28px; }

/* ---------- Live mode ---------- */
body.booting .app, body.booting #login { visibility: hidden; }
#toast.error { background: var(--bad); color: #fff; }
.kv-left dd { text-align: left; }
.health { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.health li { display: flex; gap: 10px; align-items: flex-start; }
.health li svg.i { margin-top: 2px; flex: none; }
.health li.ok svg.i { color: var(--ok); }
.health li.bad svg.i { color: var(--bad); }
.health li .muted { font-size: 12.5px; }

/* Demo ended / offline screen */
.ended {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 32px; padding: 40px 20px; text-align: center; background: var(--bg);
}
.ended-card { max-width: 420px; display: flex; flex-direction: column; align-items: center; }
.ended-card h2 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.ended-card p { margin: 10px 0 28px; }
.ended-card .login-mark { margin-bottom: 24px; }

/* ---------- Review workflow ---------- */
:root { --review: #1d4ed8; --review-bg: #eaf0ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --review: #8fb1ff; --review-bg: #16213d; } }
:root[data-theme="dark"] { --review: #8fb1ff; --review-bg: #16213d; }
.badge.review { background: var(--review-bg); color: var(--review); }
.review-note { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.review-note p { margin: 6px 0 0; white-space: pre-wrap; }
.review-note.is-changes { background: var(--bad-bg); border-color: transparent; }

/* ---------- Settings: designation tags ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 18px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px 0 12px;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface);
  font-size: 13.5px; font-weight: 500;
}
.tag.used { padding-right: 6px; }
.tag .n { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.tag button { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.tag button:hover { background: var(--bad-bg); color: var(--bad); }
.tag button svg.i { width: 13px; height: 13px; }
