:root {
  --ink: #0f2a33;
  --ink-2: #4b6470;
  --line: #e2e8eb;
  --bg: #f6f8f9;
  --card: #ffffff;
  --brand: #0e7c74;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f1;
  --info: #2563eb;
  --warn: #c2410c;
  --warn-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --muted-soft: #eef2f4;
  --demo-bg: #fef3c7;
  --demo-ink: #78350f;
  --radius: 10px;
  color-scheme: light;
}
/* Dark palette: used when the user picks Dark, or picks Auto and the computer is in dark mode. */
:root[data-theme="dark"] {
  --ink: #e7eef0; --ink-2: #9db1b9; --line: #2a3a40; --bg: #12191c; --card: #1a2428;
  --brand: #2bb3a7; --brand-ink: #06221f; --brand-soft: #173a37; --info: #60a5fa;
  --warn: #fb923c; --warn-soft: #3a2416; --ok: #4ade80; --ok-soft: #173322; --muted-soft: #222e33;
  --demo-bg: #3b2f10; --demo-ink: #fde68a;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7eef0; --ink-2: #9db1b9; --line: #2a3a40; --bg: #12191c; --card: #1a2428;
    --brand: #2bb3a7; --brand-ink: #06221f; --brand-soft: #173a37; --info: #60a5fa;
    --warn: #fb923c; --warn-soft: #3a2416; --ok: #4ade80; --ok-soft: #173322; --muted-soft: #222e33;
    --demo-bg: #3b2f10; --demo-ink: #fde68a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-by { font-size: 11px; color: var(--ink-2); }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chip-muted { background: var(--muted-soft); color: var(--ink-2); font-weight: 500; }

.notice { margin: 10px 14px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--warn-soft); display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.notice p { margin: 0; font-size: 13px; }

.customer { margin: 10px 14px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.customer-name { font-weight: 600; }
.customer-meta { font-size: 12px; color: var(--ink-2); }

.tabs { display: flex; gap: 2px; padding: 10px 14px 0; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 4px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { flex: 1; padding: 12px 14px 20px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin: 18px 0 8px; font-weight: 600; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--ink-2); }
.stat-value { font-size: 18px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-value.warn { color: var(--warn); }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 110px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 10px 6px; }
.bar { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-fill { width: 100%; max-width: 22px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-label { font-size: 10px; color: var(--ink-2); }

.list { display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--ink-2); font-size: 13px; padding: 14px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; white-space: pre-line; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }

.status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.status-new { background: var(--warn-soft); color: var(--warn); }
.status-paid { background: var(--brand-soft); color: var(--brand); }
.status-delivered { background: var(--ok-soft); color: var(--ok); }
.status-cancelled { background: var(--muted-soft); color: var(--ink-2); text-decoration: line-through; }
.tiny { font-size: 11.5px; color: var(--ink-2); }
.due { color: var(--warn); font-weight: 600; }

.toolbar { display: flex; gap: 8px; }
.toolbar input { flex: 1; }
.filters { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.pill { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.pill.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.form h2 { margin: 0 0 4px; font-size: 16px; }
.opt { font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { font-size: 12.5px; color: var(--ink-2); margin: 0 0 10px; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; background: var(--muted-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; font-weight: 500; border-radius: 6px; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--card); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-danger { color: var(--warn); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }
.file-btn { display: inline-flex; align-items: center; font-size: 14px; color: var(--ink); }
#addReply { margin-top: 10px; width: 100%; }
.saved { color: var(--ok); font-weight: 600; font-size: 13px; }

dialog { border: 0; border-radius: 14px; padding: 16px; width: min(94vw, 420px); background: var(--card); color: var(--ink); box-shadow: 0 20px 50px rgb(0 0 0 / 0.25); }
dialog::backdrop { background: rgb(10 20 25 / 0.45); }

.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; max-width: 90vw; box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); }

.foot { text-align: center; font-size: 11px; color: var(--ink-2); padding: 10px; border-top: 1px solid var(--line); }

.demo-banner { margin: 10px 14px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--demo-bg); color: var(--demo-ink); display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: 12.5px; }
.card .hint { margin: 4px 0 10px; }
#diagCount { margin-top: 8px; }

/* ---------- dashboard ---------- */
.section-title.first { margin-top: 0; }
#dueWrap { margin-bottom: 14px; }
.period-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--ink-2); }
.kpi-value { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.kpi-sub { display: block; font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.kpi-sub.up { color: var(--ok); }
.kpi-sub.down { color: var(--warn); }
.kpi-hero { border-color: var(--brand); background: var(--brand-soft); }
.kpi-hero .kpi-value { color: var(--brand); }
.kpi-warn .kpi-value { color: var(--warn); }
.trend { display: flex; align-items: flex-end; gap: 3px; height: 120px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 10px 4px; }
.tbar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.tbar-fill { width: 100%; max-width: 26px; background: var(--brand); border-radius: 3px 3px 0 0; }
.tbar-label { font-size: 10px; color: var(--ink-2); height: 14px; margin-top: 3px; white-space: nowrap; }
.statusbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--line); }
.statusbar > div { height: 100%; }
.legends { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.tops { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toplist { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.toplist li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-top: 1px solid var(--line); font-size: 13px; }
.toplist li:first-child { border-top: 0; }
.toplist li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplist li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.toplist li.muted { color: var(--ink-2); }
.full-dash-btn { width: 100%; margin-top: 16px; }

.hint a { color: var(--brand); }

/* theme toggle */
.top-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.icon-btn { border: 1px solid var(--line); background: var(--card); color: var(--ink-2); width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; padding: 0; }
.icon-btn:hover { color: var(--brand); border-color: var(--brand); }
.icon-btn svg { width: 16px; height: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.top .brand { flex: none; }
.top-right { max-width: 60%; justify-content: flex-end; }
.top-right .chip { max-width: none; min-width: 0; flex: 0 1 auto; }

/* v0.5 */
.notice-alert { background: var(--warn-soft); border: 1px solid var(--warn); }
.notice-info { background: var(--brand-soft); }
.notice-alert, .notice-info { flex-wrap: wrap; }
.notice-alert p, .notice-info p { flex: 1 1 230px; }
.notice .btn-row.nowrap { flex-wrap: nowrap; margin: 0; }
.notice .btn { white-space: nowrap; }
.privacy-box { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); background: var(--brand-soft); font-size: 13px; line-height: 1.45; margin-bottom: 8px; }
.privacy-box svg { flex-shrink: 0; color: var(--brand); margin-top: 1px; }
.review-card { margin-bottom: 10px; border-color: var(--brand); }
#restoreDialog .form > .btn { width: 100%; }
#restoreDialog .form > .hint { margin-top: -4px; }
a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
