/*
  Faithful Stays v2 — Design System
  app/static/css/app.css

  Token decisions:
  - Palette matches the Faithful Stays logo: silver/brushed-metallic grayscale.
    All three themes use cool silvers, soft charcoals, and near-black ink.
    No color accents, no pastels, no gradients, no shadows. (Std #8)
  - Single accent: silver-gray. Reserved for active-nav indicators and brand marks.
  - 3px border-radius. Rounds only enough to prevent the "box is a button" ambiguity
    without introducing pill shapes.
  - No drop shadows. Hierarchy via background tone + border only.
  - No gradients anywhere.
  - System font stack: Inter loaded via Google Fonts in base.html; falls back to
    -apple-system / system-ui.
*/

/* ─────────────────────────────────────────
   0. Reset & custom properties
───────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Theme: Dark (default data-theme="dark") ──
   Near-black surfaces, soft-white ink, silver accent.
   No gradients, no shadows, no pastels. (Std #8) */
:root,
:root[data-theme="dark"] {
  /* Backgrounds */
  --bg:          #0f0f0f;
  --surface:     #181818;
  --surface-2:   #222222;
  --surface-3:   #2a2a2a;

  /* Borders */
  --border:      #2e2e2e;
  --border-2:    #3a3a3a;

  /* Text */
  --text:        #e4e4e4;
  --text-2:      #a0a0a0;
  --text-3:      #666666;

  /* Accent — silver-gray; used sparingly */
  --accent:      #a0a0a8;
  --accent-dim:  #686870;

  /* Semantic status — muted, not pastel */
  --ok:          #1e3d2a;
  --ok-text:     #5aab7a;
  --warn:        #3a3018;
  --warn-text:   #b09050;
  --bad:         #3a1e1e;
  --bad-text:    #c86060;
  --neutral:     #303030;
  --neutral-text:#a0a0a0;

  /* Positive / negative deltas */
  --positive:    #5aab7a;
  --negative:    #c86060;
}

/* ── Theme: Light (data-theme="light") ──
   Very-light-gray surfaces, charcoal ink, silver-gray accent.
   Nav uses #eaeaea so the silver logo reads without a box. (Std #8) */
:root[data-theme="light"] {
  /* Backgrounds — slightly cooled so the silver logo reads on the nav */
  --bg:          #f0f0f2;
  --surface:     #f8f8f9;
  --surface-2:   #eaeaec;
  --surface-3:   #dededf;

  /* Borders */
  --border:      #d2d2d4;
  --border-2:    #c0c0c2;

  /* Text */
  --text:        #1a1a1c;
  --text-2:      #52525a;
  --text-3:      #909098;

  /* Accent — mid silver-gray; reads on light surfaces */
  --accent:      #606068;
  --accent-dim:  #404048;

  /* Semantic status — muted, not pastel */
  --ok:          #d8ece2;
  --ok-text:     #1e5c38;
  --warn:        #ede6d0;
  --warn-text:   #6a4800;
  --bad:         #edd8d8;
  --bad-text:    #7a1818;
  --neutral:     #e4e4e6;
  --neutral-text:#606068;

  /* Positive / negative deltas */
  --positive:    #1e6840;
  --negative:    #aa2020;
}

/* ── Theme: Night (data-theme="night") ──
   Warm off-black surfaces, warm off-white ink, silver accent.
   Easier on the eyes than dark; still silver-family, not a different hue.
   No gradients, no shadows, no pastels. (Std #8) */
:root[data-theme="night"] {
  /* Backgrounds — warm-shifted charcoals */
  --bg:          #18171a;
  --surface:     #201f22;
  --surface-2:   #2a292c;
  --surface-3:   #323135;

  /* Borders */
  --border:      #383638;
  --border-2:    #484650;

  /* Text — warm off-white, reduced contrast */
  --text:        #d8d6dc;
  --text-2:      #9a98a0;
  --text-3:      #666470;

  /* Accent — cool silver-gray; silver family, slightly warmer */
  --accent:      #9898a4;
  --accent-dim:  #686472;

  /* Semantic status — desaturated muted tones */
  --ok:          #1e2e26;
  --ok-text:     #70a888;
  --warn:        #2e2a1e;
  --warn-text:   #a08840;
  --bad:         #2e1e1e;
  --bad-text:    #b85858;
  --neutral:     #2a292c;
  --neutral-text:#9a98a0;

  /* Positive / negative deltas */
  --positive:    #70a888;
  --negative:    #b85858;
}

