/* ==========================================================================
   THEME PALETTES: LIGHT (DEFAULT) & SOFT SLATE DARK
   Primary brand color: #68479D (Regal Purple)
   ========================================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  color: #151b26;
  background: #f6f8fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;

  /* Surfaces & Backgrounds */
  --bg-app: #f6f8fb;
  --bg-sidebar: #edf1f7;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-subtle: #f5f7fb;
  --bg-input: #ffffff;

  /* Borders */
  --border-subtle: #e2e6f0;
  --border-medium: #d0d6e4;
  --border-strong: #b4bed2;

  /* Typography Colors */
  --text-primary: #151b26;
  --text-secondary: #4f5b6e;
  --text-tertiary: #7d889b;
  --text-dim: #9fa9ba;

  /* Brand Accents (#68479D) */
  --brand-primary: #68479D;
  --brand-hover: #7b56bc;
  --brand-dark: #50337d;
  --brand-subtle: rgba(104, 71, 157, 0.08);
  --brand-border: rgba(104, 71, 157, 0.22);
  --brand-text: #68479D;
  --brand-glow: rgba(104, 71, 157, 0.32);

  /* Auxiliary Accents */
  --accent-blue: #0284c7;
  --accent-blue-subtle: #e0f2fe;
  --accent-amber: #b45309;
  --accent-amber-subtle: #fef3c7;
  --accent-red: #dc2626;
  --accent-red-subtle: #fee2e2;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(21, 27, 38, 0.05);
  --shadow-md: 0 4px 16px rgba(21, 27, 38, 0.07);
  --shadow-lg: 0 10px 30px rgba(21, 27, 38, 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  color: #f1f5f9;
  background: #151823;

  /* Surfaces & Backgrounds - Soft Slate, not harsh black */
  --bg-app: #151823;
  --bg-sidebar: #1a1e2c;
  --bg-surface: #202536;
  --bg-surface-elevated: #262c40;
  --bg-surface-subtle: #1c2130;
  --bg-input: #171b26;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-medium: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.26);

  /* Typography Colors */
  --text-primary: #f8fafc;
  --text-secondary: #9da7bd;
  --text-tertiary: #6f7b92;
  --text-dim: #546074;

  /* Brand Accents (#68479D in Dark Mode) */
  --brand-primary: #68479D;
  --brand-hover: #7e58be;
  --brand-dark: #4f337a;
  --brand-subtle: rgba(104, 71, 157, 0.22);
  --brand-border: rgba(187, 164, 243, 0.35);
  --brand-text: #c0a6f8;
  --brand-glow: rgba(104, 71, 157, 0.45);

  /* Auxiliary Accents */
  --accent-blue: #38bdf8;
  --accent-blue-subtle: rgba(56, 189, 248, 0.14);
  --accent-amber: #fbbf24;
  --accent-amber-subtle: rgba(251, 191, 36, 0.14);
  --accent-red: #f87171;
  --accent-red-subtle: rgba(248, 113, 113, 0.14);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-primary);
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.25);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.4);
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  position: relative;
  background: var(--bg-app);
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidebar {
  display: flex;
  flex: 0 0 270px;
  flex-direction: column;
  min-height: 0;
  padding: 16px 14px 12px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  user-select: none;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text-primary);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #68479D 0%, #4f337a 100%);
  color: #ffffff;
  font-size: 16px;
  font-weight: 850;
  box-shadow: 0 3px 12px var(--brand-glow);
}

