/* Ledger — bookkeeping prototype
   Minimal, single-blue accent, generous whitespace, type-led hierarchy. */

:root {
  color-scheme: light;
  --accent: #0066cc;
  --accent-focus: #0071e3;
  --accent-on-dark: #2997ff;
  --ink: #1d1d1f;
  --ink-80: #333333;
  --ink-48: #7a7a7a;
  --ink-32: #a8a8ad;
  --hairline: #e0e0e0;
  --hairline-soft: #f0f0f0;
  --canvas: #ffffff;
  --parchment: #f5f5f7;
  --pearl: #fafafc;
  --black: #000000;

  /* heatmap (calendar) — derived from accent at low chroma */
  --heat-0: #f5f5f7;
  --heat-1: #e7eef8;
  --heat-2: #cbdcf2;
  --heat-3: #94b8e3;
  --heat-4: #5c8fd2;

  /* category tints (label dots only; never floods) */
  --c-food:      #d96a3a;
  --c-transport: #2a6fdb;
  --c-shopping:  #b54a8f;
  --c-entertain: #c0a51f;
  --c-home:      #3a8a6b;
  --c-health:    #cc4747;
  --c-social:    #7c3aed;
  --c-other:     #7a7a7a;

  /* density-driven sizes (overridden via [data-density]) */
  --row-pad-y: 14px;
  --row-pad-x: 18px;
  --row-font: 15px;
}

[data-density="緊湊"] { --row-pad-y: 8px;  --row-pad-x: 14px; --row-font: 14px; }
[data-density="寬鬆"] { --row-pad-y: 18px; --row-pad-x: 20px; --row-font: 16px; }

/* ────────── Dark Theme (Apple-flavoured) ────────── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #2997ff;          /* Sky Link Blue */
  --accent-focus: #5ab1ff;
  --accent-on-dark: #2997ff;

  --ink: #ffffff;
  --ink-80: rgba(235, 235, 245, 0.85);
  --ink-48: rgba(235, 235, 245, 0.55);
  --ink-32: rgba(235, 235, 245, 0.32);

  --hairline: rgba(255, 255, 255, 0.10);
  --hairline-soft: rgba(255, 255, 255, 0.06);

  --canvas: #1c1c1e;          /* card surface (iOS grouped) */
  --parchment: #000000;        /* page background — true black */
  --pearl: #2c2c2e;            /* chip / hover surface */
  --black: #000000;

  /* heatmap — accent-tinted, darker base */
  --heat-0: rgba(255, 255, 255, 0.04);
  --heat-1: rgba(41, 151, 255, 0.14);
  --heat-2: rgba(41, 151, 255, 0.28);
  --heat-3: rgba(41, 151, 255, 0.52);
  --heat-4: rgba(41, 151, 255, 0.78);

  /* category dots — slightly desaturated for dark surfaces */
  --c-food:      #ff8c5a;
  --c-transport: #4d92ff;
  --c-shopping:  #d76ab1;
  --c-entertain: #e6cd47;
  --c-home:      #5ab18a;
  --c-health:    #ff6b6b;
  --c-social:    #9d7cf0;
  --c-other:     #a8a8ad;
}
[data-theme="dark"] body,
[data-theme="dark"] #root { background: #000000; color: #ffffff; }

/* ────────── Dark Theme — control-surface overrides ────────── */
/* Many controls (chips, pills, inputs, toggles) use var(--parchment) for a
   "subtle raised surface" feel. In dark mode --parchment is true black (page bg),
   so we re-tint those controls to a slightly raised charcoal so they show on cards. */
