/* =====================================================
   Crumb — Magicbeans-inspired light theme
   ===================================================== */

:root {
  /* Colors */
  --canvas-white:  #ffffff;
  --ghostly-gray:  #faf6f0;
  --hover-tint:    #e6e1d8;
  --carbon-black:  #000000;
  --graphite:      #1a1a19;
  --charcoal:      #333331;
  --fog:           #f4efe9;
  --border-soft:   #e9e3d9;
  --subtle-gray:   #808080;
  --card-bg:       #fffcf8;
  --card-hover:    #ffffff;
  --topbar-tint:   rgba(250, 246, 240, 0.82);
  --overlay:       rgba(26, 26, 25, 0.32);

  color-scheme: light;

  /* Semantic accents — confident but grounded (danger / positive / info).
     Used for over-budget + destructive actions, on-track state, and info tints. */
  --magic-orange:  #d0503a;
  --magic-green:   #3f9d5f;
  --product-blue:  #3a6fc0;

  /* Category palette — saturated, considered defaults (not neon, not dusty).
     Overridden at runtime by the user's saved per-category choices
     (applyCategoryColors in app.js); keep in sync with DEFAULT_CATEGORY_COLORS. */
  --cat-housing:       #d05a43;
  --cat-utilities:     #e08636;
  --cat-subscriptions: #3a6fc0;
  --cat-savings:       #46955c;
  --cat-investments:   #279685;
  --cat-other:         #8a8178;

  --font-family: 'Figtree', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Type scale — even steps: 12 / 14 / 16 / 18 / 20 / 24 / 32 / 40 / 48 / 56 */
  --text-base:       16px;
  --text-lg:         18px;
  --text-heading:    24px;

  /* Spacing */
  --space-8:  8px;
  --space-16: 16px;
  --space-24: 24px;
  --space-32: 32px;
  --space-40: 40px;
  --space-64: 64px;

  /* Radii */
  --radius-card:   12px;
  --radius-input:  10px;
  --radius-2xl:    16px;
  --radius-button: 9999px;

  /* Shadow */
  --shadow-pop:
    0 16px 48px rgba(0,0,0,0.10),
    0 4px 12px rgba(0,0,0,0.06);
}

/* Dark theme — warm near-black, vibrant category colors stay lit */
:root[data-theme="dark"] {
  --canvas-white:  #232120;
  --ghostly-gray:  #131211;
  --hover-tint:    #2e2b27;
  --carbon-black:  #ffffff;
  --graphite:      #f2efe9;
  --charcoal:      #c9c5bd;
  --fog:           #262421;
  --border-soft:   #2c2925;
  --subtle-gray:   #979187;
  --card-bg:       #1e1c1a;
  --card-hover:    #292724;
  --topbar-tint:   rgba(19, 18, 17, 0.82);
  --overlay:       rgba(0, 0, 0, 0.55);

  color-scheme: dark;

  --shadow-pop:
    0 16px 48px rgba(0,0,0,0.45),
    0 4px 12px rgba(0,0,0,0.30);
}
:root[data-theme="dark"] .item,
:root[data-theme="dark"] .insight-card { box-shadow: 0 6px 16px rgba(0,0,0,0.25); }
:root[data-theme="dark"] .fab { box-shadow: 0 2px 4px rgba(0,0,0,0.45); }
:root[data-theme="dark"] .fab:hover { box-shadow: 0 6px 14px rgba(0,0,0,0.55); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ghostly-gray);
  color: var(--graphite);
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  min-height: 100vh;
  min-height: 100dvh;
}
button { font-family: inherit; }
input { font-family: inherit; color: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--topbar-tint);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--fog);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-24);
  height: calc(64px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}
.brand { display: flex; align-items: center; gap: 4px; color: var(--graphite); text-decoration: none; }
.brand-mark {
  width: 16px; height: 16px;
  border-radius: 4px;
  background: var(--carbon-black);
  color: var(--ghostly-gray);
  display: grid; place-items: center;
}
.brand-name {
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.02em;
}

/* ---------- Buttons ---------- */
.ghost-btn, .primary-btn {
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease,
              color .14s ease, transform .14s ease, box-shadow .14s ease;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
}
.ghost-btn {
  background: var(--canvas-white);
  color: var(--graphite);
  border-color: var(--border-soft);
  padding: 10px 16px;
  font-size: 14px;
}
.ghost-btn:hover { background: var(--hover-tint); border-color: var(--subtle-gray); }
.ghost-btn.icon-only {
  padding: 0;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  color: var(--charcoal);
  background: transparent;
  border-color: var(--fog);
}
.ghost-btn.danger { color: var(--magic-orange); border-color: transparent; background: transparent; }
.ghost-btn.danger:hover {
  background: color-mix(in srgb, var(--magic-orange) 8%, transparent);
  border-color: color-mix(in srgb, var(--magic-orange) 18%, transparent);
}