.brand-info {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.brand-name {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  background: var(--bg-surface);
  color: var(--text-primary);
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.new-chat-button:hover {
  background: var(--bg-surface-subtle);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

.new-chat-icon {
  font-size: 17px;
  color: var(--brand-primary);
  font-weight: 700;
  line-height: 1;
}

.sidebar-search {
  margin-bottom: 10px;
}

.chat-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-search-input::placeholder {
  color: var(--text-tertiary);
}

.chat-search-input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px var(--brand-subtle);
}

.sidebar-heading {
  margin: 12px 6px 6px;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-empty {
  margin: 14px 8px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 3px 0;
  padding: 8px 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  font-size: 12px;
  transition: all 0.12s ease;
}

.chat-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item:hover {
  background: rgba(100, 116, 139, 0.08);
  color: var(--text-primary);
}

.chat-item.active {
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-weight: 650;
}

.sidebar-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 6px 0;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: 10.5px;
}

.version-tag {
  color: var(--brand-text);
  font-weight: 600;
}

/* ==========================================================================
   MAIN PANEL & TOPBAR
   ========================================================================== */
.main-panel {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--bg-app);
  position: relative;
  transition: background-color 0.2s ease;
}

.topbar {
  display: flex;
  flex: 0 0 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  backdrop-filter: blur(8px);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.topbar-title strong {
  overflow: hidden;
  color: var(--text-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.mode-pill {
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 10px;
  font-weight: 650;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.topbar-btn:hover {
  background: var(--brand-subtle);
  color: var(--brand-text);
  border-color: var(--brand-border);
}

.theme-toggle-btn {
  padding: 5px 10px;
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  transition: all 0.2s ease;
}

.status-dot.busy {
  background: var(--brand-primary);
  box-shadow: 0 0 8px var(--brand-primary);
  animation: pulseDot 1.4s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.connection-state {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
}

.connection-state.busy {
  color: var(--brand-text);
  font-weight: 600;
}

.mobile-menu {
  display: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 18px;
}

/* ==========================================================================
   PROGRESS & STEPPER BAR
   ========================================================================== */
.progress-section {
  flex: 0 0 auto;
  padding: 10px 20px 8px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto 6px;
  max-width: 840px;
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-primary);
}

.progress-badge {
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.progress-count {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
}

.progress-track {
  max-width: 840px;
  height: 4px;
  margin: 0 auto 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--border-subtle);
}

.progress-value {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4f337a 0%, #68479D 50%, #8960cf 100%);
  box-shadow: 0 0 10px var(--brand-glow);
  transition: width 0.35s ease;
}

.stepper-bar {
  display: flex;
  gap: 4px;
  max-width: 840px;
  margin: 0 auto;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: thin;
}

.step-pill {
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-tertiary);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.step-pill:hover {
  border-color: var(--border-medium);
  color: var(--text-primary);
  background: var(--bg-surface-subtle);
}

.step-pill.completed {
  background: var(--brand-subtle);
  border-color: var(--brand-border);
  color: var(--brand-text);
}

.step-pill.active {
  background: #68479D;
  border-color: #68479D;
  color: #ffffff;
  font-weight: 750;
  box-shadow: 0 2px 12px var(--brand-glow);
}

/* ==========================================================================
   CONVERSATION & WELCOME SCREEN
   ========================================================================== */
.conversation {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.welcome {
  display: flex;
  width: 100%;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 20px;
  text-align: center;
}

.welcome-icon {
  display: grid;
  width: 50px;
  height: 50px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 16px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: #68479D;
  font-size: 26px;
  box-shadow: 0 0 24px var(--brand-glow);
}

.welcome h1 {
  margin: 0 0 10px;
  color: var(--text-primary);
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 750;
  letter-spacing: -0.03em;
}

.welcome > p {
  max-width: 560px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.65;
}

.welcome-features {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 14px;
}

.feature-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
}

.feature-tag span {
  color: var(--brand-primary);
  font-weight: 700;
}

.prompt-cards {
  display: grid;
  width: min(840px, 100%);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 32px;
}

.prompt-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 100px;
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  text-align: left;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
}

.prompt-card strong {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 650;
}

.prompt-card span {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-tertiary);
}

.prompt-card:hover {
  border-color: var(--brand-primary);
  background: var(--bg-surface-subtle);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 14px var(--brand-subtle);
}

/* ==========================================================================
   MESSAGES & TASK CARDS
   ========================================================================== */
.message-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding: 24px 20px 48px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  width: min(840px, 100%);
  flex: 0 0 auto;
  gap: 12px;
  align-self: center;
}

.message.user {
  justify-content: flex-end;
}

.message-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 12px;
  font-weight: 800;
}

.message.user .message-avatar {
  order: 2;
  background: var(--border-subtle);
  border-color: var(--border-medium);
  color: var(--text-secondary);
}

.message-body {
  min-width: 0;
  max-width: 86%;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message.user .message-body {
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.message.assistant .message-body {
  padding-top: 4px;
}

.message.system {
  justify-content: center;
}

.message.system .message-body {
  max-width: min(720px, 100%);
  padding: 10px 16px;
  border-radius: 9px;
  background: var(--accent-red-subtle);
  color: var(--accent-red);
  text-align: center;
  font-size: 12px;
  border: 1px solid rgba(220, 38, 38, 0.25);
}

/* ==========================================================================
   TASK CARD (STEP CONTAINER)
   ========================================================================== */
.task-card {
  width: min(840px, 100%);
  flex: 0 0 auto;
  align-self: center;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s;
}

.task-card:hover {
  border-color: var(--border-medium);
}

.task-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.task-kicker {
  color: var(--brand-text);
  font-size: 10.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.task-title {
  margin: 3px 0 0;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.task-header-status {
  flex: 0 0 auto;
}

.step-status-chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 10px;
  font-weight: 650;
  color: var(--text-tertiary);
}

.step-status-chip.approved {
  background: var(--brand-subtle);
  border-color: var(--brand-border);
  color: var(--brand-text);
}

.task-content {
  padding: 18px 20px;
  overflow-x: auto;
}

.task-raw {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-x: auto;
}

.task-error {
  border-color: rgba(220, 38, 38, 0.3);
  color: var(--accent-red);
  background: var(--accent-red-subtle);
}

/* SCOPE AND OPPORTUNITY TAGS */
.opportunity-summary-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
}

.opportunity-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
}

.opportunity-tag strong {
  color: var(--text-primary);
  font-weight: 650;
}

.search-scope-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.scope-badge {
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-weight: 600;
}

.scope-badge.highlight {
  background: var(--accent-blue-subtle);
  border-color: rgba(2, 132, 199, 0.3);
  color: var(--accent-blue);
}

/* COHORT STATS DASHBOARD */
.cohort-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.cohort-stat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cohort-stat-label {
  font-size: 9.5px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.cohort-stat-value {
  font-size: 15px;
  font-weight: 750;
  color: var(--text-primary);
  font-feature-settings: "tnum";
}

/* TABLE FORMATTING */
.task-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  line-height: 1.5;
}

.task-table th,
.task-table td {
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}

.task-table th {
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.task-table tr:hover td {
  background: rgba(100, 116, 139, 0.03);
}

/* TABLE BADGES */
.direct-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
}

.adjacent-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-blue-subtle);
  border: 1px solid rgba(2, 132, 199, 0.25);
  color: var(--accent-blue);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
}