/* ── Shared invariants (type, spacing, radius, transitions) ── */
:root {
  /* Type */
  --font-sans:   "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:   "JetBrains Mono", "Fira Code", ui-monospace, monospace;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radius */
  --radius: 3px;
  --radius-2: 4px; /* absolute max */

  /* Transitions */
  --t: 120ms ease;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}


/* ─────────────────────────────────────────
   1. App Shell — top nav + layout
───────────────────────────────────────── */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Top nav — desktop only; hidden on mobile (bottom tabs take over) */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topnav__brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
  margin-right: var(--sp-2);
}

.topnav__logo {
  display: block;
  height: 30px;
  width: auto;
}

.topnav__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

/* ── 5-area nav list ── */
.topnav__areas {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  list-style: none;
  flex: 1;
}

.topnav__area-item {
  position: relative;
  list-style: none;
}

/* Shared style for area links and dropdown buttons */
.topnav__area-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 450;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--t), background var(--t);
  white-space: nowrap;
  height: 32px;
}

.topnav__area-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* Active state for the plain <a> Home link */
.topnav__area-link.is-active {
  color: var(--text);
  font-weight: 500;
}

/* Active group: dropdown button slightly brighter */
.topnav__area-item.is-active > .topnav__area-link {
  color: var(--text);
  font-weight: 500;
}

.topnav__caret {
  font-size: 0.5rem;
  opacity: 0.6;
  transition: transform var(--t);
}

.topnav__dropdown.is-open .topnav__caret {
  transform: rotate(180deg);
}

/* ── Dropdown panel ── */
.topnav__drop-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 200;
  min-width: 168px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--sp-1) 0;
}

.topnav__dropdown.is-open .topnav__drop-menu {
  display: block;
}

.topnav__drop-menu li a {
  display: block;
  padding: var(--sp-2) var(--sp-4);
  font-size: 0.8125rem;
  color: var(--text-2);
  white-space: nowrap;
  transition: color var(--t), background var(--t);
}

.topnav__drop-menu li a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.topnav__drop-menu li a.active {
  color: var(--text);
  font-weight: 500;
}

/* ── Hide top nav on mobile; bottom tabs take over ── */
@media (max-width: 640px) {
  .topnav {
    display: none;
  }
}

/* ── Dashboard two-column row: single column on mobile ── */
@media (max-width: 640px) {
  .dashboard-two-col {
    grid-template-columns: 1fr !important;
  }
}

/* ─────────────────────────────────────────
   1b. Mobile bottom tab bar
───────────────────────────────────────── */

.bottom-tabs {
  display: none; /* shown only on mobile */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 110;
  height: 56px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-direction: row;
  align-items: stretch;
}

@media (max-width: 640px) {
  .bottom-tabs {
    display: flex;
  }

  /* Push page content above the tab bar (incl. iOS safe-area inset) */
  .shell {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
}

.bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-3);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color var(--t);
  padding-bottom: 0; /* safe-area inset now handled on .bottom-tabs itself */
}

.bottom-tab:hover,
.bottom-tab.is-active {
  color: var(--text);
}

.bottom-tab__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.bottom-tab__label {
  line-height: 1;
}

/* ─────────────────────────────────────────
   1c. Floating assistant chat widget
───────────────────────────────────────── */

.chat-trigger {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  right: var(--sp-5);
  z-index: 120;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t);
}

.chat-trigger:hover {
  background: var(--text-2);
}

.chat-trigger svg {
  width: 20px;
  height: 20px;
}

/* On desktop, place above footer zone */
@media (min-width: 641px) {
  .chat-trigger {
    bottom: var(--sp-8);
    right: var(--sp-8);
  }
}

/* Chat panel */
.chat-panel {
  position: fixed;
  z-index: 130;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;

  /* Hidden by default */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 160ms ease;
}

.chat-panel.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* Desktop: compact panel bottom-right */
@media (min-width: 641px) {
  .chat-panel {
    bottom: calc(var(--sp-8) + 52px);
    right: var(--sp-8);
    width: 340px;
    height: 440px;
    border-radius: var(--radius-2);
  }
}

/* Mobile: full-width sheet rising from bottom */
@media (max-width: 640px) {
  .chat-panel {
    bottom: 56px;
    left: 0;
    right: 0;
    height: 60vh;
    border-top-left-radius: var(--radius-2);
    border-top-right-radius: var(--radius-2);
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
}

.chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.chat-panel__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  border-radius: var(--radius);
  transition: color var(--t), background var(--t);
}

.chat-panel__close:hover {
  color: var(--text);
  background: var(--surface-2);
}

