/* Light theme — default (no .dark class on <html>) */
:root {
  /* Keeps native form-control chrome (date/time picker icons, scrollbars)
     in sync with the app's manually-toggled .dark class below, rather
     than the OS's own light/dark preference — without this, a dark-theme
     date input still gets the browser's light-mode calendar icon glyph,
     which is nearly invisible against a dark field background. */
  color-scheme: light;

  --bg-page:        #f7f5f0;
  --bg-surface:     #ffffff;
  --bg-card:        #ffffff;
  --bg-sidebar:     #ffffff;
  --bg-hover:       #eee9de;
  --border-subtle:  #e4ddd0;
  --border-card:    rgba(0,0,0,0.08);
  --glass-bg:       rgba(255,255,255,0.75);

  --text-primary:   #1f2430;
  --text-secondary: #5b6478;
  --text-muted:     #9aa1b0;

  --gold:           #b8842a;
  --gold-dim:       rgba(184,132,42,0.14);
  --gold-glow:      0 0 24px rgba(184,132,42,0.18);

  --emerald:        #16a34a;
  --emerald-dim:    rgba(22,163,74,0.12);
  --sky:            #2563eb;
  --red:            #dc2626;
  --red-dim:        rgba(220,38,38,0.12);
  --amber:          #d97706;
  --amber-dim:      rgba(217,119,6,0.12);

  /* Legacy custom properties — read directly via getComputedStyle() by
     chart.js. Keep the names, point them at the new
     palette so those scripts stay themed without any JS changes.
     --legend-color uses --text-primary (not --text-secondary) so chart
     legend/tooltip/datalabel text stays high-contrast against both the
     page background and the colored pie slices in both themes. */
  --bg-color:       var(--bg-card);
  --text-color:     var(--text-primary);
  --legend-color:   var(--text-primary);
  --tooltip-bg:     var(--bg-surface);
  --income-color:   var(--emerald);
  --expense-color:  var(--red);
  --balance-color:  var(--gold);

  /* Note/event color tokens — a closed six-color set shared by Notes and
     Calendar's time-blocked events, namespaced (--note-*) rather than
     reusing --emerald/--red/--sky/--amber, which already carry income/
     expense/danger meaning elsewhere in the app; reusing those directly
     here would be confusing. Read live via getComputedStyle() (see
     static/js/chart.js's cssVar() for the established pattern) rather
     than duplicated as hex literals in JS, so a color always renders
     correctly in whichever theme is active. */
  --note-sage-bg:     #eef3e6; --note-sage-border:  #cfdfbe; --note-sage-text:  #3f5c2b;
  --note-coral-bg:    #fbeae4; --note-coral-border: #f0c3b3; --note-coral-text: #a34527;
  --note-plum-bg:     #f3e8f4; --note-plum-border:  #ddc0e0; --note-plum-text:  #6b3d72;
  --note-slate-bg:    #ecedf3; --note-slate-border: #c9cfdd; --note-slate-text: #3d4a5c;
  --note-sky-bg:      #e7eefb; --note-sky-border:   #bcd2f0; --note-sky-text:   #2c5599;
  --note-amber-bg:    #fdf1dc; --note-amber-border: #f0d69f; --note-amber-text: #8a5f11;
}