[data-theme="dark"] .field input,
[data-theme="dark"] .chip-cat:not(.chip-on),
[data-theme="dark"] .chip-sub:not(.chip-on),
[data-theme="dark"] .pill:not(.pill-on),
[data-theme="dark"] .btn-utility-ghost,
[data-theme="dark"] .mini-chip:not(.mini-chip-on):not(.mini-chip-focus),
[data-theme="dark"] .mp-cell:not(.mp-cell-sel),
[data-theme="dark"] .sort-toggle,
[data-theme="dark"] .view-toggle,
[data-theme="dark"] .list-head-meta .tag {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-80);
}
[data-theme="dark"] .pill:hover { background: rgba(255, 255, 255, 0.10); }
[data-theme="dark"] .mini-chip:hover { background: rgba(255, 255, 255, 0.10); }
[data-theme="dark"] .field input:focus {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--accent);
}
[data-theme="dark"] .pill-on,
[data-theme="dark"] .mini-chip-focus { background: #fff; color: #000; border-color: #fff; }
[data-theme="dark"] .mini-chip-on { background: var(--accent); color: #fff; }
[data-theme="dark"] .view-tab-on {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
[data-theme="dark"] .seg-on { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: none; }

/* MonthPicker popover */
[data-theme="dark"] .mp-pop {
  background: #2c2c2e;
  border-color: rgba(255,255,255,0.10);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
[data-theme="dark"] .mp-step:hover { background: rgba(255,255,255,0.10); }
[data-theme="dark"] .mp-cell-sel { background: var(--accent); color: #fff; }
[data-theme="dark"] .mp-today:hover { background: rgba(41, 151, 255, 0.16); }

/* Side panel */
[data-theme="dark"] .panel-x:hover { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .panel { box-shadow: 0 0 80px rgba(0,0,0,0.55); }
[data-theme="dark"] .panel-scrim { background: rgba(0,0,0,0.5); }

/* Sub-cat / category dot wrappers in dark — keep colors but soften ring */
[data-theme="dark"] .focus-dot {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.10);
}

/* Stat row delta pills */
[data-theme="dark"] .delta-up   { background: rgba(255, 82, 82, 0.16); color: #ff8a80; }
[data-theme="dark"] .delta-down { background: rgba(48, 209, 88, 0.16); color: #5cd97a; }

/* Charts */
[data-theme="dark"] .donut-num { fill: #ffffff; }
[data-theme="dark"] .donut-lbl { fill: var(--ink-48); }
[data-theme="dark"] .bar-lbl { fill: var(--ink-48); }
[data-theme="dark"] .bar-today { fill: #ffffff; }
[data-theme="dark"] .hbar-track { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .budget-bar { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .budget-pace { background: #ffffff; }

/* Calendar cell defaults — heat-0 needs to read as "empty cell" on dark */
[data-theme="dark"] .cal-cell { color: var(--ink-80); }
[data-theme="dark"] .cal-cell:hover { border-color: rgba(255,255,255,0.18); }

/* Keyboard hint */
[data-theme="dark"] .kbd-hint {
  background: rgba(28,28,30,0.85);
  border-color: rgba(255,255,255,0.10);
}
[data-theme="dark"] .kbd-hint kbd {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.14);
  color: var(--ink-80);
}

/* Tweaks panel — the starter ships its own light styling; subtly adapt */
[data-theme="dark"] .twk-panel {
  background: rgba(28,28,30,0.85) !important;
  color: #fff !important;
}

* { box-sizing: border-box; }

html, body, #root {
  margin: 0;
  padding: 0;
  background: var(--parchment);
  color: var(--ink);
  font-family: "SF Pro Text", "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
               "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

button, input { font: inherit; color: inherit; }
button { cursor: default; }
input { background: transparent; }
ul { list-style: none; padding: 0; margin: 0; }
a { color: var(--accent); text-decoration: none; }

/* ───────────────────────── Global nav ───────────────────────── */

.global-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 32px;
  background: var(--black);
  color: #fff;
  font-size: 13px;
  letter-spacing: -0.01em;
}
.gn-left { display: flex; align-items: center; gap: 28px; }
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 14px; letter-spacing: 0;
  color: #fff;
}
.logo svg { color: #fff; }
.gn-links { display: flex; gap: 22px; }
.gn-link {
  background: transparent;
  border: 0;
  padding: 4px 0;
  color: rgba(255,255,255,.82);
  font-size: 13px;
  font-family: inherit;
  letter-spacing: -0.01em;
  cursor: default;
  position: relative;
}
.gn-link:hover { color: #fff; }
.gn-link-active { color: #fff; }
.gn-link-active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -16px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
}
.gn-link-soon { color: rgba(255,255,255,.40); }
.gn-link-soon:hover { color: rgba(255,255,255,.55); }
.gn-right { display: flex; align-items: center; gap: 12px; }

.search {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  width: 280px;
  height: 32px;
  padding: 0 12px;
  background: rgba(255,255,255,.10);
  border-radius: 8px;
  color: rgba(255,255,255,.82);
  transition: background .15s ease, width .2s ease;
}
.search:focus-within { background: rgba(255,255,255,.16); width: 320px; }
.search input {
  flex: 1; border: 0; outline: 0; background: transparent;
  color: #fff; font-size: 13px;
}
.search input::placeholder { color: rgba(255,255,255,.5); }
.search kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  background: rgba(255,255,255,.12);
  border-radius: 4px;
  color: rgba(255,255,255,.7);
}

.btn-utility {
  height: 32px;
  padding: 0 14px;
  background: rgba(255,255,255,.10);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
}
.btn-utility:hover { background: rgba(255,255,255,.16); }

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px;
  padding: 0 14px 0 12px;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  transition: transform .12s ease, filter .12s ease;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.96); }
.btn-primary .plus { font-size: 14px; line-height: 1; }
.kbd-on-blue {
  display: inline-block;
  padding: 1px 5px;
  font-size: 10.5px;
  background: rgba(255,255,255,.22);
  border-radius: 4px;
  margin-left: 2px;
}

/* ───────────────────────── Sub nav ───────────────────────── */

.sub-nav {
  position: sticky; top: 52px; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px 14px;
  background: rgba(245, 245, 247, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
[data-theme="dark"] .sub-nav {
  background: rgba(0, 0, 0, 0.72);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
.sn-left { display: flex; align-items: center; gap: 18px; }
.sn-title {
  margin: 0;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.sn-title-wrap { position: relative; }
.sn-title-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 0;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 8px;
  color: var(--ink);
  transition: background .12s ease;
}
.sn-title-btn:hover { background: rgba(0,0,0,0.04); }
.sn-caret {
  color: var(--ink-48);
  margin-left: 2px;
  margin-top: 4px;
  transition: transform .15s ease;
}
.sn-title-btn[aria-expanded="true"] .sn-caret { transform: rotate(180deg); }

/* MonthPicker popover */
.mp-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 60;
  width: 320px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.10);
  padding: 14px;
  animation: mpIn .15s ease;
}
@keyframes mpIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mp-head {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 12px;
}
.mp-step {
  width: 28px; height: 28px;
  flex-shrink: 0;
  background: transparent;
  border: 0; border-radius: 6px;
  font-size: 14px;
  color: var(--ink-48);
}
.mp-step:hover { background: rgba(0,0,0,0.05); color: var(--ink); }
.mp-year-strip {
  flex: 1;
  display: flex; gap: 2px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.mp-year-strip::-webkit-scrollbar { display: none; }
.mp-year {
  flex-shrink: 0;
  padding: 4px 8px;
  background: transparent;
  border: 0; border-radius: 6px;
  font-size: 12.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
}
.mp-year:hover { background: rgba(0,0,0,0.04); color: var(--ink); }
.mp-year-cur { color: var(--ink); font-weight: 600; }
.mp-year-sel { color: var(--accent); font-weight: 600; }

.mp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.mp-cell {
  height: 40px;
  background: var(--parchment);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
  transition: background .12s ease, color .12s ease;
}
.mp-cell:hover { background: rgba(0, 102, 204, 0.08); color: var(--accent); }
.mp-cell-sel { background: var(--accent); color: #fff; }
.mp-cell-sel:hover { background: var(--accent); color: #fff; filter: brightness(1.08); }

.mp-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline-soft);
}
.mp-today {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: 6px;
}
.mp-today:hover { background: rgba(0, 102, 204, 0.08); }
.mp-hint { font-size: 11px; color: var(--ink-32); }
.sn-stepper { display: inline-flex; gap: 4px; }
.step {
  height: 32px; min-width: 32px;
  padding: 0 10px;
  background: rgba(0,0,0,0.04);
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
}
.step:hover { background: rgba(0,0,0,0.08); }
.step-today { font-size: 12px; padding: 0 12px; color: var(--accent); font-weight: 500; }

.sn-right { display: flex; align-items: center; gap: 10px; }

/* Range preset chips in sub-nav */
.range-presets {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.range-chip {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 14px;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-80);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.range-chip:hover { background: #fff; }
[data-theme="dark"] .range-chip {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.10);
}
[data-theme="dark"] .range-chip:hover { background: rgba(255,255,255,0.12); }
.range-chip-on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.range-chip-on:hover { background: var(--accent); filter: brightness(1.08); }
.range-chip-custom { cursor: default; pointer-events: none; }
.range-hint {
  font-size: 11px;
  color: var(--ink-48);
  margin-left: 4px;
  letter-spacing: 0;
}

/* Legacy filter-chips kept for the list-section filter row */
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 28px;
  padding: 0 12px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-80);
  transition: background .12s ease, color .12s ease;
}
.chip:hover { background: rgba(0,0,0,0.05); }
.chip-on {
  background: var(--accent);
  color: #fff;
}
.chip-on:hover { background: var(--accent); filter: brightness(1.08); }
[data-theme="dark"] .chip:hover { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .chip-on { background: var(--accent); color: #fff; }

/* ───────────────────────── Page shell ───────────────────────── */

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 32px 96px;
}

/* ───────────────────────── Stat row ───────────────────────── */

.stat-row {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr;
  gap: 18px;
  margin-bottom: 24px;
}
.stat {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.stat-hero {
  grid-row: span 1;
}
.stat-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.stat-value {
  display: flex; align-items: baseline; gap: 8px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1;
}
.stat-value .mark {
  font-size: 16px;
  color: var(--ink-48);
  font-weight: 500;
  letter-spacing: 0;
}
.stat-value .num {
  font-size: 44px;
  color: var(--ink);
}
.stat-hero .stat-value .num { font-size: 52px; }

.stat-meta { display: flex; flex-direction: column; gap: 6px; }
.stat-meta-quiet { font-size: 13px; color: var(--ink-48); }

.stat-delta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px;
}
.delta-date { color: var(--ink-48); }
.delta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.delta-up   { background: rgba(192, 57, 43, 0.10); color: #b32d1f; }
.delta-down { background: rgba(58, 138, 107, 0.12); color: #2c6a4f; }

.budget-bar {
  position: relative;
  height: 6px;
  background: var(--hairline-soft);
  border-radius: 999px;
  overflow: hidden;
}
.budget-fill {
  position: absolute; inset: 0 auto 0 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .25s ease;
}
.budget-pace {
  position: absolute; top: -3px; bottom: -3px;
  width: 2px;
  background: var(--ink);
  border-radius: 1px;
  transform: translateX(-1px);
}
.budget-legend {
  display: flex; justify-content: space-between;
  font-size: 12px;
  color: var(--ink-48);
}
.budget-legend .pace { color: var(--ink-80); }
.budget-legend .pace-over { color: #c0392b; font-weight: 500; }

/* ───────────────────────── Grid (calendar | rank | list) ───────────────────────── */

.grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  grid-template-areas:
    "cal  rank"
    "list list";
  gap: 18px;
}
.card-cal  { grid-area: cal; }
.card-rank { grid-area: rank; }
.card-list { grid-area: list; }

.card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  overflow: hidden;
}

/* ───────────────────────── Calendar ───────────────────────── */

.calendar { padding: 20px 22px 18px; }
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.cal-head-l { display: flex; align-items: baseline; gap: 12px; }
.cal-head-r { display: flex; align-items: center; gap: 12px; }
.cal-pick-hint {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}
.cal-clear {
  height: 28px;
  padding: 0 12px;
  background: rgba(0, 102, 204, 0.08);
  border: 0;
  border-radius: 999px;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
}
.cal-clear:hover { background: rgba(0, 102, 204, 0.14); }
[data-theme="dark"] .cal-clear { background: rgba(41, 151, 255, 0.14); }
[data-theme="dark"] .cal-clear:hover { background: rgba(41, 151, 255, 0.22); }
.cal-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.cal-legend {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  color: var(--ink-48);
}
.cal-legend i {
  width: 10px; height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-grid-head { margin-bottom: 6px; gap: 6px; }
.cal-dow {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-48);
  text-align: center;
  padding: 6px 0 2px;
  letter-spacing: 0.02em;
}
.cal-dow-end { color: var(--ink-32); }

.cal-cell {
  position: relative;
  min-height: 62px;
  padding: 8px 8px 8px;
  background: var(--heat-0);
  border: 1px solid transparent;
  border-radius: 10px;
  display: flex; flex-direction: column; justify-content: space-between;
  align-items: flex-start;
  font-size: 12px;
  color: var(--ink);
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.cal-cell:hover { border-color: rgba(0,0,0,0.12); }
.cal-cell:active { transform: scale(0.97); }
.cal-blank { background: transparent; pointer-events: none; }

.cal-d { font-weight: 500; color: var(--ink-80); }
.cal-amt {
  align-self: flex-end;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.cal-cell.cal-heat-1 { background: var(--heat-1); }
.cal-cell.cal-heat-2 { background: var(--heat-2); }
.cal-cell.cal-heat-3 { background: var(--heat-3); color: #fff; }
.cal-cell.cal-heat-3 .cal-d, .cal-cell.cal-heat-3 .cal-amt { color: #fff; }
.cal-cell.cal-heat-4 { background: var(--heat-4); color: #fff; }
.cal-cell.cal-heat-4 .cal-d, .cal-cell.cal-heat-4 .cal-amt { color: #fff; }

/* Calendar range selection */
.cal-cell.cal-single {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent);
}
.cal-cell.cal-single .cal-d,
.cal-cell.cal-single .cal-amt { color: #fff !important; }

.cal-cell.cal-in-range {
  background: var(--heat-1) !important;
  color: var(--ink) !important;
}
.cal-cell.cal-in-range .cal-d,
.cal-cell.cal-in-range .cal-amt { color: var(--ink) !important; }

.cal-cell.cal-range-between {
  border-radius: 4px;
}

.cal-cell.cal-range-start,
.cal-cell.cal-range-end {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent);
  position: relative;
}
.cal-cell.cal-range-start .cal-d,
.cal-cell.cal-range-end .cal-d,
.cal-cell.cal-range-start .cal-amt,
.cal-cell.cal-range-end .cal-amt { color: #fff !important; }

.cal-cell.cal-range-start { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.cal-cell.cal-range-end   { border-top-left-radius: 4px;  border-bottom-left-radius: 4px; }

.cal-cell.cal-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.cal-cell.cal-today.cal-single,
.cal-cell.cal-today.cal-range-start,
.cal-cell.cal-today.cal-range-end { outline-color: #fff; }

.cal-selbar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 0 0;
  padding: 10px 14px;
  background: rgba(0, 102, 204, 0.06);
  border-radius: 10px;
  font-size: 13px;
}
[data-theme="dark"] .cal-selbar { background: rgba(41, 151, 255, 0.10); }
.cal-selbar-tail { color: var(--ink-48); margin-left: 4px; }
.cal-selbar-pending {
  background: rgba(0, 102, 204, 0.06);
  color: var(--accent);
}
.cal-selbar-pending b { color: var(--accent); }
.link {
  background: transparent; border: 0; padding: 0;
  color: var(--accent); font-size: 13px;
}
.link:hover { text-decoration: underline; }

/* ───────────────────────── Rank ───────────────────────── */

.rank { padding: 20px 22px 14px; }
.rank-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
  gap: 10px;
}
.rank-head-r { display: flex; align-items: center; gap: 8px; }
.rank-mode-toggle {
  display: inline-flex;
  background: var(--parchment);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
[data-theme="dark"] .rank-mode-toggle { background: rgba(255,255,255,0.06); }
.rank-mode {
  height: 26px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink-48);
  font-weight: 500;
}
.rank-mode-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
[data-theme="dark"] .rank-mode-on { background: rgba(255,255,255,0.14); color: #fff; box-shadow: none; }

.rank-total-line {
  font-size: 12px;
  color: var(--ink-48);
  margin-bottom: 12px;
}

.rank-empty {
  padding: 24px 0;
  color: var(--ink-48);
  font-size: 13px;
}

/* All-categories grid */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px 0 8px;
}
.cat-tile {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 12px;
  text-align: left;
  position: relative;
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
}
.cat-tile:hover {
  background: var(--canvas);
  border-color: var(--hairline);
}
[data-theme="dark"] .cat-tile {
  background: rgba(255,255,255,0.04);
}
[data-theme="dark"] .cat-tile:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
}
.cat-tile-empty { opacity: 0.55; }
.cat-tile:active { transform: scale(0.985); }
.cat-tile-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid var(--hairline);
}
[data-theme="dark"] .cat-tile-icon { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.10); }
.cat-tile-icon .cat-dot { width: 10px; height: 10px; border-radius: 3px; }
.cat-tile-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-tile-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}
.cat-tile-meta {
  font-size: 11.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-tile-arrow {
  color: var(--ink-32);
  font-size: 14px;
}
.cat-tile:hover .cat-tile-arrow { color: var(--accent); }
.cat-tile-pip {
  position: absolute;
  top: 10px; right: 10px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.rank-list { display: flex; flex-direction: column; }
.rank-item { border-bottom: 1px solid var(--hairline-soft); }
.rank-item:last-child { border-bottom: 0; }

.rank-row {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto auto 16px;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  background: transparent;
  border: 0;
  text-align: left;
  position: relative;
}
.rank-rank {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-32);
  letter-spacing: 0.04em;
}
.rank-name {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 15px;
  color: var(--ink);
  font-weight: 500;
}
.rank-name .cat-dot { width: 7px; height: 7px; border-radius: 2px; }
.rank-share {
  font-size: 12px; color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  min-width: 32px; text-align: right;
}
.rank-amt {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-48);
  min-width: 100px; text-align: right;
}
.rank-amt b { color: var(--ink); font-weight: 600; font-size: 15px; margin-left: 4px; }
.rank-caret {
  font-size: 14px; color: var(--ink-48);
  text-align: center;
}
.rank-bar {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--hairline-soft);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}
.rank-bar i {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .25s ease;
}
.rank-item-open .rank-bar i { background: var(--accent); }
.rank-item-filtered .rank-name { color: var(--accent); }
.rank-item-filtered .rank-bar i { background: var(--accent); }

.rank-subs {
  padding: 6px 0 18px;
}
.rank-sub-tools { margin: 0 0 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.mini-chip {
  height: 26px; padding: 0 12px;
  background: var(--parchment);
  border: 0; border-radius: 999px;
  font-size: 12px; color: var(--ink-80);
}
.mini-chip-on { background: var(--accent); color: #fff; }
.mini-chip-focus { background: var(--ink); color: #fff; }
.mini-chip-focus:hover { filter: brightness(1.15); }

.rank-sub-list { display: flex; flex-direction: column; gap: 8px; padding-left: 38px; }
.rank-sub {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 12px;
  font-size: 13px;
}
.rank-sub-name { color: var(--ink-80); }
.rank-sub-amt { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.rank-sub-bar {
  grid-column: 1 / -1;
  height: 2px;
  background: var(--hairline-soft);
  border-radius: 2px;
  overflow: hidden;
}
.rank-sub-bar i {
  display: block; height: 100%;
  background: var(--accent);
  opacity: 0.7;
  border-radius: 2px;
}

/* View tab toggle (list / chart) */
.view-toggle {
  display: inline-flex;
  background: var(--parchment);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.view-tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 12px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-48);
  font-weight: 500;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.view-tab:hover { color: var(--ink); }
.view-tab-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.view-tab svg { opacity: 0.72; }
.view-tab-on svg { opacity: 1; }

/* ───────────────────────── Charts ───────────────────────── */

.charts {
  padding: 18px 22px 22px;
  display: flex; flex-direction: column; gap: 28px;
}
.chart-block { display: flex; flex-direction: column; gap: 14px; }
.chart-head {
  display: flex; align-items: baseline; justify-content: space-between;
}
.chart-head-meta {
  display: inline-flex; align-items: center; gap: 14px;
  font-size: 12px; color: var(--ink-48);
}
.legend-dot {
  display: inline-flex; align-items: center; gap: 6px;
}
.legend-dot::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  background: var(--accent);
  margin-right: 2px;
}
.legend-line::before {
  width: 14px; height: 2px;
  background: var(--ink-32);
  border-radius: 1px;
}

.chart-bars {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bar-canvas {
  position: relative;
  height: 140px;
  width: 100%;
}
.bars {
  display: flex;
  align-items: flex-end;
  height: 100%;
  gap: 3px;
  width: 100%;
}
.bar-track {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
}
.bar {
  width: 100%;
  background: var(--accent);
  opacity: 0.78;
  border-radius: 2px;
  min-height: 1px;
  transition: opacity .15s ease;
}
.bar:hover { opacity: 1; }
.bar-today {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 0 1.4px var(--accent-focus) inset;
}
.bar-avg-line {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px dashed var(--ink-32);
  pointer-events: none;
  z-index: 1;
}
.bar-labels {
  display: flex;
  width: 100%;
  gap: 3px;
}
.bar-lbl-col {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: visible;
}

.chart-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline-soft);
}
.cs-item { display: flex; flex-direction: column; gap: 4px; }
.cs-k {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.cs-item b {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.chart-pair {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 800px) {
  .chart-pair { grid-template-columns: 1fr; }
}

.donut-wrap {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 22px;
  align-items: center;
}
.donut-slice {
  transition: opacity .15s ease;
}
.donut-slice:hover { opacity: 0.82; }
.donut-num {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}
.donut-lbl {
  font-size: 10px;
  fill: var(--ink-48);
  letter-spacing: 0.04em;
}
.donut-legend {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px;
}
.dl-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 8px;
}
.dl-name { color: var(--ink-80); }
.dl-pct { color: var(--ink-48); font-variant-numeric: tabular-nums; font-size: 12px; }

/* Donut & hbar fills mirror category colors */
.donut-food,      .cat-fill-food      { fill: var(--c-food);      background: var(--c-food); }
.donut-transport, .cat-fill-transport { fill: var(--c-transport); background: var(--c-transport); }
.donut-shopping,  .cat-fill-shopping  { fill: var(--c-shopping);  background: var(--c-shopping); }
.donut-entertain, .cat-fill-entertain { fill: var(--c-entertain); background: var(--c-entertain); }
.donut-home,      .cat-fill-home      { fill: var(--c-home);      background: var(--c-home); }
.donut-health,    .cat-fill-health    { fill: var(--c-health);    background: var(--c-health); }
.donut-social,    .cat-fill-social    { fill: var(--c-social);    background: var(--c-social); }
.donut-other,     .cat-fill-other     { fill: var(--c-other);     background: var(--c-other); }

.hbar-list { display: flex; flex-direction: column; gap: 10px; }
.hbar-row {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.hbar-name {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-80);
}
.hbar-track {
  height: 8px;
  background: var(--hairline-soft);
  border-radius: 4px;
  overflow: hidden;
}
.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  opacity: 0.85;
}
.hbar-amt {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 500;
}

.chart-note {
  font-size: 12px;
  color: var(--ink-48);
  padding-top: 4px;
  border-top: 1px dashed var(--hairline);
  margin-top: 4px;
}

/* ───────────────────────── List ───────────────────────── */

.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--hairline-soft);
}
.list-head-l { display: flex; flex-direction: column; gap: 4px; }
.list-head-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 13px; color: var(--ink-48);
}
.list-head-meta .tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  background: var(--parchment);
  border-radius: 999px;
  font-size: 12px; color: var(--ink);
}
/* Category focus banner */
.focus-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  background: linear-gradient(180deg, rgba(0, 102, 204, 0.06), rgba(0, 102, 204, 0.02));
  border-bottom: 1px solid var(--hairline-soft);
}
[data-theme="dark"] .focus-banner {
  background: linear-gradient(180deg, rgba(41, 151, 255, 0.10), rgba(41, 151, 255, 0.03));
}
.focus-exit {
  height: 32px; padding: 0 14px;
  background: rgba(0, 102, 204, 0.08);
  border: 0; border-radius: 999px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}
.focus-exit:hover { background: rgba(0, 102, 204, 0.14); }
[data-theme="dark"] .focus-exit { background: rgba(41, 151, 255, 0.14); }
[data-theme="dark"] .focus-exit:hover { background: rgba(41, 151, 255, 0.22); }
.focus-banner-l {
  display: flex; align-items: center; gap: 14px;
}
.focus-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--hairline);
}
.focus-dot .cat-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
}
.focus-title {
  font-size: 15px;
  color: var(--ink-80);
}
.focus-title b {
  color: var(--ink);
  font-weight: 600;
  margin-left: 2px;
}
.focus-meta {
  font-size: 12.5px;
  color: var(--ink-48);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.focus-exit {
  height: 32px; padding: 0 14px;
  background: rgba(0, 102, 204, 0.08);
  border: 0; border-radius: 999px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}
.focus-exit:hover { background: rgba(0, 102, 204, 0.14); }

.chip-sub {
  background: var(--parchment);
  color: var(--ink-80);
}
.list-filter-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 12px 22px 12px;
  border-bottom: 1px solid var(--hairline-soft);
}
.chip-cat {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--parchment);
}
.chip-cat .cat-dot { width: 6px; height: 6px; border-radius: 2px; }
.chip-cat .chip-count {
  font-size: 11px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.chip-cat.chip-on { background: var(--accent); color: #fff; }
.chip-cat.chip-on .chip-count { color: rgba(255,255,255,.78); }
.chip-cat.chip-on .cat-dot { opacity: 0.9; }
  display: inline-flex;
  background: var(--parchment);
  border-radius: 8px;
  padding: 2px;
}
.seg {
  background: transparent;
  border: 0;
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--ink-80);
}
.seg-on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.04); }

.tx-list { padding: 4px 0 4px; }
.tx-group { padding: 8px 0; }
.tx-group-sel .tx-day { color: var(--accent); }

.tx-day {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 12px 22px 8px;
  border-bottom: 1px solid var(--hairline-soft);
  font-size: 13px;
}
.tx-day-l { display: flex; align-items: baseline; gap: 8px; }
.tx-day-rel { font-weight: 600; color: var(--ink); font-size: 14px; }
.tx-day-dot { color: var(--ink-32); }
.tx-day-date { color: var(--ink-48); }
.tx-day-r { display: flex; align-items: baseline; gap: 14px; }
.tx-day-count { color: var(--ink-48); font-size: 12px; }
.tx-day-total {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.tx-rows { }
.tx-row {
  display: grid;
  grid-template-columns: 52px 168px 1fr 80px 140px;
  align-items: center;
  gap: 14px;
  padding: var(--row-pad-y) var(--row-pad-x);
  font-size: var(--row-font);
  cursor: default;
  transition: background .1s ease;
  border-bottom: 1px solid var(--hairline-soft);
}
.tx-row:last-child { border-bottom: 0; }
.tx-row:hover { background: var(--pearl); }
.tx-row-sel { background: rgba(0, 102, 204, 0.06); }
.tx-row-sel:hover { background: rgba(0, 102, 204, 0.08); }
[data-theme="dark"] .tx-row-sel { background: rgba(41, 151, 255, 0.10); }
[data-theme="dark"] .tx-row-sel:hover { background: rgba(41, 151, 255, 0.14); }

.tx-time {
  color: var(--ink-48);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding-left: 8px;
}
.tx-cat {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px;
  color: var(--ink);
  min-width: 0;
  max-width: 100%;
}
/* Wraps the category+subcategory text so the ellipsis applies to the text,
   not to the row's flex container (which would also clip the cat-dot). */
.tx-cat-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-dot {
  width: 7px; height: 7px;
  border-radius: 2px;
  background: var(--c-other);
  flex-shrink: 0;
}
.tx-cat-food      .cat-dot { background: var(--c-food); }
.tx-cat-transport .cat-dot { background: var(--c-transport); }
.tx-cat-shopping  .cat-dot { background: var(--c-shopping); }
.tx-cat-entertain .cat-dot { background: var(--c-entertain); }
.tx-cat-home      .cat-dot { background: var(--c-home); }
.tx-cat-health    .cat-dot { background: var(--c-health); }
.tx-cat-social    .cat-dot { background: var(--c-social); }
.tx-cat-other     .cat-dot { background: var(--c-other); }
.tx-sub { color: var(--ink-48); font-size: 12.5px; margin-left: 1px; }
.tx-note {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  color: var(--ink-80);
  min-width: 0;
}
.tx-name {
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-note-extra {
  color: var(--ink-48);
  font-size: 12.5px;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-acct {
  color: var(--ink-48);
  font-size: 12.5px;
  text-align: left;
}
.tx-time {
  color: var(--ink-48);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
.tx-fx {
  color: var(--ink-48);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.dv-time { color: var(--ink-48); font-variant-numeric: tabular-nums; }
.dv-fx {
  color: var(--ink-48);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.tx-amt {
  display: inline-flex; justify-content: flex-end; align-items: baseline; gap: 4px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: 4px;
}
.tx-amt-mark {
  font-size: 11px;
  color: var(--ink-48);
  letter-spacing: 0;
  font-weight: 500;
}
.tx-amt-num {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  min-width: 64px;
  text-align: right;
}

.tx-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 20px;
  color: var(--ink-48);
  text-align: center;
}
.tx-empty-mark { font-size: 32px; color: var(--ink-32); margin-bottom: 8px; }
.tx-empty-h { font-size: 16px; color: var(--ink); margin-bottom: 4px; font-weight: 500; }

/* ───────────────────────── Side panel ───────────────────────── */

.panel-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.18);
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes panelSlideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ───────────────────────── Mobile bottom tab bar ───────────────────────── */
/* Default: hidden on desktop. Mobile @media block toggles to flex below. */
.mobile-tab-bar { display: none; }

/* Calendar collapse — toggle btn + summary hidden on desktop */
.cal-collapse-btn { display: none; }
.cal-summary { display: none; }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 101;
  width: 440px; max-width: 100vw;
  background: var(--canvas);
  display: flex; flex-direction: column;
  box-shadow: 0 0 60px rgba(0,0,0,0.18);
  animation: slideIn .22s cubic-bezier(.2,.7,.2,1);
  overflow-y: auto;
}
.panel-head {
  display: flex; align-items: center;
  padding: 18px 20px 8px;
  gap: 12px;
}
.panel-x {
  width: 32px; height: 32px;
  background: transparent;
  border: 0; border-radius: 8px;
  font-size: 14px;
  color: var(--ink-48);
}
.panel-x:hover { background: rgba(0,0,0,0.05); }
.panel-eyebrow {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.panel-actions { display: flex; gap: 6px; }
.btn-utility-ghost {
  height: 32px; padding: 0 12px;
  background: var(--parchment);
  border: 0; border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
}

.panel-amount {
  display: flex; align-items: baseline; gap: 6px;
  padding: 20px 24px 4px;
}
.panel-amt-mark {
  font-size: 18px;
  color: var(--ink-48);
  font-weight: 500;
}
.panel-amt-input {
  flex: 1;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 56px;
  font-weight: 600;
  letter-spacing: -0.03em;
  border: 0; outline: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-variant-numeric: tabular-nums;
  width: 100%;
}
.panel-amt-day {
  padding: 0 24px 24px;
  font-size: 13px;
  color: var(--ink-48);
}

.panel-fields {
  padding: 12px 24px;
  display: flex; flex-direction: column; gap: 20px;
  border-top: 1px solid var(--hairline-soft);
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.field input {
  height: 40px;
  padding: 0 14px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 15px;
  color: var(--ink);
  outline: 0;
  width: 100%;
}
.field input:focus { border-color: var(--accent); background: #fff; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.field-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  height: 32px; padding: 0 14px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-80);
  transition: background .12s ease, color .12s ease;
}
.pill:hover { background: var(--hairline); }
.pill-sub { background: transparent; }
.pill-sub:hover { background: var(--parchment); }
.pill-on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.pill-on:hover { background: var(--ink); filter: brightness(1.15); }

.panel-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 20px 24px 24px;
  border-top: 1px solid var(--hairline-soft);
  margin-top: auto;
}
.panel-foot .spacer { flex: 1; }
.btn-text-danger {
  background: transparent;
  border: 0;
  color: #c0392b;
  font-size: 13px;
  padding: 0;
}
.btn-text-danger:hover { text-decoration: underline; }

/* ───────────────────────── Detail Panel · View Mode ───────────────────────── */

.panel { overflow-y: auto; }

.btn-edit {
  display: inline-flex; align-items: center; gap: 5px;
}

/* Hero block — name, big amount, badges */
.dv-hero {
  padding: 24px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--hairline-soft);
}
.dv-cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  height: 28px;
  padding: 0 12px;
  background: var(--parchment);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-80);
}
[data-theme="dark"] .dv-cat-badge { background: rgba(255,255,255,0.08); }
.dv-cat-badge .cat-dot { width: 7px; height: 7px; border-radius: 2px; }
.dv-cat-badge .dv-sub { color: var(--ink-48); }

.dv-name {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
  word-break: break-word;
}
.dv-name-empty { color: var(--ink-48); font-style: italic; font-weight: 400; }

.dv-amt {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 4px;
}
.dv-amt-mark {
  font-size: 16px;
  color: var(--ink-48);
  font-weight: 500;
}
.dv-amt-num {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 48px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.dv-when, .dv-acct {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-48);
}
.dv-when svg, .dv-acct svg { opacity: 0.7; }
.dv-dot { color: var(--ink-32); margin: 0 2px; }
.dv-rel { color: var(--ink-80); font-weight: 500; }

/* Note block */
.dv-note {
  margin: 18px 24px 0;
  padding: 14px 16px;
  background: var(--parchment);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
[data-theme="dark"] .dv-note { background: rgba(255,255,255,0.06); }
.dv-note-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.dv-note-body {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
  text-wrap: pretty;
}

/* Stats grid */
.dv-stats {
  margin: 18px 24px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dv-stat {
  padding: 14px 14px;
  background: var(--parchment);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
[data-theme="dark"] .dv-stat { background: rgba(255,255,255,0.06); }
.dv-stat-k {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.dv-stat-v {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.dv-stat-up { color: #b32d1f; }
.dv-stat-down { color: #2c6a4f; }
[data-theme="dark"] .dv-stat-up { color: #ff8a8a; }
[data-theme="dark"] .dv-stat-down { color: #6fd6a5; }
.dv-stat-sub {
  font-size: 11.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
}

/* Sections (sparkline, similar) */
.dv-section {
  margin: 22px 24px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dv-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.dv-section-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.dv-section-meta { font-size: 12px; color: var(--ink-48); }

.dv-similar {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dv-similar-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.dv-similar-row:hover { background: var(--parchment); }
[data-theme="dark"] .dv-similar-row:hover { background: rgba(255,255,255,0.06); }
.dv-similar-date { color: var(--ink-48); font-variant-numeric: tabular-nums; }
.dv-similar-sub {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-80);
}
.dv-similar-sub .cat-dot { width: 6px; height: 6px; border-radius: 2px; }
.dv-similar-amt {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--ink);
}

/* Edit-mode name input — slightly bigger */
.field-input-name {
  font-size: 17px !important;
  font-weight: 500 !important;
  height: 44px !important;
}

/* ───────────────────────── Confirm dialog ───────────────────────── */

.confirm-scrim {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4);
  animation: fadeIn .15s ease;
}
.confirm-dialog {
  position: fixed; z-index: 201;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 380px; max-width: calc(100vw - 32px);
  background: var(--canvas);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
  overflow: hidden;
  animation: confirmIn .18s cubic-bezier(.2,.7,.2,1);
  border: 1px solid var(--hairline);
}
[data-theme="dark"] .confirm-dialog { box-shadow: 0 24px 80px rgba(0,0,0,0.7); }
@keyframes confirmIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.confirm-body { padding: 24px 24px 14px; }
.confirm-title {
  margin: 0 0 8px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.confirm-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-80);
  text-wrap: pretty;
}
.confirm-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--hairline-soft);
}
.btn-confirm-danger {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px;
  padding: 0 16px;
  background: #c0392b;
  color: #fff;
  border: 0; border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: filter .12s ease, transform .12s ease;
}
.btn-confirm-danger:hover { filter: brightness(1.06); }
.btn-confirm-danger:active { transform: scale(0.96); }
.btn-confirm-danger:disabled {
  background: var(--hairline);
  color: var(--ink-32);
  cursor: not-allowed;
}
[data-theme="dark"] .btn-confirm-danger { background: #ff453a; }
[data-theme="dark"] .btn-confirm-danger:disabled { background: rgba(255,255,255,0.10); color: rgba(255,255,255,0.3); }

/* ───────────────────────── Bulk action bar ───────────────────────── */

.bulk-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px;
  background: rgba(0, 102, 204, 0.06);
  border-top: 1px solid var(--hairline-soft);
  border-bottom: 1px solid var(--hairline-soft);
  gap: 12px;
  flex-wrap: wrap;
}
[data-theme="dark"] .bulk-bar { background: rgba(41, 151, 255, 0.10); }
.bulk-bar-l, .bulk-bar-r { display: flex; align-items: center; gap: 12px; }
.bulk-selectall {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.bulk-selectall:hover { background: rgba(0,0,0,0.04); }
[data-theme="dark"] .bulk-selectall:hover { background: rgba(255,255,255,0.06); }
.bulk-checkbox {
  width: 18px; height: 18px;
  border: 1.5px solid var(--ink-48);
  border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .12s ease, border-color .12s ease;
}
.bulk-checkbox-on { background: var(--accent); border-color: var(--accent); }
.bulk-summary {
  font-size: 13px;
  color: var(--ink-80);
  font-variant-numeric: tabular-nums;
}
.bulk-summary b { color: var(--ink); font-weight: 600; }

/* Transactions in bulk mode */
.tx-check {
  width: 22px; height: 22px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 4px;
}
.tx-check input {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  margin: 0;
  border: 1.5px solid var(--ink-48);
  border-radius: 5px;
  background: transparent;
  position: relative;
}
.tx-check input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.tx-check input:checked::after {
  content: '';
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff;
  border-width: 0 1.7px 1.7px 0;
  transform: rotate(45deg);
}
.tx-list-bulk .tx-row {
  grid-template-columns: 28px 52px 168px 1fr 80px 140px;
}
.tx-row-checked { background: rgba(0, 102, 204, 0.04); }
.tx-row-checked:hover { background: rgba(0, 102, 204, 0.08); }
[data-theme="dark"] .tx-row-checked { background: rgba(41, 151, 255, 0.08); }
[data-theme="dark"] .tx-row-checked:hover { background: rgba(41, 151, 255, 0.12); }

/* ───────────────────────── Manage categories overlay ───────────────────────── */

.cm-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.18);
  animation: fadeIn .15s ease;
}
.cm-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 101;
  width: 520px; max-width: 100vw;
  background: var(--canvas);
  display: flex; flex-direction: column;
  box-shadow: 0 0 60px rgba(0,0,0,0.18);
  animation: slideIn .22s cubic-bezier(.2,.7,.2,1);
  overflow-y: auto;
}
[data-theme="dark"] .cm-panel { box-shadow: 0 0 80px rgba(0,0,0,0.55); }
.cm-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 24px 12px;
  position: sticky; top: 0; z-index: 2;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline-soft);
}
.cm-meta {
  padding: 12px 24px 16px;
  font-size: 12px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
}
.cm-error {
  margin: 0 24px 12px;
  padding: 10px 14px;
  background: rgba(204, 71, 71, 0.10);
  border: 1px solid rgba(204, 71, 71, 0.35);
  border-radius: 10px;
  color: #cc4747;
  font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.cm-newcat-form {
  margin: 0 24px 12px;
  padding: 16px;
  background: var(--parchment);
  border-radius: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
[data-theme="dark"] .cm-newcat-form { background: rgba(255,255,255,0.06); }
.cm-newcat-form input {
  height: 40px;
  padding: 0 14px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font-size: 14px;
  color: var(--ink);
  outline: 0;
}
[data-theme="dark"] .cm-newcat-form input { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.10); }
.cm-newcat-form input:focus { border-color: var(--accent); }
.cm-color-row { display: flex; gap: 8px; }
.cm-color {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: transform .12s ease;
}
.cm-color:hover { transform: scale(1.1); }
.cm-color-on { border-color: var(--ink); box-shadow: inset 0 0 0 1px #fff; }
[data-theme="dark"] .cm-color-on { border-color: #fff; }
.cm-form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.cm-list {
  padding: 0 16px 16px;
  display: flex; flex-direction: column; gap: 6px; flex: 1;
}
.cm-item {
  background: transparent;
  border-radius: 10px;
  transition: background .12s ease;
}
.cm-item-selected { background: rgba(0, 102, 204, 0.06); }
[data-theme="dark"] .cm-item-selected { background: rgba(41, 151, 255, 0.10); }

.cm-row {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
}
.cm-check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
}
.cm-check input {
  appearance: none;
  -webkit-appearance: none;
  width: 17px; height: 17px;
  margin: 0;
  border: 1.5px solid var(--ink-48);
  border-radius: 4px;
  background: transparent;
  position: relative;
}
.cm-check input:checked { background: var(--accent); border-color: var(--accent); }
.cm-check input:checked::after {
  content: '';
  position: absolute;
  left: 4.5px; top: 0.5px;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 1.7px 1.7px 0;
  transform: rotate(45deg);
}
.cm-expand {
  display: grid;
  grid-template-columns: 22px 1fr auto 16px;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 8px 8px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  color: var(--ink);
  width: 100%;
}
.cm-expand:hover { background: rgba(0,0,0,0.03); }
[data-theme="dark"] .cm-expand:hover { background: rgba(255,255,255,0.04); }
.cm-dot {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--parchment);
  border-radius: 6px;
}
.cm-dot .cat-dot { width: 10px; height: 10px; border-radius: 3px; }
[data-theme="dark"] .cm-dot { background: rgba(255,255,255,0.06); }
.cm-name-input {
  background: transparent;
  border: 1px solid transparent;
  outline: 0;
  font: inherit;
  color: var(--ink);
  font-weight: 500;
  padding: 4px 6px;
  border-radius: 6px;
  min-width: 0;
  width: 100%;
}
.cm-name-input:hover { background: rgba(0,0,0,0.03); }
.cm-name-input:focus { background: var(--canvas); border-color: var(--accent); }
[data-theme="dark"] .cm-name-input:hover { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .cm-name-input:focus { background: rgba(255,255,255,0.10); }
.cm-count {
  font-size: 11.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cm-caret { color: var(--ink-32); font-size: 11px; }
.cm-delete-icon {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--ink-48);
}
.cm-delete-icon:hover { background: rgba(192,57,43,0.10); color: #c0392b; }
[data-theme="dark"] .cm-delete-icon:hover { background: rgba(255,69,58,0.16); color: #ff8a80; }

.cm-subs { padding: 0 8px 8px 32px; }
.cm-slug-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 8px 0;
  font-size: 12px;
}
.cm-slug-label {
  color: var(--ink-64);
  letter-spacing: 0.02em;
}
.cm-slug-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--hairline-soft);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
.cm-slug-input:focus {
  outline: none;
  border-color: var(--accent);
}
.cm-sub-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 1px solid var(--hairline-soft);
  padding-left: 12px;
}
.cm-sub {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}
.cm-sub:hover { background: rgba(0,0,0,0.03); }
[data-theme="dark"] .cm-sub:hover { background: rgba(255,255,255,0.04); }
.cm-sub-selected { background: rgba(0, 102, 204, 0.06); }
[data-theme="dark"] .cm-sub-selected { background: rgba(41, 151, 255, 0.10); }
.cm-sub-name { color: var(--ink-80); }
.cm-sub-count {
  font-size: 11px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
}
.cm-sub-new {
  grid-template-columns: 28px 1fr auto auto;
  background: var(--parchment);
}
[data-theme="dark"] .cm-sub-new { background: rgba(255,255,255,0.06); }
.cm-sub-new input {
  background: transparent;
  border: 0;
  font: inherit;
  color: var(--ink);
  padding: 4px 0;
  grid-column: 2;
  min-width: 0;
  width: 100%;
  outline: 0;
}
.cm-sub-addbtn { background: transparent; }
.cm-add-sub {
  grid-column: 1 / -1;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
}
.cm-add-sub:hover { text-decoration: underline; }
.link-muted { color: var(--ink-48); }

.cm-bulk-bar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 24px;
  background: var(--canvas);
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  z-index: 2;
}
.cm-bulk-bar .spacer { flex: 1; }
.cm-bulk-bar b { font-weight: 600; color: var(--ink); }

/* Categories page header — split */
.cats-page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px;
}
.cats-page-head-l { flex: 1; min-width: 0; }
.cats-page-head-r { flex-shrink: 0; }
.btn-utility-pale {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px;
  padding: 0 16px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.btn-utility-pale:hover {
  background: var(--parchment);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="dark"] .btn-utility-pale {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.10);
}
[data-theme="dark"] .btn-utility-pale:hover {
  background: rgba(255,255,255,0.12);
  border-color: var(--accent);
}

/* "Select" toggle button (outside view-toggle group) */
.view-tab-solo {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 12px;
  background: var(--parchment);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
  font-weight: 500;
  margin-right: 8px;
}
.view-tab-solo:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .view-tab-solo { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .view-tab-solo:hover { background: rgba(255,255,255,0.12); }
.view-tab-solo.view-tab-on { background: var(--accent); color: #fff; }

/* ───────────────────────── Settings page ───────────────────────── */

.settings-page {
  max-width: 720px;
  margin: 0 auto;
}
.sg-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  margin-bottom: 18px;
  overflow: hidden;
}
.sg-card-head {
  padding: 20px 24px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
  border-bottom: 1px solid var(--hairline-soft);
}
.sg-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--hairline-soft);
}
.sg-row-last { border-bottom: 0; }
.sg-row-l { flex: 1; min-width: 0; }
.sg-row-title {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.sg-row-sub {
  font-size: 12.5px;
  color: var(--ink-48);
  margin-top: 2px;
  line-height: 1.4;
  text-wrap: pretty;
}
.sg-value {
  font-size: 13.5px;
  color: var(--ink-80);
  font-variant-numeric: tabular-nums;
}
.sg-value-link {
  color: var(--accent);
  font-weight: 500;
  cursor: default;
}

/* iOS-style toggle */
.sg-toggle {
  position: relative;
  width: 50px; height: 30px;
  background: var(--hairline);
  border: 0;
  border-radius: 999px;
  transition: background .2s ease;
  flex-shrink: 0;
}
[data-theme="dark"] .sg-toggle { background: rgba(255,255,255,0.16); }
.sg-toggle-on { background: var(--accent) !important; }
.sg-toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.18);
  transition: transform .2s cubic-bezier(.2,.7,.2,1);
}
.sg-toggle-on .sg-toggle-knob { transform: translateX(20px); }

/* Swatches */
.sg-swatches { display: flex; gap: 8px; }
.sg-swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: default;
  transition: transform .12s ease;
}
.sg-swatch:hover { transform: scale(1.1); }
.sg-swatch-on {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px #fff;
}
[data-theme="dark"] .sg-swatch-on { border-color: #fff; }

/* Segmented */
.sg-seg {
  display: inline-flex;
  background: var(--parchment);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
[data-theme="dark"] .sg-seg { background: rgba(255,255,255,0.08); }
.sg-seg-btn {
  height: 30px;
  padding: 0 16px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-48);
  font-weight: 500;
}
.sg-seg-btn-on {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
[data-theme="dark"] .sg-seg-btn-on {
  background: rgba(255,255,255,0.14);
  box-shadow: none;
}

/* Input */
.sg-input-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px;
  padding: 0 12px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 10px;
  transition: border-color .15s ease;
}
.sg-input-wrap:focus-within { border-color: var(--accent); background: var(--canvas); }
[data-theme="dark"] .sg-input-wrap { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .sg-input-wrap:focus-within { background: rgba(255,255,255,0.12); }
.sg-input-prefix {
  font-size: 12px;
  color: var(--ink-48);
  font-weight: 500;
}
.sg-input {
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 120px;
  font-weight: 500;
}

/* Action rows (buttons) */
.sg-action-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 16px 24px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--hairline-soft);
  text-align: left;
  font: inherit;
  color: var(--ink);
  transition: background .12s ease;
}
.sg-action-row:hover { background: var(--parchment); }
[data-theme="dark"] .sg-action-row:hover { background: rgba(255,255,255,0.04); }
.sg-action-arrow {
  color: var(--ink-32);
  font-size: 14px;
  transition: transform .12s ease, color .12s ease;
}
.sg-action-row:hover .sg-action-arrow { color: var(--accent); transform: translateX(2px); }
.sg-action-danger .sg-row-title { color: #c0392b; }
[data-theme="dark"] .sg-action-danger .sg-row-title { color: #ff6b6b; }
.sg-action-danger:hover { background: rgba(192,57,43,0.06); }
[data-theme="dark"] .sg-action-danger:hover { background: rgba(255,69,58,0.10); }

/* Settings icon button in global nav */
.btn-icon-utility {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.10);
  border: 0;
  border-radius: 8px;
  color: #fff;
}
.btn-icon-utility:hover { background: rgba(255,255,255,0.16); }
.btn-icon-utility-on { background: rgba(255,255,255,0.22); }

.fab {
  display: none;
  position: fixed;
  right: 20px; bottom: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: 24px;
  box-shadow: 0 8px 24px rgba(0,102,204,0.35);
  z-index: 40;
}
.fab:active { transform: scale(0.94); }

/* ───────────────────────── Keyboard hint ───────────────────────── */

.kbd-hint {
  position: fixed;
  left: 24px; bottom: 18px;
  display: flex; gap: 12px;
  font-size: 11px;
  color: var(--ink-48);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--hairline-soft);
  z-index: 30;
  opacity: 1;
  transition: opacity .4s ease, transform .4s ease;
}
.kbd-hint-hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.kbd-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: inherit;
  background: var(--parchment);
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-size: 10.5px;
  color: var(--ink-80);
  margin-right: 4px;
}

