/* Mobile-first. Tokens first; layout follows. */

:root {
  /* light theme */
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef1f3;
  --fg: #14171a;
  --fg-soft: #2a2f36;
  --muted: #6b7480;
  --border: #dde2e7;
  --hover-bg: #e9edf1;

  --accent: #15803d;
  --accent-strong: #16a34a;
  --accent-2: #22c55e;
  --accent-title-mid: #16a34a;
  --accent-glow: rgba(22, 163, 74, 0.14);

  --danger: #b53b3b;
  --danger-soft: rgba(181, 59, 59, 0.12);
  --danger-glow: rgba(181, 59, 59, 0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 20, 25, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 20, 25, 0.10);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161c24;
  --surface-2: #1c242e;
  --fg: #e6edf3;
  --fg-soft: #c5cdd6;
  --muted: #8b95a3;
  --border: #232d39;
  --hover-bg: #1f2933;

  --accent: #22c55e;
  --accent-strong: #34d399;
  --accent-2: #6ee7b7;
  --accent-title-mid: #34d399;
  --accent-glow: rgba(34, 197, 94, 0.16);

  --danger: #e76e6e;
  --danger-soft: rgba(231, 110, 110, 0.14);
  --danger-glow: rgba(231, 110, 110, 0.16);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

/* Theme toggle is intentionally instant — no cross-fade. */

/* ---------- header ----------
   Sizes mirror gold-bar-tracker: header padding 1rem desktop / 0.7rem 1rem
   mobile, h1 1.3rem / 1.05rem, burger 46x46 desktop / 36x36 mobile with a
   bigger glyph on mobile to compensate for the smaller frame. */
/* Center-align the burger and title. Gold-bar uses flex-end because
   its .header-title also holds a tab-strip — bottom-aligning both
   children makes sense there. We have only an h1, so flex-end +
   padding-bottom over-shoots and pushes the title higher than the
   burger. Center alignment + a tight `line-height: 1.2` on the h1
   (see below) keeps the title glyph optically centered against the
   burger glyph. */
header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 100;
}
.menu-wrapper { flex: 0 0 auto; }
.header-title {
  display: flex; align-items: center;
  flex: 1; min-width: 0;
}
header h1 {
  margin: 0;
  font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em;
  /* Tight line-height keeps the line box close to the glyph cap-height,
     so center-alignment in the header lands the glyphs at the burger's
     optical center. With the default body line-height (1.45), the line
     box has ~7px of empty descender space below the glyphs that
     visually shifts them up. */
  line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-title-mid) 50%, var(--accent-2) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  cursor: pointer;
}

.icon-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--fg-soft);
  width: 46px; height: 46px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  font-size: 1.45rem; cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-2); color: var(--fg); border-color: var(--border); }
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
#menu-btn { font-size: 1.25rem; }

@media (max-width: 480px) {
  header { padding: 0.7rem 1rem; gap: 0.15rem; }
  header h1 { font-size: 1.15rem; }
  .icon-btn { width: 40px; height: 40px; font-size: 1.2rem; }
  /* Bigger glyph + 2px upward nudge so the burger sits visually above
     the title baseline rather than centered with the descender space. */
  #menu-btn {
    width: 36px; height: 36px;
    font-size: 1.75rem;
    transform: translateY(-2px);
  }
}

/* ---------- drawer ---------- */
.menu-dropdown {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(280px, 82vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.35);
  padding: 1.25rem 0.85rem 2.5rem;
  z-index: 200;
  display: flex; flex-direction: column; gap: 0.35rem;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  pointer-events: none;
}
.menu-dropdown.is-open { transform: translateX(0); pointer-events: auto; }

.menu-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
}
.menu-backdrop.is-open { opacity: 1; pointer-events: auto; }

.menu-brand {
  padding: 0.25rem 0.85rem 0.7rem;
  margin-bottom: 0.3rem;
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-title-mid) 50%, var(--accent-2) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  border-bottom: 1px solid var(--border);
}

