:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f1f0ed;
  --border: #e4e3de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-bg: #e5effb;
  --good: #0f7a3d;
  --good-bg: #e3f4ea;
  --warn: #9a6200;
  --warn-bg: #fdf1d8;
  --bad: #c22f2e;
  --bad-bg: #fbe6e5;
  --weekly: #6250d6;
  --weekly-bg: #ecebfb;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 3px 12px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #30302d;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c85;
    --accent: #3987e5; --accent-bg: #162538;
    --good: #4cc27c; --good-bg: #16301f; --warn: #e0a83a; --warn-bg: #33270f;
    --bad: #ef7472; --bad-bg: #3a1a19; --weekly: #9085e9; --weekly-bg: #24213d; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #30302d;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c85;
  --accent: #3987e5; --accent-bg: #162538;
  --good: #4cc27c; --good-bg: #16301f; --warn: #e0a83a; --warn-bg: #33270f;
  --bad: #ef7472; --bad-bg: #3a1a19; --weekly: #9085e9; --weekly-bg: #24213d; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.brand-name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: var(--text-2); cursor: pointer; user-select: none; }
nav a i { font-style: normal; width: 22px; text-align: center; }
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
nav a.more-link { display: none; }
.save-state { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; }
.save-state.err { color: var(--bad); font-weight: 600; }
main { padding: 26px 28px 60px; max-width: 980px; width: 100%; min-width: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--text-2); margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- cards & tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 650; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--text-2); font-size: 13.5px; }
.tile .value { font-size: 26px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .hint { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile.blue { background: var(--accent-bg); border-color: transparent; }
.tile.green { background: var(--good-bg); border-color: transparent; }
.tile.green .value { color: var(--good); }
.tile.red { background: var(--bad-bg); border-color: transparent; }
.tile.red .value { color: var(--bad); }

/* ---------- buttons */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.green { background: var(--good); border-color: var(--good); color: #fff; }
.btn.sm { padding: 6px 12px; font-size: 13.5px; }
.btn.danger { color: var(--bad); }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-actions .btn { padding: 16px; font-size: 16px; border-radius: 14px; }
.icon-btn { border: 0; background: none; color: var(--text-2); font-size: 17px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.link { color: var(--accent); cursor: pointer; font-weight: 550; text-decoration: none; }
.link:hover { text-decoration: underline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 7px 14px; border-radius: 999px; font: inherit; font-size: 14px; cursor: pointer; }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.tabs button .count { opacity: .7; margin-left: 4px; }
.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 11px; gap: 3px; max-width: 100%; overflow-x: auto; }
.seg button { flex: none; border: 0; background: none; padding: 8px 14px; border-radius: 8px; font: inherit; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- simple lists (used everywhere instead of wide tables) */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row.click { cursor: pointer; border-radius: 8px; }
.row.click:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--text-2); font-size: 13px; margin-top: 1px; }
.row .right { text-align: right; flex: none; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; font-weight: 700; flex: none; font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; }
.total-row { display: flex; justify-content: space-between; padding: 12px 4px 2px; font-weight: 700; border-top: 2px solid var(--border); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; vertical-align: 1px; }
.tag.m { background: var(--accent-bg); color: var(--accent); }
.tag.w { background: var(--weekly-bg); color: var(--weekly); }
.tag.good { background: var(--good-bg); color: var(--good); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.mute { background: var(--surface-2); color: var(--text-2); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; max-width: 220px; }
.progress > span { display: block; height: 100%; background: var(--good); border-radius: 999px; }

/* ---------- forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--text-2); font-weight: 600; }
.field .help { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.summary { background: var(--good-bg); border-radius: 12px; padding: 12px 14px; line-height: 1.7; }
.summary b { font-variant-numeric: tabular-nums; }
.notice { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.info { background: var(--accent-bg); }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; padding: 4px 0; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '▸ '; }
details[open] > summary::before { content: '▾ '; }
.search { max-width: 320px; margin-bottom: 12px; }

/* ---------- modal */
dialog { border: 0; border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(600px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-foot:empty { display: none; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.mini-grid div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.mini-grid span { display: block; font-size: 12.5px; color: var(--text-2); }
.mini-grid b { font-size: 17px; font-variant-numeric: tabular-nums; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100vw - 32px); text-align: center; }

/* ---------- planner */
.flow { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.flow-step { flex: 1 1 140px; background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.flow-step span { font-size: 12.5px; color: var(--text-2); }
.flow-step b { font-size: 20px; font-variant-numeric: tabular-nums; }
.flow-step small { color: var(--muted); font-size: 12px; }
.flow-step.good { background: var(--good-bg); }
.flow-step.good b { color: var(--good); }
.flow-arrow { display: grid; place-items: center; color: var(--muted); font-size: 20px; }
.choice-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.choice { text-align: left; font: inherit; color: var(--text); background: var(--surface); cursor: pointer; border: 1.5px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.choice span { color: var(--text-2); font-size: 13px; }
.choice.on { border-color: var(--accent); background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.result { text-align: center; padding: 24px 16px; background: var(--accent-bg); border-color: transparent; }
.result-line { font-size: 16px; color: var(--text-2); }
.result-big { font-size: 42px; font-weight: 750; letter-spacing: -.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.where .row .emoji { font-size: 22px; width: 32px; text-align: center; flex: none; }
.made-of { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; color: var(--text-2); }
.made-of b { color: var(--text); }
.pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pick label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; }
.pick input { width: 80px; text-align: center; }
.pick label.on input { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; font-weight: 650; }
table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.simple th:first-child, table.simple td:first-child { text-align: left; }
table.simple th { font-size: 13px; color: var(--text-2); font-weight: 600; }
table.simple tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.more-grid a { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; padding: 18px; font-weight: 650; cursor: pointer; color: var(--text); }
.more-grid a i { font-style: normal; font-size: 26px; }

/* ---------- phone: app-style bottom menu */
@media (max-width: 760px) {
  body { font-size: 15.5px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; z-index: 20; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border); flex-direction: row; }
  .brand, .save-state { display: none; }
  nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 0; }
  nav a { flex: 1; flex-direction: column; gap: 1px; padding: 6px 2px; font-size: 11.5px; border-radius: 10px; }
  nav a i { font-size: 20px; width: auto; }
  nav a:not([data-main]) { display: none; }
  nav a.more-link { display: flex; }
  nav a.active { background: none; }
  main { padding: 18px 16px calc(90px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 22px; }
  .tile .value { font-size: 22px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .flow-arrow { display: none; }
  .result-big { font-size: 34px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  dialog form { max-height: 92vh; }
}
@media print { .sidebar, .btn, .tabs { display: none !important; } .app { grid-template-columns: 1fr; } }

/* ID proofs */
.docs { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 6px; font-weight: 400; color: var(--text); }
.doc { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.doc .main { flex: 1; min-width: 0; }
.doc .title { font-weight: 600; font-size: 14px; }
.doc .meta { color: var(--text-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-thumb { width: 48px; height: 48px; border-radius: 8px; overflow: hidden; background: var(--surface); display: grid; place-items: center; font-size: 22px; flex: none; text-decoration: none; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Login */
[hidden] { display: none !important; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px 22px; }
.auth-card .brand { padding: 0; }
.auth-card h2 { margin: 4px 0 0; font-size: 21px; }
.auth-card .btn { padding: 12px; font-size: 16px; }
.me { padding: 10px 8px 0; border-top: 1px solid var(--border); margin-top: auto; }
.me .title { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me + .save-state { margin-top: 6px; }
.choice:disabled { opacity: .6; cursor: default; }
@media (max-width: 760px) { .me { display: none; } }
.modal-body > * { flex-shrink: 0; }
.auth-card .brand { display: flex !important; }
