/* ===== CSS Variables (Theme) ===== */
:root {
  /* Light theme (default) */
  --bg-page: #f5f5fa;
  --bg-panel: #ffffff;
  --bg-input: #ffffff;
  --bg-surface: #ffffff;
  --bg-hover: #f9fafb;
  --bg-result-row: #f9fafb;
  --bg-highlight: #eff6ff;
  --border-subtle: #e5e7eb;
  --border-cell: #f3f4f6;
  --border-color: #d1d5db;
  --border-highlight: #bfdbfe;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #5f6b7a; /* #103: 5.43:1 on panel / 4.99:1 on page / 5.19:1 on rows — old #9ca3af measured 2.54:1 */
  /* #103: the header is dark in the light theme, so muted text there needs a
     LIGHT value (a single token cannot clear 4.5:1 on both #ffffff and
     #1a1a2e). 6.72:1 on --header-bg. */
  --header-subtitle: #9ca3af;
  --header-bg: #1a1a2e;
  --header-text: #ffffff;
  --shadow-panel: rgba(0, 0, 0, 0.08);
  --color-income: #16a34a;
  --color-expense: #ef4444;
  --color-primary: #2563eb;
  --warn-amber: #d97706;
  --radius-sm: 0.375rem;
  --radius-xs: 0.25rem;
}

/* Scoped to html: a bare [data-theme=...] selector would re-define the tokens
   on ANY element carrying the attribute (e.g. theme-dropdown options). */
html[data-theme="dark"] {
  --bg-page: #0f172a;
  --bg-panel: #1e293b;
  --bg-input: #0f172a;
  --bg-surface: #1e293b;
  --bg-hover: #334155;
  --bg-result-row: #1e293b;
  --bg-highlight: #1e3a5f;
  --border-subtle: #334155;
  --border-cell: #1e293b;
  --border-color: #475569;
  --border-highlight: #1e40af;
  --text-primary: #e5e7eb;
  --text-secondary: #d1d5db;
  --text-muted: #a5adba; /* #103: 6.47:1 on panel / 7.89:1 on page / 4.58:1 on hover — old #6b7280 measured 2.14–4.14:1 */
  --header-subtitle: #a5adba; /* #103: 8.85:1 on --header-bg #020817 (old #6b7280 was 4.14:1) */
  --header-bg: #020817;
  --header-text: #ffffff;
  --shadow-panel: rgba(0, 0, 0, 0.3);
  --color-income: #4ade80;
  --color-expense: #f87171;
  --color-primary: #3b82f6;
  --warn-amber: #fbbf24;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-page);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select {
  font: inherit;
  background-color: var(--bg-input);
  color: var(--text-primary);
}

/* ===== Colors ===== */
.text--income { color: var(--color-income); }
.text--expense { color: var(--color-expense); }
.text--debt { color: var(--color-expense); font-weight: 600; }
.text-muted { color: var(--text-muted); }

/* ===== Disabled Row Styling ===== */
.account-row--disabled {
  opacity: 0.45;
  background-color: rgba(107, 114, 128, 0.06);
}

/* ===== Debt Account Row Styling ===== */
.account-row--debt {
  background-color: rgba(239, 68, 68, 0.04);
}
[data-theme="dark"] .account-row--debt {
  background-color: rgba(239, 68, 68, 0.08);
}
.account-row--debt:hover {
  background-color: rgba(239, 68, 68, 0.08);
}
[data-theme="dark"] .account-row--debt:hover {
  background-color: rgba(239, 68, 68, 0.12);
}

/* Debt indicator icon */
.debt-indicator {
  margin-left: 0.4rem;
  font-size: 0.75rem;
  vertical-align: middle;
  opacity: 0.8;
}

/* Disabled transaction row */
.transaction-row--disabled {
  opacity: 0.45;
  background-color: rgba(107, 114, 128, 0.06);
}

.text-strikethrough {
  text-decoration: line-through;
}

/* ===== Checkbox Column for Enable/Disable ===== */
/* (#153) Content-hugging, left-aligned: the checkbox sits 2px after the
   drag handle and the row title follows 12px after the checkbox, instead
   of floating centered in a 36px column (the base th/td 10px padding
   rules have higher specificity than a bare .col-enable, hence the
   .grid-table prefix). */
.grid-table .col-enable {
  width: 26px;
  padding-left: 2px;
  padding-right: 8px;
  text-align: left;
}

.grid-table .cell-enable {
  padding-left: 2px;
  padding-right: 8px;
  text-align: left;
}

/* (#153) Row title starts 4px after the checkbox; the header label is
   padded identically so it stays aligned with the values. */
.grid-table .col-name,
.grid-table .cell-name {
  padding-left: 4px;
}

