/* ============================================================================
   Operator Console — Fanvue GFE Bot
   Refined dark minimalism. Built for 8-hour daily use; legibility over flair.
   ============================================================================ */

:root {
  /* ============================================================
     v27.1.10 — Fanvue chat-product retheme (corrects v27.1.7).
     v27.1.7 retheme'd to cream + pink based on the Fanvue marketing
     site. The chat product the operator is mirroring is the OPPOSITE
     palette: dark charcoal backgrounds, near-black side rail, mid-grey
     panels, and the Fanvue lime-green accent (the green pill you see
     on the "Generate message with AI" button and the active "Messages"
     tab underline). This swap is again token-only — no structural
     changes to the layout. Every page picks up the new look because
     everything reads from these variables.

     Tokens are still named bg-0/bg-1/text-0 etc so existing overrides
     on chats.css / personas.css / etc keep working. We just shifted
     what those variables hold.

     Palette derived directly from screenshots of fanvue.com/messages:
       - Page canvas:   #15171a  (charcoal, slightly warm)
       - Side rail:     #0a0b0d  (near-black, deeper than canvas)
       - Card surface:  #1c1f24  (one shade lighter than canvas)
       - Hover/active:  #262a31
       - Primary text:  #e6e7e9
       - Accent green:  #a4d65d  (the leafy lime visible on the "AI"
                                  button and active-tab underline)
     ============================================================ */

  /* Backgrounds — dark charcoal scale */
  --bg-0: #15171a;          /* page canvas — main dark charcoal */
  --bg-1: #1c1f24;          /* card / surface (one step lighter) */
  --bg-2: #22262d;          /* subtle inset (filter rows, code blocks) */
  --bg-3: #2c313a;          /* hover / selected */
  --bg-rail: #0a0b0d;       /* far-left navigation rail (deepest) */

  /* Borders — subtle dark */
  --border: #2a2e36;
  --border-soft: #20242b;

  /* Text — light on dark */
  --text-0: #e6e7e9;        /* primary */
  --text-1: #c2c5cb;        /* secondary */
  --text-2: #8a8e96;        /* tertiary */
  --text-3: #5d6168;        /* muted / placeholder */

  /* Accent — Fanvue brand green. v27.1.33: bumped from lime (#a4d65d)
     to match the brighter shell green used by console.html's inline
     override. Pre-v27.1.33 the login screen rendered noticeably duller
     than the post-login console shell. Tokens here MUST stay in sync
     with the inline :root override in console.html. */
  --accent: #49f264;
  --accent-bright: #6cff85;
  --accent-dim: #1fef40;
  --accent-soft: rgba(73, 242, 100, 0.12);
  --accent-glow: 0 0 0 3px rgba(73, 242, 100, 0.22);

  /* Status */
  --warn: #f5b945;
  --danger: #ef5e5e;
  --info: #6da7e6;

  /* Typography — keep Inter Tight + Instrument Serif (already
     close to Fanvue's brand pairing — modern sans + display serif) */
  --font-sans: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Spacing rhythm — unchanged */
  --pad-xs: 4px;
  --pad-sm: 8px;
  --pad-md: 12px;
  --pad-lg: 16px;
  --pad-xl: 24px;
  --pad-2xl: 32px;

  /* Other — deeper shadows on the dark palette so cards still float */
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 4px 16px rgba(0, 0, 0, 0.22);
  --transition: 150ms cubic-bezier(0.2, 0, 0, 1);
}

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--bg-0); }

/* === Layout shell ========================================================= */
.app {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* 2-column variant for pages that don't need the conversation-list middle
   column (stats, personas, settings, audit, webhooks). The 3-column layout
   inherited from chats was crushing these pages into a 30% column on the
   right, leaving the middle 320px slot empty and wasted. */
.app--full {
  grid-template-columns: 240px 1fr;
}

/* === Left rail: navigation ================================================ */
.rail {
  background: var(--bg-rail);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: var(--pad-lg);
  gap: var(--pad-xl);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: var(--pad-sm) var(--pad-xs);
}
.brand .mark {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text-0);
}
.brand .ext {
  font-size: 10px;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: var(--pad-sm) var(--pad-md) var(--pad-xs);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--pad-md);
  padding: var(--pad-sm) var(--pad-md);
  border-radius: var(--radius);
  color: var(--text-1);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-size: 13px;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-0); }
