/* The app's own palette (ui/theme/Color.kt): cool slate with an emerald-teal accent. */
:root {
  --bg: #121619;
  --surface: #1b2126;
  --surface-2: #242c32;
  --divider: #2c353c;
  --accent: #2ec4a6;
  --accent-strong: #1fa88e;
  --on-accent: #04211b;
  --expense: #f0624d;
  --income: #3dd68c;
  --transfer: #5aa9f0;
  --text: #e8edf0;
  --text-2: #8d99a3;
  --text-3: #65717b;
  --top: #182025;
  --link-hover: #5fdcc4;
  --card-edge: transparent;
  --bar-dim: #2a6b62;
  --bar-hover: #5fdcc4;
  --tip: #0c0f11;
  --meter: #1f4f49;
  --meter-over: #5a2a23;
  /* A ring round a category's dot and bars, so a very pale colour still shows on the light theme's white. */
  --dot-edge: transparent;
  /* Under the sticky filter row once the page scrolls, and under the tooltip. */
  --shadow: rgba(0, 0, 0, .45);
  /* A category that rose (spent more) or fell against the period before. */
  --up: #f0624d;
  --down: #3dd68c;
  color-scheme: dark;
}

/* Light: the app's Mint Mist palette (LightEtPalette in ui/theme/Color.kt). It follows the
   visitor's system setting, or the theme button in the top bar (js/theme.js). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f7f6;
    --surface: #ffffff;
    --surface-2: #eef4f2;
    --divider: #e2eae7;
    --accent: #0b7a66;
    --accent-strong: #0b7a66;
    --on-accent: #ffffff;
    --text: #10231f;
    --text-2: #5b6b67;
    --text-3: #8a9894;
    --top: #ffffff;
    --link-hover: #075e4f;
    --card-edge: #e2eae7;
    --expense: #b4372b;
    --income: #1b7a47;
    --transfer: #2a5bb8;
    --bar-dim: #a8d8ca;
    --bar-hover: #075e4f;
    --tip: #ffffff;
    --meter: #dff3ec;
    --meter-over: #f6dad5;
    --dot-edge: rgba(16, 35, 31, .2);
    --shadow: rgba(16, 35, 31, .14);
    --up: #b4372b;
    --down: #1b7a47;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f7f6;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --divider: #e2eae7;
  --accent: #0b7a66;
  --accent-strong: #0b7a66;
  --on-accent: #ffffff;
  --text: #10231f;
  --text-2: #5b6b67;
  --text-3: #8a9894;
  --top: #ffffff;
  --link-hover: #075e4f;
  --card-edge: #e2eae7;
  --expense: #b4372b;
  --income: #1b7a47;
  --transfer: #2a5bb8;
  --bar-dim: #a8d8ca;
  --bar-hover: #075e4f;
  --tip: #ffffff;
  --meter: #dff3ec;
  --meter-over: #f6dad5;
  --dot-edge: rgba(16, 35, 31, .2);
  --shadow: rgba(16, 35, 31, .14);
  --up: #b4372b;
  --down: #1b7a47;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }
.muted { color: var(--text-2); }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-2); }

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
}
button { cursor: pointer; }
button:hover:not(:disabled), select:hover { border-color: var(--text-3); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
button.icon { padding: 6px 10px; min-width: 36px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--top);
  border-bottom: 1px solid var(--divider);
}
.brand { font-weight: 600; }
.source { flex: 1 1 240px; font-size: 13px; }
.guide { font-size: 14px; color: var(--accent); text-decoration: none; }
.guide:hover { text-decoration: underline; }
.theme-toggle { min-width: 36px; padding: 4px 8px; font-size: 16px; line-height: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* A phone: the name, Guide and the theme button share the first line; the backup's line and its
   buttons, when a backup is open, go under it, and take no room while they are empty. */
@media (max-width: 600px) {
  .guide { order: 1; margin-left: auto; }
  .theme-toggle { order: 2; }
  .source { order: 3; flex-basis: 100%; }
  .actions { order: 4; }
  .source:empty, .actions:empty { display: none; }
}

main { max-width: 1120px; margin: 0 auto; padding: 16px; }