.primary-btn {
  background: var(--graphite);
  color: var(--canvas-white);
  padding: 10px 20px;
  font-size: 14px;
}
.primary-btn:hover { background: var(--carbon-black); transform: translateY(-1px); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.ghost-btn:active, .primary-btn:active {
  transform: scale(0.97);
  transition-duration: .1s;
}
.primary-btn:disabled:active { transform: none; }

/* ---------- Focus-visible (keyboard) ---------- */
.ghost-btn:focus-visible,
.primary-btn:focus-visible,
.fab:focus-visible,
.menu-item:focus-visible,
.cat-option:focus-visible,
.seg:not(.seg-empty):focus-visible {
  outline: 2px solid var(--graphite);
  outline-offset: 2px;
}
.menu-item:focus-visible { outline-offset: -2px; border-radius: 8px; }

/* ---------- Menu dropdown ---------- */
.topbar-right { position: relative; z-index: 1; }
.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--canvas-white);
  border: 1px solid var(--fog);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 35;
}
.menu-dropdown[hidden] { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--graphite);
  text-align: left;
  width: 100%;
  transition: background .12s;
}
.menu-item:hover { background: var(--hover-tint); }
.menu-item.danger { color: var(--magic-orange); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--magic-orange) 8%, transparent); }
.menu-item svg { color: var(--subtle-gray); }
.menu-item.danger svg { color: var(--magic-orange); }
.menu-divider { height: 1px; background: var(--fog); margin: 4px 6px; }

/* ---------- Layout ---------- */
.content {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-32) var(--space-24) 120px;
  padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--space-24);
}

/* ---------- Cards ---------- */
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-head-left { display: flex; align-items: center; gap: 6px; }
.card-caption {
  font-size: 17px;
  font-weight: 600;
  color: var(--graphite);
  letter-spacing: -0.01em;
}
.muted { color: var(--subtle-gray); font-size: 13px; font-weight: 500; }

/* ---------- Hero visualization (no card) ---------- */
.hero-viz {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 4px 0;
}

.viz-caption-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.viz-caption-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.viz-caption {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle-gray);
}
.placeholder-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.4;
  color: var(--charcoal);
  background: var(--fog);
  border: 1px solid var(--border-soft);
  padding: 2px 8px;
  border-radius: var(--radius-button);
  white-space: nowrap;
}
.placeholder-tag[hidden] { display: none; }
.viz-meta {
  display: block;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--magic-green);
  letter-spacing: -0.005em;
  transition: color .2s ease;
}
.viz-meta strong { font-weight: 700; color: inherit; }
.viz-meta.negative { color: var(--magic-orange); }
.viz-meta.muted { color: var(--subtle-gray); }

.budget-input-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: -2px 0 4px;
}
.budget-currency {
  font-size: 48px;
  font-weight: 400;
  color: var(--subtle-gray);
  letter-spacing: -0.02em;
  line-height: 1;
}
.budget-input {
  font-family: var(--font-family);
  font-size: 56px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--graphite);
  background: transparent;
  border: 0;
  outline: 0;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 8px;
  width: 4ch;
  min-width: 1ch;
  max-width: 100%;
  transition: background .15s;
}
.budget-input::placeholder { color: var(--border-soft); font-weight: 500; }
.budget-input:focus { background: var(--hover-tint); }
.budget-input::-webkit-outer-spin-button,
.budget-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Bar labels */
.bar-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
  color: var(--subtle-gray);
  margin-bottom: 0;
  font-weight: 500;
  letter-spacing: -0.005em;
  min-height: 16px;
}
.bar-labels:empty { display: none; }
.bar-labels span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  animation: fadeIn .35s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; }
}

