/* ============================================================
   Mirrion Finance — Brand Tokens + Base Styles
   Mobile-first. Finance vertical: Deep Violet / Electric Blue.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  /* Core palette */
  --m-blue:        #5a7fff;
  --m-violet:      #9b7dfa;
  --m-teal:        #2ecfb5;
  --m-deep-violet: #7050d8;

  /* Finance vertical */
  --f-primary:     #7050d8;
  --f-secondary:   #5a7fff;
  --f-glow:        rgba(112, 80, 216, 0.12);

  /* Surfaces */
  --m-bg:          #06060e;
  --m-surface:     #0c0c1a;
  --m-card:        #0f0f1e;
  --m-border:      #22223a;  /* was #161626 — lifted for visibility */
  --m-border-mid:  #2c2c48;  /* was #1e1e32 — lifted for visibility */

  /* Text */
  --m-text:        #c8c8e0;
  --m-text-dim:    #7878a0;  /* was #505070 ~2.5:1 — now ~4.7:1 WCAG AA */
  --m-text-muted:  #3a3a58;  /* was #2a2a44 — lifted slightly */
  --m-white:       #eeeeff;

  /* Status */
  --s-positive:    #2ecfb5;
  --s-warning:     #d4940a;
  --s-negative:    #e06040;

  /* Typography */
  --m-font:        'Outfit', sans-serif;
  --m-mono:        'DM Mono', monospace;

  /* Type scale — mobile base */
  --text-xs:       0.75rem;
  --text-sm:       0.875rem;
  --text-base:     1rem;
  --text-lg:       1.125rem;
  --text-xl:       1.25rem;
  --text-2xl:      1.5rem;
  --text-3xl:      1.875rem;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-12: 3rem;

  /* Nav */
  --nav-height:      56px;
  --top-bar-height:  52px;
  --safe-bottom:     env(safe-area-inset-bottom, 0px);
  --safe-top:        env(safe-area-inset-top, 0px);
}

@media (min-width: 768px) {
  :root {
    --text-3xl: 2.25rem;
  }
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--m-font);
  font-size: var(--text-base);
  color: var(--m-text);
  background: var(--m-bg);
  min-height: 100dvh;
  /* Reserve space for fixed top bar + bottom nav */
  padding-top: calc(var(--top-bar-height) + var(--safe-top));
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

@media (min-width: 768px) {
  body {
    padding-bottom: 0;
  }
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

input, button, select, textarea {
  font-family: inherit;
  font-size: var(--text-base); /* >= 16px prevents iOS zoom */
}

/* ── Utilities ───────────────────────────────────────────── */
.mono       { font-family: var(--m-mono); }
.text-right { text-align: right; }
.text-dim   { color: var(--m-text-dim); }
.text-muted { color: var(--m-text-muted); }
.text-pos   { color: var(--s-positive); }
.text-neg   { color: var(--s-negative); }
.text-warn  { color: var(--s-warning); }
.text-primary { color: var(--f-primary); }

.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;
}

/* ── Layout ──────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.page {
  padding: var(--space-6) var(--space-4);
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--m-card);
  border: 1px solid var(--m-border);
  border-radius: 12px;
  padding: var(--space-4);
}

.card--glow {
  border-color: var(--f-primary);
  box-shadow: 0 0 0 1px var(--f-glow), 0 4px 24px var(--f-glow);
}

/* ── Bottom Tab Bar (mobile) ─────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--m-surface);
  border-top: 1px solid var(--m-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  z-index: 100;
}

@media (min-width: 768px) {
  .bottom-nav { display: none; }
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  color: var(--m-text-dim);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.bottom-nav__item.active,
.bottom-nav__item:hover {
  color: var(--f-primary);
}

.bottom-nav__icon {
  width: 22px;
  height: 22px;
}

/* Hide Alpine x-show elements before Alpine initialises */
[x-cloak] { display: none !important; }

/* ── Top header bar ──────────────────────────────────────── */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--top-bar-height) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: var(--space-4);
  padding-right: var(--space-3);
  background: var(--m-surface);
  border-bottom: 1px solid var(--m-border);
  display: flex;
  align-items: center;
  /* No justify-content here — logo flex:1 + actions margin-left:auto handle alignment */
  z-index: 101;
}

.top-bar__logo {
  font-weight: 300;
  font-size: var(--text-base);
  color: var(--m-white);
  white-space: nowrap;
  flex: 1;
}
.top-bar__logo strong {
  font-weight: 700;
  color: var(--f-primary);
}