.menu-item {
  display: flex; align-items: center; width: 100%;
  background: transparent; border: none;
  padding: 0.65rem 0.85rem;
  color: var(--fg-soft);
  font: inherit; font-size: 0.95rem;
  text-align: left; cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 100ms ease, color 100ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .menu-item:hover { background: var(--hover-bg); color: var(--fg); }
  .menu-item:hover .menu-icon { color: var(--accent-strong); }
}
.menu-item.active { background: var(--hover-bg); color: var(--fg); }
.menu-item.active .menu-icon { color: var(--accent-strong); }
.menu-item:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
.menu-item[hidden],
.menu-account-info[hidden],
.menu-divider[hidden] { display: none; }

/* Icon slot is a FIXED-size flex box with an SVG inside. The SVG renders
   at exact pixel sizes, no font-metric drift like unicode glyphs had. */
.menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem; height: 1.5rem;
  flex: 0 0 1.5rem;
  margin-right: 0.6rem;
  color: var(--muted);
  transition: color 100ms ease;
}
.menu-icon svg {
  width: 14px; height: 14px;
  display: block;
}

.menu-divider {
  margin-top: 0.5rem;
  width: 100%;
  border: none; border-top: 1px solid var(--border);
  opacity: 0.6;
}
.menu-account-info {
  padding: 0.5rem 0.85rem 0.25rem;
  color: var(--muted); font-size: 0.78rem;
  word-break: break-word;
}
.menu-footer-credit {
  position: absolute;
  bottom: 0.7rem;
  left: 0.85rem; right: 0.85rem;
  font-size: 0.65rem; letter-spacing: 0.03em;
  color: var(--muted); opacity: 0.55;
  text-align: left;
}

/* ---------- main + cards + view title ---------- */
main { max-width: 960px; margin: 0 auto; padding-bottom: 2rem; }
.view { padding: 0; }
.view[hidden] { display: none; }
.view-title {
  margin: 1.2rem 1rem 0.4rem;
  font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em;
  color: var(--fg);
}

.card {
  margin: 1rem; padding: 1.1rem 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 0.65rem 0;
  font-size: 0.72rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.card h3 { margin: 0 0 0.5rem 0; font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); }
.muted-tiny { color: var(--muted); font-size: 0.78rem; }

/* ---------- buttons ----------
   Sizes copied verbatim from gold-bar-tracker:

   .btn-primary (Add Category / Add Account / standalone Add buttons),
   matches gold-bar's .site-btn-primary:
     desktop: padding 0.45rem 0.85rem, font inherits (~15px)
     mobile (<600px): padding 0.375rem 0.75rem, font-size 0.82rem

   dialog menu button (Cancel + Save inside <dialog>),
   matches gold-bar's `dialog menu button`:
     desktop: padding 0.55rem 0.95rem, font inherits
     mobile (<480px): padding 0.45rem 0.82rem, font-size 0.87rem

   Dialog buttons are intentionally larger than Add buttons —
   matches gold-bar's hierarchy. */
.btn,
.btn-primary,
.btn-danger,
.btn-ghost {
  font: inherit; font-weight: 500;
  cursor: pointer;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease, color 120ms ease, box-shadow 120ms ease, filter 120ms ease;
  white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--surface-2); border-color: var(--muted); }
  .btn-primary:hover { filter: brightness(1.06); }
  .btn-danger:hover { background: var(--danger-soft); }
  .btn-ghost:hover { color: var(--fg); background: var(--hover-bg); }
}
.btn:active, .btn-primary:active, .btn-danger:active, .btn-ghost:active { transform: scale(0.98); }
.btn:focus-visible, .btn-primary:focus-visible, .btn-danger:focus-visible, .btn-ghost:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong) 0%, var(--accent) 100%);
  color: #ffffff;
  border: 1px solid var(--accent);
  font-weight: 600;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 1px 2px var(--accent-glow);
}
.btn-danger {
  color: var(--danger); border-color: var(--danger);
  background: transparent;
}
.btn-ghost {
  background: transparent; border-color: transparent; color: var(--muted);
  padding: 0.4rem 0.6rem;
}