.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--bg-2);
  color: var(--text-0);
}
.nav-item.active {
  background: var(--bg-3);
  color: var(--text-0);
  font-weight: 500;
}
.nav-item .glyph {
  width: 16px; height: 16px;
  opacity: 0.6;
}
.nav-item .badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--bg-0);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
}

.user-card {
  padding: var(--pad-md);
  background: var(--bg-2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: var(--pad-md);
  border: 1px solid var(--border-soft);
}

/* === Rail stats: 30-day sparkline =========================================== */
.rail-stats {
  margin-top: auto;
  padding: var(--pad-md);
  background: var(--bg-2);
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--pad-md);
}
.rail-stats-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}
.rail-stats-meta {
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-3);
}
#sparkline {
  width: 100%;
  height: 36px;
  display: block;
}
#sparkline path.line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
#sparkline path.area {
  fill: var(--accent);
  fill-opacity: 0.08;
  stroke: none;
}
.rail-stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}
.rail-stats-row .mono {
  color: var(--text-0);
  font-variant-numeric: tabular-nums;
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: grid; place-items: center;
  font-weight: 600;
  color: var(--bg-0);
  font-size: 12px;
}
.user-card .meta { display: flex; flex-direction: column; min-width: 0; }
.user-card .name { font-size: 13px; font-weight: 500; color: var(--text-0); }
.user-card .role { font-size: 11px; color: var(--text-2); }

/* === Middle column: conversation list ===================================== */
.col-list {
  background: var(--bg-1);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Connect-Fanvue banner — shown until at least one creator has OAuth'd */
.connect-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pad-md);
  padding: var(--pad-md) var(--pad-lg);
  background: linear-gradient(180deg, rgba(255,180,80,0.10) 0%, rgba(255,180,80,0.04) 100%);
  border-bottom: 1px solid rgba(255,180,80,0.25);
  color: var(--text-0);
}
.connect-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}
.connect-banner-text strong {
  font-weight: 600;
  letter-spacing: 0.01em;
}
.connect-banner-text span {
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.4;
}
.connect-banner-cta {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--text-0);
  color: var(--bg-0);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
  white-space: nowrap;
  transition: opacity 0.15s ease;
}
.connect-banner-cta:hover {
  opacity: 0.85;
}

/* Send countdown — replaces the draft pane after operator approves */
.send-countdown {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px var(--pad-lg);
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin: var(--pad-md);
  animation: countdown-fade-in 0.2s ease;
}
.send-countdown-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(140, 200, 140, 0.18);
  color: rgb(140, 220, 140);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.send-countdown-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.send-countdown-text strong {
  font-weight: 600;
  color: var(--text-0);
  font-size: 13px;
}
.send-countdown-text span {
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.send-countdown-text #cd-num {
  color: var(--text-0);
  font-weight: 500;
}
@keyframes countdown-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* v24: pulse animation for the "Posting to Fanvue…" state when delay is 0
   (instant sends). Gives the operator a clear "something is happening"
   indicator until the status poll flips to Sent ✓ or Failed ✗. */
#cd-spinner {
  animation: cd-spinner-pulse 1.2s ease-in-out infinite;
}
@keyframes cd-spinner-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
.col-header {
  padding: var(--pad-lg);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: var(--pad-md);
}
.col-header h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.col-header h2 small {
  display: block;
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-2);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.search {
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-0);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.search:focus { border-color: var(--accent-dim); }

.list-tabs {
  display: flex;
  gap: var(--pad-xs);
  padding: 0 var(--pad-lg);
}
.tab {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}
.tab.active { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--accent); }
.tab .count { color: inherit; opacity: 0.6; margin-left: 4px; }

