/* Accounts — tablet-first, works down to phone width. Light and dark follow the device. */

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201f;
  --muted: #5b6765;
  --border: #d9e0de;
  --accent: #0f6b63;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ef;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --info: #3b5b8c;
  --info-soft: #e9eff8;
  --joint: #6b4fa0;
  --good: #1d7a4c;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --surface: #182120;
    --surface-2: #1f2a29;
    --text: #e6eeec;
    --muted: #9aa8a5;
    --border: #2c3a38;
    --accent: #3fb5a8;
    --accent-ink: #06201d;
    --accent-soft: #163a36;
    --bad: #f0857a;
    --bad-soft: #3a1d1a;
    --warn: #e7b157;
    --warn-soft: #362a14;
    --info: #9bb8e8;
    --info-soft: #1c2638;
    --joint: #bba3e8;
    --good: #6fd19c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 16px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
.note { background: var(--warn-soft); border-radius: 8px; padding: 10px 12px; font-size: 0.9rem; }

/* ---------- layout */
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 24px 64px; }
.page-title { font-size: 1.6rem; margin-bottom: 16px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; margin-top: 24px; }
.detail-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px 20px; }
.stack { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; }

@media (max-width: 860px) {
  .two-col, .detail-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .wrap { padding: 16px 16px 64px; }
  .row2 { grid-template-columns: 1fr; }
  .page-title { font-size: 1.35rem; }
}

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 8px 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 10px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 560px) {
  .topbar-inner { padding: 8px 12px; gap: 8px; }
  .brand { font-size: 0; gap: 0; }
  .nav a { padding: 8px 10px; }
}
.banner { background: var(--info-soft); color: var(--info); padding: 10px 24px; text-align: center; font-size: 0.95rem; }

/* brand mark: three stacked bars, drawn in CSS so no image is needed */
.brand-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--accent); position: relative; margin: 0 auto 12px; }
.brand-mark::before { content: ""; position: absolute; left: 22%; right: 22%; top: 26%; height: 14%; border-radius: 4px; background: var(--accent-ink);
  box-shadow: 0 calc(56px * 0.2) 0 var(--accent-ink), 0 calc(56px * 0.4) 0 var(--accent-ink); opacity: 0.95; }
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; margin: 0; }
.brand-mark.small::before { border-radius: 2px; box-shadow: 0 calc(28px * 0.2) 0 var(--accent-ink), 0 calc(28px * 0.4) 0 var(--accent-ink); }