/* Segment bar */
.segment-bar-wrap {
  position: relative;
}
.segment-bar {
  display: flex;
  height: 56px;
  gap: 6px;
}
.segment-bar:empty::before {
  content: "";
  flex: 1;
  background: var(--fog);
  border-radius: 8px;
}
.seg {
  height: 100%;
  border-radius: 8px;
  transition:
    flex-basis 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    background-color 0.3s ease,
    opacity 0.2s ease,
    filter 0.2s ease,
    transform 0.18s ease;
  min-width: 14px;
  cursor: pointer;
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transform-origin: 50% 100%;
}
.seg:not(.seg-empty):hover { transform: translateY(-2px); }
.segment-bar.has-active .seg:not(.seg-empty):not(.active) {
  opacity: 0.28;
  filter: saturate(0.55);
}
.seg.active:not(.seg-empty) {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.10);
}
.seg-empty {
  background: var(--fog);
  cursor: default;
}
.seg-empty:hover { transform: none; }

/* Jello wobble on the moved item's segment when a reorder lands. Horizontal-
   only squash/stretch around the centre, so the left and right ends wiggle in
   and out while the top and bottom stay put. The animation overrides the seg's
   transform transition while it runs. */
@keyframes segJello {
  0%   { transform: scaleX(1); }
  15%  { transform: scaleX(0.90); }
  30%  { transform: scaleX(1.06); }
  45%  { transform: scaleX(0.955); }
  60%  { transform: scaleX(1.03); }
  75%  { transform: scaleX(0.985); }
  100% { transform: scaleX(1); }
}
.seg.seg-jello {
  transform-origin: 50% 50%; /* wiggle both ends symmetrically, not from the base */
  animation: segJello 0.6s ease-out both;
}

/* Tooltip */
.seg-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--graphite);
  color: var(--canvas-white);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  transform: translate(-50%, 0);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.seg-tooltip[hidden] { display: none; }
.seg-tooltip.visible {
  opacity: 1;
  transform: translate(-50%, -2px);
}
.seg-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 8px; height: 8px;
  background: var(--graphite);
  border-radius: 1px;
}
.tt-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tt-text { display: flex; align-items: baseline; gap: 8px; }
.tt-name { font-weight: 600; }
.tt-detail { color: color-mix(in srgb, var(--canvas-white) 65%, transparent); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- Insights (icon-card row) ---------- */
.insights {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.insights[hidden] { display: none; }

.insights-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.insights-caption {
  font-size: 17px;
  font-weight: 600;
  color: var(--graphite);
  letter-spacing: -0.01em;
}
.insights-row {
  display: flex;
  gap: var(--space-8);
}
.insight-card {
  --tint-color: var(--magic-orange);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 14px 16px 12px;
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border-soft);
  background: var(--card-bg);
  box-shadow: 0 6px 16px rgba(0,0,0,0.04);
}
.insight-card[hidden] { display: none; }
.insight-card[data-tint="blue"] { --tint-color: var(--product-blue); }
.insight-card[data-tint="green"] { --tint-color: var(--magic-green); }
.insight-card[data-tint="orange"] { --tint-color: var(--magic-orange); }

.insight-top {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tint-color);
  margin-bottom: 8px;
  min-width: 0;
}
.insight-top svg { width: 14px; height: 14px; flex-shrink: 0; }
.insight-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  /* Deepened tint: keeps the hue but passes contrast on the light card
     (and lightens against dark cards, since --graphite flips per theme) */
  color: color-mix(in srgb, var(--tint-color) 60%, var(--graphite));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insight-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--graphite);
}
.insight-caption {
  font-size: 12px;
  font-weight: 500;
  color: var(--subtle-gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.items:empty { display: none; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  cursor: pointer;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2xl);
  box-shadow: 0 6px 16px rgba(0,0,0,0.04);
  transition: background-color .16s ease, transform .2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow .2s ease;
}
@keyframes itemFlash {
  from { background-color: var(--hover-tint); }
}
.item.item-flash { animation: itemFlash 0.7s cubic-bezier(0.22, 1, 0.36, 1); }
.item:hover {
  background: var(--card-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.item:active {
  transform: translateY(0) scale(0.99);
  transition-duration: .1s;
}
.item-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.item-text { display: flex; flex: 1; flex-direction: column; gap: 1px; min-width: 0; }
.item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--graphite);
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-cat {
  font-size: 12px;
  color: var(--subtle-gray);
  font-weight: 500;
}
.item-amount {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
  color: var(--graphite);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Drag-to-reorder handle */
.item-drag {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  margin: -6px -8px -6px -2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--subtle-gray);
  border-radius: 8px;
  cursor: grab;
  opacity: 0.45;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity .14s ease, background-color .14s ease;
}
.item-drag:hover { opacity: 1; background: var(--hover-tint); }
.item-drag:active { cursor: grabbing; }
.item:only-child .item-drag { display: none; }

.item.dragging {
  position: relative;
  z-index: 5;
  cursor: grabbing;
  background: var(--card-hover);
  box-shadow: 0 14px 30px rgba(0,0,0,0.16);
  transition: none;
  -webkit-user-select: none;
  user-select: none;
}
.item.dragging .item-drag { opacity: 1; cursor: grabbing; }

/* While a drag is in progress, kill text selection + force the grab cursor
   everywhere so the reorder feels solid on desktop. */
body.reordering { cursor: grabbing; }
body.reordering * {
  cursor: grabbing !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

/* category dot colors */
.item[data-cat="housing"]       .item-dot { background: var(--cat-housing); }
.item[data-cat="utilities"]     .item-dot { background: var(--cat-utilities); }
.item[data-cat="subscriptions"] .item-dot { background: var(--cat-subscriptions); }
.item[data-cat="savings"]       .item-dot { background: var(--cat-savings); }
.item[data-cat="investments"]   .item-dot { background: var(--cat-investments); }
.item[data-cat="other"]         .item-dot { background: var(--cat-other); }

/* ---------- Empty state ---------- */
.empty-card-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 24px 16px 12px;
  animation: fadeIn .4s ease;
}
.empty-card-state[hidden] { display: none; }
.empty-icon { color: var(--graphite); }
.empty-text { display: flex; flex-direction: column; gap: 4px; }
.empty-card-state p { margin: 0; font-size: 14px; font-weight: 600; }
.empty-card-state p.muted { font-weight: 500; font-size: 14px; }
.empty-card-state strong { color: var(--graphite); font-weight: 700; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  right: 28px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--canvas-white);
  color: var(--graphite);
  border: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
  z-index: 40;
  transition: transform .18s ease, box-shadow .18s ease;
}
.fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 14px rgba(0,0,0,0.16);
}
.fab:active { transform: translateY(0) scale(0.98); }

