/* ==========================================================================
   DEMO DESIGN SYSTEM
   Shared shell for every /demo/* page: tokens, intro, workspace grid, panel
   chrome, toolbar, status beacon, tabs, chips, buttons, console, empty states
   and evidence footer.

   Loaded by all three demos alongside their own page sheet. A demo page owns
   its workspace -- the thing it uniquely demonstrates -- and must not redefine
   anything in here. `page stylesheets do not redefine the demo system` in
   tests/unit/css-architecture.test.ts enforces that.
   ========================================================================== */
/* ==========================================================================
   STRIPE API DOCS RETRIEVAL DEMO (/demo/rag)
   Loaded only by src/pages/demo/rag.astro. The other two demos own
   page-demo-queue.css and page-demo-mcp.css.
   ========================================================================== */

/* Design Tokens */
:root {
  --demo-bg: var(--slake-bg);
  --demo-surface: #ffffff;
  --demo-text: var(--slake-text);
  --demo-text-secondary: var(--slake-subtext);
  --demo-text-muted: var(--slake-muted);
  --demo-border: var(--slake-border);
  --demo-border-hover: #cbd5e1;
  --demo-accent: var(--slake-blue);
  --demo-accent-hover: #1d4ed8;
  --demo-accent-subtle: #eff6ff;
  --demo-success: #047857;
  --demo-success-subtle: #ecfdf5;
  --demo-console-bg: #090d16;
  /* Pipeline/step states. Each theme gets values that clear AA on its own panel. */
  --demo-state-idle: #64748b;
  --demo-state-active: #0369a1;
  --demo-state-done: #047857;
  --demo-radius: 0;
  --demo-radius-sm: 0;
  --demo-font-sans: var(--font-primary);
  --demo-font-mono: var(--font-mono);
}

html:not(.light-mode),
:root[data-theme="dark"] {
  --demo-bg: var(--slake-bg);
  --demo-surface: #0b1220;
  --demo-text: var(--slake-text);
  --demo-text-secondary: var(--slake-subtext);
  --demo-text-muted: var(--slake-muted);
  --demo-border: rgba(255, 255, 255, 0.12);
  --demo-border-hover: #334155;
  --demo-accent: var(--slake-blue);
  --demo-accent-hover: #7fb2ee;
  --demo-accent-subtle: rgba(74, 144, 226, 0.12);
  --demo-success: #34d399;
  --demo-state-idle: #94a3b8;
  --demo-state-active: var(--slake-blue);
  --demo-state-done: #34d399;
  --demo-success-subtle: rgba(52, 211, 153, 0.1);
}

/* Base Page Wrapper */
.demo-page {
  background: var(--demo-bg);
  min-height: calc(100vh - var(--header-height, 80px));
  font-family: var(--demo-font-sans);
  color: var(--demo-text);
  padding: 24px 16px 80px;
  box-sizing: border-box;
}

.demo-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* 1. Page Intro Header (Always visible across all viewports) */
.demo-intro {
  margin-bottom: 20px;
  text-align: left;
  display: block;
}

.demo-intro-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--demo-font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--demo-text-muted);
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  padding: 3px 8px;
  border-radius: var(--demo-radius-sm);
  margin-bottom: 10px;
  max-width: 100%;
}

.demo-title {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
  color: var(--demo-text);
  margin: 0 0 6px 0;
  line-height: 1.25;
  display: block;
}

.demo-subtitle {
  font-size: var(--text-base-sm);
  line-height: 1.5;
  color: var(--demo-text-secondary);
  max-width: 680px;
  margin: 0;
  display: block;
}

/* Architecture facts: fixed properties of the system, stated as label/value.
   Not telemetry -- nothing here changes at runtime, which is why it is safe to
   render before anything has happened. */
.demo-facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin-top: 14px;
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  overflow: hidden;
}

.demo-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--demo-surface);
  border-right: 1px solid var(--demo-border);
  min-width: 0;
}

.demo-fact:last-child {
  border-right: none;
}