.cell-enable input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
/* ===== Tooltips ===== */
.tooltip-trigger {
  position: relative;
  cursor: help;
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  background-color: #1f2937;
  color: #ffffff;
  padding: 0.4rem 0.65rem;
  border-radius: 0.375rem;
  font-size: 0.7rem;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.tooltip-trigger:hover::after,
.tooltip-trigger:focus::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ===== Header ===== */
.app-header {
  background-color: var(--header-bg);
  color: var(--header-text);
  padding: 0.4rem 1rem;
  display: flex;
  flex-wrap: wrap; /* narrow screens: actions row may drop below the brand */
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-header__brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0; /* allow shrinking inside the flex row */
}

.app-header__title {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header__subtitle {
  font-size: 0.75rem;
  color: var(--header-subtitle, var(--text-muted)); /* #103 */
}

.app-header__actions {
  display: flex;
  flex-wrap: wrap; /* wrap buttons instead of overflowing (Issue #30) */
  gap: 0.375rem 0.5rem;
  min-width: 0;
}

/* ===== Main Layout ===== */
.app-main {
  display: grid;
  /* 5-column dashboard (POC #23): Accounts | Assets | Liabilities | Projection | Charts.
     Proportional (not equal). (#127, hazhir 2026-08-31) projection is a plain
     1fr track — tied for the narrowest column — and result rows simply fill
     it (no row-level cap: the column is what's narrow). (hazhir 2026-09-02)
     10% wider: 1fr → 1.127fr is the exact solution of k/(4.2+k) = 1.1/5.2,
     i.e. the projection takes 10% more of the free space at every width in
     this band. At ≥1920px the track freezes at its 1920 width (24.2rem,
     see below) so the label→value gap inside the rows can't grow with
     ultrawide viewports, while the other four columns keep taking the full
     viewport (no dashboard max-width — hazhir, 2026-08-26). */
  grid-template-columns: 1.1fr 1fr 1fr 1.127fr 1.1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  /* Explicit width: margin auto + fr tracks (with contained .panel children)
     otherwise resolve to min-content and the whole grid collapses.
     No max-width cap: on wide/ultrawide displays the columns take the full
     viewport instead of sitting centered in dead margins (hazhir, 2026-08-26). */
  width: 100%;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  overflow-x: hidden;
}

/* Grid items must not force tracks wider than 1fr (tables/wide content) */
.app-main > .panel {
  min-width: 0;
}

/* Each panel is a query container: inside narrow columns (5-grid at 1600px,
   stacked layouts) the grids shed low-value cells instead of squeezing the
   editable name/amount cells (POC #23). */
.panel {
  container-type: inline-size;
}

/* Transactions grid in narrow panels: hide the per-row currency (still shown
   in the row's details dialog) and tighten cell padding. Accounts grid keeps
   its currency column — the totals depend on it. */
@container (max-width: 430px) {
  .transactions-grid .col-currency,
  .transactions-grid .cell-currency {
    display: none;
  }

  /* (.panel__body prefix: the base .grid-table th/td padding at ~line 490
     would otherwise win the cascade — same specificity, later in file.) */
  .panel__body .grid-table td {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  .panel__body .grid-table thead th {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  /* Expense grids must FIT the panel whenever the panel is narrow — at any
     viewport (#114 compaction moved panel-relative): the 1400–1599 band and
     the ≥1920 fluid tracks leave the Assets/Liabilities panels ~344px, where
     the desktop column widths pushed the row action buttons past the panel
     edge. Mirrors the ≤640px phone block below. */
  .transactions-grid .col-enable {
    width: 26px;
    padding-left: 4px;
  }

  .transactions-grid .col-actions {
    width: 54px;
    min-width: 54px;
  }

  .transactions-grid .cell-actions {
    gap: 0.1rem;
    padding-right: 0.25rem;
  }

  .transactions-grid .cell-actions .btn--icon {
    padding: 0.25rem 0.3rem;
  }
}

/* Prevent horizontal scroll on body */
body {
  overflow-x: hidden;
}

/* ===== Panel ===== */
.panel {
  background-color: var(--bg-panel);
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.panel__header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.panel__actions {
  display: flex;
  gap: 0.5rem;
}

.panel__body {
  padding: 0.75rem 1rem;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: background-color 0.2s ease;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.4rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

/* ===== Line-art button icons =====
   Stroke icons rendered with currentColor: they inherit each button variant's
   ink (white on primary/danger, text color on ghost) and match the Destiny
   etched language without per-theme duplication. */
.btn-icon {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.18em;
  flex: none;
}

.btn:not(.btn--icon) .btn-icon { margin-right: 0.35rem; }

/* Compact square icon-only buttons (grid row actions, scenario delete) */
.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.3rem;
  line-height: 1;
}
.btn--icon .btn-icon { width: 0.95em; height: 0.95em; vertical-align: middle; margin: 0; }

/* Icon-only buttons in panel headers (Accounts/Assets/Liabilities): the label
   lives in the tooltip + aria-label; slightly larger tap target than row
   actions. */
.panel__actions .btn--icon {
  font-size: 1rem;
  padding: 0.3rem 0.45rem;
}

/* ===== Column minimize/maximize (#116) ===== */
/* Minimized panel: body + footer hidden on every breakpoint; the header
   (with the expand button) stays reachable. On the 5-column desktop grid the
   panel additionally becomes a narrow rail (4rem track set inline by JS). */
.panel--minimized .panel__body,
.panel--minimized .panel__footer {
  display: none;
}

.panel__minimize-btn {
  flex: 0 0 auto;
}

@media (min-width: 1920px) {
  /* (#127 follow-up, hazhir 2026-09-01) ultrawide: the projection track
     freezes — exactly the width the fluid track has at 1920px (385.9px ≈
     387.2px) — so the column keeps the approved 1920 look and the row gap
     can't scale with the viewport. (hazhir 2026-09-02) 22rem → 24.2rem =
     352px → 387.2px, the 10%-wider column. The other four tracks absorb
     all the surplus (proportional: 1.1 / 1 / 1 / 1.1). */
  .app-main {
    grid-template-columns: 1.1fr 1fr 1fr minmax(0, 24.2rem) 1.1fr;
  }
}

@media (min-width: 1600px) {
  .panel--minimized .panel__header {
    flex-direction: column-reverse; /* expand button on top, title below */
    align-items: center;
    /* flex-end in column-reverse = anchored to the visual top, so the
       button + title read like a normal collapsed sidebar (no void above). */
    justify-content: flex-end;
    padding: 0.75rem 0.5rem;
    gap: 0.75rem;
    flex: 1;
  }

  .panel--minimized .panel__title {
    writing-mode: vertical-rl;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
  }

  /* Sibling header controls (add/clear buttons, projection currency) are
     unreachable in a 4rem rail — hide them; only the expand button remains. */
  .panel--minimized .panel__actions > :not(.panel__minimize-btn) {
    display: none;
  }
}

/* Icon + label pairs inside flex/inline contexts */
.theme-selector__current {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.theme-selector__option-name {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.theme-selector__chevron .btn-icon { width: 0.8em; height: 0.8em; margin-left: 0.2rem; }
.workspace-selector__chevron { display: inline-flex; align-items: center; }
.workspace-selector__chevron .btn-icon { width: 0.8em; height: 0.8em; margin-left: 0.3rem; }
.app-locked-banner__icon { display: inline-flex; align-items: center; }
.app-locked-banner__icon .btn-icon { width: 1.1em; height: 1.1em; }
h3 .btn-icon { margin-right: 0.45rem; vertical-align: -0.2em; }
.settings-value .btn-icon { margin-right: 0.3rem; }

.btn--primary {
  background-color: #2563eb;
  color: #ffffff;
}
.btn--primary:hover { background-color: #1d4ed8; }

.btn--danger {
  background-color: #dc2626;
  color: #ffffff;
}
.btn--danger:hover { background-color: #b91c1c; }

.btn--ghost {
  background-color: transparent;
  color: var(--text-secondary);
  padding: 0.25rem 0.35rem;
  border-radius: 0.375rem;
  font-size: 0.9rem;
}
.btn--ghost:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* ===== Grid Tables (spreadsheet-style) ===== */
.grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.grid-table thead th {
  text-align: left;
  padding: 0.5rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border-subtle);
  white-space: nowrap;
}

.grid-table tbody tr {
  transition: background-color 0.1s ease;
}

.grid-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.grid-table td {
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--border-cell);
  vertical-align: middle;
}

/* Touch-friendly cells */
@media (hover: none) and (pointer: coarse) {
  .grid-table td {
    padding: 0.625rem 0.75rem;
  }

  .grid-table .cell-name:hover,
  .grid-table .cell-balance:hover,
  .grid-table .cell-amount:hover,
  .grid-table .cell-freq:hover,
  .grid-table .cell-currency:hover,
  .grid-table .cell-dates:hover,
  .grid-table .cell-end:hover {
    background-color: transparent; /* remove hover highlight on touch */
  }
}

/* Editable cells — click to edit */
.grid-table .cell-name,
.grid-table .cell-balance,
.grid-table .cell-amount,
.grid-table .cell-freq,
.grid-table .cell-currency,
.grid-table .cell-dates,
.grid-table .cell-end {
  cursor: pointer;
  position: relative;
}

.grid-table .cell-name:hover,
.grid-table .cell-balance:hover,
.grid-table .cell-amount:hover,
.grid-table .cell-freq:hover,
.grid-table .cell-currency:hover,
.grid-table .cell-dates:hover,
.grid-table .cell-end:hover {
  background-color: var(--bg-highlight);
  border-radius: 0.25rem;
}

/* Editing state */
.grid-table .cell-editing {
  padding: 0 !important;
}

.grid-table .cell-editing input,
.grid-table .cell-editing select {
  width: 100%;
  padding: 0.375rem 0.5rem;
  border: 2px solid #2563eb;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  outline: none;
  background-color: var(--bg-input);
  color: var(--text-primary);
}

.grid-table .cell-editing input[type="date"] {
  font-size: 0.8rem;
}

.grid-table .cell-editing select {
  cursor: pointer;
}

/* Column widths */
.col-name { width: 35%; }
.col-amount, .col-balance { width: 20%; text-align: right; }
.col-freq { width: 15%; }
.col-currency { width: 12%; }
.col-dates, .col-end { width: 12%; }
.col-actions { width: 70px; min-width: 70px; text-align: right; }

/* Tight row clusters (#153): the %-widths above distribute the leftover
   panel space across the data columns, which on wide viewports leaves large
   dead gaps between adjacent row components (measured ~250px between name
   and amount at a 3440px viewport). For the Accounts / Assets /
   Liabilities grids, pin every column but the trailing actions column to a
   content-appropriate width so the drag handle, enable checkbox, name and
   amount sit close together; the actions column (only one left without a
   specified width) absorbs the leftover space, keeping the row buttons
   right-aligned at the panel edge. At narrow widths the pinned sum exceeds
   the table width, so auto layout compresses the columns to min-content
   (names wrap) — the same fit behavior as before. */
.accounts-grid .col-name,
.transactions-grid .col-name { width: 7.5rem; }
.accounts-grid .col-balance,
.transactions-grid .col-amount { width: 5.5rem; }
.accounts-grid .col-currency,
.transactions-grid .col-currency { width: 4.75rem; }
.transactions-grid .col-freq { width: 4.25rem; }
.accounts-grid .col-actions,
.transactions-grid .col-actions { width: auto; min-width: 0; }

.cell-actions {
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.15rem;
}

/* ===== Tables wrappers ===== */
.accounts-grid,
.transactions-grid {
  margin: 0;
}

/* Ensure table containers never cause body overflow */
.accounts-list {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Transaction lists should not show horizontal scrollbars; content wraps within viewport */
.transactions-list {
  overflow-x: hidden;
}

/* ===== Transaction Sections: fair, independent space for income and expenses =====
   Each list is its own scroll region with an equal share of the panel height,
   so a long expense list can no longer push income off-screen (Issue #88). */
.transaction-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  gap: 0.25rem;
}

.transaction-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.transaction-section__header .btn {
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.transaction-section__label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.125rem 0.25rem 0;
}

.transactions-list--income,
.transactions-list--expenses {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

/* Sticky column headers inside each independently scrolling list */
.transactions-list thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: var(--bg-panel);
}

.transactions-list .empty-state {
  padding-top: 1.25rem;
}

/* ===== Transaction row color hints ===== */
tr.text--income td.cell-amount { font-weight: 600; }
tr.text--expense td.cell-amount { font-weight: 600; }

/* Checkbox column for enable/disable */
.col-enable {
  width: 36px;
  padding-left: 12px;
  text-align: center;
}

.cell-enable {
  text-align: center;
}

.cell-enable input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ===== Conditional transaction highlighting ===== */
.transaction--conditional {
  background-color: rgba(250, 204, 21, 0.08);
}
[data-theme="dark"] .transaction--conditional {
  background-color: rgba(250, 204, 21, 0.12);
}
.condition-indicator {
  margin-left: 0.35rem;
  font-size: 0.75rem;
  vertical-align: middle;
}
.transaction-icon {
  margin-right: 0.35rem;
  font-size: 0.85rem;
  vertical-align: middle;
}

/* ===== Account Summary ===== */
.transactions-summary {
  /* No margin-top: auto — that pinned the line to the bottom of the old
     Transactions panel. In the projection hub (POC #23) it absorbs every
     free pixel between the period controls and the summary, producing a
     blank band on tall viewports. */
  margin-top: 0;
  padding-top: 0.75rem;
  border-top: 2px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.accounts-summary__label,
.transactions-summary__label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.accounts-summary__value,
.transactions-summary__value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Pinned column footers (POC #23/#26/#27) =====
   Accounts total / Total Income / Total Expenses sit below the scroll region
   so they stay visible while lists scroll. .accounts-summary keeps its class
   for destiny theming but is a <footer> element now. */
.panel__footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.625rem 1rem;
  border-top: 2px solid var(--border-subtle);
  background-color: var(--bg-panel);
  font-size: 0.875rem;
}

.panel__footer-label {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  min-width: 0;
  font-weight: 600;
  color: var(--text-primary);
}

.panel__footer-hint {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel__footer-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ===== Projection cash-flow grid (POC #24) ===== */
.projection-cashflow {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm, 0.5rem);
  min-height: 0;
}

/* Empty until renderIncomeSummary populates it (POC #24) */
.projection-cashflow:empty { display: none; }

.projection-cashflow__title {
  /* (#127) sub-14px floor: 0.7 → 0.8rem */
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.125rem;
}

.projection-cashflow__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.projection-cashflow__label {
  color: var(--text-secondary);
}

.projection-cashflow__value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ===== Chart column slots (POC #28) =====
   Future charts land in these placeholders without layout changes. */
.panel__body > #expenseCategoryChart,
.panel__body > #savingsRateTrend {
  flex: 0 0 auto;
}

/* #99 live charts: empty-state note inside a chart plate */
.chart-empty-note {
  margin: 0.5rem 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ===== Accounts grouped by category (POC #25; single table per #115) ===== */
.accounts-list {
  display: flex;
  flex-direction: column;
  /* The list is the accounts column's scroll region; the single table
     (#115) fills it. */
  flex: 1 1 auto;
  min-height: 0;
}

/* One column header for the whole Accounts column, pinned to the top of
   the scroll region (#115) — matching the transactions lists. */
.accounts-list thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: var(--bg-panel);
}

/* Category group headers are full-width rows inside the single accounts
   table (#115) — same structure as the expense category groups (#114). */
.account-group-header td {
  padding: 0;
}

.account-group-header__inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.375rem 0.5rem;
  background-color: var(--bg-hover);
  color: var(--text-primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
}

.account-group-header__inner:hover { background-color: var(--bg-highlight); }

.account-group__chevron {
  display: inline-flex;
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex: none;
}

.account-group-header--collapsed .account-group__chevron { transform: rotate(-90deg); }

.account-group__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-group__count {
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* #118: quick-add '+' button on the Accounts category group header.
   Right of the title, distinct from the collapse chevron, own >=24x24 hit
   target, touch-friendly. stopPropagation in JS keeps it from collapsing.
   Hidden automatically via the template when the workspace is locked (#85). */
.account-group__add {
  flex: none;
  width: 26px;
  height: 26px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-subtle, transparent);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 400;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.account-group__add:hover,
.account-group__add:focus-visible {
  background-color: var(--bg-highlight);
  border-color: var(--text-muted);
  outline: none;
}

tr.account-row--hidden { display: none; }

/* ===== Compact one-line summary (click opens the breakdown dialog, Issue #89) ===== */
.transactions-summary {
  padding: 0.5rem 0.75rem;
  gap: 0.75rem;
  cursor: pointer;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  transition: background-color 0.15s ease;
  user-select: none;
}

.transactions-summary:hover {
  background-color: var(--bg-hover);
}

.transactions-summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.transactions-summary__pair {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  min-width: 0;
}

.transactions-summary .transactions-summary__label {
  font-size: 0.75rem;
  white-space: nowrap;
}

.transactions-summary .transactions-summary__value {
  font-size: 0.9375rem;
}

.transactions-summary__hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

/* Semantic colors must win over the shared .transactions-summary__value rule */
.transactions-summary .transactions-summary__value.text--income,
.breakdown-dialog .transactions-summary__value.text--income {
  color: var(--color-income);
}

.transactions-summary .transactions-summary__value.text--expense,
.breakdown-dialog .transactions-summary__value.text--expense {
  color: var(--color-expense);
}

/* ===== Breakdown overlay dialog (Issue #89) ===== */
.breakdown-dialog {
  width: min(380px, calc(100vw - 2rem));
}

/* Income vs Expenses comparison inside the dialog */
.breakdown-dialog__vs {
  margin-top: 0.875rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.breakdown-dialog__vs-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.breakdown-dialog__vs-label {
  width: 4.25rem;
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.breakdown-dialog__vs-track {
  flex: 1;
  height: 0.625rem;
  background-color: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}

.breakdown-dialog__vs-fill {
  height: 100%;
  border-radius: 999px;
}

.breakdown-dialog__vs-fill--income {
  background-color: var(--color-income);
}

.breakdown-dialog__vs-fill--expense {
  background-color: var(--color-expense);
}

.breakdown-dialog__vs-value {
  min-width: 5.5rem;
  text-align: right;
}

.breakdown-dialog__vs-ratio {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.125rem;
}

.breakdown-dialog__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: -0.25rem;
}

.breakdown-dialog__rows {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin: 0.75rem 0 1rem;
}

.breakdown-dialog__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border-cell);
}

.breakdown-dialog__row:last-child {
  border-bottom: none;
}

.breakdown-dialog__row-values {
  display: inline-flex;
  align-items: baseline;
  gap: 0.375rem;
  white-space: nowrap;
}

.breakdown-dialog__vs-sep {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Ratio Chart ===== */
.ratio-chart {
  /* First child of the charts column (POC #28) — no auto-push. */
  margin-top: 0;
  padding: 0.625rem 0.75rem;
  background-color: var(--bg-subtle);
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
}

.ratio-chart__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.375rem;
}

.ratio-chart__title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

.ratio-chart__ratio {
  font-size: 0.8125rem;
  font-weight: 700;
}

.ratio-chart__bars {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ratio-chart__bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ratio-chart__bar-label {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  width: 4.25rem;
  flex-shrink: 0;
  text-align: right;
}

.ratio-chart__bar-track {
  flex: 1;
  height: 0.625rem;
  background-color: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.ratio-chart__bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
  min-width: 0;
}

.ratio-chart__bar-fill--income {
  background-color: var(--color-income);
}

.ratio-chart__bar-fill--expense {
  background-color: var(--color-expense);
}

.ratio-chart__bar-value {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  width: auto;
  min-width: 0;
  flex-shrink: 0;
  text-align: left;
}

/* Narrow chart columns: keep the track usable instead of starving it */
@container (max-width: 460px) {
  .ratio-chart__bar-label {
    width: 3.5rem;
  }
}

/* Projection hub in narrow columns (5-grid, stacked flows): the compact
   cash-flow line stacks into its own rows instead of crowding the pairs. */
@container (max-width: 600px) {
  .transactions-summary {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
  }

  .transactions-summary__pair {
    justify-content: space-between;
  }

  .transactions-summary__hint {
    text-align: right;
  }
}

/* Content blocks never shrink below their natural height (POC #23): flex
   shrinking clipped the cash-flow grid and rendered its rows over the budget
   box. Scrollable lists keep their own flex rules (defined above). */
.panel__body > .projection-controls,
.panel__body > .projection-results,
.panel__body > .projection-cashflow,
.panel__body > .transactions-summary,
.panel__body > .budget-overview,
.panel__body > .ratio-chart,
.panel__body > .projection-charts {
  flex: 0 0 auto;
}

/* ===== Projection Controls ===== */
.projection-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.projection-controls__presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.projection-controls__custom {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  width: 100%;
  flex-wrap: wrap;
}

.projection-controls__input {
  width: 3.5rem;
  padding: 0.25rem 0.35rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.8rem;
  text-align: center;
  background-color: var(--bg-input);
  color: var(--text-primary);
}

.projection-controls__input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.projection-controls__unit {
  /* (#127) sub-14px floor: 0.7 → 0.8rem */
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.projection-controls__preset {
  padding: 0.3rem 0.65rem;
  border-radius: 9999px;
  /* (#127) sub-14px floor: 0.75 → 0.8125rem */
  font-size: 0.8125rem;
  font-weight: 500;
  background-color: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  transition: all 0.15s ease;
}

.projection-controls__preset:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.projection-controls__preset--active {
  background-color: #2563eb;
  color: #ffffff;
}

/* #126: day-based period — slider + exact entry + smart label */
.projection-controls__slider {
  flex: 1 1 auto;
  width: auto;
  min-height: 24px;
  margin: 0.1rem 0 0.15rem;
  accent-color: #2563eb;
  cursor: pointer;
}

/* #126 follow-up: slider + end-date field share one row (field on the right) */
.projection-controls__slider-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.projection-controls__date {
  /* (hazhir 2026-09-02) visually hidden: the visible affordance is the
     button below (#projEndBtn → showPicker). Kept in the DOM so it stays
     keyboard-reachable (native date editing), testable, and the source of
     truth for the button label. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.projection-controls__date-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: auto; /* right of the days row; slider gets full width */
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  font-family: inherit;
  font-size: 0.8125rem; /* #127 step; ≥11px floor even at the 15px mobile root */
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  background-color: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
}

.projection-controls__date-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.projection-controls__date-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.projection-controls__days-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  position: relative; /* anchor for the visually-hidden date input */
  width: 100%;
}

.projection-controls__period-detail {
  width: 100%;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.projection-controls__locked {
  width: 100%;
  display: flex;
  align-items: center;
  min-height: 40px;
  font-size: 0.8rem;
}

/* (hazhir 2026-09-02) the header period chip (.projection-controls__period-label)
   was removed — the period-detail line below the slider already shows the
   full period, so the header carries only the currency control. */
/* Projection display-currency dropdown (Issue #84) — top-right of the
   projection column header. The warning glyph appears when the selected
   currency has no exchange rate and values fall back to base. */
.projection-currency {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.projection-currency__select {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  /* (#127) sub-14px floor: 0.72 → 0.8125rem */
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-secondary);
  background-color: var(--bg-input);
  cursor: pointer;
}

.projection-currency__select:hover {
  color: var(--text-primary);
}

.projection-currency__select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.projection-currency__warn {
  display: inline-flex;
  align-items: center;
  color: var(--warn-amber);
  cursor: help;
}

.projection-currency__warn .btn-icon {
  width: 0.95em;
  height: 0.95em;
  vertical-align: middle;
}

/* ===== Projection Results ===== */
.projection-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.projection-result__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* (#127) Rows fill the projection column exactly — the column itself is
     what's narrow (1.127fr track, frozen at 24.2rem on ≥1920px viewports,
     hazhir 2026-09-02), so no
     row-level cap: a row-only cap was leaving the other components
     (cashflow/budget/charts) much wider than the rows (hazhir 2026-09-01). */
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  background-color: var(--bg-result-row);
  font-size: 0.875rem;
  transition: background-color 0.2s ease;
}

.projection-result__row--highlight {
  background-color: var(--bg-highlight);
  border: 1px solid var(--border-highlight);
}

.projection-result__label {
  font-weight: 500;
  color: var(--text-secondary);
}

.projection-result__value {
  font-weight: 700;
  color: var(--text-primary);
}

.projection-result__section-divider {
  height: 1px;
  background-color: var(--border-subtle);
  margin: 0.25rem 0;
}

.projection-result__trend {
  /* (#127) sub-14px floor: 0.75 → 0.8125rem */
  font-size: 0.8125rem;
  margin-left: 0.35rem;
}

/* (#96) Headline "drowning depth" hero — first block of the Projection hub.
   Tokens only (--bg-highlight / --warn-amber / --color-income / --color-expense
   are defined per theme), so light, dark and destiny all get the same
   escalation semantics: ok/income green, amber at 3-6 mo runway, red below
   3 mo (or already underwater). */
.projection-hero {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem;
  border-radius: 0.625rem;
  background-color: var(--bg-highlight);
  border: 1px solid var(--border-highlight);
}

.projection-hero__label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.projection-hero__value {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--text-primary);
}

.projection-hero__sub {
  font-size: 0.8125rem; /* (#127) sub-14px floor */
  color: var(--text-secondary);
}

.projection-hero--ok .projection-hero__value,
.projection-hero--debt-free .projection-hero__value,
.projection-hero--on-track .projection-hero__value {
  color: var(--color-income);
}

.projection-hero--amber .projection-hero__value {
  color: var(--warn-amber);
}

.projection-hero--debt-free-pending .projection-hero__value,
.projection-hero--debt-free-pending .projection-hero__sub {
  color: var(--risk-color, var(--warn-amber));
}

.projection-hero--debt-free-achieved .projection-hero__value {
  color: var(--color-income);
  text-decoration: line-through;
}

.projection-hero--red .projection-hero__value,
.projection-hero--underwater .projection-hero__value {
  color: var(--color-expense);
}

.projection-hero--flat .projection-hero__value {
  color: var(--text-secondary);
}

/* (#154) Runway scope: the RUNWAY hero gains a vertical checkbox column on
   its right edge — which balances count toward the numerator. The hero
   becomes a row only when scoped; every other kind keeps the column
   layout above. */
.projection-hero--scoped {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
}

.projection-hero--scoped .projection-hero__main {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.projection-hero__scope {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex-shrink: 0;
}

.projection-hero__scope-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.projection-hero__scope-item input[type="checkbox"] {
  margin: 0;
  accent-color: var(--color-income);
}

/* (#144) Drowning map: legend chips + tip labels (SVG-internal elements
   style from the document CSS; the SVG itself is viewBox-scaled). */
.drowning-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.8rem;
  margin-top: 0.45rem;
}

.drowning-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.drowning-legend__swatch {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.drowning-legend__state--drowned,
.drowning-legend__state--underwater {
  color: var(--color-expense);
  font-weight: 600;
}

.drowning-legend__state--afloat {
  color: var(--color-income);
}

.drowning-tip {
  font-size: 11px; /* sub-14px floor: 0.8125rem — kept 11px to match axis labels */
  font-weight: 600;
}

/* ===== Projection Charts ===== */
.projection-charts {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.projection-chart {
  background-color: var(--bg-subtle);
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
  padding: 0.625rem 0.75rem;
}

.projection-chart__title {
  /* (#127) sub-14px floor: 0.75 → 0.8125rem */
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.375rem 0;
}

.projection-chart__container {
  width: 100%;
  overflow: hidden;
}

.projection-chart__svg {
  width: 100%;
  height: auto;
  display: block;
}

.projection-chart__axis-label {
  /* (#127) no 9px anywhere: SVG axis labels 9 → 11px */
  font-size: 11px;
  fill: var(--text-muted);
  font-family: inherit;
}

/* #146: Net cash flow chart — D/W/M granularity toggle */
.projection-chart__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.375rem;
}
.projection-chart__head .projection-chart__title {
  margin: 0;
}
.ie-gran {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  overflow: hidden;
}
.ie-gran-btn {
  appearance: none;
  background: var(--bg-panel);
  border: 0;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.3125rem 0.5rem;
  cursor: pointer;
}
.ie-gran-btn + .ie-gran-btn {
  border-left: 1px solid var(--border-color);
}
.ie-gran-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.ie-gran-btn.is-active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.ie-gran-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}
.ie-gran-note {
  margin: 0.25rem 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* #100 first-run CTA inside the accounts empty state */
.empty-state p {
  margin-bottom: 0.75rem;
}
.empty-state__cta {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  padding: 0.45rem 0.9rem;
}
.empty-state__hint {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.75rem;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-result-row);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.app-footer__version {
  letter-spacing: 0.05em;
  font-weight: 500;
  /* #188 review: the version is clickable — it reopens the release-notes
     dialog. Same muted-underline affordance as the #156 disclaimer link
     beside it, so the two read as one cluster of footer actions. */
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.app-footer__version:hover {
  text-decoration-thickness: 2px;
}

/* #156: footer link reopens the disclaimer dialog */
.app-footer__disclaimer {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.75rem;
  font: inherit;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.app-footer__disclaimer:hover {
  color: var(--text-primary);
}

/* #170: save status — Saving…/Saved fade on their own; an error stays
   until the retry click succeeds, so a failed save is never silent. */
.app-footer__status {
  margin-left: 0.75rem;
}

.app-footer__status--error {
  color: #c0392b;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

/* ===== Responsive ===== */

/* 3-column arrangement (1400–1599px, POC #23): five side-by-side columns
   can't hold the 7-column transaction grid below ~1600px, so the data-entry
   columns (Accounts/Assets/Liabilities) share the top row; the Projection hub
   spans two of the bottom row with Charts. Fixed viewport: panels fill and
   scroll internally. */
@media (max-width: 1599px) {
  /* (#127 follow-up, hazhir 2026-09-01) the projection column stays narrow
     here too — it no longer spans two of three columns (that kept the panel
     ~970px wide). Row 1 is four columns with the projection as the last
     (~24.2rem, hazhir 2026-09-02: 10% wider) track, so it stays close to
     the other three (≈1.1:1 at 1500px) instead of being a sliver rail;
     row 2 is the full-width charts strip. */
  .app-main {
    grid-template-columns: 1fr 1fr 1fr minmax(0, 24.2rem);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .panel--charts {
    grid-column: 1 / -1;
  }
}

/* 2-column flow (≤1399px, POC #23): panels flow two per row (Charts spans
   both), the page scrolls between panels, and each panel keeps a 75vh cap so
   long lists scroll internally once the cap is hit. */
@media (max-width: 1399px) {
  .app-main {
    grid-template-columns: 1fr 1fr;
    /* max-content rows (not `auto`): Blink sizes `auto` tracks to an even
       viewport split, which compressed the panels (Issue #30). */
    grid-template-rows: repeat(3, max-content);
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .panel {
    max-height: 75vh;
  }

  /* Content-sized panel bodies: the panel (not the body) is the scroll
     region's cap; lists keep natural height so short columns don't stretch. */
  .panel__body {
    flex: 0 1 auto;
    min-height: 4rem;
  }

  .transactions-list--income,
  .transactions-list--expenses {
    flex: 0 0 auto;
  }

  .panel--projection {
    grid-column: span 1;
  }

  .panel--charts {
    grid-column: span 2;
  }
}

/* Mobile: single column, touch-friendly */
@media (max-width: 640px) {
  html { font-size: 15px; }

  .app-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .app-header__actions {
    flex-wrap: wrap;
  }

  .app-header__title {
    font-size: 1.25rem;
  }

  .app-header__subtitle {
    display: none; /* save space on small screens */
  }

  .app-header__actions {
    gap: 0.375rem;
  }

  /* Single-column stack (Issue #30): content-sized rows and the main area
     scrolls vertically between panels. Panels that exceed 75vh get a
     definite bound so their internal scroll regions stay functional. */
  .app-main {
    grid-template-columns: 1fr;
    /* max-content rows (not `auto`): with `auto`, Blink sizes the tracks to
       an even split of the viewport instead of the content height, which
       compresses the panels and collapses the lists to ~0px (Issue #30).
       align-content:start packs the content rows to the top; the main area
       scrolls between panels. The 75vh panel cap below bounds long lists. */
    /* 5 stacked panels (POC #23) */
    grid-template-rows: repeat(5, max-content);
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .panel--projection,
  .panel--charts {
    grid-column: span 1;
  }

  .panel {
    max-height: 75vh;
  }

  /* The stacked single column scrolls the page between panels (Issue #30);
     empty-state bodies stay minimal so short viewports don't force scroll. */
  .panel__body {
    min-height: 0;
  }

  /* Panel adjustments */
  .panel__header {
    padding: 0.875rem 1rem;
    flex-wrap: wrap;
  }

  .panel__actions {
    gap: 0.375rem;
    flex-wrap: wrap;
  }

  .panel__body {
    padding: 0.625rem 0.75rem;
  }

  /* Buttons: larger touch targets on mobile */
  .btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    min-height: 44px; /* Apple HIG touch target */
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn--ghost {
    padding: 0.375rem 0.5rem;
    min-height: auto;
  }

  /* Tables: horizontal scroll wrapper on container divs (not table elements) */
  .accounts-list,
  .transactions-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Transaction grids must FIT the panel on phones (#114): the generic
     min-width: 500px (below) pushes the action buttons off-screen, and the
     per-row Cat column is gone (replaced by category group headers), so the
     remaining columns can shrink to fit. The min-width: 0 override for
     .transactions-grid is declared AFTER the 500px rule so it wins the
     cascade. Accounts keep the 500px floor — their grid is unchanged. */
  .transactions-grid .col-enable {
    width: 26px;
    padding-left: 4px;
  }

  .transactions-grid .col-actions {
    width: 54px;
    min-width: 54px;
  }

  .transactions-grid .cell-actions {
    gap: 0.1rem;
    padding-right: 0.25rem;
  }

  .transactions-grid .cell-actions .btn--icon {
    padding: 0.25rem 0.3rem;
  }

  .grid-table {
    min-width: 500px; /* ensures table doesn't squish too much */
  }

  /* #114 — must follow the min-width: 500px rule above to win the cascade. */
  .transactions-grid {
    min-width: 0;
  }

  .col-end,
  .col-currency,
  .col-dates {
    display: none;
  }

  /* Projection controls: stack more on mobile */
  .projection-controls__presets {
    gap: 0.25rem;
  }

  .projection-controls__preset {
    padding: 0.4rem 0.625rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .projection-controls__custom {
    gap: 0.25rem;
  }

  /* #126: full-width slider with a touch-sized track on mobile */
  .projection-controls__slider {
    min-height: 36px;
  }

  .projection-controls__slider-row {
    gap: 0.375rem;
  }

  .projection-controls__date-btn {
    min-height: 36px; /* touch target, matches the 36px inputs beside it */
  }

  .projection-controls__input {
    width: 3rem;
    min-height: 36px;
    padding: 0.25rem;
  }

  /* Projection results: slightly larger touch areas */
  .projection-result__row {
    padding: 0.75rem 0.875rem;
  }

  /* Empty states remain readable */
  .empty-state {
    padding: 1.25rem 0.75rem;
    font-size: 0.875rem;
  }
}

/* Very small screens (320px) */
@media (max-width: 380px) {
  html { font-size: 14px; }

  .app-header__title {
    font-size: 1.125rem;
  }

  .btn {
    padding: 0.5rem 0.625rem;
    font-size: 0.8125rem;
  }

  .grid-table {
    min-width: 440px;
    font-size: 0.8125rem;
  }

  /* #114: keep transaction grids fitting the panel (see max-width: 640px) */
  .transactions-grid {
    min-width: 0;
  }

  .panel__title {
    font-size: 1rem;
  }
}

/* ==============================
   Dialog Overlay & Panel (dark-theme aware)
   ============================== */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  /* Tall dialogs (e.g. the transaction details dialog, ~860px) must stay
     reachable on short viewports: scroll the overlay instead of clipping.
     margin:auto on the panel centers it when it fits and pins it to the
     top when it does not. */
  overflow-y: auto;
  z-index: 1000;
}

.dialog-panel {
  margin: auto;
  background-color: var(--bg-panel);
  color: var(--text-primary);
  border-radius: 0.75rem;
  padding: 1.5rem;
  width: 360px;
  max-width: 90vw;
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.dialog-panel h3 {
  margin: 0 0 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* #156: first-run disclaimer dialog — a touch wider than the default panel */
.dialog-panel--disclaimer {
  width: 480px;
  max-width: 92vw;
}

/* #188: release-notes changelog dialog — wider panel; the entry list
   scrolls inside the panel so the header and ack stay reachable. Latest
   entry carries a NEW flag; history entries are divider-separated. */
.dialog-panel--notes {
  width: 560px;
  max-width: 92vw;
}

.release-notes__list {
  max-height: 60vh;
  overflow-y: auto;
}

.release-notes__entry {
  padding: 0.6rem 0;
  border-top: 1px solid var(--border-subtle);
}

.release-notes__entry:first-child {
  border-top: none;
  padding-top: 0;
}

.release-notes__head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.release-notes__version {
  font-weight: 600;
}

.release-notes__entry--latest .release-notes__version::after {
  content: "NEW";
  margin-left: 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--header-text);
  background: var(--header-bg);
  border-radius: 0.3rem;
  padding: 0.1rem 0.35rem;
}

.release-notes__date {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.release-notes__title {
  margin-top: 0.15rem;
  font-weight: 600;
}

.release-notes__notes {
  margin: 0.3rem 0 0;
  padding-left: 1.15rem;
  color: var(--text-secondary);
}

.release-notes__notes li {
  margin: 0.15rem 0;
  line-height: 1.45;
}

.dialog-panel--disclaimer p {
  margin: 0 0 0.75rem;
  line-height: 1.45;
}

.disclaimer__license {
  margin: 1rem 0 0;
  font-size: 0.75rem;
}

.disclaimer__license summary {
  cursor: pointer;
  color: var(--text-secondary);
}

.disclaimer__license pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background-color: var(--bg-result-row);
  border: 1px solid var(--border-subtle);
  border-radius: 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.4;
  white-space: pre-wrap;
  color: var(--text-secondary);
  max-height: 16rem;
  overflow-y: auto;
}

/* Close button (X) for dialogs */
.dialog-close-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}

.dialog-close-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* Ensure dialog-panel can position the close button */
.dialog-panel {
  position: relative;
}

.dialog-panel label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.dialog-panel label strong {
  color: var(--text-primary);
}

.dialog-input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0.375rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-sizing: border-box;
}

.dialog-input:focus {
  outline: none;
  border-color: var(--border-highlight);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ===== Custom dialog selects (v0.38.4) =====
   Native <select> popups are browser-drawn (OS-blue highlight, unthemeable)
   — showOverlay() swaps every select.dialog-input for this custom listbox
   (same pattern as the theme/workspace header selectors). The native select
   is kept hidden as the value source of truth. */
.dialog-select__native { display: none; }
.dialog-select {
  position: relative;
  display: block;
  width: 100%;
}
.dialog-select__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0.375rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}
.dialog-select__trigger:hover { border-color: var(--border-color); }
.dialog-select__trigger:focus {
  outline: none;
  border-color: var(--border-highlight);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.dialog-select__trigger[aria-expanded="true"] { border-color: var(--border-highlight); }
.dialog-select__current {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dialog-select__chevron {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.dialog-select__chevron .btn-icon { width: 0.8em; height: 0.8em; opacity: 0.7; }
.dialog-select__options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-height: 220px;
  overflow-y: auto;
}
.dialog-select__option {
  padding: 0.4rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
}
.dialog-select__option:hover,
.dialog-select__option:focus {
  outline: none;
  background-color: var(--bg-hover);
}
.dialog-select__option.selected {
  color: var(--color-primary);
  font-weight: 600;
}
/* #125: non-interactive <optgroup> header rows inside themed dialog listboxes */
.dialog-select__group {
  padding: 0.4rem 0.5rem 0.15rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  pointer-events: none;
}
.dialog-select__group:not(:first-child) {
  border-top: 1px solid var(--border-color);
  margin-top: 0.2rem;
  padding-top: 0.45rem;
}

.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}
.icon-option {
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.15rem 0.3rem;
  border-radius: 0.25rem;
  border: 1px solid transparent;
  transition: all 0.1s ease;
}
.icon-option:hover {
  background-color: var(--bg-hover);
}
.icon-option--selected {
  border-color: var(--border-highlight);
  background-color: var(--bg-hover);
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ===== Dialog Hints ===== */
.dialog-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.dialog-hint--debt {
  color: var(--color-expense);
  font-weight: 500;
}

/* ===== Settings Dialog ===== */
.settings-rates-container {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.25rem;
}

.settings-rate-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-rate-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 100px;
  text-align: right;
}

.settings-rate-input {
  flex: 1;
  max-width: 140px;
}

/* ===== Expense category groups (#114) =====
   Same visual language as the Accounts column groups (POC #25), rendered as
   full-width table rows so the single sticky thead and the list's scroll
   region are preserved. Collapsed groups hide their data rows entirely. */
.expense-group-header td {
  padding: 0;
}

.expense-group-header__inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.375rem 0.5rem;
  background-color: var(--bg-hover);
  cursor: pointer;
  user-select: none;
}

.expense-group-header__inner:hover { background-color: var(--bg-highlight); }

.expense-group-header__chevron {
  display: inline-flex;
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex: none;
}

.expense-group-header--collapsed .expense-group-header__chevron { transform: rotate(-90deg); }

.expense-group-header__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.expense-group-header__count {
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  flex: none;
}

/* #118: quick-add '+' button on the Expense category group header — same
   contract as the Accounts one: right of the title, distinct from the
   chevron, own >=24x24 touch target. Hidden when locked (#85). */
.expense-group-header__add {
  flex: none;
  width: 26px;
  height: 26px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-subtle, transparent);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 400;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.expense-group-header__add:hover,
.expense-group-header__add:focus-visible {
  background-color: var(--bg-highlight);
  border-color: var(--text-muted);
  outline: none;
}

.expense-row--hidden { display: none; }

/* Budget chip on the group header (reuses the badge metric from the old Cat
   column). Distinct background so it reads as a pill on the header bar even
   before a budget is set. */
.expense-group__budget {
  flex: none;
  max-width: 55%;
  background-color: var(--bg-subtle);
}

.expense-group__budget--over {
  color: var(--color-expense);
  font-weight: 600;
}

/* ===== Category Badge ===== */
.category-badge {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border-radius: 0.35rem;
  background-color: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ===== Budget Overview ===== */
.budget-overview {
  margin-top: 0.75rem;
  padding: 0.625rem 0.75rem;
  background-color: var(--bg-subtle);
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
}

.budget-overview--empty {
  color: var(--text-muted);
  /* (#127) align to the same step: 0.82 → 0.8125rem */
  font-size: 0.8125rem;
}

.budget-overview__title {
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.budget-overview__row {
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr minmax(0, auto);
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-subtle);
  width: 100%;
  overflow: hidden;
}

.budget-overview__row:last-child {
  border-bottom: none;
}

.budget-overview__row-left {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  max-width: 140px;
}

.budget-overview__indicator {
  font-size: 0.85rem;
  flex-shrink: 0;
}

.budget-overview__category {
  font-size: 0.78rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-overview__row-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  min-width: 0;
  justify-content: flex-end;
}

.budget-overview__actual {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
}

.budget-overview__limit {
  color: var(--text-muted);
}

.budget-overview__bar-track {
  height: 6px;
  background-color: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  grid-column: 1 / -1;
}

.budget-overview__bar-fill {
  height: 100%;
  background-color: var(--color-income);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.budget-overview__bar-fill--warning {
  background-color: #f59e0b;
}

.budget-overview__bar-fill--over {
  background-color: var(--color-expense);
}

.budget-overview__remaining {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Budget Editor Dialog ===== */
.budget-editor {
  width: 100%;
  margin-top: 0.5rem;
  border-collapse: collapse;
}

.budget-editor__row {
  border-bottom: 1px solid var(--border-subtle);
}

.budget-editor__category {
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  color: var(--text-primary);
  width: 60%;
}

.budget-editor__limit-cell {
  padding: 0.35rem 0.5rem;
  width: 40%;
}

.budget-editor__limit-input {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0.35rem;
  font-size: 0.8rem;
  background-color: var(--bg-page);
  color: var(--text-primary);
}

.budget-editor__limit-input:focus {
  outline: none;
  border-color: var(--border-highlight);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.budget-editor__header-category,
.budget-editor__header-limit {
  padding: 0.3rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

/* ===== Workspace Selector ===== */
.workspace-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  flex-wrap: wrap; /* narrow screens: wrap instead of overflowing (Issue #30) */
  min-width: 0;
}

.workspace-selector__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.workspace-selector__dropdown {
  position: relative;
  display: inline-block;
}

.workspace-selector__select {
  width: 180px;
  max-width: 100%;
  min-width: 0;
  padding: 0.35rem 1.75rem 0.35rem 0.6rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.workspace-selector__select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.workspace-selector__trigger {
  /* base button styles to match select */
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 1.75rem 0.35rem 0.6rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  width: 180px;
}

.workspace-selector__trigger:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.workspace-selector__current {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.workspace-selector__chevron {
  font-size: 0.6rem;
  color: var(--text-muted);
  pointer-events: none;
}

.workspace-selector__options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  max-height: 240px;
  overflow-y: auto;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0;
  margin: 0;
  list-style: none;
  z-index: 100;
}

.workspace-selector__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
}

.workspace-selector__option:hover {
  background-color: rgba(59, 130, 246, 0.08);
}

.workspace-selector__option.selected {
  background-color: rgba(59, 130, 246, 0.12);
  font-weight: 500;
}

.workspace-selector__option-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.workspace-selector__delete-btn {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.workspace-selector__delete-btn:hover {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-expense);
}

/* ===== Theme Selector (dropdown; replaces the binary light/dark toggle) ===== */
.theme-selector {
  position: relative;
  display: inline-block;
  min-width: 0;
}

.theme-selector__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.25rem 0.45rem;
  white-space: nowrap;
}

.theme-selector__chevron {
  font-size: 0.6rem;
  color: var(--text-muted);
  pointer-events: none;
}

.theme-selector__options {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0;
  margin: 0;
  list-style: none;
  z-index: 100;
}

.theme-selector__option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  white-space: nowrap;
}

.theme-selector__option:hover {
  background-color: rgba(59, 130, 246, 0.08);
}

.theme-selector__option.selected {
  background-color: rgba(59, 130, 246, 0.12);
  font-weight: 500;
}

/* ===== Workspace Dialog ===== */
/* Reuses .dialog-panel base styles; only add workspace-specific tweaks here */
.workspace-dialog {
  position: relative;
}

.workspace-dialog h3 {
  /* Inherits from .dialog-panel h3: margin: 0 0 1rem; font-weight: 600; */
}

.workspace-dialog__hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.workspace-dialog__label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

/* Use the standard .dialog-input class for consistency; this selector just ensures it works */
.workspace-dialog__input {
  /* Falls back to .dialog-input styles */
}

.workspace-dialog__error {
  font-size: 0.7rem;
  color: var(--color-expense);
  min-height: 1em;
  margin-bottom: 0.5rem;
}

.workspace-dialog__actions {
  /* Reuses .dialog-actions layout; this ensures consistency */
}

/* ===== Workspace Management in Settings ===== */
.settings-workspace-section {
  border-top: 1px solid var(--border-color);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
}

.settings-workspace-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.settings-workspace-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.settings-workspace-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  background-color: var(--bg-hover);
}

.settings-workspace-item--active {
  outline: 1px solid var(--color-primary);
  background-color: rgba(59, 130, 246, 0.08);
}

.settings-workspace-item__name {
  font-weight: 500;
}

.settings-workspace-item__actions {
  display: flex;
  gap: 0.3rem;
}

.settings-workspace-item__btn {
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.settings-workspace-item__btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.settings-workspace-item__btn--danger:hover {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--color-expense);
  border-color: var(--color-expense);
}

/* ===== Encryption / Lock Styles ===== */

/* #147: while locked or masked, the top bar and every column header control
   step out — the fixed banner alone could not cover the taller Destiny
   header, leaving add/clear/minimize buttons exposed under its edge. Same
   "locked means locked" policy as #118/#7 (group "+" buttons unrendered)
   and #148 (mutation guards). The workspace selector intentionally stays
   reachable: a locked workspace must not trap the user from switching
   (#183's locked boot path renders it deliberately). */
body.app-locked .app-header__actions,
body.app-locked .panel__actions {
  display: none;
}

.app-locked-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.app-locked-banner__icon {
  font-size: 1.1rem;
}

.app-locked-banner__text {
  letter-spacing: 0.01em;
}

.text-masked {
  font-family: monospace;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  user-select: none;
}

.dialog-panel--lock {
  max-width: 400px;
  text-align: center;
}

.dialog-panel--lock h3 {
  margin-bottom: 0.5rem;
}

.dialog-panel--lock .dialog-hint {
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.dialog-panel--lock .dialog-label {
  display: block;
  text-align: left;
  margin-bottom: 0.25rem;
  font-weight: 500;
  font-size: 0.875rem;
}

.dialog-panel--lock .dialog-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.dialog-panel--lock .dialog-error {
  color: var(--color-expense);
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
  min-height: 1.2em;
}

.dialog-panel--lock .dialog-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
}

.dialog-panel--lock .dialog-checkbox-label input[type="checkbox"] {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.dialog-panel--wide {
  max-width: 520px;
}

.settings-fieldset {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-top: 0.75rem;
}

.settings-fieldset legend {
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0 0.4rem;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.settings-row:last-child {
  margin-bottom: 0;
}

.settings-row--danger {
  align-items: flex-start;
}

.settings-label {
  font-weight: 500;
  font-size: 0.875rem;
  min-width: 80px;
}

.settings-value {
  color: var(--text-primary);
  font-size: 0.875rem;
}

.settings-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Scenarios Panel ===== */
.panel--scenarios {
  margin-top: 24px;
}

.panel--scenarios .panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.scenarios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.scenario-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  transition: all 0.15s ease;
}

.scenario-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.scenario-card--selected {
  border-color: #3b82f6;
  background: #eff6ff;
}

.scenario-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.scenario-card__header strong {
  font-size: 14px;
  color: #111827;
}

.scenario-card__delete {
  padding: 2px 6px;
  font-size: 14px;
  opacity: 0.6;
}

.scenario-card__delete:hover {
  opacity: 1;
  color: #ef4444;
}

.scenario-card__stats {
  font-size: 13px;
  margin-bottom: 6px;
  color: #374151;
}

.scenario-card__stats strong {
  color: #059669;
}

.scenario-card__meta {
  font-size: 11px;
  color: #9ca3af;
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.scenario-card__select {
  font-size: 12px;
  color: #6b7280;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* ===== Comparison Panel ===== */
.panel--comparison {
  margin-top: 24px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.comparison-table th,
.comparison-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid #e5e7eb;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: #374151;
}

.comparison-table th {
  background: #f3f4f6;
  font-weight: 600;
  color: #111827;
}

/* #172: currency tag shown when a scenario's base differs from the live base. */
.comparison-table__base {
  font-size: 10px;
  font-weight: 400;
  color: #6b7280;
}

.diff-positive {
  color: #059669 !important;
  font-weight: 600;
}

.diff-negative {
  color: #dc2626 !important;
  font-weight: 600;
}

/* ===== In-Memory Lock Banner Variant ===== */
.app-locked-banner--memory {
  background: linear-gradient(135deg, #f59e0b, #d97706) !important;
}

/* ===== #95 Calendar view dialog (week/month/year) ===== */
.calendar-dialog {
  width: 90vw; /* #95: large, ~90vw / max-width ~1400px, ~80vh with internal scroll */
  max-width: 1400px;
  height: 80vh;
  display: flex;
  flex-direction: column;
}

.calendar-dialog__body {
  flex: 1;
  overflow-y: auto; /* #95: internal scroll */
  min-height: 0;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

/* #95 view-mode segment control (default: month) */
.calendar-seg {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  overflow: hidden;
}

.calendar-seg__btn {
  padding: 0.3rem 0.85rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border: none;
  cursor: pointer;
}

.calendar-seg__btn + .calendar-seg__btn {
  border-left: 1px solid var(--border-color);
}

.calendar-seg__btn--active {
  background: var(--bg-highlight);
  color: var(--text-primary);
  font-weight: 600;
}

.calendar-period-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.calendar-nav {
  display: inline-flex;
  gap: 0.25rem;
  margin-left: auto; /* #95: Prev / Next / Today */
}

.calendar-nav__btn {
  padding: 0.15rem 0.6rem;
}

/* --- Week view (#95): 7 columns Mon–Sun, wide cells list each occurrence (name + amount) plus the day readout --- */
.calendar-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  min-height: 100%; /* #122: fill the dialog — no empty space below */
}

.calendar-week__col {
  border: 1px solid var(--border-subtle);
  border-radius: 0.5rem;
  padding: 0.5rem;
  min-height: 104px; /* #122: larger cells */
  display: flex; /* #141: pin the bottom readout to the column floor */
  flex-direction: column;
}

.calendar-day--today {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

.calendar-week__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem; /* #122 */
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.calendar-week__dnum {
  font-weight: 600;
  color: var(--text-primary);
}

.calendar-week__items {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto; /* #141: absorb free height so the readout sits at the bottom */
}

/* #141: week-view bottom readout (NW + available cash) — only rendered on
   day columns with transactions; reuses the month view's readout classes. */
.calendar-week__readouts {
  margin-top: 0.4rem;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.3rem;
}

.calendar-week__items li {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.8rem; /* #122 */
  line-height: 1.35;
  margin-bottom: 0.2rem;
}

.calendar-item-name {
  overflow: hidden; /* #95: truncated */
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-item-amount {
  flex: none;
  font-weight: 600;
}

.calendar-week__empty {
  height: 1rem;
  flex: 1 1 auto; /* #141: keep empty columns filling the cell */
}

/* --- Month view (#95): standard 7×4–6 grid; active days show compact stacked readout + one colored tick per occurrence --- */
.calendar-month__dow {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  font-size: 0.75rem; /* #122 */
  color: var(--text-muted);
  text-align: center;
}

.calendar-month { /* #122: month view fills the dialog height (no empty space below) */
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.calendar-month__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  flex: 1; /* #122 */
}

.calendar-month__cell {
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-cell);
  min-height: 108px; /* #122: larger cells (was 84px, #95) */
  padding: 0.35rem 0.4rem;
}

.calendar-month__cell:nth-child(7n + 1) { border-left: none; }

.calendar-day--out { background: transparent; pointer-events: none; }

.calendar-day-num {
  display: block;
  font-size: 0.8rem; /* #122 */
  font-weight: 600;
  color: var(--text-secondary);
}

.calendar-readout {
  display: block;
  font-size: 0.78rem; /* #122 */
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-nw { color: var(--text-primary); font-weight: 600; }
.calendar-muted { color: var(--text-muted); }
/* #121: cash readout — one size step under NW so tight cells never overflow
   (inherits nowrap/ellipsis from .calendar-readout); negative → expense color */
.calendar-cash { font-size: 0.7rem; color: var(--text-secondary); }

.calendar-ticks {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 2px;
}

.calendar-tick {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.calendar-tick--income { background: var(--color-income); }
.calendar-tick--expense { background: var(--color-expense); }

/* --- Year view (#95): 12 mini-months in a 3×4 grid — month net + net worth at month end --- */
.calendar-year {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)); /* #95: 3 columns × 4 rows (cols-first, like the "7×4–6" month grid) */
  min-height: 100%; /* #122: fill the dialog — no empty space below */
}

.calendar-year__month {
  border-top: 1px solid var(--border-subtle);
  padding: 0.6rem; /* #122 */
}

.calendar-year__name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.calendar-year__nw {
  display: block;
  font-size: 0.8rem; /* #122 */
  color: var(--text-secondary);
}
/* #121: month-end cash — compact, same overflow behavior as the readouts */
.calendar-year__cash {
  display: block;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

/* ===== Visually hidden (screen-reader-only) ===== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Drag & drop row reorder (#119) =====
   Pointer-based (mouse + touch) via the per-row grip handle. The drop
   indicator is absolutely positioned inside the section container — each
   must be a positioning anchor (and the transactions lists are their own
   scroll regions, so the JS adds scrollTop when computing top). */
#accountsList,
#incomeList,
#expenseList {
  position: relative;
}

/* (#153) content-hugging: the 24px handle button fills the cell
   edge-to-edge (was 1.75rem + 2px left pad + 4px right pad). */
.grid-table .col-drag {
  width: 1.5rem;
  padding: 0;
}

.grid-table .cell-drag {
  padding: 0;
  width: 1.5rem;
}

.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.75rem; /* touch-friendly target */
  cursor: grab;
  touch-action: none; /* the pointer drag must win over page/scroll panning */
  color: var(--text-secondary);
  opacity: 0.55;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle:hover {
  opacity: 1;
}

/* #133: the handle is a real <button> (keyboard reorder). Reset native
   button chrome so it renders identically to the old span, and give it a
   visible focus ring for keyboard users — same token as other grid controls. */
.drag-handle {
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
}

.drag-handle:focus-visible {
  outline: 2px solid var(--color-primary, #4f7cff);
  outline-offset: 1px;
  opacity: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle .btn-icon {
  width: 0.9rem;
  height: 0.9rem;
}

/* While a row drag is active: grabbing cursor + no text selection, even
   when the pointer leaves the handle (pointer capture keeps events flowing
   to the handle, but the cursor follows the geometry). */
body.is-dragging-row {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

/* The lifted row: dimmed in place while the indicator shows the target. */
.grid-table .row--dragging {
  opacity: 0.45;
}

.grid-table .row--dragging td {
  border-bottom-color: var(--color-primary, #4f7cff);
}

.drop-indicator {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  height: 2px;
  border-radius: 1px;
  background: var(--color-primary, #4f7cff);
  pointer-events: none;
  z-index: 3;
}