/* Dark theme — toggled by theme.js adding .dark to <html> */
.dark {
  color-scheme: dark;

  --bg-page:        #12151e;
  --bg-surface:     #181d2a;
  --bg-card:        #1e2435;
  --bg-sidebar:     #0e1118;
  --bg-hover:       #242b3d;
  --border-subtle:  #252d40;
  --border-card:    rgba(255,255,255,0.06);
  --glass-bg:       rgba(30,36,53,0.7);

  --text-primary:   #f0ede8;
  --text-secondary: #8b95a8;
  --text-muted:     #4a5468;

  --gold:           #d4a843;
  --gold-dim:       rgba(212,168,67,0.15);
  --gold-glow:      0 0 24px rgba(212,168,67,0.18);

  --emerald:        #22c55e;
  --emerald-dim:    rgba(34,197,94,0.12);
  --sky:            #60a5fa;
  --red:            #ef4444;
  --red-dim:        rgba(239,68,68,0.12);
  --amber:          #f59e0b;
  --amber-dim:      rgba(245,158,11,0.12);

  --note-sage-bg:     #1f2a1a; --note-sage-border:  #3a4a2c; --note-sage-text:  #a3cf8a;
  --note-coral-bg:    #2c1e19; --note-coral-border: #4a3128; --note-coral-text: #e6a17e;
  --note-plum-bg:     #26202c; --note-plum-border:  #443a4c; --note-plum-text:  #d4a3d8;
  --note-slate-bg:    #1c212e; --note-slate-border: #313a4d; --note-slate-text: #b0b9cf;
  --note-sky-bg:      #182233; --note-sky-border:   #2c405c; --note-sky-text:   #93b8ec;
  --note-amber-bg:    #2b2213; --note-amber-border: #4a3c1f; --note-amber-text: #edc370;
}

/* =========================
    Global
   ========================= */

body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
}

h1, h2, h3, .stat-number {
  font-family: 'Fraunces', serif;
}

/* Glass card — the primary card style everywhere */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: 16px;
}

/* Section eyebrow labels */
.eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
}

/* Money figures */
.scenario-money {
  font-family: 'JetBrains Mono', monospace;
  /* A leading "-" on a negative value ("-$3,000.00") is a recognized
     soft break point in standard text line-breaking (the ASCII hyphen
     is a break-after character even without any whitespace around it),
     so on a narrow enough column the browser can legally wrap right
     after the sign, splitting it onto its own line above the amount.
     These are short, atomic values, never meant to wrap. */
  white-space: nowrap;
}

.money-positive { color: var(--emerald); }
.money-negative { color: var(--red); }
.money-gold     { color: var(--gold); font-family: 'JetBrains Mono', monospace; }

/* Verdict badges */
.badge-do-it  { background: var(--emerald-dim); color: var(--emerald); border: 1px solid rgba(34,197,94,0.3); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-wait   { background: rgba(245,158,11,0.12); color: var(--amber); border: 1px solid rgba(245,158,11,0.3); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-bad    { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.3); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }

/* Stat number style */
.stat-number {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.1;
  /* Same fix as .scenario-money above: a leading "-" on a negative
     stat (Net Balance going negative, etc.) is a legal line-break
     point on its own, so a narrow enough card can wrap right after
     the sign without this. */
  white-space: nowrap;
}

/* Buttons */
.btn-primary {
  background: var(--gold);
  color: #000;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-secondary:active { transform: scale(0.97); }

.btn-danger {
  color: var(--red);
  border-radius: 8px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-danger:hover { background: var(--red-dim); }
.btn-danger:active { transform: scale(0.97); }

/* Inputs */
.field-input {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 10px 14px;
}
.field-input::placeholder { color: var(--text-muted); }
.field-input:focus {
  outline: 2px solid rgba(212,168,67,0.45);
  outline-offset: 1px;
}

/* iOS Safari paints its own solid-black chrome behind a date/time
   input's value text regardless of the background we set on the
   element, which reads as a mismatched black pill next to the other
   form fields. -webkit-appearance:none stops it from doing that.
   text-align:inherit makes the value follow whatever alignment the
   input itself already has (left by default, or right/center where a
   specific form explicitly sets it) instead of Safari's forced center. */
input[type="date"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  text-align: inherit;
}

/* Same native-chrome mismatch as date/time inputs above, but for <select>:
   iOS Safari's default select chrome doesn't fully honor the custom
   background/color .field-input sets. -webkit-appearance:none removes it,
   which also removes the native dropdown arrow, so a CSS-drawn chevron
   replaces it — themed separately for light/dark since it's a background
   image, not a color a CSS variable can reach. */
select.field-input {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6478' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 11px;
  padding-right: 22px;
}
.dark select.field-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b95a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* Scenario list cards (sidebar) */
.scenario-list-card:hover {
  border-color: rgba(212,168,67,0.4) !important;
}
.scenario-list-card:active {
  transform: scale(0.98);
}

/* Scenario detail — card entrance motion */
@keyframes scenario-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.scenario-card-1 { animation: scenario-card-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both; }
.scenario-card-2 { animation: scenario-card-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) 0.06s both; }

/* Scenario detail — before/after net comparison bars */
.scenario-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-hover);
  overflow: hidden;
  margin-top: 8px;
}
@keyframes scenario-bar-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
.scenario-bar-fill {
  height: 100%;
  border-radius: 999px;
  transform-origin: left;
  animation: scenario-bar-fill 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
}