.demo-fact-value {
  font-family: var(--demo-font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--demo-text);
  letter-spacing: var(--tracking-snug);
}

.demo-fact-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-button);
  text-transform: uppercase;
  color: var(--demo-text-muted);
}

/* Live session counters. Distinct from .demo-facts: these change at runtime, so
   they must start at zero and only move when something actually happened. */
.demo-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 14px;
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  overflow: hidden;
}

.demo-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--demo-surface);
  border-right: 1px solid var(--demo-border);
  min-width: 0;
}

.demo-metric:last-child {
  border-right: none;
}

.demo-metric-value {
  font-family: var(--demo-font-mono);
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--demo-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.demo-metric-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-button);
  text-transform: uppercase;
  color: var(--demo-text-muted);
}

/* 2. Workspace: Responsive 2-Column Grid */
.demo-workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  width: 100%;
  margin-top: 18px;
}

/* 3. Left Panel (Query Composer) */
/* Shared card chrome. Both panels carried an identical copy of these six
   declarations; the modifiers now hold only what actually differs. */
.demo-panel {
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Control panel: follows the reader down a long result. */
.demo-panel--control {
  position: sticky;
  top: calc(var(--header-height, 80px) + 16px);
  z-index: 10;
  padding: 18px;
}

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

.demo-panel-label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--demo-text);
  display: block;
}

.demo-panel-badge {
  font-family: var(--demo-font-mono);
  font-size: var(--text-xs);
  color: var(--demo-text-muted);
}

.demo-textarea {
  width: 100%;
  background: var(--demo-bg);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-sm);
  padding: 10px 12px;
  font-family: var(--demo-font-sans);
  font-size: var(--text-base-sm);
  line-height: 1.5;
  color: var(--demo-text);
  box-sizing: border-box;
  resize: none;
  min-height: 80px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.demo-textarea:focus {
  border-color: var(--demo-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.demo-chip-group {
  margin-top: 12px;
}

.demo-chip-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--demo-text-muted);
  margin-bottom: 6px;
  display: block;
}

/* Symmetric 2x2 Grid for Query Chips (Eliminates lone orphan chips) */
.demo-chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.demo-chip {
  background: var(--demo-bg);
  color: var(--demo-text-secondary);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-sm);
  padding: 6px 8px;
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  font-family: var(--demo-font-sans);
  transition: all 0.12s ease;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.demo-chip:hover {
  background: var(--demo-surface);
  border-color: var(--demo-accent);
  color: var(--demo-accent);
}

.demo-chip:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 1px;
}

.demo-panel-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--demo-border);
}

.demo-note {
  font-size: var(--text-xs);
  color: var(--demo-text-muted);
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 12px 0 0 0;
}

.demo-note i {
  margin-top: 2px;
  color: var(--demo-text-muted);
  flex-shrink: 0;
}

.demo-hint {
  margin: 8px 0 0 0;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--demo-text-muted);
}

.demo-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--demo-border);
  border-bottom-width: 2px;
  border-radius: var(--demo-radius-sm);
  background: var(--demo-bg);
  color: var(--demo-text-secondary);
  font-family: var(--demo-font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
}

/* Pointer-only affordance: on touch there is no Cmd/Ctrl key to press. */
@media (hover: none) {
  .demo-hint { display: none; }
}

.demo-cta-btn {
  background: var(--demo-text);
  color: var(--demo-surface);
  min-height: 40px;
  border-radius: var(--demo-radius-sm);
  font-weight: 600;
  font-size: var(--text-sm);
  border: none;
  width: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.demo-cta-btn:hover:not(:disabled) {
  opacity: 0.9;
}

/* Secondary action: same size and rhythm, lower visual weight, so a page can
   offer an alternate path without two primary buttons competing. */
.demo-cta-btn--secondary {
  margin-top: 8px;
  background: var(--demo-bg);
  color: var(--demo-text-secondary);
  border: 1px solid var(--demo-border);
  font-weight: 600;
}

.demo-cta-btn--secondary:hover:not(:disabled) {
  opacity: 1;
  border-color: var(--demo-border-hover);
  color: var(--demo-text);
}

html:not(.light-mode) .demo-cta-btn--secondary,
:root[data-theme="dark"] .demo-cta-btn--secondary {
  background: var(--demo-bg);
  color: var(--demo-text-secondary);
  border-color: var(--demo-border);
}

.demo-cta-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.demo-cta-btn:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}