.top-bar__actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;        /* never wrap onto a second line */
  gap: var(--space-1);
  margin-left: auto;        /* pushes to far right when logo is hidden on desktop */
}

.top-bar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--m-text-dim);
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  text-decoration: none;
  flex-shrink: 0;
}
.top-bar__btn:hover {
  color: var(--m-white);
  background: rgba(255,255,255,0.06);
}
.top-bar__btn--active { color: var(--f-primary); }

.notif-badge {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--s-negative);
  border: 2px solid var(--m-surface);
}

/* Notification dropdown */
.notif-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  background: var(--m-card);
  border: 1px solid var(--m-border-mid);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
}
.notif-dropdown__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--m-border);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--m-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.notif-dropdown__empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--m-text-dim);
}

[data-theme="light"] .top-bar {
  background: #ffffff;
  border-color: var(--m-border);
}
[data-theme="light"] .top-bar__btn:hover {
  background: rgba(0,0,0,0.05);
}
[data-theme="light"] .notif-dropdown {
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

/* ── Sidebar Nav (desktop) — removed ────────────────────── */
.sidebar { display: none !important; }

.sidebar__logo {
  font-weight: 300;
  font-size: var(--text-lg);
  color: var(--m-white);
  margin-bottom: var(--space-8);
  letter-spacing: -0.01em;
}

.sidebar__logo strong {
  font-weight: 600;
  color: var(--f-primary);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}

.sidebar__footer {
  padding-top: var(--space-4);
  border-top: 1px solid var(--m-border);
}

.sidebar__footer form {
  margin: 0;
  padding: 0;
}

.sidebar__email {
  display: block;
  font-size: var(--text-xs);
  color: var(--m-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: var(--space-2);
}

.sidebar__logout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  background: none;
  border: none;
  font-size: var(--text-xs);
  font-family: var(--m-font);
  font-weight: 500;
  color: var(--m-text-dim);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.sidebar__logout:hover {
  background: var(--f-glow);
  color: var(--m-text);
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  color: var(--m-text-dim);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar__item:hover,
.sidebar__item.active {
  background: var(--f-glow);
  color: var(--m-white);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-6);
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn--primary {
  background: var(--f-primary);
  color: #fff;
}

.btn--primary:hover { opacity: 0.88; }

.btn--ghost {
  background: transparent;
  border: 1px solid var(--m-border-mid);
  color: var(--m-text);
}

.btn--ghost:hover { border-color: var(--f-primary); color: var(--f-primary); }

/* ── Forms ───────────────────────────────────────────────── */
.input {
  width: 100%;
  background: var(--m-surface);
  border: 1px solid var(--m-border-mid);
  border-radius: 8px;
  padding: var(--space-3) var(--space-4);
  color: var(--m-white);
  font-size: var(--text-base);
  transition: border-color 0.15s;
  outline: none;
}

.input:focus { border-color: var(--f-primary); }
.input::placeholder { color: var(--m-text-muted); }

/* ── Currency values ─────────────────────────────────────── */
.amount {
  font-family: var(--m-mono);
  font-size: var(--text-xl);
  font-weight: 500;
  text-align: right;
  color: var(--m-white);
}

.amount--large {
  font-size: var(--text-2xl);
}

.amount--pos { color: var(--s-positive); }
.amount--neg { color: var(--s-negative); }

/* ── Transaction rows ────────────────────────────────────── */
.tx-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-2);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--m-border);
}

.tx-row__info { overflow: hidden; }
.tx-row__merchant {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--m-white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-row__meta {
  font-size: var(--text-xs);
  color: var(--m-text-dim);
  margin-top: var(--space-1);
}
.tx-row__amount {
  font-family: var(--m-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

/* ── Loading indicator (HTMX) ───────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }
.htmx-request.htmx-indicator { display: block; }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--m-border-mid);
  border-top-color: var(--f-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-4);
  gap: var(--space-4);
  color: var(--m-text-dim);
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--m-text);
}

/* ── Section header ──────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--m-text-dim);
}

/* Insight list rows — flex kept in CSS so Alpine x-show doesn't drop display:flex */
.insight-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

/* ── Workbench ───────────────────────────────────────────── */

/* Full-width category filter strip — scrollable, sorted by spend */
.wb-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-top: 1px solid var(--m-border);
  background: var(--m-bg);
  flex-shrink: 0;
}
.wb-filter::-webkit-scrollbar { display: none; }

/* Static "Filter" label that anchors the filter strip — stays visible
   when the pills overflow horizontally. */
.wb-filter__label {
  position: sticky;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 0 10px 0 0;
  margin-right: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--m-text-dim);
  background: var(--m-bg);
  border-right: 1px solid var(--m-border);
  white-space: nowrap;
  z-index: 1;
}

/* Compact pill — ~30% smaller than .chip */
.wb-pill {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--m-font);
  cursor: pointer;
  border: 1px solid var(--chip-bdr, var(--m-border-mid));
  background: var(--chip-bg, var(--m-surface));
  color: var(--chip-txt, var(--m-text-dim));
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  letter-spacing: 0.01em;
}
.wb-pill:hover { opacity: 0.82; }
.wb-pill--on {
  background: var(--chip-bg);
  border-color: var(--chip-bdr);
  color: var(--chip-txt);
  font-weight: 700;
}

