/* =============================================================================
   WHERE IT GOES — App layer
   The pieces the live app needs on top of Elena's tokens/base/components:
   checklines, the subscriptions two-step, mini-bars, the perception panel,
   the projection toggle + columns, debts, and a few small compositions.
   Everything keys off tokens.css — no new colors, no CDN, no network.
   ============================================================================= */

/* --- Top bar right cluster --- */
.topbar__right { display: inline-flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }

/* --- Rail intro & notes --- */
.rail__intro { margin-bottom: var(--space-5); }
.rail__lede { font-size: var(--text-sm); color: var(--ink-muted); line-height: var(--leading-normal); margin-top: var(--space-2); }
.rail__note { font-size: var(--text-xs); color: var(--ink-faint); line-height: var(--leading-normal); margin-bottom: var(--space-3); }

/* --- Checkline toggles --- */
.toggle-field { display: flex; flex-direction: column; gap: var(--space-3); margin: var(--space-3) 0 var(--space-4); }
.checkline {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-3);
  align-items: start; font-size: var(--text-sm); color: var(--ink); cursor: pointer;
}
.checkline input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; margin: 2px 0 0; flex: 0 0 auto;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; position: relative;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.checkline input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.checkline input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 5px; top: 1px;
  width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.checkline input[type="checkbox"]:focus-visible { box-shadow: var(--ring); }
.checkline .field__hint { display: block; margin-top: 2px; }

/* Ensure the class tag always drops below the label in ranking rows */
.cat-row__labelcell .cat-row__label { display: block; }

/* --- Category fields in the rail --- */
.field--cat { align-items: start; }
.cat-field__controls { display: inline-flex; align-items: center; gap: var(--space-2); }
.btn-remove {
  border: 0; background: none; color: var(--ink-ghost); font-size: 18px; line-height: 1;
  padding: 0 var(--space-1); cursor: pointer;
}
.btn-remove:hover { color: var(--leak-ink); }

.band-select { display: block; margin-top: var(--space-2); }
.band-select__q { display: block; font-size: var(--text-2xs); color: var(--ink-faint); margin-bottom: 2px; }
.band-select select {
  font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 4px 6px; max-width: 100%;
}
.band-select select:focus-visible { box-shadow: var(--ring); outline: none; }

/* --- Subscriptions two-step --- */
.subs-field .subs-step1 { flex-wrap: wrap; gap: var(--space-2); }
.btn--sm { padding: 4px var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }

/* --- Debts --- */
.debt-row {
  display: grid; grid-template-columns: 1fr 96px 66px auto; gap: var(--space-2);
  align-items: center; margin-bottom: var(--space-2);
}
.debt-name {
  font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0 var(--space-3); height: 34px;
}
.debt-name:focus-visible { box-shadow: var(--ring); outline: none; border-color: var(--accent); }
.money-input.debt-bal { padding: 0 var(--space-2); }
.money-input.debt-bal input { width: 60px; }
.pct-input {
  display: inline-flex; align-items: center; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 0 var(--space-2); height: 34px;
}
.pct-input:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.pct-input input {
  border: 0; background: transparent; outline: none; width: 38px; text-align: right;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--text-sm); color: var(--ink-strong);
}
.pct-input__suffix { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-faint); }

/* =============================================================================
   CANVAS PANELS
   ============================================================================= */
.headline-panel .headline-number { gap: var(--space-3); }
.headline-number__value { align-items: baseline; }
.headline-number__title { margin-top: var(--space-1); max-width: 34ch; }

.notice {
  margin-top: var(--space-4); padding: var(--space-3) var(--space-4);
  background: var(--watch-fill); border: 1px solid var(--watch-line); border-radius: var(--radius-md);
  font-size: var(--text-sm); color: var(--watch-ink);
}

.panel__foot { padding: var(--space-3) var(--space-6) var(--space-5); font-size: var(--text-xs); line-height: var(--leading-normal); }

/* Empty state hint button */
.empty__hint { margin-top: var(--space-5); }

/* The two rankings stack full-width, each spending the canvas. Never merged. */
.rankings { display: flex; flex-direction: column; gap: var(--panel-gap); }