@media (max-width: 599px) {
  .btn, .btn-primary, .btn-danger {
    padding: 0.375rem 0.75rem;
    font-size: 0.82rem;
  }
}

/* tiny inline action button (e.g. delete on a list row) */
.row-action {
  background: transparent; border: 0; color: var(--muted);
  width: 32px; height: 32px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; line-height: 1;
  transition: background 120ms ease, color 120ms ease;
}
.row-action:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- forms ---------- */
input[type=text], input[type=email], input[type=number], textarea {
  font: inherit; font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  width: 100%;
  min-height: 40px;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
@media (max-width: 599px) {
  /* iOS Safari zooms the viewport when an input has font-size < 16px on focus.
     16px is the minimum that prevents auto-zoom — we use it on mobile inputs
     deliberately, accepting the slightly bigger glyph as the cost of not
     having the page yank around when the keyboard opens. */
  input[type=text], input[type=email], input[type=number], textarea {
    min-height: 36px;
    padding: 0.5rem 0.7rem;
    font-size: 16px;
  }
}

label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; }

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; }
.field + .field { margin-top: 0.7rem; }

/* Defensive: the `hidden` attribute must beat any author display rule. */
[hidden] { display: none !important; }

/* ---------- custom dropdown ----------
   Themed div-based dropdown — replaces native <select> wherever we'd otherwise
   inherit the browser's default option popup. Backed by shared/dropdown.js. */