/* Landing */
.landing { max-width: 640px; margin: 6vh auto 0; display: grid; gap: 20px; }
.landing h1 { font-size: 28px; line-height: 1.25; }
.landing h2 { font-size: 15px; }
.gets { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.gets li { display: flex; gap: 10px; align-items: baseline; }
.gets li::before { content: "✓"; color: var(--accent); font-weight: 600; }
.steps { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; font-size: 14px; }
.steps li::marker { color: var(--accent); font-weight: 600; }
.choices { display: grid; gap: 12px; }
.choice { background: var(--surface); border: 1px solid var(--divider); border-radius: 12px; padding: 16px; display: grid; gap: 10px; justify-items: start; }
.choice p { font-size: 13px; }
.drop { outline: 2px dashed var(--accent); outline-offset: 4px; }
.notice { background: var(--surface); border-left: 3px solid var(--expense); border-radius: 8px; padding: 10px 14px; }
.notice.info { border-left-color: var(--accent); }

/* Filters: one row above everything they scope */
.filters {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  background: var(--bg);
  transition: box-shadow .15s ease;
}
/* Once the page scrolls under it, a shadow sets the row apart. */
.scrolled .filters { box-shadow: 0 8px 12px -10px var(--shadow); }
.period { display: flex; align-items: center; gap: 4px; }
.period-title { min-width: 11em; text-align: center; font-weight: 600; }
.filters label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.filters .check { margin-left: auto; color: var(--text); }
.filters input[type="checkbox"] { min-height: 0; padding: 0; width: 16px; height: 16px; accent-color: var(--accent); }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 8px 0 12px; }
.tile { background: var(--surface); border: 1px solid var(--card-edge); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.tile { display: grid; gap: 2px; align-content: start; }
.tile .label { font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 22px; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12px; color: var(--text-2); }
/* Spent leads: wider on a wide screen, larger, with the trend's six periods drawn small beside its note. */
.tile.lead .value { font-size: 30px; line-height: 1.2; }
.tile.lead .foot { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 4px 12px; }
.spark { width: 120px; max-width: 100%; height: 32px; flex: none; overflow: visible; }
.spark polyline { fill: none; stroke: var(--expense); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--expense); }
@media (min-width: 761px) { .tile.lead { grid-column: span 2; } }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px var(--dot-edge); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--card-edge); border-radius: 12px; padding: 16px; min-width: 0; display: grid; gap: 12px; align-content: start; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.card-head .sub { font-size: 13px; color: var(--text-2); }
.empty { color: var(--text-2); font-size: 13px; padding: 12px 0; }
@media (max-width: 760px) { .cards { grid-template-columns: minmax(0, 1fr); } }

details.table > summary { cursor: pointer; font-size: 12px; color: var(--text-2); width: fit-content; }
details.table table { margin-top: 8px; }

/* Charts */
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--divider); stroke-width: 1; }
.chart .baseline { stroke: var(--text-3); stroke-width: 1; }
.chart .reference { stroke: var(--text-2); stroke-width: 1; }
.chart .axis { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .direct { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .direct.muted { fill: var(--text-2); font-weight: 400; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { fill: var(--bar-dim); }
.chart .bar.hover { fill: var(--bar-hover); }
.chart .hit { fill: transparent; outline: none; }
.chart .hit:focus-visible { stroke: var(--accent); stroke-width: 1; }

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--tip);
  border: 1px solid var(--divider);
  box-shadow: 0 4px 12px var(--shadow);
  border-radius: 8px;
  padding: 6px 10px;
  display: grid;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}
.tip strong { color: var(--text); font-size: 14px; }

/* The categories ring above its ranked list, or beside it when the card is wide enough to leave the bars room */
.card:has(> .split) { container-type: inline-size; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: center; justify-items: center; }
.split .rank { width: 100%; }
.donut { display: block; width: 150px; height: 150px; }
.donut circle { fill: none; stroke-width: 26; }
.donut .donut-track { stroke: var(--surface-2); }
.donut .slice { outline: none; transition: stroke-width .1s ease; }
.donut .slice.pickable { cursor: pointer; }
.donut .slice.hover, .donut .slice:focus-visible, .donut .slice[aria-pressed="true"] { stroke-width: 32; }
.donut-value { fill: var(--text); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.donut-label { fill: var(--text-2); font-size: 12px; }
@container (min-width: 500px) {
  .split { grid-template-columns: auto minmax(0, 1fr); justify-items: stretch; }
  /* Beside the ring the names give the bars more room. */
  .split .rank-row { grid-template-columns: minmax(0, 7em) minmax(40px, 1fr) auto 3em; gap: 8px; }
}

/* Tabs */
.tabs { display: flex; gap: 4px; }
.tabs button { min-height: 30px; padding: 2px 12px; font-size: 13px; background: transparent; color: var(--text-2); }
.tabs button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }

/* Ranked category bars and budget meters */
.rank { display: grid; gap: 2px; }
.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 9em) minmax(40px, 1fr) auto 3.2em;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 2px 6px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
}
.rank-row:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.rank-row[aria-pressed="true"] { background: var(--surface-2); border-color: var(--text-3); }
.rank-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rank-row .hash { color: var(--accent); font-weight: 600; flex: none; }
.rank-row .name span:last-child, .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .amount, .rank-row .share, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank-row .share { color: var(--text-2); font-size: 13px; }
.track { height: 10px; }
.track > span { display: block; height: 100%; min-width: 2px; border-radius: 0 4px 4px 0; box-shadow: inset 0 0 0 1px var(--dot-edge); }