/* Ranking B — its own compact, purpose-built grid (label | over% | recoverable $) */
.rankb-row {
  display: grid;
  grid-template-columns: 3px minmax(120px, 1fr) 82px 104px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-3) 0;
  border-bottom: 1px solid var(--line-faint);
}
.rankb-row:last-child { border-bottom: 0; }
.rankb-row:hover { background: var(--surface-sunk); }
.rankb-row__edge { align-self: stretch; background: var(--leak-ink); border-radius: 2px; }
.rankb-row--note .rankb-row__edge { background: var(--watch-ink); }
.rankb-row__labelcell { display: flex; flex-direction: column; gap: 3px; padding-left: var(--space-2); min-width: 0; }
.rankb-row__over {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--text-sm); color: var(--leak-ink); font-weight: var(--weight-medium); text-align: right;
}
.rankb-row--note .rankb-row__over { color: var(--watch-ink); }
.rankb-row__amt {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--text-sm); color: var(--ink-strong); text-align: right;
}
.rankb-row__amt small { display: block; font-size: var(--text-2xs); color: var(--ink-faint); font-family: var(--font-ui); }
.cat-row--empty { grid-template-columns: 1fr !important; padding: var(--space-6); }
.cat-row--empty:hover { background: transparent; }

/* Essential notes (quiet, de-emphasized) */
.essential-notes { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--line-faint); }
.essential-notes__head { font-size: var(--text-xs); color: var(--ink-faint); margin-bottom: var(--space-2); }
.essential-note { font-size: var(--text-sm); color: var(--ink-muted); line-height: var(--leading-normal); padding: var(--space-1) 0; }

.leak-empty, .leak-item + .leak-empty { padding: var(--space-6); }
.leak-empty p { font-size: var(--text-sm); color: var(--ink-muted); max-width: 52ch; }
.leak-list { padding: 0 var(--space-6); }

.badge-large {
  display: inline-block; margin-left: var(--space-2);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  color: var(--watch-ink); background: var(--watch-fill);
  padding: 1px 6px; border-radius: 3px; vertical-align: middle;
}

/* --- Perception gap panel --- */
.perception { background: var(--surface); }
.perception__figures {
  display: flex; align-items: center; gap: var(--space-6);
  margin: var(--space-4) 0 var(--space-4); flex-wrap: wrap;
}
.perception__col { display: flex; flex-direction: column; gap: var(--space-1); }
.perception__lbl { font-size: var(--text-xs); color: var(--ink-faint); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
.perception__arrow { font-size: var(--text-xl); color: var(--ink-ghost); }
.perception__caption { font-size: var(--text-sm); color: var(--ink-muted); line-height: var(--leading-normal); max-width: 64ch; }

/* --- mini bars (savings rate, emergency fund) --- */
.mini-bar {
  position: relative; height: 8px; border-radius: 4px; background: var(--surface-sunk);
  margin-top: var(--space-3); overflow: visible;
}
.mini-bar__fill { position: absolute; inset: 0 auto 0 0; height: 100%; border-radius: 4px; background: var(--bar-size-lead); }
.mini-bar__fill--gain { background: var(--gain-ink); }
.mini-bar--target { overflow: visible; }
.mini-bar__tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--accent); border-radius: 1px; }

/* --- Deficit plan --- */
.deficit-plan__line { display: flex; align-items: baseline; justify-content: space-between; padding: var(--space-2) 0; border-bottom: 1px solid var(--line-faint); }
.deficit-plan__line .figure { font-size: var(--text-lg); }

/* --- Projection --- */
.seg { display: inline-flex; background: var(--surface-sunk); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 3px; gap: 3px; margin-bottom: var(--space-4); }
.seg__btn {
  border: 0; background: transparent; color: var(--ink-muted);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg__btn--on { background: var(--surface); color: var(--ink-strong); box-shadow: var(--shadow-panel); }
.seg__btn:hover:not(.seg__btn--on) { color: var(--ink); }

.proj-cols { display: flex; gap: var(--space-5); flex-wrap: wrap; }
.proj-col { display: flex; flex-direction: column; gap: var(--space-1); min-width: 96px; }
.proj-col__yr { font-size: var(--text-2xs); color: var(--ink-faint); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
.proj-col__val { font-size: var(--text-xl); font-weight: var(--weight-medium); color: var(--gain-ink); }
.proj-col--sub .proj-col__val { font-size: var(--text-lg); color: var(--ink); }
.projection__assume { margin-top: var(--space-4); max-width: 66ch; line-height: var(--leading-normal); }

.proj-childcare { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.proj-childcare__head { font-size: var(--text-sm); color: var(--ink-muted); margin-bottom: var(--space-3); max-width: 60ch; }

/* --- Completeness note --- */
.completeness { background: var(--surface-sunk); box-shadow: none; }
.completeness .meta { line-height: var(--leading-normal); }

/* =============================================================================
   PHONE — app-layer reflows on top of Elena's component media query
   ============================================================================= */
@media (max-width: 880px) {
  .topbar__right { width: 100%; justify-content: space-between; }
  .privacy-line { order: -1; width: 100%; }
  .debt-row { grid-template-columns: 1fr 84px 58px auto; }
  .perception__figures { gap: var(--space-4); }
  .proj-cols { gap: var(--space-4); }
  .proj-col { min-width: 84px; }
}