.dd { position: relative; width: 100%; }
.dd-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: 40px;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font: inherit; font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  gap: 0.5rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.dd-trigger:hover { border-color: var(--muted); }
.dd-trigger:focus-visible {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.dd-label { flex: 1; min-width: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.dd-chevron {
  width: 9px; height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 150ms ease, border-color 150ms ease;
  flex: 0 0 auto;
}
.dd.dd-open .dd-chevron {
  transform: rotate(-135deg) translateY(0);
  border-color: var(--accent-strong);
}
.dd-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  list-style: none; padding: 4px; margin: 0;
  max-height: 280px; overflow-y: auto;
  z-index: 50;
}
.dd.dd-open .dd-list { display: block; }
.dd-option {
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--fg-soft);
  transition: background 120ms ease, color 120ms ease;
  user-select: none;
}
.dd-option:hover { background: var(--hover-bg); color: var(--fg); }
.dd-option.active {
  background: linear-gradient(180deg, var(--accent-strong) 0%, var(--accent) 100%);
  color: #ffffff;
}
.dd-option.active:hover { color: #ffffff; }

@media (max-width: 599px) {
  .dd-trigger { min-height: 36px; padding: 0.5rem 0.7rem; font-size: 0.9rem; }
  .dd-option { padding: 0.5rem 0.65rem; font-size: 0.88rem; }
}

/* ---------- settings sections (custom collapsibles) ----------
   Native <details> can't animate the open/close transition smoothly:
   when [open] is toggled, the browser flips body children from
   display:none to visible instantly, which iOS Safari paints as a
   visible flash. To get a buttery expand/collapse, we use a plain
   <section> + <button> with a wrapper around the body. The wrapper is
   a CSS grid whose `grid-template-rows` animates from 0fr → 1fr — the
   modern "fully CSS, no JS measurement" expand pattern. Body content
   is always rendered (never display:none), so there's nothing to
   flash. */
.settings-section {
  margin: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.settings-summary {
  width: 100%;
  background: transparent; border: 0;
  cursor: pointer;
  padding: 0.95rem 1.1rem;
  display: flex; align-items: center; justify-content: space-between;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  color: var(--fg);
  text-align: left;
  user-select: none;
  /* iOS Safari paints a translucent grey overlay on tap by default;
     on a header-row button this reads as the title text "flashing"
     each time you toggle. Suppress it. */
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms ease;
}
.settings-summary:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: -2px;
}
.settings-summary::after {
  content: "›";
  color: var(--muted);
  font-size: 1.3rem;
  margin-left: 0.5rem;
  transition: transform 360ms cubic-bezier(0.4, 0, 0.2, 1);
}
.settings-section[data-open="true"] > .settings-summary::after {
  transform: rotate(90deg);
}
.settings-section .count {
  color: var(--muted); font-weight: 500; font-size: 0.85rem;
  margin-left: 0.5rem;
}

/* The wrap is a plain block with `overflow: hidden` and an animatable
   height. Closed = height 0; opening = JS sets explicit height to the
   measured scrollHeight, transition runs, then we clear back to auto
   so future content changes (adding a row) don't need re-measurement.
   Plain height transitions are much smoother than grid-template-rows
   on mobile Safari because they don't trigger grid layout recompute
   each frame. */
.settings-section > .settings-body-wrap {
  overflow: hidden;
  height: 0;
  transition: height 260ms cubic-bezier(0.32, 0.72, 0, 1);
}
.settings-section > .settings-body-wrap > .settings-body {
  padding: 0 1.1rem 1.1rem;
}
/* While the wrap is animating or fully open but not yet "revealed",
   keep the body's overflow clipped so popups don't leak. Once the
   open transition settles, JS flips [data-revealed=true] which lets
   the asset dropdown / color picker escape the card bounds. */
.settings-section > .settings-body-wrap > .settings-body {
  overflow: hidden;
}
.settings-section[data-open="true"][data-revealed="true"]
  > .settings-body-wrap > .settings-body {
  overflow: visible;
}

.list-rows { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.list-rows li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}
.list-rows li:first-child { border-top: 0; }
.list-rows .meta { color: var(--muted); font-size: 0.78rem; }
.list-rows .empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

.add-row {
  display: grid; gap: 0.5rem; grid-template-columns: 1fr auto;
  margin-bottom: 0.5rem;
}

/* ---------- color picker ----------
   "Pick a color" prompt + circular color chip, both hidden until the
   category name is non-empty. Click the chip → floating swatch popup. */
.color-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.color-picker[hidden] { display: none; }
.color-prompt {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.color-picker-trigger {
  width: 30px; height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0; cursor: pointer;
  display: inline-block;
  flex: 0 0 auto;
  transition: border-color 120ms ease, transform 80ms ease;
}
.color-picker-trigger:hover { border-color: var(--muted); transform: scale(1.06); }
.color-picker-trigger:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 2px;
}
.color-picker-trigger:active { transform: scale(0.94); }

.color-picker-popup {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 10px;
  z-index: 80;
  width: max-content;
}
.color-picker-popup[hidden] { display: none; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 28px);
  gap: 8px;
}
.swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0; cursor: pointer;
  position: relative;
  transition: transform 100ms ease, box-shadow 120ms ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--fg);
}
.swatch.active::after {
  content: "✓";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 0.8rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.swatch:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 2px;
}

@media (max-width: 479px) {
  .color-picker-trigger { width: 26px; height: 26px; }
  .color-prompt { font-size: 0.8rem; }
  .color-grid { grid-template-columns: repeat(6, 24px); gap: 6px; }
  .swatch { width: 24px; height: 24px; }
}

/* small color dot used in the category list */
.cat-dot {
  display: inline-block; vertical-align: middle;
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--muted);
  margin-right: 0.5rem;
  flex: 0 0 auto;
}

/* Category add-row layout: name fills, color picker + Add wrap to a 2nd
   line on narrow screens. align-items: center keeps the chip baseline
   matched to the Add button. */