/* Mobile-only tab switcher */
.wb-tabs {
  display: flex;
  border-bottom: 1px solid var(--m-border);
  background: var(--m-surface);
}
.wb-tab {
  flex: 1;
  padding: var(--space-3);
  background: none;
  border: none;
  font-size: var(--text-sm);
  font-family: var(--m-font);
  font-weight: 500;
  color: var(--m-text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.wb-tab--active {
  color: var(--f-primary);
  border-bottom-color: var(--f-primary);
}

/* Two-pane container */
.wb {
  display: flex;
  overflow: hidden;
  height: calc(100dvh - 155px); /* mobile: below top-bar + tabs + filter strip */
}

/* Pane wrapper */
.wb__pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.wb__pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  height: 44px;
  border-bottom: 1px solid var(--m-border);
  background: var(--m-surface);
  flex-shrink: 0;
  box-sizing: border-box;
}
.wb__pane-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--m-white);
}
.wb__toggle {
  background: none;
  border: 1px solid var(--m-border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--m-text-dim);
  transition: border-color 0.15s, color 0.15s;
}
.wb__toggle:hover {
  border-color: var(--f-primary);
  color: var(--f-primary);
}
.wb__divider {
  width: 1px;
  background: var(--m-border);
  flex-shrink: 0;
}

/* Expand/collapse via data-view attribute */
.wb[data-view="left"]  .wb__pane--right { display: none; }
.wb[data-view="right"] .wb__pane--left  { display: none; }
.wb[data-view="left"]  .wb__divider     { display: none; }
.wb[data-view="right"] .wb__divider     { display: none; }

/* Mobile: show one pane at a time, hide toggle buttons */
@media (max-width: 767px) {
  .wb-tabs { display: flex; }
  .wb {
    height: calc(100dvh - 120px);
  }
  .wb__pane--right { display: none; }
  .wb__divider     { display: none; }
  .wb__toggle      { display: none; }
}

/* Desktop: side-by-side panes, hide tab bar */
@media (min-width: 768px) {
  .wb-tabs { display: none; }
  .wb {
    height: calc(100dvh - 91px); /* top-bar 56px + filter strip ~35px */
  }
  .wb__pane--right { display: flex; }
  .wb__toggle      { display: flex; }
}

/* ── IDE — wrapper + three-pane layout ──────────────────── */
.ide-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--top-bar-height) - var(--safe-top));
}
.ide {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0; /* allow flex child to shrink below content size */
}

.ide__pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  transition: flex-basis 0.22s ease, flex-grow 0.22s ease, min-width 0.22s ease, max-width 0.22s ease;
}
.ide__pane--txn     { flex: 1; }
.ide__pane--queries { flex: 1; position: relative; }
.ide__pane--chat    { flex: 2; }

/* ── Desktop: collapsed pane = 44px rail with rotated label ── */
@media (min-width: 768px) {
  .ide__pane--collapsed {
    flex: 0 0 44px !important;
    min-width: 44px;
    max-width: 44px;
    cursor: pointer;
    background: var(--m-surface);
  }
  .ide__pane--collapsed:hover {
    background: rgba(112,80,216,0.06);
  }
  .ide__pane--collapsed .wb__pane-header {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    height: auto;
    padding: var(--space-3) 0;
    gap: var(--space-3);
    border-bottom: none;
    background: transparent;
  }
  .ide__pane--collapsed .wb__pane-title {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--m-text);
    white-space: nowrap;
    -webkit-background-clip: border-box !important;
    -webkit-text-fill-color: currentColor !important;
    background: none !important;
  }
  .ide__pane--collapsed .ide-pane-body,
  .ide__pane--collapsed .ide-when-expanded { display: none !important; }
}