.budget { display: grid; gap: 4px; }
.budget + .budget { margin-top: 10px; }
/* A subcategory's budget, carved out of the main category's above it. */
.budget.sub { margin-left: 18px; }
.budget .line { display: flex; justify-content: space-between; gap: 12px; }
.budget .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.budget .state { font-size: 13px; color: var(--text-2); text-align: right; }
.meter { height: 8px; border-radius: 4px; background: var(--meter); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.over { background: var(--meter-over); }
.meter.over > span { background: var(--expense); }

/* Tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 6px 10px; border-bottom: 1px solid var(--divider); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--divider); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td .cell { display: flex; align-items: center; gap: 8px; }
td.note { color: var(--text-2); min-width: 10em; max-width: 28em; white-space: pre-wrap; overflow-wrap: anywhere; }
.rec-tag { display: inline-block; margin: 2px 0 0 4px; padding: 0 6px; border: 1px solid var(--text-3); border-radius: 8px; font-size: 11px; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td .mini { height: 6px; margin-top: 4px; }
td .mini > span { display: block; height: 100%; min-width: 2px; border-radius: 0 3px 3px 0; margin-left: auto; box-shadow: inset 0 0 0 1px var(--dot-edge); }
tfoot td { color: var(--text-2); font-size: 13px; }

/* Sortable headings: the whole heading is the button */
th:has(> .sort) { padding: 0; }
.sort { width: 100%; min-height: 30px; padding: 6px 10px; border: 0; border-radius: 0; background: transparent; color: inherit; font: inherit; text-align: inherit; white-space: nowrap; }
.sort:hover:not(:disabled) { color: var(--text); }
.sort.active { color: var(--text); }
.sort .arrow { font-size: 10px; color: var(--accent); }

/* Insights */
.insights-body, .insights-main, .insights-side { display: grid; gap: 14px; align-content: start; min-width: 0; }
@media (min-width: 761px) { .card.wide .insights-body { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; } }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.fact { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.fact .label { font-size: 12px; color: var(--text-2); }
.fact .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fact .note { font-size: 12px; color: var(--text-2); }
.largest, .changes { display: grid; gap: 6px; }
.largest { overflow-x: auto; }
.largest table { font-size: 13px; }
@media (max-width: 600px) { .largest th:nth-child(3), .largest td.note { display: none; } }
.largest td.note { min-width: 0; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.largest .name, .changes .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.changes ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.changes li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; align-items: baseline; font-size: 14px; }
.changes .from { grid-column: 1 / -1; font-size: 12px; padding-left: 18px; }
.changes .up { color: var(--up); font-weight: 600; }
.changes .down { color: var(--down); font-weight: 600; }

/* Records on a phone: each a short row, date and amount over category and account, then the note */
@media (max-width: 600px) {
  table.records, table.records tbody, table.records thead { display: block; }
  table.records thead tr { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--divider); }
  table.records th { border: 0; padding: 0; }
  table.records th.note-head { display: none; }
  table.records .sort { padding: 4px 8px; }
  table.records tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "date amount" "category account" "note note";
    gap: 2px 12px;
    padding: 8px 2px;
    border-bottom: 1px solid var(--divider);
  }
  table.records tbody tr:last-child { border-bottom: 0; }
  table.records td { border: 0; padding: 0; min-width: 0; }
  table.records td.date { grid-area: date; font-weight: 500; }
  table.records td.amount { grid-area: amount; font-weight: 600; }
  table.records td.type { display: none; }
  table.records td.category { grid-area: category; font-size: 13px; }
  table.records td.account { grid-area: account; font-size: 13px; color: var(--text-2); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  table.records td.note { grid-area: note; max-width: none; min-width: 0; font-size: 13px; }
  table.records td.note.blank { display: none; }
}

/* The line that says what a printed report covers; only on paper */
.print-head { display: none; }

/* On paper: light colours whatever the theme, no controls, every record, cards kept whole where they fit */
@media print {
  :root:not(#print), :root[data-theme]:not(#print) {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1f4f3;
    --divider: #d5dcda;
    --accent: #0b7a66;
    --accent-strong: #0b7a66;
    --on-accent: #ffffff;
    --text: #111111;
    --text-2: #4a5552;
    --text-3: #8a9894;
    --top: #ffffff;
    --link-hover: #075e4f;
    --card-edge: #d5dcda;
    --expense: #b4372b;
    --income: #1b7a47;
    --transfer: #2a5bb8;
    --bar-dim: #a8d8ca;
    --bar-hover: #0b7a66;
    --tip: #ffffff;
    --meter: #dff3ec;
    --meter-over: #f6dad5;
    --dot-edge: rgba(0, 0, 0, .25);
    --shadow: transparent;
    --up: #b4372b;
    --down: #1b7a47;
    color-scheme: light;
  }
  body { font-size: 12px; }
  main { max-width: none; padding: 0; }
  .top { border: 0; padding: 0 0 6px; }
  .top .actions, .top .source, .guide, .theme-toggle, .filters, #download-note, .records-tools:not(.muted), details.table, .tabs, .tip, #more { display: none !important; }
  .print-head { display: block; font-weight: 600; margin-bottom: 8px; }
  .cards { display: block; }
  .tile, .card { border: 1px solid var(--card-edge); }
  .card { margin-bottom: 10px; break-inside: avoid; }
  .card.wide { break-inside: auto; }
  tr { break-inside: avoid; }
  .scroll, .records-scroll { overflow: visible; max-height: none; }
  .records-scroll thead th { position: static; }
  .sort .arrow { display: none; }
  .dot, .track > span, .meter, .meter > span, .chart, .donut, .spark, td .mini > span { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.records-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.records-tools input[type="search"] { flex: 1 1 220px; }
.hint { color: var(--text-2); font-size: 13px; margin-top: 8px; }

/* The AI tip over the tiles: a sparkle, what to do and what to ask, and the download itself */
.ai-tip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 14px;
  align-items: start;
  margin: 4px 0 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--card-edge);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
}
.ai-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); color: var(--accent); font-size: 18px; }
.ai-text { display: grid; gap: 6px; min-width: 0; font-size: 14px; }
.ai-text h2 { font-size: 15px; }
.ai-text p { color: var(--text-2); }
.ai-questions { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.ai-questions li { padding: 3px 10px; border-radius: 14px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.ai-text .ai-small { font-size: 12px; color: var(--text-3); }
.ai-text .ai-address { font-size: 13px; overflow-wrap: anywhere; }
.ai-text .ai-address code { color: var(--text); }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover { color: var(--text); }
@media (max-width: 600px) {
  .ai-tip { grid-template-columns: auto minmax(0, 1fr); }
  .ai-actions { grid-column: 1 / -1; justify-content: space-between; }
}

/* The records scroll inside their card, the headings staying in view, so a long list doesn't make a long page */
.records-scroll { max-height: min(70vh, 640px); overflow: auto; overscroll-behavior: contain; border-radius: 8px; }
.records-scroll:focus-visible { outline-offset: 0; }
.records-scroll thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
@media (max-width: 600px) {
  .records-scroll { max-height: 75vh; }
  .records-scroll thead { position: sticky; top: 0; z-index: 1; background: var(--surface); }
  .records-scroll thead th { position: static; }
}
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 2px 10px; border-radius: 15px; font-size: 13px; }