/* Scenario detail — income/expense mini icon dots */
.scenario-flow-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.scenario-flow-icon svg { width: 12px; height: 12px; }

/* Scenario detail — AI verdict hero icon badge */
.scenario-verdict-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.scenario-verdict-icon svg { width: 22px; height: 22px; }

/* Scenario detail — "projected" chip */
.scenario-chip-projected {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--gold-dim);
  color: var(--gold);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  font-size: 11px;
  font-weight: 500;
}
.scenario-chip-projected::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
}

/* Shared checkbox style, used anywhere a plain <input type="checkbox">
   appears outside its own bespoke widget (e.g. Notes' checklist rows
   already have their own). Native checkboxes render an unstyleable white
   fill in their unchecked state (accent-color only affects the checked
   fill), which reads jarring against a dark UI — appearance:none plus a
   hand-drawn checkmark fixes both states. */
.field-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-card);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.field-checkbox:hover { border-color: var(--gold); }
.field-checkbox:checked {
  background: var(--gold);
  border-color: var(--gold);
}
.field-checkbox:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #000;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.field-checkbox:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Scenario form — cost type tabs */
.cost-tab-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cost-tab-btn:hover {
  background: var(--bg-hover);
}
.cost-tab-btn.cost-tab-active {
  background: var(--gold);
  color: #000;
  border-color: var(--gold);
}

/* Finance page — month tab row */
.month-tab-pill {
  display: block;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.month-tab-pill:hover {
  background: var(--bg-hover);
}
.month-tab-pill.month-tab-active {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold);
}
.month-tab-row {
  scrollbar-width: none;
}
.month-tab-row::-webkit-scrollbar {
  display: none;
}

/* Recurring transaction toggle pill */
.tx-recurring-toggle {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tx-recurring-toggle:hover {
  background: var(--bg-card);
}
.tx-recurring-toggle.tx-recurring-on {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold);
}
.tx-recurring-toggle svg, .tx-recurring-toggle i { width: 14px; height: 14px; stroke-width: 2; }

/* Same pill, as a native checkbox+label for the new-transaction form
   (a plain POST, unlike the per-row toggle's AJAX button above) — the
   checkbox itself is invisibly stretched over the visual pill so the
   whole circle is clickable, not just its center. */
.tx-recurring-toggle-label {
  position: relative;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}