/* ---------- Sheet (modal/bottom sheet) ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.22s;
}
.sheet-overlay[hidden] { display: none; }
.sheet-overlay.visible { opacity: 1; }

.edit-sheet, .colors-modal {
  position: fixed;
  z-index: 51;
  background: var(--canvas-white);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
}
.edit-sheet[hidden], .colors-modal[hidden] { display: none; }

@media (min-width: 700px) {
  .edit-sheet, .colors-modal {
    inset: 0;
    margin: auto;
    width: min(440px, calc(100vw - 32px));
    height: fit-content;
    max-height: calc(100vh - 64px);
    border-radius: var(--radius-card);
    border: 1px solid var(--fog);
    transform-origin: center center;
  }
  .sheet-handle { display: none; }
}
@media (max-width: 699px) {
  .edit-sheet, .colors-modal {
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sheet-handle {
    width: 36px; height: 4px;
    background: var(--subtle-gray);
    opacity: 0.5;
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
  }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 8px;
}
.sheet-title { margin: 0; font-size: var(--text-heading); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.sheet-close { width: 32px; height: 32px; }

.sheet-body {
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle-gray);
}
.field-input {
  width: 100%;
  border: 1px solid var(--border-soft);
  background: var(--canvas-white);
  color: var(--graphite);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  font-size: var(--text-base);
  font-weight: 500;
  outline: 0;
  transition: border-color .14s, box-shadow .14s;
}
.field-input:focus {
  border-color: var(--graphite);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.field-input::placeholder { color: var(--subtle-gray); }

.amount-input {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border: 1px solid var(--border-soft);
  background: var(--canvas-white);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  transition: border-color .14s, box-shadow .14s;
}
.amount-input:focus-within {
  border-color: var(--graphite);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.amount-currency {
  color: var(--subtle-gray);
  font-weight: 500;
  /* Match the hero row's $-to-number size ratio (~0.85) so the baseline-
     aligned prefix reads as aligned next to the 24px amount */
  font-size: 20px;
  line-height: 1;
}
.amount-suffix { color: var(--subtle-gray); font-size: 12px; }
.amount-input .field-input {
  flex: 1;
  border: 0;
  padding: 0;
  background: transparent;
  font-size: var(--text-heading);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.amount-input .field-input:focus { box-shadow: none; }
.amount-input .field-input::-webkit-outer-spin-button,
.amount-input .field-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount-input .field-input[type=number] { -moz-appearance: textfield; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.cat-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--canvas-white);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--graphite);
  text-align: left;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.cat-option:hover { background: var(--hover-tint); border-color: var(--subtle-gray); }