.ide-collapse-btn {
  background: var(--m-surface);
  border: 1px solid var(--m-border-mid);
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  color: var(--f-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s, transform 0.2s, border-color 0.15s;
  flex-shrink: 0;
  padding: 0;
}
.ide-collapse-btn:hover {
  background: rgba(112,80,216,0.12);
  border-color: var(--f-primary);
  color: var(--m-white);
}
.ide__pane--collapsed .ide-collapse-btn { transform: rotate(180deg); }

/* Mobile: collapse is a no-op (tab bar handles single-pane) */
@media (max-width: 767px) {
  .ide-collapse-btn { display: none; }
}

.ide__divider {
  width: 1px;
  background: var(--m-border);
  flex-shrink: 0;
}

/* Query card in the middle pane */
.ide-query-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  border-radius: 12px;
  padding: var(--space-3) var(--space-4);
  padding-left: calc(var(--space-4) + 3px);
  margin-bottom: var(--space-2);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 0.18s, background 0.18s, transform 0.12s;
  font-family: var(--m-font);
}
.ide-query-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--f-primary), var(--f-secondary));
  border-radius: 3px 0 0 3px;
  opacity: 0.5;
  transition: opacity 0.18s;
}
.ide-query-card:hover {
  border-color: rgba(112,80,216,0.45);
  background: rgba(112,80,216,0.07);
  transform: translateX(1px);
}
.ide-query-card:hover::before {
  opacity: 1;
}
.ide-query-card.htmx-request {
  border-color: var(--f-primary);
  opacity: 0.65;
}
.ide-query-card__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--m-white);
  line-height: 1.3;
}
.ide-query-card__desc {
  font-size: 11px;
  color: var(--m-text-dim);
  line-height: 1.4;
}
.ide-query-card--user {
  border-color: rgba(90,127,255,0.2);
  cursor: default;
}
.ide-query-card--user::before {
  background: linear-gradient(180deg, var(--f-secondary), #22d3ee);
}
.ide-query-card--user > div:first-child {
  cursor: pointer;
}

/* Mobile: show one pane at a time */
@media (max-width: 767px) {
  .ide {
    height: calc(100dvh - 155px);
  }
  .ide__pane--txn  { display: none; }
  .ide__pane--chat { display: none; }
  .ide__divider    { display: none; }
}

/* Desktop */
@media (min-width: 768px) {
  .ide {
    height: calc(100dvh - 91px);
  }
  .ide__pane--txn,
  .ide__pane--chat { display: flex; }
  .ide__divider    { display: block; }
}

/* ── Period pill selector ────────────────────────────────── */
.period-pills {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.period-pills::-webkit-scrollbar { display: none; }

.period-pill {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--m-text-dim);
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.period-pill:hover {
  color: var(--m-text);
  border-color: var(--f-primary);
}
.period-pill--active {
  background: var(--f-primary);
  color: #fff;
  border-color: var(--f-primary);
}

/* ── Stat card ───────────────────────────────────────────── */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.stat-card__label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--m-text-dim);
}
.stat-card__value {
  font-family: var(--m-mono);
  font-size: var(--text-2xl);
  font-weight: 500;
  color: var(--m-white);
  line-height: 1.1;
}
.stat-card__sub {
  font-size: var(--text-xs);
  color: var(--m-text-dim);
  margin-top: 2px;
}

/* ── Category bars ───────────────────────────────────────── */
.cat-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}
.cat-bar__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.cat-bar__name {
  font-size: var(--text-sm);
  color: var(--m-text);
  font-weight: 500;
}
.cat-bar__amount {
  font-family: var(--m-mono);
  font-size: var(--text-sm);
  color: var(--m-white);
  font-weight: 500;
}
.cat-bar__track {
  height: 4px;
  background: var(--m-border-mid);
  border-radius: 2px;
  overflow: hidden;
}
.cat-bar__fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--f-primary), var(--f-secondary));
}

/* ── Monthly strip ───────────────────────────────────────── */
.month-strip {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}
.month-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}
.month-bar__fill {
  width: 100%;
  background: var(--m-border-mid);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
  transition: background 0.2s;
}
.month-bar--current .month-bar__fill {
  background: linear-gradient(180deg, var(--f-secondary), var(--f-primary));
}
.month-bar__label {
  font-size: var(--text-xs);
  color: var(--m-text-dim);
  text-align: center;
}
.month-bar__amount {
  font-family: var(--m-mono);
  font-size: 0.65rem;
  color: var(--m-text-dim);
  text-align: center;
}