.peer-type-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 9.5px;
  font-weight: 600;
}

.score-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 9.5px;
  font-weight: 700;
}

.source-chip {
  display: inline-block;
  padding: 2px 6px;
  margin: 0 2px;
  border-radius: 4px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-weight: 650;
  font-size: 9.5px;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, monospace;
  cursor: pointer;
  transition: all 0.15s ease;
}

.source-chip:hover {
  background: #68479D;
  color: #ffffff;
  box-shadow: 0 0 8px var(--brand-glow);
}

.unsourced-chip {
  background: var(--accent-amber-subtle);
  border-color: rgba(180, 83, 9, 0.3);
  color: var(--accent-amber);
}

/* TASK FOOTER */
.task-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: 11px;
  background: var(--bg-surface-subtle);
}

.task-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.step-verified-tag {
  color: var(--brand-text);
  font-weight: 650;
}

.task-sources {
  width: 100%;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 8px;
  margin-top: 4px;
}

.task-sources summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--brand-text);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
}

.task-sources summary:hover {
  color: var(--brand-hover);
  text-decoration: underline;
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.source-card {
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-surface);
  font-size: 10.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.source-card:hover {
  border-color: var(--brand-border);
  background: var(--bg-surface-subtle);
}

.source-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.source-provider {
  font-weight: 700;
  color: var(--text-primary);
  background: var(--border-subtle);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 9.5px;
}

.source-method {
  font-size: 9px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.source-title {
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.source-meta {
  color: var(--text-tertiary);
  font-size: 9.5px;
  line-height: 1.4;
}

.source-link {
  color: var(--brand-text);
  text-decoration: none;
  font-weight: 500;
}

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

/* ==========================================================================
   IN-MESSAGE STEP APPROVAL ACTION BAR
   ========================================================================== */
.task-action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--brand-subtle);
  border-radius: 0 0 13px 13px;
  min-height: 58px;
}

.task-action-bar.approved {
  background: var(--bg-surface-subtle);
  justify-content: flex-start;
  padding: 10px 20px;
  min-height: 44px;
}

.task-action-bar.completed {
  background: var(--brand-subtle);
  justify-content: center;
  padding: 12px 20px;
}

.step-action-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  flex-wrap: wrap;
}

