/* ============================================================
   GenQA — design tokens & base styles
   Notion-like dark UI with engineering polish
   ============================================================ */

:root {
  /* Color tokens — dark theme (default) */
  --bg-base: #0b0d10;
  --bg-surface: #15181c;
  --bg-surface-2: #1a1e23;
  --bg-elevated: #1f2429;
  --bg-hover: #20252b;
  --bg-active: #262c33;
  --bg-input: #15181c;

  --border: #262a30;
  --border-strong: #343a42;
  --border-focus: #4f7cf7;

  --text-primary: #e6e8eb;
  --text-secondary: #9ba3ad;
  --text-tertiary: #6b727c;
  --text-muted: #4a5159;
  --text-inverse: #0b0d10;

  --accent: #6c8eff;
  --accent-hover: #82a0ff;
  --accent-soft: rgba(108, 142, 255, 0.12);
  --accent-border: rgba(108, 142, 255, 0.3);

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --info: #7dd3fc;
  --info-soft: rgba(125, 211, 252, 0.12);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  /* Sizing */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --rail-width: 56px;
  --sidebar-width: 240px;
  --topbar-height: 48px;

  /* Density */
  --density-y: 8px;
  --density-x: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  --bg-base: #fafaf9;
  --bg-surface: #ffffff;
  --bg-surface-2: #f7f7f6;
  --bg-elevated: #ffffff;
  --bg-hover: #f1f1f0;
  --bg-active: #ebebea;
  --bg-input: #ffffff;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #78716c;
  --text-muted: #a8a29e;
  --text-inverse: #ffffff;
  --accent-soft: rgba(79, 124, 247, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

[data-density="compact"] {
  --density-y: 6px;
  --density-x: 10px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  color: inherit;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ============================================================
   App shell: rail + sidebar + main
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  height: 100vh;
  background: var(--bg-base);
}

.app-shell.no-sidebar { grid-template-columns: var(--rail-width) 1fr; }
.app-shell.with-sidebar { grid-template-columns: var(--rail-width) var(--sidebar-width) 1fr; }

/* ----- Left rail ----- */
.rail {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  z-index: 10;
}

.rail-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #a5b4fc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.rail-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  position: relative;
  transition: all 0.12s;
}

.rail-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.rail-btn .tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  box-shadow: var(--shadow-sm);
  z-index: 100;
}

.rail-btn:hover .tooltip {
  opacity: 1;
}

.rail-spacer { flex: 1; }

/* ----- Sidebar (contextual) ----- */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-section {
  padding: 8px 6px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.1s;
  margin: 1px 0;
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: 500;
}

.sidebar-item .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-base);
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* ----- Main content area ----- */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

.topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.breadcrumb-sep {
  color: var(--text-muted);
}

.breadcrumb-item {
  cursor: pointer;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
}
.breadcrumb-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.breadcrumb-item.active { color: var(--text-primary); font-weight: 500; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--text-tertiary);
}

.content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ============================================================
   Buttons (standardized)
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all 0.12s;
  white-space: nowrap;
  cursor: pointer;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 14px; height: 14px; }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.18);
}

.btn-success {
  background: var(--success);
  color: #052e16;
}
.btn-success:hover:not(:disabled) { background: #6ee7a3; }

.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-lg { height: 38px; padding: 0 16px; font-size: 14px; }
.btn-icon-only { width: 32px; padding: 0; }

/* ============================================================
   Form controls (standardized)
   ============================================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-hint {
  font-size: 11.5px;
  color: var(--text-tertiary);
}

.field-required {
  color: var(--danger);
}

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-primary);
  transition: all 0.12s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-muted);
}

.textarea {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.select {
  appearance: none;
  background-image:
    url("data:image/svg+xml;charset=US-ASCII,%3Csvg width='18' height='18' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(var(--border), var(--border));
  background-repeat: no-repeat, no-repeat;
  background-position: right 13px center, right 42px center;
  background-size: 18px 18px, 1px 22px;
  padding-right: 52px;
  cursor: pointer;
}

/* Phase 52 — on-brand grouped prompt picker (replaces the native prompt select). */
.prompt-picker { position: relative; width: 100%; }
.prompt-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 40px 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s;
  background-image:
    url("data:image/svg+xml;charset=US-ASCII,%3Csvg width='18' height='18' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%236b7280' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 18px 18px;
}
.prompt-picker-trigger:hover { border-color: var(--border-strong); }
.prompt-picker-trigger:disabled { opacity: 0.55; cursor: not-allowed; }
/* Phase 53 — modifiers so StyledSelect matches the native .select variants. */
.prompt-picker-trigger.is-sm { min-height: 32px; padding: 5px 34px 5px 10px; font-size: 12px; }
.prompt-picker-trigger.is-mono { font-family: var(--font-mono); }
.prompt-picker-row.is-disabled { opacity: 0.5; cursor: not-allowed; }
.prompt-picker-row.is-disabled:hover { background: transparent; }
.prompt-picker-trigger-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prompt-picker-trigger-label strong { font-weight: 600; }
.prompt-picker-sep { color: var(--text-tertiary); }
/* Portaled to <body> + fixed-positioned inline (top/left/width) so it escapes
   ancestor overflow:hidden (.panel) and modal stacking. z-index above drawers. */
.prompt-picker-panel {
  z-index: 4000;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.30);
  overflow: hidden;
}
.prompt-picker-search { padding: 10px; border-bottom: 1px solid var(--border); }
.prompt-picker-search .input { width: 100%; }
.prompt-picker-list { max-height: 340px; overflow-y: auto; padding: 4px; }
.prompt-picker-group {
  position: sticky;
  top: 0;
  background: var(--bg-surface-2);
  color: var(--text-tertiary);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 6px 10px;
  margin: 2px 0;
  border-radius: 5px;
  z-index: 1;
}
.prompt-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.prompt-picker-row:hover { background: var(--bg-active); }
.prompt-picker-row.is-active { background: var(--accent-soft); }
.prompt-picker-task {
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prompt-picker-meta { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
.prompt-picker-badge { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; }
.prompt-picker-badge.is-live { color: var(--success); font-weight: 600; }
.prompt-picker-empty { padding: 16px 12px; text-align: center; color: var(--text-tertiary); font-size: 12px; }

.input-group {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 10px;
  gap: 8px;
  transition: all 0.12s;
}

.input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-group .input {
  border: none;
  background: transparent;
  padding: 7px 0;
}
.input-group .input:focus { box-shadow: none; }

.input-group .icon {
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 180px; }

/* ============================================================
   Cards / panels
   ============================================================ */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-body {
  padding: 18px;
}

.panel-body.no-pad { padding: 0; }

/* ============================================================
   Page wrappers
   ============================================================ */
.page {
  padding: 24px 32px 80px;
  max-width: 1320px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
}

/* ============================================================
   Tables
   ============================================================ */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-tertiary);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.tbl tbody tr {
  transition: background 0.1s;
  cursor: pointer;
}

.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl tbody tr:last-child td { border-bottom: none; }

.cell-mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); }
.cell-muted { color: var(--text-tertiary); }