/* ── Banners ─────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.banner--warn {
  background: rgba(212, 148, 10, 0.12);
  border: 1px solid rgba(212, 148, 10, 0.3);
  color: var(--s-warning);
}

/* ── Category filter chips ───────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--m-font);
  cursor: pointer;
  border: 1px solid var(--chip-bdr, var(--m-border-mid));
  background: var(--chip-bg, var(--m-surface));
  color: var(--chip-txt, var(--m-text-dim));
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  letter-spacing: 0.01em;
}

.chip:hover { opacity: 0.82; }

.chip--on {
  background: var(--chip-bg);
  border-color: var(--chip-bdr);
  color: var(--chip-txt);
  font-weight: 700;
}

/* ── Markdown rendered content ───────────────────────────── */
.md-content                { line-height: 1.55; }
.md-content > :first-child { margin-top: 0; }
.md-content > :last-child  { margin-bottom: 0; }
.md-content p              { margin: 0 0 var(--space-2); }
.md-content p:last-child   { margin-bottom: 0; }
.md-content ul, .md-content ol {
  margin: 4px 0 var(--space-2);
  padding-left: 20px;
}
.md-content ul             { list-style-type: disc; }
.md-content ol             { list-style-type: decimal; }
.md-content li             { margin-bottom: 4px; }
.md-content li:last-child  { margin-bottom: 0; }
/* Demote large headings: the prompt forbids H1/H2 but render defensively. */
.md-content h1, .md-content h2 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--m-white);
  margin: var(--space-2) 0 2px;
}
.md-content h3, .md-content h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--m-white);
  margin: var(--space-2) 0 2px;
}
.md-content code {
  font-family: var(--m-mono);
  font-size: 0.92em;
  background: rgba(112,80,216,0.14);
  border: 1px solid rgba(112,80,216,0.22);
  border-radius: 4px;
  padding: 1px 6px;
}
.md-content pre {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--m-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  overflow-x: auto;
  margin: var(--space-2) 0;
}
.md-content pre code { background: none; padding: 0; }
.md-content strong { color: var(--m-white); font-weight: 600; }
.md-content blockquote {
  border-left: 3px solid var(--f-primary);
  margin: var(--space-2) 0;
  padding-left: var(--space-3);
  color: var(--m-text-dim);
}
.md-content hr {
  border: none;
  border-top: 1px solid var(--m-border);
  margin: var(--space-3) 0;
}

/* ── Chat message delete hover ───────────────────────────── */
.chat-msg-wrap {
  position: relative;
}
.chat-delete-btn {
  position: absolute;
  top: 0;
  right: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--m-surface);
  border: 1px solid var(--m-border-mid);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  color: var(--m-text-dim);
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  z-index: 2;
}
.chat-msg-wrap:hover .chat-delete-btn {
  opacity: 1;
  pointer-events: auto;
}
.chat-delete-btn:hover {
  color: #e06040;
  border-color: rgba(224,96,64,0.4);
}

/* Clear all button */
/* Blue pill — used for non-destructive pane actions like Rules */
.pane-pill-btn {
  background: rgba(90,127,255,0.08);
  border: 1px solid rgba(90,127,255,0.25);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--m-font);
  color: rgba(90,127,255,0.85);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}
.pane-pill-btn:hover {
  background: rgba(90,127,255,0.18);
  border-color: rgba(90,127,255,0.55);
  color: var(--f-secondary);
}

.chat-clear-btn {
  background: rgba(224,96,64,0.08);
  border: 1px solid rgba(224,96,64,0.22);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--m-font);
  color: rgba(224,96,64,0.75);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}
.chat-clear-btn:hover {
  background: rgba(224,96,64,0.16);
  border-color: rgba(224,96,64,0.55);
  color: #e06040;
}

