:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1a1f36;
  --muted: #5b6380;
  --line: #e2e5ef;
  --brand: #1f3a8a;
  --brand-ink: #ffffff;
  --accent: #f5c518;
  --ok: #0f7b4b;
  --ok-bg: #e6f6ee;
  --warn: #8a5a00;
  --warn-bg: #fff6dc;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info: #1d4ed8;
  --info-bg: #e8efff;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --surface: #171b2e;
    --text: #e8eaf3;
    --muted: #a3a9c2;
    --line: #2a3050;
    --brand: #6d8cff;
    --brand-ink: #0b0e1a;
    --ok: #4ade80;
    --ok-bg: #12301f;
    --warn: #fbbf24;
    --warn-bg: #33280c;
    --bad: #f87171;
    --bad-bg: #3a1515;
    --info: #93b4ff;
    --info-bg: #17234a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 1.2rem 0 .6rem; }
h2 { font-size: 1.3rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: .8rem 0 .4rem; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.1rem; text-decoration: none; color: var(--text); }
.brand::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); margin-right: 8px; box-shadow: 0 0 0 3px var(--brand); vertical-align: 1px; }
.top nav { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.top nav a { text-decoration: none; color: var(--muted); font-weight: 600; }
.top nav a:hover { color: var(--text); }
.admin-top { border-bottom: 3px solid var(--accent); }
.who { color: var(--muted); font-size: .85rem; }
.preview-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px 16px; font-weight: 600; font-size: .9rem; }

.hero { padding: 2rem 0 1rem; }
.hero h1 { font-size: 2.4rem; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 1rem 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 14px 0; }
.card h2:first-child, .card h3:first-child, .card h1:first-child { margin-top: 0; }
.narrow { max-width: 560px; margin: 2rem auto; }
.steps li { margin: .4rem 0; }

.btn { display: inline-block; background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 10px 18px; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--brand); box-shadow: inset 0 0 0 2px var(--brand); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .9rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 700; }
tfoot td { font-weight: 800; border-bottom: 0; }
tbody tr:last-child td { border-bottom: 0; }
table.rates input.qty { width: 110px; }

label { display: block; font-weight: 600; margin: .6rem 0; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input.mismatch { border-color: var(--bad); }
table input, table select { margin-top: 0; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
label.check input { width: auto; margin-top: 5px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.checks { margin: 1rem 0; }
.cf-turnstile { margin: 1rem 0; }
.est-final { font-size: 1.15rem; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1 1 240px; margin: 0; }
form.inline { display: inline-block; margin: 0 8px 8px 0; }
form.stack { margin: 10px 0 18px; }
.actions form.stack { border-top: 1px solid var(--line); padding-top: 10px; }
.cancel-form { margin: 2rem 0; }

.alert { border-radius: var(--radius); padding: 12px 16px; margin: 14px 0; }
.alert ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.alert.ok, .card.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad, .card.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--info-bg); color: var(--info); }

.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; vertical-align: middle; }
.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.info { background: var(--info-bg); color: var(--info); }
.badge.done { background: var(--ok); color: #fff; }
.badge.muted { background: var(--line); color: var(--muted); }

.timeline { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.timeline li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; font-size: .9rem; }
.timeline li span:first-child { font-weight: 700; color: var(--muted); }
.timeline li.done { border-color: var(--ok); }
.timeline li.done span:first-child { color: var(--ok); }
.timeline li.done span:first-child::before { content: "✓ "; }

pre.address { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; font: 600 1rem/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; }
pre.address.big { font-size: 1.25rem; }
.note-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 6px 0 10px; }
.note-opt { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.note-opt b { display: block; }
.note-opt p { margin: 6px 0; }
.handwritten { background: var(--warn-bg); color: var(--text); border-radius: 6px; padding: 10px 14px; font: 700 1.15rem/1.5 ui-monospace, Consolas, monospace; word-break: break-all; transform: rotate(-1deg); display: inline-block; }
pre.email { white-space: pre-wrap; font: .9rem/1.45 ui-monospace, Consolas, monospace; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; text-decoration: none; color: var(--text); }
.stat b { display: block; font-size: 1.7rem; }
.stat span { color: var(--muted); font-size: .9rem; }
.search { display: flex; gap: 8px; align-items: center; margin: .5rem 0; }
.search input { margin: 0; max-width: 360px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); background: var(--surface); font-size: .9rem; font-weight: 600; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }

.prose { max-width: 720px; }
.prose details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.prose summary { font-weight: 700; cursor: pointer; }

.slip { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 1rem 0; }
.slip-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.slip-id { font: 800 2.4rem/1 ui-monospace, Consolas, monospace; letter-spacing: 2px; margin: .2rem 0 .6rem; }
.qr svg { width: 150px; height: 150px; background: #fff; display: block; }

.foot { margin-top: 3rem; padding: 1.2rem 0 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.safety { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 10px; }

@media (max-width: 600px) {
  h1 { font-size: 1.55rem; }
  .hero h1 { font-size: 1.9rem; }
  .top nav { margin-left: 0; gap: 12px; font-size: .95rem; }
  .slip-id { font-size: 1.8rem; }
  .sell-form .col-rate, .sell-form .col-est { display: none; }
  .sell-form .rate-sub, table.lines .rate-sub { display: block; }
  table.lines .col-lrate { display: none; }
  table.lines th, table.lines td { padding: 8px 10px; }
  .sell-form table.rates input.qty { width: 92px; }
  .sell-form th, .sell-form td { padding: 8px 10px; }
}
.rate-sub { display: none; color: var(--muted); font-size: .85rem; font-weight: 600; }
@media print {
  .top, .foot, .preview-banner, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  .slip { border: 0; padding: 0; }
  .table-wrap { border: 0; }
}