.chat-panel__close svg {
  width: 14px;
  height: 14px;
}

.chat-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.chat-msg {
  max-width: 90%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-2);
  font-size: 0.8125rem;
  line-height: 1.55;
}

.chat-msg--assistant {
  background: var(--surface-2);
  color: var(--text);
  align-self: flex-start;
}

.chat-msg--user {
  background: var(--text);
  color: var(--bg);
  align-self: flex-end;
}

.chat-msg--loading {
  background: var(--surface-2);
  color: var(--text-3);
  align-self: flex-start;
  font-style: italic;
}

.chat-panel__form {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-panel__input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--t);
}

.chat-panel__input:focus {
  border-color: var(--text-3);
}

.chat-panel__send {
  flex-shrink: 0;
}

/* Content area */
.page-wrap {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
}

/* Footer */
.footer {
  position: relative;
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* "Powered by Ophanim AI" — centered, quiet (now the only footer item) */
.footer__ophanim {
  font-size: 0.6875rem;
  color: var(--text-3);
  letter-spacing: 0.02em;
  white-space: nowrap;
}


/* ─────────────────────────────────────────
   2. Page head (title + subtitle + actions)
───────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.page-head__copy {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.page-head__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.page-head__subtitle {
  font-size: 0.8125rem;
  color: var(--text-2);
}

.page-head__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}


/* ─────────────────────────────────────────
   3. Section divider
───────────────────────────────────────── */

.section-divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-8) 0 var(--sp-6);
}

.section-divider__label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}

.section-divider::before,
.section-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.section-divider--no-label::after {
  display: none;
}


/* ─────────────────────────────────────────
   4. Card
───────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--sp-5);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.card__title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.card__body {
  padding: var(--sp-5);
}


/* ─────────────────────────────────────────
   5. KPI tiles
───────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.kpi-tile__label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
}

.kpi-tile__value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.1;
}

.kpi-tile__trend {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
}

.kpi-tile__trend--up   { color: var(--positive); }
.kpi-tile__trend--down { color: var(--negative); }

.kpi-tile__trend-arrow {
  font-size: 0.625rem;
  line-height: 1;
}


/* ─────────────────────────────────────────
   6. Table
───────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table thead {
  background: var(--surface-2);
}

.data-table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

/* Sortable header affordance */
.data-table th.sortable {
  cursor: pointer;
}

.data-table th.sortable:hover {
  color: var(--text-2);
  background: var(--surface-3);
}

.data-table th .sort-indicator {
  display: inline-block;
  margin-left: var(--sp-1);
  opacity: 0.4;
  font-size: 0.5625rem;
  vertical-align: middle;
}

.data-table th.sort-asc  .sort-indicator,
.data-table th.sort-desc .sort-indicator {
  opacity: 1;
  color: var(--accent);
}

.data-table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover > td {
  background: var(--surface-2);
}

/* Numeric cells — right-aligned, mono */
.data-table td.num,
.data-table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}


/* ─────────────────────────────────────────
   7. Expandable row (parent + child lines)

   Pattern: the parent <tr> carries data-expandable and a toggle button.
   Clicking it toggles aria-expanded and shows/hides child <tr>s that
   carry data-child-of="<parent-id>". Pure JS; no library.
───────────────────────────────────────── */

.data-table tr[data-expandable] td:first-child {
  padding-left: var(--sp-3);
}

.expand-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: var(--sp-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: none;
  color: var(--text-3);
  font-size: 0.5rem;
  cursor: pointer;
  vertical-align: middle;
  transition: color var(--t), border-color var(--t);
  flex-shrink: 0;
}

.expand-toggle:hover {
  color: var(--text);
  border-color: var(--text-3);
}

/* Arrow rotates when open */
.expand-toggle .toggle-arrow {
  display: inline-block;
  transition: transform var(--t);
  font-size: 0.5625rem;
}

tr[data-expandable][aria-expanded="true"] .toggle-arrow {
  transform: rotate(90deg);
}

/* Child rows */
.data-table tr.child-row {
  display: none;
  background: var(--surface-2);
}

.data-table tr.child-row.visible {
  display: table-row;
}

.data-table tr.child-row td {
  border-bottom: 1px solid var(--border);
  padding-left: var(--sp-10); /* indent to show hierarchy */
  font-size: 0.75rem;
  color: var(--text-2);
}

.data-table tr.child-row:last-of-type td {
  border-bottom: 2px solid var(--border-2);
}