/* Creator filter row — sits below status tabs, only visible with 2+ creators */
.creator-tabs {
  display: flex;
  gap: 4px;
  padding: 6px var(--pad-lg) 0;
  flex-wrap: wrap;
}
.creator-pill {
  padding: 4px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}
.creator-pill:hover { color: var(--text-1); border-color: var(--border); }
.creator-pill.active {
  background: var(--bg-1);
  border-color: var(--text-2);
  color: var(--text-0);
}

.conv-list { overflow-y: auto; flex: 1; padding: var(--pad-md) 0; }

.conv {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: var(--pad-md);
  padding: 10px var(--pad-lg);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--transition);
  align-items: center;
}
.conv:hover { background: var(--bg-2); }
.conv.active {
  background: var(--bg-2);
  border-left-color: var(--accent);
}
.conv .avatar { width: 36px; height: 36px; font-size: 13px; }
.conv .body { min-width: 0; }
.conv .name-row {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 13px; font-weight: 500;
}
.conv .name { color: var(--text-0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .stage {
  font-size: 9px;
  color: var(--text-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
}
.conv .preview {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.conv .meta-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.conv .time { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.conv .pill {
  background: var(--accent);
  color: var(--bg-0);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
/* v24: distinct pill for "fresh fan message, no draft yet" — appears for the
   ~5-15s window between webhook arrival and AI draft generation. Different
   colour from the regular `draft` pill so the operator can tell at a glance
   whether they need to wait (new) or can act (draft). */
.conv .pill.pill-new {
  background: rgba(120, 200, 80, 0.85);
  animation: pill-new-pulse 1.6s ease-in-out infinite;
}
@keyframes pill-new-pulse {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}
.conv.unread .name { font-weight: 600; }

/* === Right column: chat thread + draft review ============================= */
.col-thread {
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  overflow: hidden;
}

.thread-header {
  display: flex;
  align-items: center;
  gap: var(--pad-md);
  padding: var(--pad-lg) var(--pad-xl);
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-1);
}
.thread-header .avatar { width: 40px; height: 40px; font-size: 14px; }
.thread-header .who { display: flex; flex-direction: column; gap: 2px; }
.thread-header .who h3 { font-size: 16px; font-weight: 500; letter-spacing: -0.01em; }
.thread-header .who .sub { font-size: 11px; color: var(--text-2); }
.thread-header .actions { margin-left: auto; display: flex; gap: var(--pad-sm); }

.thread-fan-meta {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-soft);
  padding: var(--pad-md) var(--pad-xl);
  display: grid;
  /* 4 narrow columns + 1 wide column for activity, which has a longer string */
  grid-template-columns: repeat(4, max-content) 1fr;
  gap: var(--pad-lg);
  align-items: start;
}
.fan-stat .label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}
.fan-stat .val {
  font-size: 13px;
  color: var(--text-0);
  font-weight: 500;
  margin-top: 2px;
  white-space: nowrap;
}
.fan-stat .val.muted {
  color: var(--text-3);
}

.thread-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad-xl);
  display: flex;
  flex-direction: column;
  gap: var(--pad-md);
}

.bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  position: relative;
}
.bubble .ts {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.bubble.fan {
  background: var(--bg-2);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.creator {
  background: var(--accent-soft);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(184, 230, 57, 0.2);
}
.bubble.creator.edited::after {
  content: "edited";
  font-size: 9px;
  color: var(--text-3);
  margin-left: 6px;
}

/* Failed-send state: red border so it's visible at a glance */
.bubble.creator.failed {
  background: rgba(239, 94, 94, 0.10);
  border-color: rgba(239, 94, 94, 0.45);
}
.bubble.creator.skipped {
  background: var(--bg-2);
  border-color: var(--border-soft);
  opacity: 0.55;
  text-decoration: line-through;
  text-decoration-color: var(--text-3);
}

/* Inline error inside a failed bubble */
.bubble-error {
  margin-top: 8px;
  padding: 6px 8px;
  background: rgba(239, 94, 94, 0.10);
  border-left: 2px solid var(--danger);
  border-radius: 3px;
  font-size: 11px;
  color: var(--text-1);
  line-height: 1.4;
  cursor: help;  /* tooltip = full raw error */
}

/* v16: copy-diagnostics button on a failed bubble. Sits at the right
   side of the error block — clear "I want to send this to debugging"
   affordance without dominating the message content. */
.bubble-error .diag-btn {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 9px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(239, 94, 94, 0.18);
  color: var(--danger);
  border: 1px solid rgba(239, 94, 94, 0.35);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms;
}
.bubble-error .diag-btn:hover {
  background: rgba(239, 94, 94, 0.30);
}
.bubble-error .diag-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Status badge inline with the timestamp */
.bubble .ts .status-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
}
.status-badge.sent     { background: rgba(140,200,140,0.15); color: rgb(160,220,160); }
.status-badge.approved { background: rgba(180,180,255,0.15); color: rgb(180,180,255); }
.status-badge.failed   { background: rgba(239,94,94,0.20);   color: var(--danger); }
.status-badge.skipped  { background: var(--bg-2);            color: var(--text-3); }

/* === Draft review pane ==================================================== */
.draft-pane {
  background: var(--bg-1);
  border-top: 1px solid var(--border-soft);
  padding: var(--pad-lg) var(--pad-xl);
  display: flex;
  flex-direction: column;
  gap: var(--pad-md);
}
.draft-label {
  display: flex;
  align-items: center;
  gap: var(--pad-sm);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-2);
}
.draft-label .dot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}
.draft-label .meta {
  margin-left: auto;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-3);
}