/* ───────────────────────── Categories tab ───────────────────────── */

.cats-page {
  margin-top: 0;
  padding: 4px 0 0;
}
.cats-page-head { margin-bottom: 22px; }
.cats-page-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
  margin-bottom: 6px;
}
.cats-page-title {
  margin: 0 0 6px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--ink);
}
.cats-page-sub {
  margin: 0;
  font-size: 14px;
  color: var(--ink-48);
}
.cats-page-sub b { color: var(--ink); font-weight: 600; }

.cats-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 1280px) { .cats-overview { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .cats-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 540px)  { .cats-overview { grid-template-columns: 1fr; } }

.cats-tile {
  width: 100%;
  display: flex; flex-direction: column; gap: 10px;
  padding: 20px 20px 16px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  text-align: left;
  transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease;
  position: relative;
}
.cats-tile:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}
[data-theme="dark"] .cats-tile:hover { box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4); }
.cats-tile-empty { opacity: 0.6; }

.cats-tile-head {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
}
.cats-tile-icon {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--parchment);
  border-radius: 10px;
}
.cats-tile-icon .cat-dot { width: 14px; height: 14px; border-radius: 4px; }
[data-theme="dark"] .cats-tile-icon { background: rgba(255,255,255,0.06); }

.cats-tile-title-wrap { min-width: 0; }
.cats-tile-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.cats-tile-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: var(--ink-48);
  margin-top: 2px;
}
.cats-tile-active-pip {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.cats-tile-arrow {
  color: var(--ink-32);
  font-size: 16px;
  transition: color .12s ease, transform .12s ease;
}
.cats-tile:hover .cats-tile-arrow { color: var(--accent); transform: translateX(2px); }

.cats-tile-amt {
  display: flex; align-items: baseline; gap: 4px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
}
.cats-tile-amt-mark {
  font-size: 11px;
  color: var(--ink-48);
  font-weight: 500;
}
.cats-tile-amt-num {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.cats-tile-empty-txt {
  font-size: 14px;
  color: var(--ink-48);
}

.cats-tile-foot {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px;
  color: var(--ink-48);
  margin-top: 2px;
}
.cats-tile-rt { font-variant-numeric: tabular-nums; }

/* Sparkline */
.spark { display: block; overflow: visible; }
.spark-area {
  fill: var(--accent);
  fill-opacity: 0.12;
}
.spark-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.spark-end { fill: var(--accent); }
.spark-empty .spark-area, .spark-empty .spark-line, .spark-empty .spark-end {
  fill: var(--ink-32);
  stroke: var(--ink-32);
  fill-opacity: 0.5;
}
/* Per-category sparkline tints */
.spark-cat-food      .spark-area { fill: var(--c-food); fill-opacity: 0.10; }
.spark-cat-food      .spark-line, .spark-cat-food      .spark-end { stroke: var(--c-food); fill: var(--c-food); }
.spark-cat-transport .spark-area { fill: var(--c-transport); fill-opacity: 0.10; }
.spark-cat-transport .spark-line, .spark-cat-transport .spark-end { stroke: var(--c-transport); fill: var(--c-transport); }
.spark-cat-shopping  .spark-area { fill: var(--c-shopping); fill-opacity: 0.10; }
.spark-cat-shopping  .spark-line, .spark-cat-shopping  .spark-end { stroke: var(--c-shopping); fill: var(--c-shopping); }
.spark-cat-entertain .spark-area { fill: var(--c-entertain); fill-opacity: 0.10; }
.spark-cat-entertain .spark-line, .spark-cat-entertain .spark-end { stroke: var(--c-entertain); fill: var(--c-entertain); }
.spark-cat-home      .spark-area { fill: var(--c-home); fill-opacity: 0.10; }
.spark-cat-home      .spark-line, .spark-cat-home      .spark-end { stroke: var(--c-home); fill: var(--c-home); }
.spark-cat-health    .spark-area { fill: var(--c-health); fill-opacity: 0.10; }
.spark-cat-health    .spark-line, .spark-cat-health    .spark-end { stroke: var(--c-health); fill: var(--c-health); }
.spark-cat-social    .spark-area { fill: var(--c-social); fill-opacity: 0.10; }
.spark-cat-social    .spark-line, .spark-cat-social    .spark-end { stroke: var(--c-social); fill: var(--c-social); }
.spark-cat-other     .spark-area { fill: var(--c-other); fill-opacity: 0.10; }
.spark-cat-other     .spark-line, .spark-cat-other     .spark-end { stroke: var(--c-other); fill: var(--c-other); }

/* Category detail */
.cat-detail {
  display: flex; flex-direction: column; gap: 18px;
}
.cat-detail-back {
  align-self: flex-start;
  background: transparent;
  border: 0;
  padding: 6px 10px 6px 4px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}
.cat-detail-back:hover { background: rgba(0, 102, 204, 0.06); }
[data-theme="dark"] .cat-detail-back:hover { background: rgba(41, 151, 255, 0.10); }

.cat-detail-head {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 22px 26px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
}
.cat-detail-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--parchment);
  display: inline-flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .cat-detail-icon { background: rgba(255,255,255,0.06); }
.cat-detail-icon .cat-dot { width: 20px; height: 20px; border-radius: 5px; }
.cat-detail-name {
  margin: 0;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.cat-detail-sub {
  font-size: 13px;
  color: var(--ink-48);
  margin-top: 4px;
}
.cat-detail-amt {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  letter-spacing: -0.025em;
}
.cat-detail-amt .mark { font-size: 16px; color: var(--ink-48); }
.cat-detail-amt .num {
  font-size: 36px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.cat-detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 22px 26px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
}
.cat-detail-stats .cs-item { gap: 6px; }
.cat-detail-stats .cs-sub {
  font-size: 11px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
}

.cat-detail-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}
@media (max-width: 1024px) { .cat-detail-grid { grid-template-columns: 1fr; } }

.cat-detail-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 22px 26px;
  display: flex; flex-direction: column; gap: 16px;
}
.cat-detail-list { padding: 0; }
.cat-detail-list .list-head,
.cat-detail-list .list-filter-row { padding-left: 22px; padding-right: 22px; }