html:not(.light-mode) .demo-cta-btn,
:root[data-theme="dark"] .demo-cta-btn {
  background: var(--demo-accent);
  color: #090d16;
}

/* 4. Right Panel (Result Console) */


/* Consolidated Result Toolbar */
.demo-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--demo-border);
  flex-wrap: wrap;
  gap: 8px;
}

.demo-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--demo-text);
}

.demo-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--demo-text-muted);
  flex-shrink: 0;
}

.demo-status-dot.is-idle    { background: var(--demo-text-muted); }
.demo-status-dot.is-busy    { background: var(--demo-accent); }
.demo-status-dot.is-ok      { background: var(--demo-success); }
.demo-status-dot.is-error   { background: #ef4444; }@media (prefers-reduced-motion: no-preference) {
  .demo-status-dot.is-busy { animation: demo-pulse 1.1s ease-in-out infinite; }
}


@keyframes demo-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.demo-toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Accessible Tab Group */
.demo-tabs {
  display: inline-flex;
  background: var(--demo-bg);
  padding: 2px;
  border-radius: var(--demo-radius-sm);
  border: 1px solid var(--demo-border);
}

.demo-tab {
  background: transparent;
  color: var(--demo-text-muted);
  border: none;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--demo-radius-sm);
  cursor: pointer;
  font-family: var(--demo-font-sans);
  transition: all 0.12s ease;
  min-height: 28px;
}

.demo-tab {
  white-space: nowrap;
}

.demo-tab-count {
  display: inline-block;
  min-width: 1.25em;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--demo-border);
  color: var(--demo-text-secondary);
  font-family: var(--demo-font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  text-align: center;
}

.demo-tab.active .demo-tab-count {
  background: var(--demo-accent);
  color: var(--demo-surface);
}

.demo-tab:hover {
  color: var(--demo-text);
}

.demo-tab.active {
  background: var(--demo-surface);
  color: var(--demo-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.demo-tab:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 1px;
}

/* Toolbar Action Buttons (Copy & Reset) */
.demo-toolbar-actions {
  display: inline-flex;
  gap: 6px;
}

.demo-btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--demo-text-secondary);
  background: var(--demo-bg);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-sm);
  cursor: pointer;
  font-family: var(--demo-font-sans);
  min-height: 28px;
  transition: all 0.12s ease;
}

.demo-btn-tool:hover {
  background: var(--demo-surface);
  color: var(--demo-text);
  border-color: var(--demo-border-hover);
}

.demo-btn-tool:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 1px;
}

/* Result Canvas Content Views */
.demo-panel-body {
  padding: 18px 20px;
  min-height: 300px;
  box-sizing: border-box;
}

.demo-tab-view {
  display: none;
}

.demo-tab-view.active {
  display: block;
}

.demo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 44px 16px;
  text-align: center;
  color: var(--demo-text-muted);
}

.demo-empty-icon {
  font-size: var(--text-2xl);
  color: var(--demo-accent);
  margin-bottom: 10px;
}

.demo-empty-text {
  margin: 0;
  font-size: var(--text-base-sm);
  line-height: 1.5;
  max-width: 420px;
}