.tx-recurring-checkbox {
  position: absolute;
  inset: 0;
  width: 28px;
  height: 28px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.tx-recurring-toggle-visual {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tx-recurring-checkbox:checked + .tx-recurring-toggle-visual {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold);
}
.tx-recurring-toggle-visual svg, .tx-recurring-toggle-visual i { width: 14px; height: 14px; stroke-width: 2; }
.tx-recurring-checkbox:focus-visible + .tx-recurring-toggle-visual {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Navigation active state (sidebar) */
.nav-link {
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-active {
  background: rgba(212,168,67,0.08);
  border-left: 2px solid var(--gold);
  color: var(--text-primary);
}
.nav-active:hover {
  background: rgba(212,168,67,0.12);
}

/* =========================
    Finance
   ========================= */

.finance-tab {
    color: var(--text-primary);
}

.finance-tab form > * {
    min-width: 0;
}

.finance-income {
    color: var(--emerald) !important;
    font-family: 'JetBrains Mono', monospace;
}

.finance-expense {
    color: var(--red) !important;
    font-family: 'JetBrains Mono', monospace;
}

.finance-balance {
    color: var(--gold) !important;
    font-family: 'JetBrains Mono', monospace;
}

.finance-tab .tx-amount[data-type="income"] {
    color: var(--emerald) !important;
}

.finance-tab .tx-amount[data-type="expense"] {
    color: var(--red) !important;
}

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

.finance-tab input,
.finance-tab select,
.finance-tab textarea {
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.finance-tab input:focus,
.finance-tab select:focus,
.finance-tab textarea:focus,
.finance-tab .tx-desc:focus,
.finance-tab .tx-amount:focus {
    outline: 2px solid rgba(212,168,67,0.45);
    outline-offset: 2px;
}

/* Finance list behavior */
#tx-list {
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
    scroll-behavior: smooth;
}

#tx-list::-webkit-scrollbar { width: 8px; }
#tx-list::-webkit-scrollbar-track { background: transparent; }
#tx-list::-webkit-scrollbar-thumb {
    background: rgba(139, 149, 168, 0.35);
    border-radius: 9999px;
}
#tx-list::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 149, 168, 0.55);
}

/* AI chat scrollbar */
#ai-messages::-webkit-scrollbar { width: 8px; }
#ai-messages::-webkit-scrollbar-track { background: transparent; }
#ai-messages::-webkit-scrollbar-thumb {
    background: rgba(139, 149, 168, 0.35);
    border-radius: 9999px;
}
#ai-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 149, 168, 0.55);
}

/* Sidebar nav scrollbar */
.app-sidebar::-webkit-scrollbar { width: 6px; }
.app-sidebar::-webkit-scrollbar-track { background: transparent; }
.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(139, 149, 168, 0.25);
    border-radius: 9999px;
}