.cat-monthly {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}
/* Per-category bar background (for cat-detail monthly chart) */
.bar-cat { background: var(--accent); }
.cat-bg-food      { background: var(--c-food); }
.cat-bg-transport { background: var(--c-transport); }
.cat-bg-shopping  { background: var(--c-shopping); }
.cat-bg-entertain { background: var(--c-entertain); }
.cat-bg-home      { background: var(--c-home); }
.cat-bg-health    { background: var(--c-health); }
.cat-bg-social    { background: var(--c-social); }
.cat-bg-other     { background: var(--c-other); }
.bar-highlight {
  opacity: 1;
  box-shadow: 0 0 0 1.4px var(--accent-focus) inset;
}
.bar-dim { opacity: 0.22; }
.cat-monthly {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-empty-block {
  padding: 24px 6px;
  text-align: center;
  color: var(--ink-48);
  font-size: 13px;
}

/* Rank panel "全部分類 →" button */
.rank-seeall {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}
.rank-seeall:hover { background: rgba(0, 102, 204, 0.06); }
[data-theme="dark"] .rank-seeall:hover { background: rgba(41, 151, 255, 0.10); }

.hbar-name-btn {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 6px;
  text-align: left;
  color: var(--ink-80);
}
.hbar-name-btn:hover { background: rgba(0,0,0,0.04); color: var(--ink); }
[data-theme="dark"] .hbar-name-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.hbar-name-on { color: var(--accent); font-weight: 600; }

/* "完整分類分析 →" chip link */
.chip-link {
  background: transparent !important;
  color: var(--accent) !important;
  border: 1px dashed var(--hairline);
}
[data-theme="dark"] .chip-link { border-color: rgba(255,255,255,0.18); }
.chip-link:hover { background: rgba(0, 102, 204, 0.06) !important; }
[data-theme="dark"] .chip-link:hover { background: rgba(41, 151, 255, 0.10) !important; }

/* Ledger tab — calendar + list, no rank panel */
.grid-ledger {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(0, 1.5fr);
  gap: 18px;
}
@media (max-width: 1100px) {
  .grid-ledger { grid-template-columns: 1fr; }
}

/* ───────────────────────── Responsive ───────────────────────── */
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 6px;
  text-align: left;
  color: var(--ink-80);
}
.hbar-name-btn:hover { background: rgba(0,0,0,0.04); color: var(--ink); }
[data-theme="dark"] .hbar-name-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.hbar-name-on { color: var(--accent); font-weight: 600; }

