/* Strahl Family Budget. Always dark. Chart colors are the reference palette's dark steps. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --raised: #232321;
  --hover: #2a2a28;
  --line: #2c2c2a;
  --line-strong: #383835;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --accent: #7cc49a;
  --accent-ink: #0b1a11;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --good-text: #3fbf5c;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #f07070;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin-bottom: 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--ink-2); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }

/* ---------- top bar & tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) 20px 10px;
  background: rgba(13, 13, 13, 0.88);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 10px;
  color: var(--ink-2); font-weight: 550;
}
.tabs a:hover { background: var(--raised); text-decoration: none; }
.tabs a.active { background: var(--raised); color: var(--ink); }
.tabs svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 900px; margin: 0 auto; padding: 18px 20px 60px; }

@media (max-width: 760px) {
  /* No blur on the header here: a blurred parent would pin the "fixed" tab bar to the header instead of the screen bottom. */
  .top { padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--page); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0;
    justify-content: space-around;
    padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
    background: rgba(20, 20, 19, 0.94);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabs a { flex-direction: column; gap: 2px; padding: 5px 4px; font-size: 11px; flex: 1; }
  .tabs a.active { background: none; color: var(--accent); }
  .tabs svg { width: 22px; height: 22px; }
  main { padding: 14px 16px calc(env(safe-area-inset-bottom) + 90px); }
}

/* ---------- building blocks ---------- */
.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.notice { display: block; border-color: rgba(124, 196, 154, 0.35); }
a.notice { color: var(--ink); }
a.notice:hover { text-decoration: none; background: var(--raised); }
a.notice span { display: block; color: var(--accent); margin-top: 2px; }
.notice.error { border-color: rgba(208, 59, 59, 0.5); }
.empty { text-align: center; padding: 30px 18px; }
.loading { color: var(--muted); padding: 30px 0; text-align: center; }
.page-title { font-size: 24px; margin: 4px 0 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .page-title { margin-bottom: 6px; }
.footnote { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--raised); color: var(--ink);
  font: 600 14px var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--raised); }
.btn.danger { color: var(--critical-text); }
.btn.primary.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 0; background: transparent; color: var(--ink-2);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--raised); color: var(--ink); }
.icon-btn:disabled { opacity: 0.25; cursor: default; background: none; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

input, select, textarea {
  font: 15px var(--font); color: var(--ink);
  background: var(--page); border: 1px solid var(--line-strong); border-radius: 10px;
  min-height: 40px; padding: 8px 10px; width: 100%;
}
select { padding-right: 28px; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); margin: 0; }
input[type="file"] { padding: 7px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; max-width: 360px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; gap: 0; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink-2); margin: 4px 0 6px; }
.check input { margin-top: 2px; flex: none; }