/* Stream Log Console */
.demo-console {
  background: var(--demo-console-bg);
  border: 1px solid #1e293b;
  border-radius: var(--demo-radius-sm);
  padding: 14px 16px;
  font-family: var(--demo-font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: #94a3b8;
  max-height: 380px;
  overflow-y: auto;
  box-sizing: border-box;
}

/* Log lines wrap rather than scrolling sideways. A <pre> keeps its default
   white-space, so at 320px the queue console scrolled 163px inside its own box
   -- readable only by dragging, on the narrowest screens where that is hardest. */
.demo-console pre,
.demo-console code {
  margin: 0;
  font: inherit;
  color: inherit;
  background: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.demo-console-line {
  margin-bottom: 4px;
  display: block;
}

.terminal-line--log {
  color: #cbd5e1;
}

.demo-console-line span {
  color: #8b98ab;
  margin-right: 6px;
}

/* 5. Evidence Footer */
.demo-footer {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--demo-border);
}

.demo-sub-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--demo-text);
  background: var(--demo-surface);
  border: 1px solid var(--demo-border);
  border-radius: var(--demo-radius-sm);
  text-decoration: none;
  transition: all 0.12s ease;
  min-height: 36px;
}

.demo-sub-btn:hover {
  border-color: var(--demo-accent);
  color: var(--demo-accent);
}

.demo-sub-btn:focus-visible {
  outline: 2px solid var(--demo-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* Tablet (768px - 1023px) */
@media (max-width: 1023px) {
  .demo-workspace {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .demo-panel--control {
    position: static;
  }
}

/* Mobile (320px - 767px) */
@media (max-width: 767px) {
  .demo-page {
    padding: 16px 24px 64px;
  }

  .demo-facts {
    grid-template-columns: repeat(2, 1fr);
  }

  .demo-fact:nth-child(2) {
    border-right: none;
  }

  .demo-fact:nth-child(1),
  .demo-fact:nth-child(2) {
    border-bottom: 1px solid var(--demo-border);
  }

  .demo-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .demo-metric:nth-child(1) {
    border-right: 1px solid var(--demo-border);
    border-bottom: 1px solid var(--demo-border);
  }

  .demo-metric:nth-child(2) {
    border-right: none;
    border-bottom: 1px solid var(--demo-border);
  }

  .demo-metric:nth-child(3) {
    grid-column: 1 / -1;
    border-right: none;
    border-bottom: none;
  }

  .demo-intro {
    margin-bottom: 16px;
  }

  .demo-intro-meta {
    font-size: var(--text-xs);
    padding: 2px 7px;
    margin-bottom: 8px;
  }

  .demo-title {
    font-size: var(--text-lg);
    letter-spacing: var(--tracking-tight);
  }

  .demo-subtitle {
    font-size: var(--text-sm);
    line-height: 1.45;
  }

  .demo-workspace {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 14px;
  }

  .demo-panel--control {
    position: static;
    padding: 14px;
  }

  .demo-textarea {
    font-size: var(--text-base); /* Prevents iOS auto-zoom */
  }

  .demo-chip-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .demo-chip {
    min-height: 38px;
    font-size: var(--text-xs);
    padding: 4px 6px;
  }

  /* Two-row toolbar on mobile: status on top, controls beneath. */
  .demo-toolbar {
    padding: 10px 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* The status dot belongs NEXT TO its label. `space-between` on a full-width
     row pinned the dot left and the text right -- measured 280px apart at
     430px wide, which reads as a broken indicator rather than a status. */
  .demo-status {
    justify-content: flex-start;
    width: 100%;
  }

  .demo-toolbar-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .demo-tabs {
    flex: 1 1 auto;
    display: flex;
    min-width: 0;
  }

  .demo-tab {
    flex: 1 1 0;
    min-height: 36px;
    padding: 6px 4px;
    font-size: var(--text-xs);
    text-align: center;
  }

  .demo-toolbar-actions {
    display: flex;
    flex-shrink: 0;
    gap: 4px;
  }

  .demo-btn-tool {
    min-height: 36px;
    padding: 6px 8px;
  }

  /* Icon-only tool buttons below 380px, where the labels crowd the tabs out. */
  @media (max-width: 379px) {
    .demo-btn-tool span { display: none; }
    .demo-btn-tool { padding: 6px 10px; }
  }

  .demo-panel-body {
    padding: 14px 12px;
    min-height: 220px;
  }

  .demo-footer {
    margin-top: 20px;
    padding-top: 14px;
  }
}

/* Demo CTAs speak with the same button voice as the rest of the site. */
.demo-cta-btn {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