/* "完整分類分析 →" chip link */
.chip-link {
  background: transparent !important;
  color: var(--accent) !important;
  border: 1px dashed var(--hairline);
}
[data-theme="dark"] .chip-link { border-color: rgba(255,255,255,0.18); }
.chip-link:hover { background: rgba(0, 102, 204, 0.06) !important; }
[data-theme="dark"] .chip-link:hover { background: rgba(41, 151, 255, 0.10) !important; }

/* Ledger tab — calendar + list, no rank panel */
.grid-ledger {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(0, 1.5fr);
  gap: 18px;
}
@media (max-width: 1100px) {
  .grid-ledger { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; grid-template-areas: "cal" "rank" "list"; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat-hero { grid-column: 1 / -1; }
}
@media (max-width: 740px) {
  /* ── Global nav ── */
  .global-nav { padding: 0 12px; gap: 8px; }
  .gn-left { gap: 12px; min-width: 0; flex: 1; }
  .gn-links { display: none; }
  .gn-right { gap: 6px; }
  .search { flex: 1; width: auto; min-width: 0; max-width: 200px; }
  .search:focus-within { width: auto; max-width: 240px; }
  .search input { font-size: 14px; }
  .search kbd { display: none; }
  .btn-utility { display: none; }                       /* 匯出 — defer to settings/menu */
  .btn-primary .kbd-on-blue { display: none; }
  .btn-primary { padding: 0 12px; }

  /* ── Sub nav ── */
  /* backdrop-filter creates a containing block for position:fixed descendants;
     mp-pop bottom-sheet needs to anchor to viewport, so disable on mobile */
  .sub-nav {
    padding: 12px 12px 10px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--canvas);
  }
  .sn-left { width: 100%; justify-content: space-between; gap: 12px; }
  .sn-right { width: 100%; }
  .sn-title { font-size: 24px; }

  /* Range chips: wrap → horizontal scroll (avoid above-fold height blowup) */
  .range-presets {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    width: 100%;
    padding-bottom: 2px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }
  .range-presets::-webkit-scrollbar { display: none; }
  .range-chip { flex: 0 0 auto; }

  /* ── Page shell ── */
  /* extra padding-bottom to clear mobile-tab-bar height + safe-area */
  .page { padding: 14px 12px calc(72px + env(safe-area-inset-bottom)); }

  /* ── Mobile bottom tab bar ── */
  .mobile-tab-bar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    background: var(--canvas);
    border-top: 1px solid var(--hairline);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 2px;
  }
  [data-theme="dark"] .mobile-tab-bar {
    background: rgba(0,0,0,0.92);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top-color: rgba(255,255,255,0.08);
  }
  .mtb-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    min-height: 52px;
    padding: 6px 4px;
    background: transparent;
    border: 0;
    border-radius: 10px;
    color: var(--ink-48);
    font-size: 11px;
    font-weight: 500;
    transition: color .12s ease, background .12s ease;
  }
  .mtb-btn:active { background: rgba(0,0,0,0.04); }
  [data-theme="dark"] .mtb-btn:active { background: rgba(255,255,255,0.06); }
  .mtb-btn-on { color: var(--accent); }
  .mtb-label { letter-spacing: 0.02em; }

  /* ── Stat row: hero card full-width + 2-col sub-stats below ── */
  .stat-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "main main"
      "today avg";
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-hero { grid-area: main; padding: 18px 18px; }
  .stat-hero .stat-value .num { font-size: 40px; }
  .stat-row > .stat:not(.stat-hero) { padding: 14px 14px; gap: 6px; }
  .stat-row > .stat:not(.stat-hero) .stat-value .num { font-size: 26px; }
  .stat-row > .stat:not(.stat-hero) .stat-value .mark { font-size: 13px; }
  .stat-row > .stat:not(.stat-hero) .stat-delta { font-size: 11px; gap: 6px; }
  .stat-row > .stat:not(.stat-hero) .stat-delta .delta-pill { font-size: 10.5px; padding: 1px 7px; }

  /* ── Grid (cal | rank | list): stack with list-priority order ── */
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas: "list" "cal" "rank";
    gap: 14px;
  }

  .filter-chips { overflow-x: auto; flex-wrap: nowrap; width: 100%; padding-bottom: 4px; }
  .filter-chips::-webkit-scrollbar { display: none; }

  /* ── List section ── */
  .list-head { padding: 12px 14px 10px; gap: 8px; }
  .list-head-l { gap: 2px; min-width: 0; }
  .list-head-meta { font-size: 12px; gap: 4px; }
  .list-head-meta .tag { padding: 1px 7px; font-size: 11px; }

  /* List filter chips: wrap → horizontal scroll (same pattern as range-presets) */
  .list-filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 10px 14px 10px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }
  .list-filter-row::-webkit-scrollbar { display: none; }
  .list-filter-row .chip,
  .list-filter-row .chip-link { flex: 0 0 auto; }

  /* Day group header */
  .tx-day { padding: 10px 14px 8px; font-size: 12.5px; }
  .tx-day-rel { font-size: 13.5px; }
  .tx-day-r { gap: 10px; }
  .tx-day-total { font-size: 14px; }

  /* Transaction row — collapse to 2-line layout with cat-dot anchor */
  .tx-row {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "time cat amt"
      "time note amt";
    column-gap: 10px; row-gap: 2px;
    padding: 11px 14px;
  }
  .tx-time { grid-area: time; padding-left: 0; align-self: center; min-width: 38px; }
  .tx-cat  { grid-area: cat; font-size: 13px; }
  .tx-cat .cat-dot { width: 8px; height: 8px; }
  .tx-sub  { font-size: 12px; }
  .tx-note { grid-area: note; font-size: 13px; color: var(--ink-48); }
  .tx-name { font-weight: 500; }
  .tx-acct { display: none; }
  .tx-amt  { grid-area: amt; align-self: center; padding-right: 0; }
  .tx-amt-num { font-size: 16px; min-width: 0; }
  .tx-amt-mark { font-size: 10.5px; }

  .fab { display: flex; align-items: center; justify-content: center; }

  /* ── Detail / Edit panel → bottom sheet 80dvh ── */
  .panel {
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100vw;
    height: 80dvh; max-height: 80dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.18);
    animation: panelSlideUp .24s cubic-bezier(.2,.7,.2,1);
  }
  .panel::before {
    content: '';
    position: sticky; top: 0;
    display: block;
    width: 36px; height: 4px;
    margin: 8px auto 0;
    background: var(--hairline);
    border-radius: 2px;
    flex-shrink: 0;
    z-index: 1;
  }
  .panel-head { padding-top: 4px; }
  .panel-foot {
    position: sticky; bottom: 0;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--canvas);
  }

  /* Keyboard open: expand sheet to full screen so form fields stay visible */
  .panel.panel--full {
    height: 100dvh; max-height: 100dvh;
    border-radius: 0;
  }
  .panel.panel--full::before { display: none; }

  .kbd-hint { display: none; }
  .calendar, .rank { padding: 16px 16px 12px; }
  .cal-cell { min-height: 50px; padding: 6px; }
  .cal-amt { font-size: 11px; }

  /* Calendar collapse: chevron toggle visible, summary line acts as collapsed view */
  .cal-collapse-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    background: transparent;
    border: 0; border-radius: 8px;
    color: var(--ink-48);
    transition: transform .15s ease, background .12s ease;
  }
  .cal-collapse-btn:active { background: rgba(0,0,0,0.05); }
  [data-theme="dark"] .cal-collapse-btn:active { background: rgba(255,255,255,0.06); }
  .calendar--collapsed .cal-collapse-btn svg { transform: rotate(-90deg); }

  .cal-summary {
    display: none;
    width: 100%;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0 4px;
    background: transparent;
    border: 0;
    color: var(--ink-80);
    font-size: 13px;
  }
  .cal-summary b { color: var(--ink); font-weight: 600; margin: 0 2px; }
  .cal-summary-r { color: var(--ink-48); font-variant-numeric: tabular-nums; }

  .calendar--collapsed .cal-grid,
  .calendar--collapsed .cal-legend { display: none; }
  .calendar--collapsed .cal-summary { display: flex; }


  /* ── Charts (donut + hbar) ── */
  .donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 14px;
  }
  .donut-wrap > svg { width: min(60vw, 220px); height: auto; }
  .donut-legend {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    font-size: 12.5px;
  }
  .dl-item { grid-template-columns: 10px 1fr auto; gap: 6px; }
  .dl-pct { font-size: 11px; }

  .hbar-row {
    grid-template-columns: 84px 1fr 72px;
    gap: 10px;
    font-size: 12.5px;
  }
  .hbar-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* ── MonthPicker → bottom sheet ── */
  .mp-pop {
    position: fixed;
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 70dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.18);
    padding: 8px 14px 16px;
    animation: panelSlideUp .22s cubic-bezier(.2,.7,.2,1);
    z-index: 200;
  }
  .mp-pop::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    margin: 4px auto 10px;
    background: var(--hairline);
    border-radius: 2px;
  }
  .mp-grid { gap: 8px; }
  .mp-cell { height: 48px; font-size: 14px; }

  /* ── Cats overview / detail ── */
  .cats-page-head { padding-left: 0; padding-right: 0; }
  .cats-tile { padding: 14px 14px 12px; gap: 8px; border-radius: 14px; }
  .cats-tile-head { grid-template-columns: 32px 1fr auto; gap: 10px; }
  .cats-tile-icon { width: 32px; height: 32px; border-radius: 8px; }
  .cats-tile-name { font-size: 15px; }
  .cats-tile-meta { font-size: 11.5px; }
  .cats-tile-amt-num { font-size: 22px; }

  .cat-detail { padding: 0; }
  .cat-detail-card { padding: 16px 16px; border-radius: 14px; gap: 12px; }
  .cat-detail-stats { padding: 16px 16px; gap: 10px; }
  .cat-detail-stats .cs-item { font-size: 12px; }

  /* ── Settings page ── */
  .settings-page { max-width: 100%; }
  .sg-card { border-radius: 14px; margin-bottom: 12px; }
  .sg-card-head { padding: 16px 16px 10px; }
  .sg-row { padding: 14px 16px; gap: 12px; flex-wrap: wrap; }
  .sg-row-l { flex: 1 1 100%; min-width: 0; }
  .sg-row-title { font-size: 14px; }
  .sg-row-sub { font-size: 12px; }
  .sg-swatches { flex-wrap: wrap; }
  .sg-seg { width: 100%; }
}