.draft-text {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-md);
  color: var(--text-0);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 70px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.draft-text:focus { border-color: var(--accent-dim); }

.draft-actions {
  display: flex;
  gap: var(--pad-sm);
  flex-wrap: wrap;
}
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-0);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all var(--transition);
  /* Prevent text-selection flash when user clicks rapidly during keyboard nav */
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { background: var(--bg-3); border-color: var(--text-3); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn.primary {
  background: var(--accent);
  color: var(--bg-0);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-bright); }
.btn.primary:focus-visible {
  outline-color: var(--accent);
  /* v27.1.33: shifted from rgba(164, 214, 93, 0.25) (lime) to match
     the new --accent palette (#49f264 / rgba(73, 242, 100, ...)). */
  box-shadow: 0 0 0 4px rgba(73, 242, 100, 0.25);
}
.btn.ghost { background: transparent; border-color: var(--border-soft); color: var(--text-2); }
.btn.ghost:hover { color: var(--text-0); border-color: var(--border); }
.btn.danger { color: var(--danger); border-color: rgba(239, 94, 94, 0.3); }
.btn.danger:hover { background: rgba(239, 94, 94, 0.1); border-color: rgba(239, 94, 94, 0.5); }
.btn.danger:focus-visible { outline-color: var(--danger); box-shadow: 0 0 0 4px rgba(239, 94, 94, 0.2); }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn-group .label { font-size: 10px; color: var(--text-3); margin-right: var(--pad-sm); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; }

/* === Empty state ========================================================== */
.empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--pad-2xl);
}
.empty .title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text-1);
  margin-bottom: 8px;
}
.empty .sub { font-size: 13px; color: var(--text-2); max-width: 340px; line-height: 1.6; }

/* === Login screen ========================================================= */
.login {
  height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at top, rgba(184, 230, 57, 0.04) 0%, transparent 50%),
    var(--bg-0);
}
.login-card {
  background: var(--bg-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--pad-2xl);
  width: 360px;
  box-shadow: var(--shadow);
}
.login-card .mark {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.login-card .sub { font-size: 12px; color: var(--text-2); margin-bottom: var(--pad-xl); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--pad-md); }
.field label { font-size: 11px; color: var(--text-2); font-weight: 500; letter-spacing: 0.04em; }
.field input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text-0);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.field input:focus { border-color: var(--accent-dim); }
.error-banner {
  background: rgba(239, 94, 94, 0.1);
  border: 1px solid rgba(239, 94, 94, 0.3);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: var(--pad-md);
}
.info-banner {
  background: rgba(140, 200, 140, 0.10);
  border: 1px solid rgba(140, 200, 140, 0.30);
  color: rgb(160, 220, 160);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: var(--pad-md);
}

