/* SDDI Invoicing — admin UI */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --ink: #0f1b2d;
  --ink-2: #4a5671;
  --ink-3: #7f8aa3;
  --line: #e2e7f0;
  --line-2: #eef1f6;
  --accent: #1d4ed8;
  --accent-2: #1e40af;
  --accent-soft: #e8efff;
  --ok: #067647;
  --ok-soft: #e7f6ee;
  --warn: #b54708;
  --warn-soft: #fff4e5;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 4px 16px rgba(15, 27, 45, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1320;
    --surface: #151d2e;
    --ink: #e6ebf5;
    --ink-2: #b2bccf;
    --ink-3: #8390a8;
    --line: #26314a;
    --line-2: #1d2639;
    --accent: #6d95ff;
    --accent-2: #8eadff;
    --accent-soft: #1d2a4d;
    --ok: #4bd08c;
    --ok-soft: #14301f;
    --warn: #f5a74a;
    --warn-soft: #3a2a14;
    --danger: #ff7a6e;
    --danger-soft: #3b1a18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; background: var(--line-2); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
h4 { font-size: 13px; margin: 14px 0 6px; color: var(--ink-2); }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* ── Top bar ───────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 20px; height: 58px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand-mark.big { width: 52px; height: 52px; border-radius: 14px; font-size: 24px; margin: 0 auto 12px; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: var(--ink-2); padding: 7px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--line-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.me { display: flex; align-items: center; gap: 12px; }
.me-link { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.me-link:hover { text-decoration: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--line-2); display: grid; place-items: center; font-weight: 700; color: var(--ink-2); }
.linklike { background: none; border: 0; color: var(--ink-2); cursor: pointer; font: inherit; padding: 0; }
.linklike:hover { color: var(--ink); text-decoration: underline; }
.role { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.role-ADMIN { background: var(--accent-soft); color: var(--accent); }
.role-ISSUER { background: var(--ok-soft); color: var(--ok); }

/* ── Layout ────────────────────────────────────────── */
.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 64px; }
.narrow { max-width: 560px; margin: 0 auto; padding: 32px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; }
.crumb { display: inline-block; color: var(--ink-3); font-size: 13px; margin-bottom: 4px; }
.count { font-size: 14px; font-weight: 600; color: var(--ink-3); background: var(--line-2); padding: 2px 9px; border-radius: 99px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-2.wide-left { grid-template-columns: 1.6fr 1fr; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .table { margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 10px; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card h2:not(:first-child) { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.pad { padding: 0 20px; margin: 0 0 8px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ── Flash ─────────────────────────────────────────── */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.err { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash.info { background: var(--accent-soft); color: var(--ink); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.copy-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.token { font-size: 13px; padding: 6px 10px; background: var(--surface); color: var(--ink); word-break: break-all; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.success:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: var(--ink-3); font-size: 20px; line-height: 1; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* ── Forms ─────────────────────────────────────────── */
label, .label-text { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; color: var(--ink); }
.hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.req { color: var(--danger); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { resize: vertical; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); }
input[type="file"] { padding: 6px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: var(--line-2); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.form-actions.sticky { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); padding: 12px 0; margin: 0; border-top: 1px solid var(--line); z-index: 5; }
.with-link { display: flex; gap: 10px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 5px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: 38px; width: fit-content; }
.segmented label { flex-direction: row; align-items: center; gap: 0; font-weight: 600; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.segmented span { padding: 8px 16px; color: var(--ink-2); white-space: nowrap; }
.segmented label + label span { border-left: 1px solid var(--line); }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.segmented input:disabled + span { opacity: .6; cursor: not-allowed; }
.with-link select { flex: 1; }
.inline-form { display: flex; gap: 8px; margin: 12px 0; }
.inline-form input { flex: 1; }
.inline-after { display: flex; gap: 10px; align-items: center; margin: -8px 0 22px; }
.logo-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.logo-row img { max-height: 44px; max-width: 200px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.logo-row input[type="file"] { max-width: 320px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters input[type="search"] { flex: 1 1 220px; width: auto; }
.filters select, .filters input[type="date"] { width: auto; }

/* ── Tables ────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 10px 16px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--line-2) 50%, transparent); }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: 7px 12px; }
.table .empty { text-align: center; color: var(--ink-3); padding: 34px 16px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--line-2); }
.table tr.dim td { opacity: .55; }
.table th.right, .table td.right { text-align: right; }
.table td form { display: inline; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; letter-spacing: .02em; vertical-align: middle; }
.st-DRAFT { background: var(--line-2); color: var(--ink-2); }
.st-ISSUED { background: var(--accent-soft); color: var(--accent); }
.st-PAID { background: var(--ok-soft); color: var(--ok); }
.st-CANCELLED { background: var(--danger-soft); color: var(--danger); }
.st-VOID { background: var(--line-2); color: var(--danger); text-decoration: line-through; }
h1 .badge { font-size: 13px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--line-2); color: var(--ink-2); font-weight: 600; margin-left: 4px; }
.tag.credit { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* ── Dashboard ─────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--ink); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; color: var(--ink-2); }

/* ── Invoice page ──────────────────────────────────── */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.preview-wrap { background: #e9edf4; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.preview { width: 100%; height: 1180px; border: 0; display: block; background: #e9edf4; }
.side .card { padding: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--ink-3); font-size: 13px; }
.kv dd { margin: 0; text-align: right; }
.plain { list-style: none; padding: 0; margin: 6px 0 10px; display: flex; flex-direction: column; gap: 4px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.timeline li { display: flex; flex-direction: column; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.t-what { font-weight: 600; text-transform: capitalize; }

/* ── Invoice editor ────────────────────────────────── */
.lines-editor th, .lines-editor td { padding: 8px 8px; vertical-align: top; }
.lines-editor th:first-child, .lines-editor td:first-child { padding-left: 16px; }
.lines-editor .c-qty { width: 90px; } .lines-editor .c-unit { width: 90px; }
.lines-editor .c-price { width: 130px; } .lines-editor .c-vat { width: 80px; } .lines-editor .c-amt { width: 130px; }
.lines-editor td.amt { padding-top: 17px; font-weight: 600; }
.lines-editor textarea { min-height: 38px; overflow: hidden; }
.lines-editor input:disabled { background: var(--line-2); color: var(--ink-3); }
.lines-foot { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px; border-top: 1px solid var(--line); gap: 16px; flex-wrap: wrap; }
.live-totals { min-width: 260px; display: flex; flex-direction: column; gap: 4px; }
.live-totals div { display: flex; justify-content: space-between; gap: 24px; font-variant-numeric: tabular-nums; }
.live-totals .grand { font-size: 17px; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }

/* ── Login ─────────────────────────────────────────── */
.login { margin-top: 8vh; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand h1 { justify-content: center; }

@media (max-width: 960px) {
  .invoice-layout { grid-template-columns: 1fr; }
  .preview { height: 900px; }
  .grid-2, .grid-2.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .me-name { display: none; }
  .wrap { padding: 18px 16px 64px; }
  .form-grid { grid-template-columns: 1fr; }
  .table th, .table td { padding: 9px 10px; }
  .card.flush { overflow-x: auto; }
  .lines-editor { min-width: 680px; }
  .preview { height: 640px; }
}

.table select { min-width: 112px; width: auto; }
.table td a.strong { white-space: nowrap; }
@media (max-width: 720px) { .card.flush > .table:not(.lines-editor) { min-width: 620px; } }

.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.void-card { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.void-card h3 { color: var(--danger); }
.side > .muted.small { margin: -8px 0 16px; }