/* ── M4 Recurring (固定支出) ────────────────────────────────────────────── */
/* Ported from new_tab_UI/new-screens.css + new-screens-detail.css. Form-field
   helpers (.fp-*, .df-*, .money-input-wrap) are scoped under .recurring-page
   so they coexist with the projects.css copies without leaking globally. */

.recurring-page .page { padding: 24px 32px 32px; }

/* Page heading + mini stats — global so they layer cleanly with .page */
.recurring-page .ph {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 22px;
}
.recurring-page .ph-l { display: flex; flex-direction: column; gap: 6px; }
.recurring-page .ph-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.recurring-page .ph-title {
  margin: 0;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1;
}
.recurring-page .ph-sub { font-size: 13px; color: var(--ink-48); }
.recurring-page .ph-r { display: flex; align-items: center; gap: 10px; }
.recurring-page .ph-r .plus { margin-right: 4px; }

/* Mini stats — 3-up */
.recurring-page .mstat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.recurring-page .mstat {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.recurring-page .mstat-k {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.recurring-page .mstat-v {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.recurring-page .mstat-v .mark {
  font-size: 13px;
  color: var(--ink-48);
  font-weight: 500;
}
.recurring-page .mstat-v .num { font-size: 28px; color: var(--ink); }
.recurring-page .mstat-sub {
  font-size: 12.5px;
  color: var(--ink-48);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.recurring-page .mstat-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: rgba(0, 102, 204, 0.08);
  border-radius: 999px;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 500;
}

/* Section heads */
.recurring-page .sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 10px 0 12px;
  gap: 18px;
}
.recurring-page .sec-head-l {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.recurring-page .sec-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.recurring-page .sec-count {
  font-size: 12px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
}
.recurring-page .sec-head-r {
  font-size: 12px;
  color: var(--ink-48);
}
.recurring-page .disabled-block { margin-top: 24px; }

/* Rule cards */
.recurring-page .rule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.recurring-page .rule-card {
  position: relative;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color .15s ease, transform .1s ease;
}
.recurring-page .rule-card:hover {
  border-color: rgba(0,0,0,0.14);
}
.recurring-page .rule-card.is-off {
  background: var(--parchment);
  border-style: dashed;
  opacity: 0.78;
}
.recurring-page .rule-head {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
}
.recurring-page .rule-icon {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--hairline);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.recurring-page .rule-icon .cat-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
}
.recurring-page .rule-head-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.recurring-page .rule-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recurring-page .rule-meta {
  font-size: 12px;
  color: var(--ink-48);
  display: flex;
  align-items: center;
  gap: 6px;
}
.recurring-page .rule-meta .dot { color: var(--ink-32); }

.recurring-page .rule-body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.recurring-page .rule-amt {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.recurring-page .rule-amt .mark {
  font-size: 13px; color: var(--ink-48); font-weight: 500;
}
.recurring-page .rule-amt .num {
  font-size: 28px; font-weight: 600; letter-spacing: -0.025em;
  color: var(--ink); line-height: 1;
}
.recurring-page .rule-next {
  font-size: 12px;
  color: var(--ink-48);
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.recurring-page .rule-next-date {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.recurring-page .rule-next-rel {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(0, 102, 204, 0.08);
  color: var(--accent);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  align-self: flex-end;
}
.recurring-page .rule-next-rel.is-soon { background: rgba(192, 57, 43, 0.10); color: #b32d1f; }
.recurring-page .rule-card.is-off .rule-next-rel { background: var(--parchment); color: var(--ink-48); }
[data-theme="dark"] .recurring-page .rule-card.is-off .rule-next-rel {
  background: rgba(255,255,255,0.08);
}

/* Timeline */
.recurring-page .rule-timeline {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0 4px;
  border-top: 1px solid var(--hairline-soft);
}
.recurring-page .rule-timeline-lbl {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-32);
  font-weight: 600;
  margin-right: 4px;
  flex-shrink: 0;
}
.recurring-page .tl-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  position: relative;
}
.recurring-page .tl-dot.tl-past { opacity: 0.4; }
.recurring-page .tl-dot.tl-next {
  background: transparent;
  border: 1.5px dashed var(--accent);
  width: 9px; height: 9px;
}
.recurring-page .tl-line {
  flex: 1;
  height: 1px;
  background: var(--hairline);
  min-width: 6px;
}
.recurring-page .rule-timeline-amt {
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--ink-48);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.recurring-page .rule-timeline-amt b {
  color: var(--ink-80);
  font-weight: 600;
}

/* Hover actions */
.recurring-page .rule-actions {
  position: absolute;
  top: 14px;
  right: 56px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .12s ease;
}
.recurring-page .rule-card:hover .rule-actions { opacity: 1; }
.recurring-page .rule-act-btn {
  height: 26px;
  padding: 0 10px;
  background: var(--parchment);
  border: 0;
  border-radius: 7px;
  font-size: 12px;
  color: var(--ink-80);
}
.recurring-page .rule-act-btn:hover { background: var(--hairline); color: var(--ink); }

/* iOS-style switch (used by rule cards + side panel) */
.recurring-page .switch {
  position: relative;
  width: 36px; height: 22px;
  background: rgba(0,0,0,0.12);
  border-radius: 999px;
  flex-shrink: 0;
  transition: background .15s ease;
  cursor: pointer;
  display: inline-block;
}
.recurring-page .switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
  transition: transform .18s cubic-bezier(.2,.7,.2,1);
}
.recurring-page .switch.is-on { background: #34c759; }
.recurring-page .switch.is-on::after { transform: translateX(14px); }
[data-theme="dark"] .recurring-page .switch { background: rgba(255,255,255,0.18); }

/* Back link */
.recurring-page .dv-back {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  margin: 0 0 14px -8px;
  font-size: 13px;
  color: var(--accent);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.recurring-page .dv-back:hover { background: rgba(0, 102, 204, 0.08); }

/* Detail-view next-run card on the right of rd-hero */
.recurring-page .rd-next-card {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.recurring-page .rd-next-eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.recurring-page .rd-next-date {
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.recurring-page .rd-next-rel-pill {
  align-self: flex-end;
  padding: 3px 10px;
  background: rgba(0, 102, 204, 0.10);
  color: var(--accent);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}

/* History card */
.recurring-page .history-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  overflow: hidden;
}
.recurring-page .history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--hairline-soft);
}
.recurring-page .history-head-l {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.recurring-page .history-head-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-48);
}
.recurring-page .history-row {
  display: grid;
  grid-template-columns: 110px 1fr 160px 120px;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  font-size: 14px;
  border-bottom: 1px solid var(--hairline-soft);
}
.recurring-page .history-row:last-child { border-bottom: 0; }
.recurring-page .history-row:hover { background: var(--pearl); }
.recurring-page .history-row .h-date {
  display: flex; flex-direction: column;
}
.recurring-page .history-row .h-date b {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.recurring-page .history-row .h-date span {
  font-size: 11.5px;
  color: var(--ink-48);
}
.recurring-page .history-row .h-name { color: var(--ink); font-weight: 500; }
.recurring-page .history-row .h-note { color: var(--ink-48); font-size: 12.5px; margin-left: 6px; }
.recurring-page .history-row .h-sub {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--ink-48);
}
.recurring-page .history-row .h-amt {
  text-align: right;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.recurring-page .history-row .h-amt .mark {
  font-size: 11px; color: var(--ink-48); font-weight: 500; margin-right: 3px;
}
.recurring-page .auto-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: rgba(0, 102, 204, 0.08);
  color: var(--accent);
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 500;
  margin-left: 6px;
}

/* Side-panel form scaffolding (scoped) */
.recurring-page .fp-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.recurring-page .fp-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.recurring-page .fp-helper {
  font-size: 11.5px;
  color: var(--ink-48);
  line-height: 1.4;
}
.recurring-page .fp-helper.is-warn {
  color: #b45309;
  background: rgba(245, 158, 11, 0.10);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
.recurring-page .fp-helper.is-warn svg { flex-shrink: 0; margin-top: 1px; }

.recurring-page .fp-segmented {
  display: inline-flex;
  background: var(--parchment);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  align-self: flex-start;
}
.recurring-page .fp-segmented button {
  height: 30px;
  padding: 0 14px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-48);
  font-weight: 500;
  cursor: pointer;
}
.recurring-page .fp-segmented button.is-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.recurring-page .day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.recurring-page .day-chip {
  height: 36px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, transform .08s ease;
}
.recurring-page .day-chip:hover { background: var(--hairline); }
.recurring-page .day-chip.is-on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.recurring-page .day-chip.is-on:hover { filter: brightness(1.15); }
.recurring-page .day-chip.is-warn {
  background: rgba(245, 158, 11, 0.10);
  color: #b45309;
}
.recurring-page .day-chip.is-on.is-warn {
  background: #b45309;
  color: #fff;
  border-color: #b45309;
}
.recurring-page .day-chip:active { transform: scale(0.94); }

.recurring-page .interval-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.recurring-page .interval-row input {
  width: 96px;
  height: 40px;
  padding: 0 12px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 18px;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-align: center;
  outline: 0;
}
.recurring-page .interval-row input:focus { background: #fff; border-color: var(--accent); }
.recurring-page .interval-row .unit { font-size: 13px; color: var(--ink-48); }

.recurring-page .fp-switches {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 14px;
  background: var(--parchment);
  border-radius: 11px;
}
.recurring-page .fp-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.recurring-page .fp-switch-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.recurring-page .fp-switch-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}
.recurring-page .fp-switch-sub {
  font-size: 11.5px;
  color: var(--ink-48);
}

.recurring-page .df-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
  margin-bottom: 6px;
  display: block;
}
.recurring-page .df-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 14px;
  color: var(--ink);
  outline: 0;
}
.recurring-page .df-input:focus { background: #fff; border-color: var(--accent); }
.recurring-page .df-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.recurring-page .df-pill {
  height: 28px;
  padding: 0 12px;
  background: var(--parchment);
  border: 0;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-80);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.recurring-page .df-pill.is-on {
  background: var(--ink);
  color: #fff;
}
.recurring-page .df-pill .cat-dot { width: 6px; height: 6px; border-radius: 2px; }
.recurring-page .btn-inline {
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: 1px dashed var(--hairline);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--ink-48);
}
.recurring-page .btn-inline:hover { border-color: var(--accent); color: var(--accent); }

.recurring-page .money-input-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 12px;
  transition: background .12s ease, border-color .12s ease;
}
.recurring-page .money-input-wrap:focus-within {
  background: #fff;
  border-color: var(--accent);
}
.recurring-page .money-input-wrap .mark {
  font-size: 16px;
  color: var(--ink-48);
  font-weight: 500;
}
.recurring-page .money-input-wrap input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font-family: "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 0;
}