/* ============================================================
   Badges & status pills
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}

.badge-live { background: var(--success-soft); color: var(--success); border-color: rgba(74, 222, 128, 0.25); }
.badge-draft { background: var(--warning-soft); color: var(--warning); border-color: rgba(251, 191, 36, 0.25); }
.badge-archived { background: var(--bg-active); color: var(--text-tertiary); border-color: var(--border); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: rgba(125, 211, 252, 0.25); }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.badge-error { background: var(--danger-soft); color: var(--danger); border-color: rgba(248, 113, 113, 0.25); }

.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Placeholder chip */
.ph-chip {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin: 2px;
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

.tab .count {
  font-size: 11px;
  background: var(--bg-active);
  padding: 1px 6px;
  border-radius: 10px;
  color: var(--text-tertiary);
}

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}
.segmented-item {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
}
.segmented-item:hover { color: var(--text-primary); }
.segmented-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-tertiary);
  margin-bottom: 14px;
}

.empty-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 380px;
  line-height: 1.55;
  margin-bottom: 16px;
}

/* ============================================================
   Modals & drawers
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideRight { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 640px;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.18s ease;
}

.modal-lg { max-width: 880px; }
.modal-xl { max-width: 1100px; }

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-surface-2);
}

/* Drawer (slide from right) */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 540px;
  max-width: 92vw;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideRight 0.2s ease;
}

/* Quick Test drawer: wider by default and user-resizable from its left edge.
   Scoped to this modifier so other drawers keep the 540px default. */
.drawer-qt {
  width: min(820px, 94vw);
}
.drawer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 6px;
  cursor: ew-resize;
  z-index: 5;
  background: transparent;
}
.drawer-resize-handle:hover,
.drawer-resize-handle.dragging {
  background: var(--accent, #6c8aff);
  opacity: 0.5;
}

.drawer-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-surface-2);
  flex-shrink: 0;
}

/* ============================================================
   Code/prompt display
   ============================================================ */
.code-block {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  overflow-x: auto;
}

.code-block .ph-chip { display: inline; padding: 1px 5px; font-size: 12px; }

/* ============================================================
   Notion-like prompt editor
   ============================================================ */
.prompt-editor {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  min-height: 220px;
  outline: none;
  white-space: pre-wrap;
  color: var(--text-primary);
  transition: all 0.12s;
}

.prompt-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt-editor:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

/* ============================================================
   Notification toast
   ============================================================ */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  min-width: 240px;
  max-width: min(480px, calc(100vw - 40px));
  box-sizing: border-box;
  animation: slideRight 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  overflow: hidden;
}
.toast > .flex-1 {
  /* min-width:0 lets the flex child shrink past its intrinsic content size,
     which is the missing piece that lets word-break actually wrap. */
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
  line-height: 1.4;
}

.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); max-width: min(620px, calc(100vw - 40px)); }
.toast-warning { border-left-color: var(--warning); }
.toast-icon { flex-shrink: 0; margin-top: 1px; }

/* ============================================================
   Misc
   ============================================================ */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

.muted { color: var(--text-tertiary); }
.mono { font-family: var(--font-mono); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }

.hr { height: 1px; background: var(--border); margin: 16px 0; border: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 12px; color: var(--text-tertiary); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.02em; }
.stat-trend { font-size: 11.5px; color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* Score chips */
.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  border: 1px solid transparent;
}
.score-good { background: var(--success-soft); color: var(--success); border-color: rgba(74, 222, 128, 0.25); }
.score-mid { background: var(--warning-soft); color: var(--warning); border-color: rgba(251, 191, 36, 0.25); }
.score-bad { background: var(--danger-soft); color: var(--danger); border-color: rgba(248, 113, 113, 0.25); }

/* Diff-style version preview */
.diff-row {
  display: grid;
  grid-template-columns: 30px 1fr;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
.diff-num { color: var(--text-muted); text-align: right; padding-right: 10px; user-select: none; }
.diff-added { background: var(--success-soft); }
.diff-removed { background: var(--danger-soft); text-decoration: line-through; opacity: 0.7; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  background: var(--bg-surface);
  cursor: pointer;
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  color: var(--text-tertiary);
}