/* === Scrollbars =========================================================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* === Utilities ============================================================ */
.flex { display: flex; }
.gap-sm { gap: var(--pad-sm); }
.gap-md { gap: var(--pad-md); }
.muted { color: var(--text-2); }
.mono { font-family: var(--font-mono); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }

/* ===========================================================================
   Memory modal — operator-curated facts about a fan
   =========================================================================== */
.memory-btn {
  margin-left: auto;
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text-1);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
  align-self: center;
}
.memory-btn:hover {
  background: var(--bg-1);
  border-color: var(--border);
  color: var(--text-0);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: min(640px, 92vw);
  max-height: 80vh;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pad-lg);
  border-bottom: 1px solid var(--border-soft);
}
.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: -0.01em;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  padding: 0 8px;
}
.modal-close:hover { color: var(--text-0); }
.modal-help {
  padding: 12px var(--pad-lg) 0;
}

.memory-add-form {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  padding: var(--pad-lg);
  border-bottom: 1px solid var(--border-soft);
}
.memory-add-form input,
.memory-add-form select {
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text-0);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 12px;
}
.memory-add-form input:focus { border-color: var(--accent-dim); outline: none; }

#memory-list {
  overflow-y: auto;
  padding: 8px var(--pad-lg) var(--pad-lg);
  flex: 1;
}

.memory-row {
  display: grid;
  grid-template-columns: 70px 1fr 24px;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.memory-row:last-child { border-bottom: none; }

.mr-importance {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 1px;
  margin-top: 3px;
}
.mr-fact {
  font-size: 13px;
  color: var(--text-0);
  line-height: 1.4;
}
.mr-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 3px;
  flex-wrap: wrap;
}
.mr-cat, .mr-auto {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-2);
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.05em;
}
.mr-delete {
  background: none;
  border: 1px solid var(--border-soft);
  color: var(--text-3);
  border-radius: 3px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.mr-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Proposed (auto-extracted, awaiting review) memory facts */
.memory-section {
  margin-bottom: var(--pad-md);
}
.memory-section:last-child { margin-bottom: 0; }
.memory-section-title {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  margin: 12px 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}
.memory-section-proposed .memory-section-title {
  color: rgb(255, 200, 80);
  border-bottom-color: rgba(255, 200, 80, 0.25);
}
.memory-row-proposed {
  background: rgba(255, 200, 80, 0.05);
  border-radius: 4px;
  padding-left: 8px;
  padding-right: 8px;
  border-left: 2px solid rgba(255, 200, 80, 0.5);
}
.mr-actions {
  display: flex;
  gap: 4px;
}
.btn-sm-good, .btn-sm-bad {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  font-family: inherit;
}
.btn-sm-good {
  background: rgba(140, 220, 140, 0.15);
  border: 1px solid rgba(140, 220, 140, 0.4);
  color: rgb(160, 220, 160);
}
.btn-sm-good:hover { background: rgba(140, 220, 140, 0.30); }
.btn-sm-bad {
  background: rgba(239, 94, 94, 0.10);
  border: 1px solid rgba(239, 94, 94, 0.3);
  color: var(--danger);
}
.btn-sm-bad:hover { background: rgba(239, 94, 94, 0.20); }

/* === Toast notifications =================================================
   Defined inline in toast.js so the system works on pages without app.css
   (e.g. error states), but a few rules here let pages style toasts to
   match the design tokens if they want to. */
.cl-toast {
  font-family: var(--font-sans) !important;
}

/* === Diagnostic overlay refinements ======================================
   The 🩺 button is positioned bottom-right by api.js. Ensure no other
   fixed-position elements collide with its corner. */
@media (max-width: 720px) {
  /* On narrow viewports, scoot the diag button up to make room for any
     bottom toolbar. */
  body button[title^="Diagnostics"] {
    bottom: 60px !important;
  }
}