.add-row-with-color {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.add-row-with-color > input { flex: 1 1 200px; min-width: 0; }

.add-form {
  display: flex; flex-direction: column; gap: 0.7rem;
  margin-bottom: 0.5rem;
}
.add-form .submit-row {
  display: flex; justify-content: flex-end;
}

/* ---------- segmented control (radios as pills) ----------
   A single `.seg-indicator` element behind the buttons slides to the
   active one via transform + width. This gives a smooth "the green pill
   moves" feel instead of a cross-fade. JS sets the indicator's
   translateX/width on render and on each click; CSS animates them. */
.seg-group {
  position: relative;
  display: flex; flex-wrap: wrap;
  width: 100%;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  gap: 4px;
}
.seg-indicator {
  position: absolute;
  top: 4px; bottom: 4px;
  left: 0; width: 0;
  background: linear-gradient(180deg, var(--accent-strong) 0%, var(--accent) 100%);
  border-radius: 7px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 1px 2px var(--accent-glow);
  transform: translateX(0);
  transition: transform 320ms cubic-bezier(0.4, 0, 0.2, 1),
              width 320ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 0;
  /* Until JS measures and positions the indicator (e.g. while the
     parent accordion is closed and offsets are 0), keep it invisible
     so a stub at translateX(0)/width:0 doesn't flash on first paint. */
  opacity: 0;
}
.seg-indicator.is-ready { opacity: 1; }
.seg-group button {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  background: transparent; border: 0;
  color: var(--muted);
  font: inherit; font-size: 0.85rem; font-weight: 500;
  padding: 0.5rem 0.85rem;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
  -webkit-tap-highlight-color: transparent;
  transition: color 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
.seg-group button:hover { color: var(--fg-soft); }
.seg-group button.active { color: #ffffff; }
.seg-group.seg-pill { border-radius: 999px; }
.seg-group.seg-pill button { border-radius: 999px; }
.seg-group.seg-pill .seg-indicator { border-radius: 999px; }

@media (max-width: 599px) {
  .seg-group button {
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
    min-height: 30px;
  }
}

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface); color: var(--fg);
  max-width: 420px; width: 92%;
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h3 { margin-top: 0; }
dialog form { margin: 0; }
dialog menu {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 0; margin: 1rem 0 0;
}
dialog menu button {
  font: inherit; font-weight: 500;
  padding: 0.55rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--fg);
  cursor: pointer;
  /* Kill the translucent iOS tap overlay that paints on touch. */
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms ease, border-color 120ms ease, filter 120ms ease;
}
/* On phones, <dialog>.showModal() auto-focuses the first button (Cancel),
   and browsers paint a focus ring even for touch — looks like a stuck hover.
   Suppress the ring unless it's a real keyboard focus. */
dialog menu button:focus { outline: none; }
dialog menu button:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 2px;
}
dialog menu button[value="save"] {
  background: linear-gradient(180deg, var(--accent-strong) 0%, var(--accent) 100%);
  color: #fff; border-color: var(--accent); font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15), 0 1px 2px var(--accent-glow);
}
dialog menu button[value="save"].dialog-danger-confirm {
  background: linear-gradient(180deg, #f47b7b 0%, var(--danger) 100%);
  border-color: var(--danger);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.15), 0 1px 2px var(--danger-glow);
}
@media (hover: hover) and (pointer: fine) {
  dialog menu button:hover { background: var(--hover-bg); }
  dialog menu button[value="save"]:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent-strong) 0%, var(--accent) 100%); }
  dialog menu button[value="save"].dialog-danger-confirm:hover { filter: brightness(1.05); }
}
@media (max-width: 479px) {
  dialog { padding: 1.05rem 1rem 0.85rem; }
  dialog menu button {
    padding: 0.45rem 0.82rem;
    font-size: 0.87rem;
  }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); font-size: 0.88rem;
  opacity: 0; pointer-events: none; transition: opacity 0.18s;
  z-index: 300; max-width: 90vw; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 0.95; }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ---------- responsive bump ---------- */
@media (min-width: 600px) {
  .view-title { font-size: 1.7rem; margin: 1.4rem 1rem 0.5rem; }
}
@media (min-width: 720px) {
  .card { padding: 1.25rem 1.4rem 1.4rem; }
  .settings-summary { padding: 1.05rem 1.4rem; }
  .settings-section > .settings-body-wrap > .settings-body {
    padding: 0 1.4rem 1.3rem;
  }
}