/* ---------- gate (setup / lock) */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; text-align: center; }
.gate-card form { text-align: left; margin-top: 16px; }
.passcode { font-size: 1.6rem; letter-spacing: 0.5em; text-align: center; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ---------- forms */
label { display: grid; gap: 6px; font-weight: 500; font-size: 0.95rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 46px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; }
legend { font-weight: 600; padding: 0 6px; }
label.radio, label.check { display: flex; gap: 10px; align-items: center; font-weight: 400; }
label.radio input, label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
.tier-row { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 10px; align-items: end; }

/* ---------- buttons */
.btn {
  font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-small { min-height: 38px; padding: 0 12px; font-size: 0.875rem; }
.btn-wide { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--bad); }
.lock-btn { margin-left: auto; }
body.readonly .edit-only { display: none !important; }

/* ---------- dashboard */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.stat-sub { color: var(--muted); font-size: 0.85rem; }
.count { display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 999px; background: var(--surface-2); font-size: 0.8rem; text-align: center; color: var(--muted); vertical-align: middle; }
.empty { text-align: center; max-width: 480px; margin: 12vh auto; }

.alerts { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.alert { display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--info); border-radius: var(--radius); padding: 12px 14px; }
.alert-bad { border-left-color: var(--bad); }
.alert-bad strong { color: var(--bad); }
.alert-warn { border-left-color: var(--warn); }
.alert-warn strong { color: var(--warn); }
.alert-body { flex: 1 1 280px; }
.alert-body p { margin: 2px 0 0; }
.alert-actions { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.list li + li { border-top: 1px solid var(--border); }
.list-row { display: flex; gap: 14px; align-items: center; padding: 14px 18px; color: inherit; text-decoration: none; }
a.list-row:hover { background: var(--surface-2); }
.date-chip { flex: none; min-width: 7.5em; font-weight: 600; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 8px 16px; border-radius: 9px; cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 0.9rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 14px; min-height: 38px; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bank-group { margin-bottom: 20px; }
.bank-group h2 { font-size: 1rem; color: var(--muted); margin-bottom: 8px; }
.acc-main { flex: 1; min-width: 0; }
.acc-name { font-weight: 600; }
.acc-meta, .acc-sub { color: var(--muted); font-size: 0.875rem; }
.acc-figs { text-align: right; }
.acc-bal { font-weight: 700; font-variant-numeric: tabular-nums; }
.owner { font-weight: 600; }
.owner-joint { color: var(--joint); }
.rate-drop { color: var(--bad); font-weight: 700; }

/* ---------- account detail */
.big-fig { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.closed-note { margin-bottom: 16px; background: var(--surface-2); }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 8px 0; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; }
.table caption { text-align: left; color: var(--muted); font-size: 0.875rem; padding-bottom: 4px; }
.tiers tr.here td { background: var(--accent-soft); font-weight: 700; }
details.history { margin-top: 12px; }
details.history summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.plain { list-style: none; margin: 0; padding: 0; }
.rate-hist { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.checks { margin: 0; padding-left: 20px; }
.notes { white-space: pre-wrap; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- dialog */
dialog {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: sticky; bottom: -22px; background: var(--surface); padding: 10px 0 2px; }
.spacer { flex: 1; }
@media (max-width: 560px) { dialog { padding: 18px 16px; } }

/* ---------- toast + update bar */
.toast, .update-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 20;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; max-width: calc(100vw - 32px);
}
.update-bar { bottom: auto; top: 12px; display: flex; gap: 12px; align-items: center; }

/* ---------- phase 2: transfers, tags, calendar */
.span2 { grid-column: 1 / -1; }
.nowrap { white-space: nowrap; }
.pos { color: var(--good); }
.diff { color: var(--warn); font-weight: 600; }
.moves td { vertical-align: top; }
.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag-planned { background: var(--info-soft); color: var(--info); }
.tag-est { background: var(--warn-soft); color: var(--warn); }
.tag-ok { background: var(--accent-soft); color: var(--accent); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }
.cond-head { margin-top: 16px; }
.cond-head h3 { margin: 0; }
.ev-text { flex: 1; min-width: 0; }
.ev-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: middle; background: var(--muted); }
.dot-move { background: var(--accent); }
.dot-interest { background: var(--joint); }
.dot-key { background: var(--warn); }
.legend .dot { margin-left: 10px; margin-right: 4px; }
.legend .dot:first-child { margin-left: 0; }

.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; margin-bottom: 20px; }
.cal-head { padding: 8px; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-align: center; border-bottom: 1px solid var(--border); }
.cal-cell { min-height: 104px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: grid; align-content: start; gap: 3px; min-width: 0; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.blank { background: var(--surface-2); }
.cal-cell.today { background: var(--accent-soft); }
.cal-day { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.cal-cell.today .cal-day { color: var(--accent); }
.cal-ev { display: block; font-size: 0.72rem; line-height: 1.3; padding: 2px 5px; border-radius: 5px; text-decoration: none; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--muted); background: var(--surface-2); }
.cal-move { border-left-color: var(--accent); }
.cal-interest { border-left-color: var(--joint); }
.cal-key { border-left-color: var(--warn); }
.cal-more { font-size: 0.72rem; color: var(--muted); }
.cal-list h3 { margin: 16px 0 8px; }

@media (max-width: 700px) {
  .calendar { display: none; }
  .nav { overflow-x: auto; scrollbar-width: none; }
  .nav a { padding: 8px 9px; white-space: nowrap; }
}

/* Transfer tables stack on phones: description first, then date + amount, then status + actions. */
@media (max-width: 560px) {
  .moves, .moves tbody { display: block; }
  .moves tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: center; }
  .moves td { border: 0; padding: 0; }
  .moves td:nth-child(2) { grid-column: 1 / -1; order: -1; font-weight: 500; }
  .moves td.num { text-align: right; }
  .rate-hist { flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .table th, .table td { padding: 6px 4px; font-size: 0.9rem; }
  .checkins th:nth-child(4), .checkins td:nth-child(4) { display: none; }
  .card.pad { padding: 16px 14px; }
}
@media (max-width: 560px) {
  .dl { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
/* Phones: the five sections become a bottom tab bar. */
@media (max-width: 560px) {
  .brand { font-size: 1.05rem; gap: 8px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--border);
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow: visible; }
  .nav a { text-align: center; font-size: 0.78rem; padding: 10px 2px; border-radius: 10px; }
  .wrap { padding-bottom: 96px; }
  .toast { bottom: 84px; }
}