.step-action-note {
  font-size: 11.5px;
  color: var(--text-tertiary);
}

.step-approve-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, #68479D 0%, #4f337a 100%);
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: -0.01em;
  box-shadow: 0 4px 14px var(--brand-glow);
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.step-approve-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #7c57bc 0%, #68479D 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(104, 71, 157, 0.45);
  color: #ffffff;
}

.step-approve-btn:active:not(:disabled) {
  transform: translateY(0);
}

.step-approve-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-check {
  font-size: 14px;
  font-weight: 800;
}

.btn-arrow {
  font-size: 14px;
  font-weight: 800;
  transition: transform 0.15s ease;
}

.step-approve-btn:hover:not(:disabled) .btn-arrow {
  transform: translateX(2px);
}

.step-approved-wrapper {
  display: inline-flex;
  align-items: center;
}

.step-approved-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 6px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 11px;
  font-weight: 650;
}

.step-completed-wrapper {
  display: inline-flex;
  align-items: center;
}

.step-completed-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 8px;
  background: var(--brand-subtle);
  border: 1px solid var(--brand-border);
  color: var(--brand-text);
  font-size: 13px;
  font-weight: 750;
  box-shadow: 0 0 16px var(--brand-subtle);
}

/* Spinner for button loading */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* ==========================================================================
   PROVENANCE INSPECTOR DRAWER
   ========================================================================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.provenance-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 92vw);
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--border-subtle);
  animation: slideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
}

.drawer-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-subtitle {
  font-size: 11px;
  color: var(--text-tertiary);
}

.drawer-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  transition: all 0.15s ease;
}

.drawer-close:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-detail-card {
  padding: 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-kv {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.drawer-kv-label {
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.drawer-kv-value {
  font-size: 12.5px;
  color: var(--text-primary);
  font-weight: 500;
}

.drawer-kv-value code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--brand-subtle);
  color: var(--brand-text);
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
}

/* ==========================================================================
   COMPOSER
   ========================================================================== */
.composer-area {
  flex: 0 0 auto;
  padding: 14px 20px 18px;
  background: linear-gradient(180deg, transparent 0%, var(--bg-app) 30%);
}

.composer {
  display: flex;
  width: min(840px, 100%);
  align-items: flex-end;
  gap: 10px;
  margin: 0 auto;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--border-medium);
  border-radius: 22px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-md);
  transition: all 0.18s ease;
}

.composer:focus-within {
  border-color: var(--brand-primary);
  box-shadow: 0 4px 24px var(--brand-subtle);
}

.composer textarea {
  max-height: 140px;
  min-height: 26px;
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.6;
}

.composer textarea::placeholder {
  color: var(--text-tertiary);
}

.send-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #68479D;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  box-shadow: 0 2px 10px var(--brand-glow);
  transition: all 0.15s ease;
}

.send-button:hover:not(:disabled) {
  background: var(--brand-hover);
  transform: scale(1.05);
}

.send-button:disabled {
  background: var(--border-subtle);
  color: var(--text-tertiary);
  box-shadow: none;
}

.composer-note {
  margin: 8px auto 0;
  color: var(--text-tertiary);
  text-align: center;
  font-size: 10.5px;
}

/* ==========================================================================
   TOAST & TYPING
   ========================================================================== */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 18px;
  border-radius: 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  font-weight: 500;
  animation: slideIn 0.18s ease-out;
}

.typing {
  display: flex;
  width: min(840px, 100%);
  gap: 6px;
  align-self: center;
  padding: 8px 0;
}

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #68479D;
  animation: bounce 1.1s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.18s;
}

.typing i:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(290px, 86vw);
    transform: translateX(-105%);
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-menu {
    display: inline-grid;
    width: 32px;
    height: 32px;
    place-items: center;
  }
  .topbar {
    padding: 0 14px;
  }
  .mode-pill {
    display: none;
  }
  .prompt-cards {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 20px;
  }
  .cohort-stats-row {
    grid-template-columns: 1fr 1fr;
  }
  .step-action-prompt {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .step-approve-btn {
    width: 100%;
    justify-content: center;
  }
}