.cat-option.active {
  background: var(--graphite);
  color: var(--canvas-white);
  border-color: var(--graphite);
}
.cat-option:active { transform: scale(0.98); }
.cat-option-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
@keyframes dotPop {
  40% { transform: scale(1.45); }
}
.cat-option.active .cat-option-dot { animation: dotPop .3s cubic-bezier(0.22, 1, 0.36, 1); }

.sheet-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--fog);
}
.footer-spacer { flex: 1; }

/* ---------- Placeholder choice modal ---------- */
.choice-modal {
  position: fixed;
  z-index: 51;
  background: var(--canvas-white);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
}
.choice-modal[hidden] { display: none; }

@media (min-width: 700px) {
  .choice-modal {
    inset: 0;
    margin: auto;
    width: min(420px, calc(100vw - 32px));
    height: fit-content;
    max-height: calc(100vh - 64px);
    border-radius: var(--radius-card);
    border: 1px solid var(--fog);
    transform-origin: center center;
  }
  .choice-modal .sheet-handle { display: none; }
}
@media (max-width: 699px) {
  .choice-modal {
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.choice-header {
  padding: 20px 24px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.choice-title {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.choice-sub {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--subtle-gray);
  line-height: 1.45;
}
.choice-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 24px 24px;
}
.choice-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--canvas-white);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2xl);
  cursor: pointer;
  color: var(--graphite);
  transition: background-color .14s ease, border-color .14s ease,
              transform .14s ease, box-shadow .14s ease;
}
.choice-btn:hover {
  background: var(--card-hover);
  border-color: var(--subtle-gray);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.choice-btn:active { transform: scale(0.99); transition-duration: .1s; }
.choice-btn.primary {
  background: var(--graphite);
  border-color: var(--graphite);
  color: var(--canvas-white);
}
.choice-btn.primary:hover { background: var(--carbon-black); border-color: var(--carbon-black); }
.choice-btn-icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--fog);
  color: var(--charcoal);
}
.choice-btn.primary .choice-btn-icon {
  background: color-mix(in srgb, var(--canvas-white) 16%, transparent);
  color: var(--canvas-white);
}
.choice-btn-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice-btn-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.choice-btn-desc {
  font-size: 13px;
  font-weight: 500;
  color: var(--subtle-gray);
  line-height: 1.35;
}
.choice-btn.primary .choice-btn-desc { color: color-mix(in srgb, var(--canvas-white) 70%, transparent); }

/* ---------- Category colors modal ---------- */
.colors-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-cat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border-soft);
  background: var(--canvas-white);
  color: var(--graphite);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.color-cat:hover { background: var(--hover-tint); border-color: var(--subtle-gray); }
.color-cat.active { border-color: var(--graphite); background: var(--hover-tint); }
.color-cat-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.swatch {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--swatch);
  border: 0;
  cursor: pointer;
  position: relative;
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  transition: transform .12s ease, outline-color .12s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch:active { transform: scale(0.96); }
.swatch.selected { outline-color: var(--graphite); }
.swatch.selected::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.18);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--graphite);
  color: var(--canvas-white);
  padding: 10px 18px;
  border-radius: var(--radius-button);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
}
.toast[hidden] { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .content { padding: var(--space-24) var(--space-16) 120px; gap: var(--space-24); }
  .viz-caption-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .budget-input { font-size: 40px; }
  .budget-currency { font-size: 32px; }
  .segment-bar { height: 44px; gap: 4px; }
  .seg { border-radius: 6px; }
  .topbar { padding: 0 var(--space-16); }
  .fab {
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 52px; height: 52px;
  }
  .fab svg { width: 28px; height: 28px; }
  .cat-grid { grid-template-columns: 1fr; }
  .bar-labels { display: none; }
  .insights-row {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px 2px;
    scrollbar-width: none;
  }
  .insights-row::-webkit-scrollbar { display: none; }
  .insight-card {
    flex: 0 0 150px;
    scroll-snap-align: start;
  }
}

/* ---------- Theme crossfade (applied briefly while switching) ---------- */
html.theme-anim,
html.theme-anim body,
html.theme-anim *,
html.theme-anim *::before,
html.theme-anim *::after {
  transition: background-color .3s ease, color .3s ease,
              border-color .3s ease, box-shadow .3s ease !important;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .primary-btn:hover,
  .fab:hover { transform: none; }
}