/* ── Chat answer action buttons (copy / save) ───────────── */
.chat-answer-wrap {
  position: relative;
  max-width: 92%;
  padding-bottom: 28px;
}
.chat-answer-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-left: 2px;
}
.chat-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: transparent;
  border: 1px solid var(--m-border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 500;
  font-family: var(--m-font);
  color: var(--m-text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chat-action-btn:hover {
  border-color: var(--f-primary);
  color: var(--m-white);
  background: rgba(112,80,216,0.12);
}
.chat-action-btn--saved {
  border-color: var(--s-positive) !important;
  color: var(--s-positive) !important;
}

/* ── Artifact action buttons (copy / save) ──────────────── */
.artifact-actions {
  display: flex;
  gap: 4px;
  padding: 6px 2px var(--space-2);
}

/* (txn pane collapse removed — pane is now static) */

/* ── Insights dropdown ───────────────────────────────────── */
.insights-item {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--m-border);
  position: relative;
}
.insights-item:last-child { border-bottom: none; }
.insights-item__text {
  font-size: var(--text-xs);
  color: var(--m-text);
  line-height: 1.5;
  padding-right: var(--space-6);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.insights-item__time {
  font-size: 10px;
  color: var(--m-text-dim);
  margin-top: 3px;
}
.insights-item__del {
  position: absolute;
  top: 8px; right: 8px;
  background: none;
  border: none;
  color: var(--m-text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.insights-item__del:hover {
  color: #e06040;
  background: rgba(224,96,64,0.1);
}

/* ── Artifact bubble (rich report card in chat) ──────────── */
.artifact-bubble {
  background: var(--m-surface);
  border: 1px solid var(--m-border-mid);
  border-radius: 4px 16px 16px 16px;
  padding: var(--space-3) var(--space-4);
  width: 100%;
  max-width: 540px;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
}
.artifact-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--f-secondary);
  margin-bottom: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
}
/* Wrapper that holds the question + artifact bubble */
.artifact-exchange {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.artifact-exchange__q {
  display: flex;
  justify-content: flex-end;
}
.artifact-exchange__q-bubble {
  background: rgba(112,80,216,0.18);
  border: 1px solid rgba(112,80,216,0.3);
  border-radius: 16px 16px 4px 16px;
  padding: var(--space-2) var(--space-3);
  max-width: 80%;
}
.artifact-exchange__a {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
}

/* ── Profile form ────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
@media (max-width: 480px) {
  .profile-grid { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--m-text-dim);
}

.field-input {
  background: var(--m-bg);
  border: 1px solid var(--m-border-mid);
  border-radius: var(--radius);
  padding: 9px var(--space-3);
  font-size: var(--text-sm);
  color: var(--m-white);
  font-family: var(--m-font);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.field-input:focus { border-color: var(--f-primary); }
.field-input option { background: var(--m-bg); }

.field-range {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--m-border-mid);
  outline: none;
  cursor: pointer;
}
.field-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--f-primary);
  cursor: pointer;
}
.field-range::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--f-primary);
  border: none;
  cursor: pointer;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--m-font);
  cursor: pointer;
  border: 1px solid var(--m-border-mid);
  background: var(--m-surface);
  color: var(--m-text-dim);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}
.check-chip input[type="checkbox"] { display: none; }
.check-chip:has(input:checked) {
  background: rgba(112,80,216,0.15);
  border-color: rgba(112,80,216,0.4);
  color: var(--f-secondary);
}

/* ── Light mode ──────────────────────────────────────────── */
/* Toggled via data-theme="light" on <html>.                  */
/* Brand colours (purple, blue, teal) unchanged.              */
[data-theme="light"] {
  --m-bg:          #f0f0f8;
  --m-surface:     #ffffff;
  --m-card:        #ffffff;
  --m-border:      #dcdcec;
  --m-border-mid:  #cacade;

  --m-text:        #2a2a44;
  --m-text-dim:    #60609a;  /* ~4.6:1 on #f0f0f8 */
  --m-text-muted:  #9090b8;
  --m-white:       #0e0e22;  /* headings become dark */

  --f-glow:        rgba(112, 80, 216, 0.07);

  --s-warning:     #b07800;  /* darker amber for light bg */
}

/* Cards on light bg need a subtle shadow instead of a border glow */
[data-theme="light"] .card {
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

[data-theme="light"] .card--glow {
  box-shadow: 0 0 0 1px rgba(112,80,216,0.25), 0 4px 20px rgba(112,80,216,0.1);
}

/* Sidebar + bottom nav on light bg */
[data-theme="light"] .sidebar,
[data-theme="light"] .bottom-nav {
  background: #ffffff;
  border-color: var(--m-border);
}

/* Field inputs on light bg */
[data-theme="light"] .field-input {
  background: #f8f8fd;
  color: var(--m-white);
}
[data-theme="light"] .field-input option { background: #ffffff; }

/* Theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--m-border-mid);
  background: none;
  color: var(--m-text-dim);
  font-size: var(--text-xs);
  font-family: var(--m-font);
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  color: var(--m-text);
  border-color: var(--f-primary);
}