/* ─────────────────────────────────────────
   8. Spend-by-category bar chart (CSS-only)
───────────────────────────────────────── */

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.bar-chart__row {
  display: grid;
  grid-template-columns: 140px 1fr 72px;
  align-items: center;
  gap: var(--sp-3);
}

.bar-chart__label {
  font-size: 0.75rem;
  color: var(--text-2);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-chart__track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}

.bar-chart__fill {
  height: 100%;
  background: var(--text-3);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Largest bar (first) gets slightly brighter */
.bar-chart__row:first-child .bar-chart__fill {
  background: var(--text-2);
}

.bar-chart__value {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-2);
  text-align: right;
  white-space: nowrap;
}


/* ─────────────────────────────────────────
   9. Cash-flow chart container
───────────────────────────────────────── */

.chart-shell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  overflow: hidden;
}

.chart-shell__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.chart-shell__title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.chart-shell__meta {
  font-size: 0.75rem;
  color: var(--text-3);
}

.chart-shell__body {
  padding: var(--sp-4) var(--sp-5) var(--sp-5);
}

/* Sample data watermark */
.chart-shell__sample-badge {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  padding: 2px var(--sp-2);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  pointer-events: none;
}

/* SVG chart defaults */
.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Legend */
.chart-legend {
  display: flex;
  gap: var(--sp-5);
  margin-top: var(--sp-3);
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 0.6875rem;
  color: var(--text-3);
}

.chart-legend__swatch {
  width: 16px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}


/* ─────────────────────────────────────────
   10. Buttons
───────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  height: 32px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t), color var(--t), border-color var(--t);
  text-decoration: none;
  border: 1px solid transparent;
}

/* Default (secondary) */
.btn--default {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border-2);
}

.btn--default:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-2);
}

/* Primary */
.btn--primary {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.btn--primary:hover {
  background: var(--text-2);
}

/* Destructive */
.btn--destructive {
  background: var(--bad);
  color: var(--bad-text);
  border-color: transparent;
}

.btn--destructive:hover {
  background: #8a3030;
}

/* Small variant */
.btn--sm {
  height: 26px;
  padding: 0 var(--sp-3);
  font-size: 0.75rem;
}

/* Disabled */
.btn[disabled],
.btn--disabled {
  opacity: 0.38;
  pointer-events: none;
}


/* ─────────────────────────────────────────
   11. Form fields
───────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.field__label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.field__input,
.field__select,
.field__textarea {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text);
  width: 100%;
  transition: border-color var(--t);
  outline: none;
  appearance: none;
}

.field__input:focus,
.field__select:focus,
.field__textarea:focus {
  border-color: var(--text-3);
}

.field__hint {
  font-size: 0.6875rem;
  color: var(--text-3);
}

.field__error {
  font-size: 0.6875rem;
  color: var(--bad-text);
}

.field__select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}


/* ─────────────────────────────────────────
   12. Pills / status badges
───────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--radius);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge--neutral {
  background: var(--neutral);
  color: var(--neutral-text);
}

.badge--ok {
  background: var(--ok);
  color: var(--ok-text);
}

.badge--warn {
  background: var(--warn);
  color: var(--warn-text);
}

.badge--bad {
  background: var(--bad);
  color: var(--bad-text);
}


/* ─────────────────────────────────────────
   13. Inline utilities
───────────────────────────────────────── */

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-2); }
.dimmed { color: var(--text-3); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.accent-text { color: var(--accent); }

/* Full margin-utility scale. Templates historically used mb-3 / mb-5 / mt-3 /
   mt-5 etc. which were NEVER defined — so those classes rendered as ZERO margin
   and sections collided (spacing looked fine at the top of a page where mb-8 was
   used, then fell apart toward the bottom where the dead classes were). Defining
   the whole scale means no spacing class is ever silently inert again. */
.mt-1  { margin-top: var(--sp-1); }
.mt-2  { margin-top: var(--sp-2); }
.mt-3  { margin-top: var(--sp-3); }
.mt-4  { margin-top: var(--sp-4); }
.mt-5  { margin-top: var(--sp-5); }
.mt-6  { margin-top: var(--sp-6); }
.mt-8  { margin-top: var(--sp-8); }
.mb-1  { margin-bottom: var(--sp-1); }
.mb-2  { margin-bottom: var(--sp-2); }
.mb-3  { margin-bottom: var(--sp-3); }
.mb-4  { margin-bottom: var(--sp-4); }
.mb-5  { margin-bottom: var(--sp-5); }
.mb-6  { margin-bottom: var(--sp-6); }
.mb-8  { margin-bottom: var(--sp-8); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