/* Transaction row polish */
.tx-row {
    transition:
        transform 0.15s ease,
        background-color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.tx-row:hover {
    transform: translateY(-1px);
    background-color: var(--bg-hover);
    border-color: rgba(212,168,67,0.35);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

.tx-desc,
.tx-amount {
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.tx-desc:focus,
.tx-amount:focus {
    background-color: var(--bg-hover);
}

/* Finance — stat card icon badges */
.finance-stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.finance-stat-icon svg { width: 16px; height: 16px; }

/* Finance — card entrance motion */
@keyframes finance-card-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.finance-card-in {
    animation: finance-card-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.finance-card-in:nth-of-type(1) { animation-delay: 0s; }
.finance-card-in:nth-of-type(2) { animation-delay: 0.04s; }
.finance-card-in:nth-of-type(3) { animation-delay: 0.08s; }
.finance-card-in:nth-of-type(4) { animation-delay: 0.12s; }

/* Dashboard — same card entrance motion, own class per this codebase's
   page-prefixed convention (see e.g. ai-widget-fade-in vs scenario-card-in) */
.dashboard-card-in {
    animation: finance-card-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dashboard-card-in:nth-of-type(1) { animation-delay: 0s; }
.dashboard-card-in:nth-of-type(2) { animation-delay: 0.04s; }
.dashboard-card-in:nth-of-type(3) { animation-delay: 0.08s; }
.dashboard-card-in:nth-of-type(4) { animation-delay: 0.12s; }

/* Finance — savings rate ring */
.finance-ring-wrap {
    position: relative;
    width: 88px;
    height: 88px;
    flex-shrink: 0;
}
.finance-ring-wrap svg { transform: rotate(-90deg); }
.finance-ring-track { fill: none; stroke: var(--bg-hover); stroke-width: 8; }
.finance-ring-fill {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
.finance-ring-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 17px;
}

/* Finance — small icon badge for the category/day summary rows */
.finance-mini-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gold-dim);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.finance-mini-icon svg { width: 14px; height: 14px; }

/* Finance — transaction row flow icon (income/expense). Both arrow SVGs
   always render; data-type (kept in sync with the row's type <select> by
   transactions.js) picks which one shows and the badge's color, so
   switching a row's type updates the icon without a page reload. */
.tx-flow-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tx-flow-icon svg { width: 13px; height: 13px; }
.tx-flow-icon-income, .tx-flow-icon-expense { display: none; }
.tx-flow-icon[data-type="income"] { background: var(--emerald-dim); color: var(--emerald); }
.tx-flow-icon[data-type="income"] .tx-flow-icon-income { display: block; }
.tx-flow-icon[data-type="expense"] { background: var(--red-dim); color: var(--red); }
.tx-flow-icon[data-type="expense"] .tx-flow-icon-expense { display: block; }

@media (prefers-reduced-motion: reduce) {
    .finance-card-in,
    .finance-ring-fill,
    .dashboard-card-in {
        animation: none !important;
        transition: none !important;
    }
}

/* =========================
    Calculator
   ========================= */

.calc-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px;
  font-size: 16px;
  font-family: 'JetBrains Mono', monospace;
  transition: background 0.15s ease;
}
.calc-btn:hover { background: var(--bg-hover); }

.calc-btn-equals {
  background: var(--gold);
  color: #000;
  font-weight: 600;
}
.calc-btn-equals:hover { filter: brightness(1.08); }

.calc-btn-clear {
  background: var(--red-dim);
  color: var(--red);
  border-color: rgba(239,68,68,0.3);
}
.calc-btn-clear:hover { background: rgba(239,68,68,0.2); }

/* =========================
    Auth
   ========================= */

.auth-bg {
    background:
        radial-gradient(900px 520px at 50% 18%, rgba(212, 168, 67, 0.16), rgba(0, 0, 0, 0)),
        radial-gradient(900px 520px at 50% 86%, rgba(34, 197, 94, 0.08), rgba(0, 0, 0, 0)),
        linear-gradient(180deg, #0e1118 0%, #0a0c12 100%);
}

.auth-card {
    background: rgba(30, 36, 53, 0.72);
    border: 1px solid var(--border-card);
    backdrop-filter: blur(10px);
}

.auth-input {
    background: rgba(14, 17, 24, 0.6);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.auth-input::placeholder {
    color: var(--text-muted);
}

.auth-input:focus {
    outline: 2px solid rgba(212, 168, 67, 0.6);
    outline-offset: 2px;
}

.auth-button {
    background: var(--gold);
    color: #000;
}

.auth-button:hover {
    filter: brightness(1.08);
}

.auth-link {
    color: var(--gold);
}

.auth-link:hover {
    text-decoration: underline;
}

/* =========================
    App shell responsiveness
   ========================= */

@media (prefers-reduced-motion: reduce) {
    .scenario-card-1,
    .scenario-card-2,
    .scenario-bar-fill {
        animation: none !important;
    }
}

/* Grid items default to min-width:auto, so a nowrap-truncated child (e.g.
   a note preview) can force its column wider than the grid track intends,
   pushing the whole row past the viewport. min-width:0 lets the track's
   own sizing win so text-overflow:ellipsis can actually kick in. */
.dashboard-row > * {
    min-width: 0;
}

@media (max-width: 767px) {
    .app-sidebar {
        display: none !important;
    }
    .app-main {
        margin-left: 0 !important;
    }
    .dashboard-row {
        grid-template-columns: 1fr !important;
    }
}

/* =========================
   Feedback widget — floating button + modal, available app-wide (wired
   in base.html so every logged-in page gets it without per-template work)
   ========================= */
.feedback-fab {
    position: fixed; right: 24px; bottom: 24px; z-index: 90;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--bg-surface); border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    cursor: pointer; transition: transform 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.dark .feedback-fab { box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.feedback-fab:hover { transform: translateY(-2px) scale(1.04); color: var(--gold); box-shadow: 0 10px 26px rgba(0,0,0,0.16); }
.dark .feedback-fab:hover { box-shadow: 0 10px 26px rgba(0,0,0,0.45); }

@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop-in {
    from { opacity: 0; transform: scale(0.96) translateY(6px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.feedback-modal-backdrop {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: rgba(10, 10, 14, 0.5);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    animation: modal-fade-in 0.15s ease-out;
}
.feedback-modal-backdrop[hidden] { display: none; }
.feedback-modal {
    width: 100%; max-width: 400px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 28px 26px 24px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.28), 0 4px 16px rgba(0,0,0,0.16);
    animation: modal-pop-in 0.18s cubic-bezier(0.16,1,0.3,1);
}
.dark .feedback-modal { box-shadow: 0 24px 64px rgba(0,0,0,0.5), 0 4px 16px rgba(0,0,0,0.3); }
.feedback-modal-title {
    font-family: 'Fraunces', serif; font-size: 21px; font-weight: 500;
    color: var(--text-primary); margin: 0 0 4px;
}
.feedback-modal-subtitle {
    font-size: 13px; color: var(--text-secondary); margin: 0 0 18px;
}
.feedback-modal-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.feedback-modal-tabs .cost-tab-btn { flex: 1; text-align: center; }
.feedback-modal textarea {
    width: 100%; box-sizing: border-box; min-height: 110px; resize: vertical;
    padding: 12px 14px; font-size: 14px; font-family: inherit; line-height: 1.5;
    border: 1px solid var(--border-subtle); border-radius: 12px;
    background: var(--bg-page); color: var(--text-primary);
}
.feedback-modal textarea::placeholder { color: var(--text-muted); }
.feedback-modal-error { color: var(--red); font-size: 12px; margin: 8px 0 0; display: none; }
.feedback-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.feedback-modal-cancel { background: none; border: none; color: var(--text-secondary); font-size: 13.5px; cursor: pointer; padding: 8px 14px; border-radius: 8px; }
.feedback-modal-cancel:hover { background: var(--bg-hover); }
.feedback-modal-submit { padding: 8px 20px; font-size: 13.5px; }

.global-search-backdrop {
    position: fixed; inset: 0; z-index: 210;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 12vh 24px 24px;
    background: rgba(10, 10, 14, 0.5);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    animation: modal-fade-in 0.15s ease-out;
}
.global-search-backdrop[hidden] { display: none; }
.global-search-modal {
    width: 100%; max-width: 560px; max-height: 70vh;
    display: flex; flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.28), 0 4px 16px rgba(0,0,0,0.16);
    animation: modal-pop-in 0.18s cubic-bezier(0.16,1,0.3,1);
    overflow: hidden;
}
.dark .global-search-modal { box-shadow: 0 24px 64px rgba(0,0,0,0.5), 0 4px 16px rgba(0,0,0,0.3); }
.global-search-input-row {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}
.global-search-input-row input {
    flex: 1; min-width: 0; border: none; background: none; outline: none;
    font-size: 15px; font-family: inherit; color: var(--text-primary);
}
.global-search-input-row input::placeholder { color: var(--text-muted); }
.global-search-esc-hint {
    font-size: 11px; color: var(--text-secondary);
    background: var(--bg-card); padding: 2px 6px; border-radius: 4px;
    flex-shrink: 0;
}
.global-search-results { overflow-y: auto; padding: 8px; }
.global-search-empty, .global-search-no-results {
    padding: 32px 16px; text-align: center;
    font-size: 13px; color: var(--text-secondary);
}
.global-search-group-label {
    font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--text-muted); padding: 10px 10px 4px;
}
.global-search-result {
    display: flex; flex-direction: column; gap: 2px;
    padding: 8px 10px; border-radius: 8px;
    text-decoration: none; cursor: pointer;
}
.global-search-result-title { font-size: 13.5px; color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-search-result-snippet { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-search-result.active { background: var(--gold-dim); }
.global-search-result.active .global-search-result-title { color: var(--gold); }
