:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #efe7d8;
  --ink: #24201a;
  --ink-soft: #6f6353;
  --line: #ddd2bc;
  --gold: #9c7326;
  --gold-strong: #7a5a1c;
  --gold-tint: #f2e6c8;
  --teal: #2c5955;
  --teal-tint: #dee9e6;
  --good: #3e7d49;
  --bad: #b1462e;
  --shadow: 0 1px 2px rgba(36, 32, 26, 0.06), 0 8px 24px -12px rgba(36, 32, 26, 0.18);
  --radius: 10px;
  --font-display: "Fraunces", "Iowan Old Style", ui-serif, Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #1f1b15; --surface-2: #29241c;
    --ink: #f1ead9; --ink-soft: #b6a890; --line: #3a3226;
    --gold: #d9ac52; --gold-strong: #eec27a; --gold-tint: #3a2f18;
    --teal: #7fb2ac; --teal-tint: #1e2c2a; --good: #74c281; --bad: #e2836a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -14px rgba(0,0,0,0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #1f1b15; --surface-2: #29241c;
  --ink: #f1ead9; --ink-soft: #b6a890; --line: #3a3226;
  --gold: #d9ac52; --gold-strong: #eec27a; --gold-tint: #3a2f18;
  --teal: #7fb2ac; --teal-tint: #1e2c2a; --good: #74c281; --bad: #e2836a;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -14px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
a { color: var(--gold-strong); }

.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 64px; display: flex; flex-direction: column; gap: 32px; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--gold-tint); color: var(--gold-strong); font-family: var(--font-display); font-weight: 600; font-size: 20px; flex-shrink: 0; }
.brand h1 { font-family: var(--font-display); font-size: 24px; font-weight: 600; margin: 0; text-wrap: balance; }
.subtitle { margin: 2px 0 0; color: var(--ink-soft); font-size: 13.5px; }

.nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.nav-user { font-size: 13px; color: var(--ink-soft); }
.btn-link { color: var(--ink-soft); text-decoration: none; font-size: 13.5px; font-weight: 500; }
.btn-link:hover { color: var(--gold-strong); }
.btn-primary { background: var(--gold); color: #fff; border: none; border-radius: 7px; padding: 9px 16px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; font-size: 13.5px; }
.btn-primary:hover { background: var(--gold-strong); }
.btn-block { width: 100%; text-align: center; }

.alert { border-radius: var(--radius); padding: 10px 14px; font-size: 13.5px; }
.alert-error { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.alert-success { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--good); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }

section { display: flex; flex-direction: column; gap: 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-family: var(--font-display); font-size: 20px; font-weight: 600; margin: 0; }
.save-status { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.rate-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 22px; }
.rate-group { display: flex; flex-direction: column; gap: 10px; }
.group-title { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; display: flex; align-items: center; gap: 7px; }
.group-title::before { content: ""; width: 9px; height: 9px; border-radius: 2px; }
.group-title.gold::before { background: var(--gold); } .group-title.gold { color: var(--gold-strong); }
.group-title.fx::before { background: var(--teal); } .group-title.fx { color: var(--teal); }

.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.rate-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.rate-card .label { font-size: 12px; color: var(--ink-soft); font-weight: 500; }
.rate-card .price { font-family: var(--font-mono); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tag-est { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); background: var(--surface-2); border-radius: 999px; padding: 1px 6px; font-weight: 600; }

.chg { display: inline-flex; align-items: center; gap: 3px; font-family: var(--font-mono); font-size: 12px; font-weight: 600; width: fit-content; }
.chg.up { color: var(--good); } .chg.down { color: var(--bad); } .chg.flat { color: var(--ink-soft); }

.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
#historyChart { width: 100%; display: block; }

select, input, button { font-family: var(--font-body); font-size: 13px; }
select#metricSelect { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); min-width: 460px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); font-weight: 600; background: var(--surface-2); }
td.num, th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
tbody tr:last-child td { border-bottom: none; }
.hint { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.empty-note { padding: 18px; text-align: center; color: var(--ink-soft); font-size: 13px; }

.ledger-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); align-items: end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; color: var(--ink-soft); font-weight: 500; }
.field input, .field select { border: 1px solid var(--line); border-radius: 7px; padding: 8px 9px; background: var(--bg); color: var(--ink); }
.field input:focus-visible, .field select:focus-visible, select#metricSelect:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.ledger-form button { background: var(--gold); color: #fff; border: none; border-radius: 7px; padding: 9px 14px; font-weight: 600; cursor: pointer; height: 37px; }
.ledger-form button:hover { background: var(--gold-strong); }

.row-actions form { margin: 0; }
.row-actions button { background: none; border: none; color: var(--bad); cursor: pointer; font-size: 12px; padding: 2px 4px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.buy { background: var(--teal-tint); color: var(--teal); }
.pill.sell { background: var(--gold-tint); color: var(--gold-strong); }

.ledger-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.summary-card { background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.summary-card .label { font-size: 11.5px; color: var(--ink-soft); }
.summary-card .value { font-family: var(--font-mono); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

.cta-box { background: var(--gold-tint); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.cta-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

.auth-card { max-width: 380px; margin: 20px auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h2 { font-family: var(--font-display); margin: 0; font-size: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-alt { margin: 0; font-size: 13px; color: var(--ink-soft); text-align: center; }

.page-footer { border-top: 1px solid var(--line); padding-top: 16px; }
.page-footer p { margin: 0; font-size: 12px; color: var(--ink-soft); }
