/* ==========================================================================
   Mental: styles. Colours are tokens (light, then dark). Mobile first:
   bottom tab bar and stacked cards on phones, header menu and tables on desktop.
   ========================================================================== */

:root {
  color-scheme: light dark;
  /* Surfaces: warm off-white page, white cards. */
  --bg: #f6f3ee;
  --card: #ffffff;
  --card-2: #faf8f4;
  --border: #e7e1d8;
  --shadow: 0 1px 2px rgba(41, 33, 22, .06), 0 4px 14px rgba(41, 33, 22, .05);
  /* Ink. */
  --text: #1f2a2b;
  --muted: #6a6f6b;
  /* Brand: deep teal, with coral for highlights. */
  --accent: #0f766e;
  --accent-strong: #0f5e59;
  --accent-soft: #e2f3f0;
  --accent-text: #ffffff;
  --coral: #e8604c;
  --coral-soft: #fde9e4;
  --header: #0f5e59;
  --header-text: #e9f6f3;
  /* Status (always with an icon or a label). */
  --pos: #15803d;
  --pos-soft: #e3f4e8;
  --neg: #c2362f;
  --neg-soft: #fbe6e3;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --info: #3f5bd8;
  --info-soft: #e6eafc;
  --radius: 14px;
  --radius-sm: 9px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1515;
    --card: #162120;
    --card-2: #1b2827;
    --border: #2a3b39;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    --text: #e6efed;
    --muted: #9aaaa7;
    --accent: #3cc6b5;
    --accent-strong: #5ad6c6;
    --accent-soft: #163a37;
    --accent-text: #062321;
    --coral: #ff8a76;
    --coral-soft: #3d2420;
    --header: #0c1a19;
    --header-text: #d9ece8;
    --pos: #4fd17f;
    --pos-soft: #16301f;
    --neg: #ff7b70;
    --neg-soft: #3a1c1a;
    --warn: #f2b14a;
    --warn-soft: #36290f;
    --info: #8ea2ff;
    --info-soft: #1f2645;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom)); /* room for the tab bar */
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.25; margin: .25rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
main { max-width: 1120px; margin: 0 auto; padding: 1rem; }
main.login { max-width: 380px; padding-top: 10vh; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem calc(.55rem); padding-top: max(.55rem, env(safe-area-inset-top));
  background: var(--header); color: var(--header-text);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.1rem; color: #fff; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, var(--coral) 0 50%, #f5b041 50% 100%); }
.desktop-nav { display: none; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.lang-switch { gap: 0; background: rgba(255, 255, 255, .12); border-radius: 999px; padding: 2px; }
.lang-switch button { background: none; color: var(--header-text); border: 0; font-size: .78rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px; min-height: 0; }
.lang-switch button.active { background: #fff; color: var(--header); }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--coral); color: #fff; font-weight: 800; font-size: .9rem;
}
.avatar:hover { text-decoration: none; filter: brightness(1.05); }
.top .logout { display: none; color: var(--header-text); }

/* ---------- Bottom tab bar (phones) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
}
.tabbar > a, .tabbar summary {
  display: grid; justify-items: center; gap: 2px; padding: .45rem 0 .5rem;
  color: var(--muted); font-size: .7rem; font-weight: 600; cursor: pointer; list-style: none;
}
.tabbar summary::-webkit-details-marker { display: none; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar svg circle { fill: currentColor; stroke: none; }
.tabbar > a:hover { text-decoration: none; }
.tabbar .active, .tabbar .active > summary { color: var(--accent); }
.tabbar > a.active svg, .tabbar .active > summary svg { stroke-width: 2.3; }
.more { position: relative; }
.more[open] > summary { color: var(--accent); }
.more-menu {
  position: absolute; right: .5rem; bottom: calc(100% + .5rem); min-width: 220px;
  display: grid; padding: .4rem; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.more-menu a, .more-menu button { padding: .7rem .8rem; border-radius: var(--radius-sm); color: var(--text); text-align: left; font-weight: 500; }
.more-menu a:hover { background: var(--accent-soft); text-decoration: none; }
.more-menu a.active { background: var(--accent-soft); color: var(--accent); }
.more-menu form { border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .3rem; }
.more-menu button { width: 100%; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .desktop-nav { display: flex; gap: .15rem; flex-wrap: wrap; }
  .desktop-nav a { color: var(--header-text); opacity: .85; padding: .35rem .65rem; border-radius: 999px; font-weight: 500; font-size: .92rem; }
  .desktop-nav a:hover { opacity: 1; background: rgba(255, 255, 255, .1); text-decoration: none; }
  .desktop-nav a.active { opacity: 1; background: rgba(255, 255, 255, .16); box-shadow: inset 0 -2px 0 var(--coral); }
  .top .logout { display: inline; font-size: .85rem; opacity: .85; }
  main { padding: 1.5rem; }
  h1 { font-size: 1.65rem; }
}

/* ---------- Cards and layout ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .card { padding: 1.25rem; } }
.notice { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-soft); }
.notice.error { border-color: var(--neg); background: var(--neg-soft); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: .75rem; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1rem; }
.scroll, .chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Forms ---------- */
input, select, button, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .45rem .6rem; min-height: 38px; max-width: 100%;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type="checkbox"], input[type="radio"] { min-height: 0; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
input[type="file"] { padding: .35rem; }
input.amount { width: 7.5rem; text-align: right; font-variant-numeric: tabular-nums; }
select.empty { border-color: var(--warn); background: var(--warn-soft); }
button {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius-sm);
  padding: .5rem 1rem; min-height: 38px; font-weight: 600; cursor: pointer;
}
button:hover { background: var(--accent-strong); }
button.secondary { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
button.secondary:hover { background: var(--accent-soft); }
button.small { padding: .2rem .6rem; min-height: 30px; font-size: .85rem; }
button.link { background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }
button.danger, .danger { color: var(--neg); }
button.danger-button { background: var(--neg); color: #fff; }
.fields { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.fields label { display: grid; gap: .25rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.fields .grow { flex: 1 1 220px; }
.fields .narrow input { width: 5.5rem; }
.fields .full { flex-basis: 100%; margin: 0; }
.filters { margin-bottom: 1rem; }
label.check { display: flex !important; align-items: center; gap: .45rem; color: var(--text); font-weight: 500; font-size: .9rem; }
details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: .75rem; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; flex-wrap: wrap; }
fieldset.choice { border: 0; padding: 0; margin: 0; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
fieldset.choice legend { float: left; font-size: .82rem; font-weight: 600; color: var(--muted); margin-right: .25rem; }

/* Phones: full-width fields, bigger touch targets, 16px text (no zoom on focus in iOS). */
@media (max-width: 699px) {
  input, select, textarea { font-size: 16px; min-height: 44px; }
  button { min-height: 44px; }
  button.small { min-height: 36px; }
  .fields > label, .fields > .grow, .fields > fieldset { flex: 1 1 100%; }
  .fields > label input:not([type="checkbox"]):not([type="radio"]), .fields > label select { width: 100%; }
  .fields > button { flex: 1 1 auto; }
  .fields .narrow input { width: 100%; }
  .card { border-radius: 12px; }
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
tr.group th { background: var(--card-2); color: var(--accent); text-transform: uppercase; }
tr.group th a { text-transform: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/*
 * Stacked tables on phones: each row becomes a card and each cell shows its column name
 * (td[data-label]). Used for the wide tables (budget plan, contributions, accounts, rules…).
 */
@media (max-width: 699px) {
  table.stack-table thead { display: none; }
  table.stack-table, table.stack-table tbody, table.stack-table tr, table.stack-table td { display: block; width: 100%; }
  table.stack-table tr { padding: .6rem 0; border-bottom: 1px solid var(--border); }
  table.stack-table tr.group { padding: 0; border: 0; }
  table.stack-table tr.group th { display: block; border-radius: 8px; margin-top: .6rem; }
  table.stack-table td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; align-items: center; gap: .75rem; text-align: right; }
  table.stack-table td:first-child { font-weight: 700; font-size: 1rem; text-align: left; }
  table.stack-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
  table.stack-table td:empty { display: none; }
  table.stack-table td select, table.stack-table td input:not([type="checkbox"]) { max-width: 60%; }
  table.stack-table td form.inline { justify-content: flex-end; }
  table.stack-table tbody tr:hover { background: none; }
}

/* ---------- Tasks ---------- */
tr.status-done td:first-child a { text-decoration: line-through; color: var(--muted); }
tr.status-blocked td:first-child a { color: var(--warn); }
.status-select { font-weight: 600; border-width: 1.5px; }
.status-select.status-todo { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
.status-select.status-in_progress { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.status-select.status-blocked { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 35%, transparent); color: var(--neg); }
.status-select.status-done { background: var(--pos-soft); border-color: color-mix(in srgb, var(--pos) 35%, transparent); color: var(--pos); }
.take { background: var(--coral); color: #fff; }
.take:hover { background: color-mix(in srgb, var(--coral) 85%, #000); }
.deadline { white-space: nowrap; }
.deadline.late { color: var(--neg); font-weight: 600; }

/* Phones: each task is a card: title / category · deadline · who / status + delete. */
@media (max-width: 699px) {
  table.tasks thead { display: none; }
  table.tasks tr {
    display: grid; grid-template-columns: 1fr auto auto; gap: .35rem .75rem; align-items: center;
    grid-template-areas: "title title title" "cat date who" "status status del";
    padding: .75rem .25rem; border-bottom: 1px solid var(--border);
  }
  table.tasks td { border: 0; padding: 0; }
  table.tasks td:nth-child(1) { grid-area: title; font-weight: 600; }
  table.tasks td:nth-child(2) { grid-area: cat; color: var(--muted); font-size: .85rem; }
  table.tasks td:nth-child(3) { grid-area: date; font-size: .85rem; }
  table.tasks td:nth-child(4) { grid-area: who; font-size: .85rem; text-align: right; }
  table.tasks td:nth-child(5) { grid-area: status; }
  table.tasks td:nth-child(5) select { width: 100%; }
  table.tasks td:nth-child(6) { grid-area: del; }
  table.tasks td:nth-child(6) button { min-width: 44px; min-height: 44px; font-size: 1.1rem; }
  table.tasks tbody tr:hover { background: none; }
}

/* ---------- Operations ---------- */
@media (max-width: 699px) {
  table.ops thead { display: none; }
  table.ops tr {
    display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem;
    grid-template-areas: "desc amount" "date date" "cat cat";
    padding: .7rem .25rem; border-bottom: 1px solid var(--border);
  }
  table.ops tr.group, table.ops tr.remembered { display: block; padding: 0; }
  table.ops tr.group th { display: block; border-radius: 8px; margin-top: .6rem; }
  table.ops td { border: 0; padding: 0; }
  table.ops td:nth-child(1) { grid-area: date; font-size: .82rem; color: var(--muted); }
  table.ops td:nth-child(2) { grid-area: desc; font-weight: 600; overflow-wrap: anywhere; }
  table.ops td:nth-child(3) { grid-area: amount; font-weight: 700; }
  table.ops td:nth-child(4) { grid-area: cat; }
  table.ops td:nth-child(4) form { display: flex; }
  table.ops td:nth-child(4) select { width: 100%; }
  table.ops tr.remembered td { display: block; padding: .6rem; }
  table.ops tbody tr:hover { background: none; }
}
tr.remembered td { background: var(--pos-soft); border-left: 4px solid var(--pos); font-size: .9rem; }
tr.remembered form.inline { margin-right: .75rem; }
tr.remembered input[name="keyword"] { width: 12rem; }
.shared-toggle { margin-top: .35rem; }

/* ---------- Tabs, tiles, badges ---------- */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; }
.tabs a { padding: .35rem .75rem; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-weight: 500; font-size: .9rem; }
.tabs a:hover { text-decoration: none; border-color: var(--accent); }
.tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tabs.scope { margin: -.4rem 0 .75rem; }
.tabs.scope a.active { background: var(--coral); border-color: var(--coral); color: #fff; }
.pager { justify-content: center; align-items: center; margin-top: 1rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
@media (max-width: 699px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem .9rem .8rem 1.05rem; color: var(--muted);
  font-weight: 600; font-size: .85rem; box-shadow: var(--shadow);
}
.tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--accent); }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile strong { display: block; font-size: 1.8rem; line-height: 1.1; color: var(--text); font-weight: 800; }
.tile:nth-child(1)::before { background: var(--info); }
.tile:nth-child(2)::before { background: var(--warn); }
.tile:nth-child(3)::before { background: var(--coral); }
.tile.warn::before { background: var(--neg); }
.tile.warn strong { color: var(--neg); }
.tile:nth-child(5)::before { background: var(--accent); }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; margin-left: .3rem;
  border-radius: 999px; background: var(--card-2); border: 1px solid var(--border); color: var(--muted); vertical-align: middle;
}
.badge.size { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ---------- Text helpers ---------- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.error { color: var(--neg); }
.warn-text { color: var(--warn); }
.danger-text { color: var(--neg); }
.summary { margin: .5rem 0 1rem; }
.report { margin-top: 0; }
.savings-line { margin: .5rem 0 0; }
ul.problems { margin: 0; padding-left: 1.2rem; }
meter { width: 6rem; height: .7rem; vertical-align: middle; }
@media (max-width: 699px) { meter { width: 4rem; } }

/* ---------- Warnings ---------- */
.warning { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); background: var(--warn-soft); border-left: 5px solid var(--warn); }
.warning ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .45rem; }
.warning-icon { color: var(--warn); font-weight: 800; }

/* ---------- Page specifics ---------- */
tr.actions td { padding-top: 0; }
tr.actions details { display: inline-block; vertical-align: top; margin-right: 1.5rem; }
tr.actions summary { font-weight: 500; color: var(--accent); font-size: .9rem; }
tr.actions details[open] { display: block; margin: .5rem 0; }
tr.person td { font-weight: 600; }
tr.sub td { font-size: .88rem; color: var(--muted); border-bottom-style: dotted; }
tr.sub td:first-child { padding-left: 1.2rem; }
table.plan select { max-width: 9rem; }
table.mapping { max-width: 640px; }
table.mapping th { text-transform: none; letter-spacing: 0; font-size: .9rem; color: var(--text); font-weight: 500; width: 40%; }
table.mapping input { width: 100%; }
.chart-table { margin-top: .5rem; font-size: .9rem; }
.chart-table summary { font-weight: 500; color: var(--accent); }

/* ---------- Charts: categorical palette (validated: CVD-safe adjacent pairs, both modes) ---------- */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-other: #b4b2a9;
  --chart-grid: #ece6dc; --chart-axis: #cfc6b8; --chart-hover: rgba(15, 94, 89, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-other: #5d5c57;
    --chart-grid: #263634; --chart-axis: #3a4e4b; --chart-hover: rgba(255, 255, 255, .06);
  }
}
svg.chart { display: block; width: 100%; min-width: 560px; height: auto; font: 11px system-ui, sans-serif; }
svg.chart .tick, svg.chart .name { fill: var(--muted); }
svg.chart .name { fill: var(--text); font-size: 12px; }
svg.chart .value { fill: var(--muted); font-variant-numeric: tabular-nums; }
svg.chart .value.over { fill: var(--neg); font-weight: 600; }
svg.chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--chart-axis); stroke-width: 1; }
svg.chart .target { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
svg.chart .line { fill: none; stroke-width: 2; stroke-linecap: round; }
svg.chart .band { fill: transparent; pointer-events: all; }
svg.chart .band:hover { fill: var(--chart-hover); }
.s1 { fill: var(--series-1); } .s2 { fill: var(--series-2); } .s3 { fill: var(--series-3); } .s4 { fill: var(--series-4); }
.s5 { fill: var(--series-5); } .s6 { fill: var(--series-6); } .s7 { fill: var(--series-7); } .s-other { fill: var(--series-other); }
svg.chart .plan { stroke: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; list-style: none; padding: 0; margin: 0 0 .5rem; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .35rem; }
.legend .key { display: inline-block; }
.legend .key-swatch { width: .7rem; height: .7rem; border-radius: 3px; }
.legend .key-swatch.s1 { background: var(--series-1); } .legend .key-swatch.s2 { background: var(--series-2); }
.legend .key-swatch.s3 { background: var(--series-3); } .legend .key-swatch.s4 { background: var(--series-4); }
.legend .key-swatch.s5 { background: var(--series-5); } .legend .key-swatch.s6 { background: var(--series-6); }
.legend .key-swatch.s7 { background: var(--series-7); } .legend .key-swatch.s-other { background: var(--series-other); }
.legend .key-line { width: 1rem; height: 2px; border-radius: 1px; background: var(--text); }

/* ---------- Login ---------- */
main.login h1 { display: flex; align-items: center; gap: .5rem; color: var(--accent); }
main.login .card { box-shadow: var(--shadow); }

/* ---------- Compact filters on phones (two per row) ---------- */
@media (max-width: 699px) {
  form.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; }
  form.filters > label { flex: none; }
  form.filters > label.check { align-self: center; }
  form.filters > button { grid-column: 1 / -1; }
}
.import-box > summary { color: var(--accent); }
.import-box > summary::before { content: "⤓ "; }

/* Progress meters in the brand colours. */
meter { appearance: none; -webkit-appearance: none; border-radius: 999px; background: var(--card-2); }
meter::-webkit-meter-bar { background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; height: .7rem; }
meter::-webkit-meter-optimum-value { background: var(--accent); border-radius: 999px; }
meter::-webkit-meter-suboptimum-value { background: var(--warn); border-radius: 999px; }
meter::-webkit-meter-even-less-good-value { background: var(--neg); border-radius: 999px; }
meter::-moz-meter-bar { background: var(--accent); border-radius: 999px; }
meter:-moz-meter-sub-optimum::-moz-meter-bar { background: var(--warn); }
meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--neg); }

/* ---------- Grocery list ---------- */
.add-item { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.add-item input[name="name"] { flex: 1 1 12rem; }
.add-item .qty { flex: 0 1 7rem; width: 7rem; }
@media (max-width: 699px) { .add-item button { flex: 1 1 100%; } .add-item .qty { flex: 1 1 6rem; } }
ul.shopping { list-style: none; padding: .25rem .5rem; margin: 0 0 1rem; }
ul.shopping li { display: flex; align-items: center; gap: .5rem; border-bottom: 1px solid var(--border); }
ul.shopping li:last-child { border-bottom: 0; }
ul.shopping .toggle { flex: 1; margin: 0; }
.check-button {
  width: 100%; display: flex; align-items: center; gap: .75rem; padding: .7rem .25rem; min-height: 52px;
  background: none; color: var(--text); font-weight: 500; text-align: left; border-radius: 0;
}
.check-button:hover { background: none; }
.check-button .box {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px;
  border: 2px solid var(--accent); color: #fff; font-size: .85rem; font-weight: 800;
}
.check-button .name { flex: 1; overflow-wrap: anywhere; font-size: 1.02rem; }
.qty-tag { flex: none; font-size: .8rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: .1rem .55rem; }
li.checked .box { background: var(--accent); }
li.checked .name { text-decoration: line-through; color: var(--muted); }
li.checked .qty-tag { color: var(--muted); background: var(--card-2); }
ul.in-cart { opacity: .85; }
.remove { min-width: 44px; min-height: 44px; font-size: 1rem; }
.clear-actions { justify-content: space-between; }
.empty-list { text-align: center; padding: 2rem 0; }
.tile.groceries::before { background: var(--pos); }

a.button { display: inline-flex; align-items: center; background: var(--accent); color: var(--accent-text); border-radius: var(--radius-sm); padding: .5rem 1rem; min-height: 38px; font-weight: 600; }
a.button:hover { background: var(--accent-strong); text-decoration: none; }
.copy-field { width: 100%; font-family: ui-monospace, monospace; font-size: .8rem; }

/* Operation tools: split, merge back, manual */
.op-tools { margin-top: .35rem; font-size: .85rem; }
.op-tools > summary { font-weight: 500; color: var(--accent); font-size: .85rem; }
.split-form { display: grid; gap: .4rem; margin-top: .4rem; }
.split-part { display: flex; gap: .4rem; }
.split-part select { flex: 1; min-width: 0; }
.manual-box > summary::before { content: "＋ "; }

.log-box > summary { color: var(--coral); }
.log-box > summary::before { content: "✓ "; }
a.button.small-button { min-height: 32px; padding: .3rem .8rem; font-size: .85rem; background: var(--coral); }
a.button.small-button:hover { background: color-mix(in srgb, var(--coral) 85%, #000); }

textarea { width: 100%; resize: vertical; font: inherit; }
ul.checklist { margin-bottom: .75rem; }

.aisle-select { flex: 0 1 10rem; }
@media (max-width: 699px) { .aisle-select { flex: 1 1 100%; } }
h2.aisle-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin: 1rem .25rem .4rem; }
ul.shopping + h2.aisle-title { margin-top: .25rem; }
.star { min-width: 40px; min-height: 44px; font-size: 1.15rem; color: var(--muted); }
.star.on { color: #e3a008; }
form.usual { margin-bottom: 1rem; }
form.usual button { width: 100%; }

.goal { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.goal:last-of-type { border-bottom: 0; }
.goal-bar { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; }
.goal-bar meter { flex: 1; width: auto; height: .9rem; }
.balance-edit > summary { color: var(--accent); font-weight: 500; }
.balance-edit form { margin-top: .4rem; }

/* Stacked forms (login…): the label text always above a full-width field, whatever its length. */
.stack > label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.stack > label > input, .stack > label > select, .stack > label > textarea { width: 100%; }

ul.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
ul.plain-list li { line-height: 1.4; }
ul.plain-list .deadline { display: block; }
.postpone { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; }
button.chip { background: var(--card-2); color: var(--accent); border: 1px solid var(--border); border-radius: 999px; min-height: 28px; padding: .1rem .55rem; font-size: .78rem; font-weight: 600; }
button.chip:hover { background: var(--accent-soft); }
@media (max-width: 699px) { button.chip { min-height: 34px; } }

.tabs.lists { margin: -.4rem 0 1rem; align-items: center; }
.tabs.lists .count { display: inline-grid; place-items: center; min-width: 1.3rem; height: 1.3rem; border-radius: 999px; background: var(--coral); color: #fff; font-size: .72rem; font-weight: 800; padding: 0 .3rem; margin-left: .2rem; }
.tabs.lists a.active .count { background: #fff; color: var(--accent); }
.new-list { position: relative; }
.tab-like { list-style: none; padding: .35rem .75rem; border-radius: 999px; background: var(--card); border: 1px dashed var(--accent); color: var(--accent); font-weight: 700; cursor: pointer; }
.tab-like::-webkit-details-marker { display: none; }
.new-list[open] form { margin-top: .5rem; }
.manage-list > summary { color: var(--muted); font-weight: 500; font-size: .9rem; }
.manage-list form + form { margin-top: .5rem; }

.qr { width: 200px; max-width: 60vw; background: #fff; padding: 8px; border-radius: 10px; margin: .5rem 0; }
.qr svg { display: block; width: 100%; height: auto; }
code.secret { font-family: ui-monospace, monospace; background: var(--card-2); padding: .1rem .35rem; border-radius: 6px; word-break: normal; overflow-wrap: break-word; }
.totp-steps { margin: .25rem 0; padding-left: 1.2rem; }

/* ---------- Header: one line in every language ---------- */
.top { flex-wrap: nowrap; }
.top-tools { flex: none; }
.top-tools form.inline { flex-wrap: nowrap; }
.top .logout { white-space: nowrap; }
@media (min-width: 900px) {
  .desktop-nav { flex-wrap: nowrap; align-items: center; min-width: 0; }
  .desktop-nav a, .nav-more > summary { white-space: nowrap; }
  .nav-more { position: relative; }
  .nav-more > summary {
    list-style: none; cursor: pointer; color: var(--header-text); opacity: .85; padding: .35rem .65rem;
    border-radius: 999px; font-weight: 500; font-size: .92rem;
  }
  .nav-more > summary::-webkit-details-marker { display: none; }
  .nav-more > summary:hover, .nav-more[open] > summary { opacity: 1; background: rgba(255, 255, 255, .1); }
  .nav-more.active > summary { opacity: 1; background: rgba(255, 255, 255, .16); box-shadow: inset 0 -2px 0 var(--coral); }
  .nav-more-menu {
    position: absolute; left: 0; top: calc(100% + .4rem); z-index: 40; min-width: 210px; display: grid; padding: .4rem;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  }
  .desktop-nav .nav-more-menu a { color: var(--text); opacity: 1; border-radius: var(--radius-sm); padding: .55rem .75rem; }
  .desktop-nav .nav-more-menu a:hover { background: var(--accent-soft); }
  .desktop-nav .nav-more-menu a.active { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
}
/* Menus opening as pop-ups: their title must not move when open. */
.nav-more[open] > summary, .tabbar .more[open] > summary, .new-list[open] > summary { margin-bottom: 0; }
.goal form.inline { margin-top: .2rem; }
.achieved { margin: .75rem 0; }
.achieved > summary { color: var(--muted); }