.seg { display: inline-flex; background: var(--page); border: 1px solid var(--line-strong); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg label, .seg button {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px;
  font: 600 14px var(--font); color: var(--ink-2); background: none; border: 0; cursor: pointer;
}
.seg label:has(input:checked), .seg button.on { background: var(--raised); color: var(--ink); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg.small button { font-size: 13px; padding: 5px 10px; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--raised); color: var(--ink-2); border: 1px solid var(--line-strong); vertical-align: 1px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--page); font-weight: 600;
  padding: 10px 16px; border-radius: 12px; max-width: calc(100% - 32px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--critical); color: #fff; }
@media (max-width: 760px) { .toast { bottom: calc(env(safe-area-inset-bottom) + 84px); } }

/* ---------- dialog ---------- */
dialog.sheet {
  width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px);
  padding: 0; border: 1px solid var(--line-strong); border-radius: 18px;
  background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.sheet form { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
dialog.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 4px 18px; }
dialog.sheet h2 { margin: 0; }
.sheet-body { padding: 10px 18px 4px; overflow: auto; }
dialog.sheet footer { display: flex; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }

/* ---------- month switcher & tiles ---------- */
.month-switch { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 2px 0 14px; }
.month-title { display: flex; flex-direction: column; align-items: center; min-width: 210px; }
.month-switch h1 { font-size: 22px; text-align: center; }
.period-btn { font: 500 13px var(--font); color: var(--ink-2); background: none; border: 0; border-radius: 8px; padding: 2px 8px; cursor: pointer; }
.period-btn:hover { background: var(--raised); color: var(--ink); }
.period-btn span { color: var(--muted); }
.month-switch .icon-btn { font-size: 28px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .tiles { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .tiles.three { grid-template-columns: 1fr; } .tiles.three .tile { flex-direction: row; flex-wrap: wrap; align-items: baseline; column-gap: 10px; } .tiles.three .tile-label { width: 100%; } }
.tile { background: var(--surface); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; min-width: 0; }
.tile-label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -0.02em; }
.tile-value.over { color: var(--critical-text); }
.tile-sub { font-size: 13px; color: var(--muted); }

/* ---------- budget groups & rows ---------- */
.group { padding-top: 6px; padding-bottom: 6px; }
.group-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; color: var(--ink); font: inherit; text-align: left;
  padding: 10px 0; cursor: pointer;
}
.group-head h2 { margin: 0; }
.group-sum { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.group-sum strong { color: var(--ink-2); font-weight: 650; }
.chev { color: var(--muted); font-size: 18px; line-height: 1; transition: transform 0.15s; width: 14px; }
.group.folded .chev { transform: rotate(-90deg); }
.group.folded .cat-list { display: none; }
.group .cat-row:first-child { border-top: 1px solid var(--line); padding-top: 12px; }
.cat-row.idle { padding: 7px 0; }
.cat-row.idle .cat-name { color: var(--ink-2); font-weight: 500; }
.cat-row.idle .budget-btn { font-weight: 500; color: var(--muted); }
.tile.bad { border-color: rgba(208, 59, 59, 0.5); }
.section-title { margin: 24px 0 10px; font-size: 19px; }
.ge-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.ge-name { font-weight: 650; font-size: 16px; }

.cat-list { display: flex; flex-direction: column; }
.cat-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.cat-row:first-child { border-top: 0; padding-top: 2px; }
.cat-name { color: var(--ink); font-weight: 600; }
.cat-amounts { display: flex; align-items: center; gap: 6px; }
.cat-amounts .actual { font-weight: 650; }
.budget-btn {
  font: 600 14px var(--font); color: var(--ink-2); background: var(--raised);
  border: 1px dashed var(--line-strong); border-radius: 8px; padding: 3px 8px; cursor: pointer;
}
.budget-btn:hover { color: var(--ink); border-color: var(--muted); }
.budget-input { width: 110px; min-height: 30px; padding: 3px 8px; font-size: 14px; }
.bar { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--raised); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 99px; background: var(--series-1); }
.cat-row.near .bar span { background: var(--warning); }
.cat-row.over .bar span { background: var(--critical); }
.cat-note { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.flag { color: var(--ink-2); }
.flag.near { color: var(--warning); }
.flag.over { color: var(--critical-text); font-weight: 600; }

/* ---------- transactions ---------- */
.filters { display: grid; grid-template-columns: minmax(0, 220px) 1fr auto; gap: 10px; margin-bottom: 12px; }
@media (max-width: 520px) { .filters { grid-template-columns: 1fr auto; } .filters #f-q { grid-column: 1 / -1; grid-row: 2; } }
.list-summary { color: var(--muted); font-size: 13px; }
.tx-list { padding: 4px 0; }
.tx-day { padding: 12px 18px 4px; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tx { display: grid; grid-template-columns: 1fr 170px 100px; gap: 10px; align-items: center; padding: 6px 18px; border-left: 3px solid transparent; }
.tx:hover { background: var(--raised); }
.tx.uncat { border-left-color: var(--warning); }
.tx-main { display: flex; flex-direction: column; min-width: 0; text-align: left; background: none; border: 0; color: var(--ink); font: inherit; padding: 4px 0; cursor: pointer; }
.tx-desc { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta:empty { display: none; }
.tx-cat { min-height: 34px; padding: 4px 26px 4px 8px; font-size: 13px; background-color: var(--surface); }
.tx-amt { text-align: right; font-weight: 650; white-space: nowrap; }
.tx-amt.in, td.in { color: var(--good-text); }
@media (max-width: 600px) {
  .tx { grid-template-columns: 1fr auto; padding: 8px 16px; }
  .tx-cat { grid-column: 1 / -1; grid-row: 2; }
  .tx-day { padding: 12px 16px 4px; }
}

/* ---------- tables (import review, chart tables) ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px; border-bottom: 1px solid var(--line-strong); }
.table td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table .num { text-align: right; white-space: nowrap; }
.table.review select { min-height: 32px; padding: 3px 24px 3px 6px; font-size: 13px; width: auto; max-width: 190px; }
.table tr.dupe td { color: var(--muted); }
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--ink-2); }
.steps li { margin-bottom: 6px; }
.map-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 600px) { .map-grid { grid-template-columns: 1fr; } }

/* ---------- settings ---------- */
.cat-edit { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.ce-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ce-name { flex: 1 1 200px; min-width: 0; }
.ce-tools { display: flex; align-items: center; gap: 4px; }
.ce-tools select { width: 150px; }
.ce-tools select[data-field="kind"] { width: 120px; }
@media (max-width: 600px) {
  .ce-row { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .ce-name { flex-basis: 100%; }
  .ce-tools { width: 100%; }
  .ce-tools select { flex: 1; width: auto; min-width: 0; }
}
.ce-add { display: flex; gap: 8px; }
.seg + #c2 { margin-top: 4px; }

/* ---------- charts ---------- */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; max-width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.base { stroke: var(--line-strong); }
.chart .axis { fill: var(--muted); font: 11px var(--font); }
.chart .axis.strong { fill: var(--ink); font-weight: 650; }
.chart .hit { fill: transparent; }
.chart .sel { fill: rgba(255, 255, 255, 0.05); }
.chart .ref { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 4 3; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i, .tip-row i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.lg-ref { background: none !important; border-top: 2px dashed var(--ink); height: 0 !important; width: 14px !important; border-radius: 0 !important; }
.chart-tip {
  position: absolute; z-index: 60; display: none; pointer-events: none;
  background: var(--raised); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; min-width: 150px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.chart-tip strong { display: block; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 7px; color: var(--ink-2); }
.tip-row b { margin-left: auto; padding-left: 12px; color: var(--ink); }
.tip-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.barlist { display: flex; flex-direction: column; gap: 2px; }
.bl-row { display: grid; grid-template-columns: minmax(90px, 170px) 1fr 80px; gap: 10px; align-items: center; color: var(--ink); padding: 5px 4px; border-radius: 8px; }
.bl-row:hover { background: var(--raised); text-decoration: none; }
.bl-label { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bl-track { position: relative; height: 14px; }
.bl-bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; min-width: 2px; }
.bl-ref { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.bl-value { text-align: right; font-size: 14px; font-weight: 600; }
@media (max-width: 520px) { .bl-row { grid-template-columns: 96px 1fr 64px; gap: 8px; } .bl-label, .bl-value { font-size: 13px; } }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: min(380px, 100%); text-align: center; padding: 30px 24px; margin: 0; }
.login h1 { font-size: 22px; margin: 12px 0 22px; }
.login .field { text-align: left; }
.login-error { color: var(--critical-text); min-height: 1.4em; font-size: 14px; text-align: left; }