/* Side panel frame (renamed .demo-panel* → .rec-panel* to avoid colliding
   with any other panel system; same look as ProjectEditPanel). */
.rec-panel-frame {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.08);
  padding: 24px;
  overflow-y: auto;
  z-index: 50;
}
.rec-panel {
  background: var(--canvas);
  border-radius: 16px;
  border: 1px solid var(--hairline);
  max-width: 432px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.10);
  overflow: hidden;
}
.rec-panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 0;
}
.rec-panel-x {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--ink-48);
  font-size: 14px;
  cursor: pointer;
}
.rec-panel-x:hover { background: var(--parchment); }
.rec-panel-eyebrow {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
}
.rec-panel-fields {
  padding: 14px 22px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.rec-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-top: 1px solid var(--hairline-soft);
  margin-top: 18px;
  gap: 8px;
}
.rec-panel-foot .spacer { flex: 1; }
.rec-panel .btn-save {
  height: 34px;
  padding: 0 18px;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
}
.rec-panel .btn-save:disabled { opacity: 0.5; cursor: not-allowed; }
.rec-panel .btn-cancel {
  height: 34px;
  padding: 0 14px;
  background: var(--parchment);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
  cursor: pointer;
}
.rec-panel .switch {
  position: relative;
  width: 36px; height: 22px;
  background: rgba(0,0,0,0.12);
  border-radius: 999px;
  flex-shrink: 0;
  transition: background .15s ease;
  cursor: pointer;
  display: inline-block;
}
.rec-panel .switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
  transition: transform .18s cubic-bezier(.2,.7,.2,1);
}
.rec-panel .switch.is-on { background: #34c759; }
.rec-panel .switch.is-on::after { transform: translateX(14px); }
[data-theme="dark"] .rec-panel .switch { background: rgba(255,255,255,0.18); }
/* Side panel reuses the same form scaffolding rules — duplicate the
   .recurring-page form rules under .rec-panel so they apply when the panel
   renders standalone. */
.rec-panel .fp-section { display: flex; flex-direction: column; gap: 10px; }
.rec-panel .fp-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rec-panel .fp-helper { font-size: 11.5px; color: var(--ink-48); line-height: 1.4; }
.rec-panel .fp-helper.is-warn {
  color: #b45309;
  background: rgba(245, 158, 11, 0.10);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex; gap: 6px; align-items: flex-start;
}
.rec-panel .fp-segmented {
  display: inline-flex;
  background: var(--parchment);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
  align-self: flex-start;
}
.rec-panel .fp-segmented button {
  height: 30px;
  padding: 0 14px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-48);
  font-weight: 500;
  cursor: pointer;
}
.rec-panel .fp-segmented button.is-on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.rec-panel .day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.rec-panel .day-chip {
  height: 36px;
  background: var(--parchment);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-80);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.rec-panel .day-chip.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }
.rec-panel .day-chip.is-warn { background: rgba(245, 158, 11, 0.10); color: #b45309; }
.rec-panel .day-chip.is-on.is-warn { background: #b45309; color: #fff; border-color: #b45309; }
.rec-panel .interval-row { display: flex; align-items: center; gap: 10px; }
.rec-panel .interval-row input {
  width: 96px; height: 40px; padding: 0 12px;
  background: var(--parchment); border: 1px solid transparent; border-radius: 9px;
  font-size: 18px; font-weight: 600; color: var(--ink); text-align: center; outline: 0;
}
.rec-panel .interval-row input:focus { background: #fff; border-color: var(--accent); }
.rec-panel .interval-row .unit { font-size: 13px; color: var(--ink-48); }
.rec-panel .df-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-48);
  margin-bottom: 6px;
  display: block;
}
.rec-panel .df-input {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--parchment); border: 1px solid transparent; border-radius: 9px;
  font-size: 14px; color: var(--ink); outline: 0;
}
.rec-panel .df-input:focus { background: #fff; border-color: var(--accent); }
.rec-panel .df-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.rec-panel .df-pill {
  height: 28px; padding: 0 12px;
  background: var(--parchment); border: 0; border-radius: 999px;
  font-size: 12.5px; color: var(--ink-80);
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
}
.rec-panel .df-pill.is-on { background: var(--ink); color: #fff; }
.rec-panel .df-pill .cat-dot { width: 6px; height: 6px; border-radius: 2px; }
.rec-panel .money-input-wrap {
  display: flex; align-items: baseline; gap: 8px;
  padding: 10px 14px;
  background: var(--parchment);
  border: 1px solid transparent; border-radius: 12px;
}
.rec-panel .money-input-wrap:focus-within { background: #fff; border-color: var(--accent); }
.rec-panel .money-input-wrap .mark { font-size: 16px; color: var(--ink-48); font-weight: 500; }
.rec-panel .money-input-wrap input {
  flex: 1; background: transparent; border: 0; outline: 0;
  font-size: 28px; font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums; min-width: 0;
}
.rec-panel .fp-switches {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 14px;
  background: var(--parchment); border-radius: 11px;
}
.rec-panel .fp-switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.rec-panel .fp-switch-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rec-panel .fp-switch-title { font-size: 13.5px; font-weight: 500; color: var(--ink); }
.rec-panel .fp-switch-sub { font-size: 11.5px; color: var(--ink-48); }

/* ───────────────────────────────────────────────────────────────────────── */
/* M4 attachments — DetailPanel section + grid + upload affordance           */
/* ───────────────────────────────────────────────────────────────────────── */

.attach-section { gap: 12px; }

.attach-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.attach-thumb {
  position: relative;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  overflow: hidden;
  background: var(--pearl, #f6f3ee);
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
}
[data-theme="dark"] .attach-thumb {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

.attach-thumb-open {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.attach-thumb-open img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attach-thumb-loading {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--hairline);
  border-top-color: var(--accent);
  animation: attach-spin 0.8s linear infinite;
}
@keyframes attach-spin { to { transform: rotate(360deg); } }

.attach-thumb-err {
  font-size: 18px;
  color: #b32d1f;
}

.attach-thumb.is-pdf .attach-thumb-open {
  flex-direction: column;
  gap: 6px;
  padding: 14px 8px;
}
.attach-pdf-badge {
  display: inline-block;
  background: rgba(192, 57, 43, 0.10);
  color: #b32d1f;
  font-family: "SF Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 6px;
}
.attach-pdf-name {
  font-size: 11px;
  color: var(--ink-80, var(--ink));
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}

.attach-heic {
  font-size: 11px;
  color: var(--ink-48);
  text-align: center;
  line-height: 1.4;
}

.attach-thumb-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-thumb-x:hover { background: rgba(0, 0, 0, 0.75); }

.attach-meta-strip {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  font-size: 10.5px;
  color: var(--ink-48);
  background: rgba(0, 0, 0, 0.04);
  border-top: 1px solid var(--hairline-soft, var(--hairline));
}
[data-theme="dark"] .attach-meta-strip {
  background: rgba(0, 0, 0, 0.25);
}
.attach-meta-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.attach-meta-size { flex-shrink: 0; }

.attach-thumb.is-uploading {
  padding: 12px 10px;
  justify-content: center;
  gap: 8px;
}
.attach-thumb-uploading {
  font-size: 11.5px;
  color: var(--ink-80, var(--ink));
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}
.attach-progress {
  width: 80%;
  height: 4px;
  border-radius: 2px;
  background: var(--hairline);
  overflow: hidden;
  margin: 0 auto;
}
.attach-progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 120ms linear;
}
.attach-progress-error {
  font-size: 11px;
  color: #b32d1f;
  text-align: center;
}

.attach-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.attach-upload-hint { font-size: 11.5px; color: var(--ink-48); }
.attach-empty-hint { font-size: 12px; color: var(--ink-48); }
.attach-error {
  margin-top: 6px;
  font-size: 12px;
  color: #b32d1f;
}

/* ─── Attachment Lightbox ───────────────────────────────────────────── */

.lb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lb-inner {
  width: 100%;
  height: 100%;
  max-width: 1280px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  color: #f4f1ec;
}

.lb-top {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.lb-top-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.lb-top-name b {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-top-name span {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.55);
}
.lb-counter {
  font-family: "SF Mono", monospace;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.04em;
}
.lb-top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.lb-act {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f1ec;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-act:hover { background: rgba(255, 255, 255, 0.16); }
.lb-act.is-danger { color: #ff7a6e; }
.lb-act.is-danger:hover { background: rgba(255, 122, 110, 0.18); }

.lb-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 12px;
}
.lb-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  overflow: hidden;
}
.lb-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.lb-preview .attach-thumb-loading {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.lb-error {
  color: #ff7a6e;
  font-size: 13px;
}

.lb-heic, .lb-pdf {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
}
.lb-heic b, .lb-pdf b {
  color: #f4f1ec;
  font-size: 14px;
}

.lb-nav {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f1ec;
  font-size: 28px;
  line-height: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.18); }

.lb-strip {
  display: flex;
  gap: 6px;
  justify-content: center;
  overflow-x: auto;
  padding: 4px 0;
}
.lb-strip-thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-strip-thumb.is-active { border-color: var(--accent, #0066cc); }
.lb-strip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.lb-strip-heic {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
}

