/* ═══════════════════════════════════════════════════════════════
   RagDoctor — Clean Light Theme
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg-primary:    #f5f6f8;
  --bg-secondary:  #ffffff;
  --bg-tertiary:   #eceef2;
  --bg-card:       #f2f3f6;
  --border:        rgba(0,0,0,.11);
  --border-light:  rgba(0,0,0,.16);
  --text-primary:  #1a1d24;
  --text-secondary:#374151;
  --text-muted:    #6b7280;
  --accent:        #0d9488;
  --accent-hover:  #0f766e;
  --accent-bg:     rgba(13,148,136,.08);
  --success:       #059669;
  --danger:        #e11d48;
  --warning:       #d97706;
  --radius:        12px;
  --radius-lg:     18px;
  --font-mono:     'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
  --sidebar-w:     340px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.rd-root { height: 100vh; overflow: hidden; }

/* ── App Layout ──────────────────────────────────────────── */
.rd-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.rd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}
.rd-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.rd-logo { font-size: 32px; }
.rd-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.rd-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}
.rd-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Body (sidebar + main) ───────────────────────────────── */
.rd-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.rd-sidebar {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.rd-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
}
.rd-sidebar-footer {
  flex-shrink: 0;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.rd-brand {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

/* ── Config Sections ─────────────────────────────────────── */
.rd-config-section {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.rd-config-section:last-child { border-bottom: none; }
.rd-config-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--accent);
  margin-bottom: 14px;
}

/* ── Form Fields ─────────────────────────────────────────── */
.rd-field {
  margin-bottom: 14px;
}
.rd-field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.rd-field input[type="text"],
.rd-field input[type="password"],
.rd-field input[type="number"],
.rd-field textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.rd-field input[type="text"]::placeholder,
.rd-field input[type="password"]::placeholder,
.rd-field input[type="number"]::placeholder,
.rd-field textarea::placeholder {
  color: var(--text-muted);
}
.rd-field input:focus,
.rd-field textarea:focus {
  border-color: var(--accent);
}
.rd-field textarea {
  resize: vertical;
  font-family: inherit;
}
.rd-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.rd-val {
  float: right;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}
.rd-optional {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Radio Group ─────────────────────────────────────────── */
.rd-radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.rd-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 0;
}
.rd-radio input { accent-color: var(--accent); }

/* ── Badges ──────────────────────────────────────────────── */
.rd-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
}
.rd-badge-ok {
  background: rgba(5,150,105,.08);
  color: var(--success);
  border: 1px solid rgba(5,150,105,.2);
}
.rd-badge-warn {
  background: rgba(217,119,6,.08);
  color: var(--warning);
  border: 1px solid rgba(217,119,6,.2);
}
.rd-badge-empty {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Buttons ─────────────────────────────────────────────── */
.rd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 12px 24px;
  transition: all .15s;
  white-space: nowrap;
}
.rd-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.rd-btn-primary {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}
.rd-btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 2px 12px rgba(13,148,136,.25);
}
.rd-btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.rd-btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}
.rd-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
}
.rd-btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: rgba(0,0,0,.04);
}
.rd-btn-full { width: 100%; }
.rd-btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 16px;
  transition: all .15s;
}
.rd-btn-icon:hover {
  color: var(--danger);
  background: rgba(225,29,72,.06);
}

/* ── Spinner ─────────────────────────────────────────────── */
.rd-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: rd-spin .8s linear infinite;
}
@keyframes rd-spin { to { transform: rotate(360deg); } }

/* ── Tabs ────────────────────────────────────────────────── */
.rd-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  flex-shrink: 0;
  background: var(--bg-secondary);
}
.rd-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 16px 26px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.rd-tab:hover { color: var(--text-primary); }
.rd-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.rd-tab-count {
  font-size: 12px;
  font-weight: 700;
  background: rgba(0,0,0,.06);
  color: var(--text-secondary);
  padding: 2px 9px;
  border-radius: 999px;
}
.rd-tab.active .rd-tab-count {
  background: rgba(13,148,136,.1);
  color: var(--accent);
}

/* ── Main Content ────────────────────────────────────────── */
.rd-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.rd-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
}

/* ── Panels ──────────────────────────────────────────────── */
.rd-panel {
  max-width: 900px;
}
.rd-panel-wide {
  max-width: 1200px;
}
.rd-panel-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 18px;
}

/* ── Info / Error boxes ──────────────────────────────────── */
.rd-info-box {
  margin-top: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  background: rgba(13,148,136,.06);
  color: var(--accent);
  border: 1px solid rgba(13,148,136,.15);
  line-height: 1.5;
}
.rd-error-box {
  margin-top: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  background: rgba(225,29,72,.05);
  color: var(--danger);
  border: 1px solid rgba(225,29,72,.15);
  line-height: 1.5;
}

/* ── Rows & Helpers ──────────────────────────────────────── */
.rd-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.rd-divider {
  font-size: 14px;
  color: var(--text-muted);
}
.rd-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.rd-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 72px 28px;
  font-size: 18px;
}
.rd-empty p { margin-bottom: 10px; }
.rd-file-label { cursor: pointer; }

/* ── Input Wide ──────────────────────────────────────────── */
.rd-input-wide {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.rd-input-wide:focus { border-color: var(--accent); }

.rd-textarea-full {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: border-color .15s;
}
.rd-textarea-full:focus { border-color: var(--accent); }

/* ── Provider Info ───────────────────────────────────────── */
.rd-provider-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.rd-provider-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.rd-model-badge {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-bg);
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid rgba(13,148,136,.15);
}

/* ── API Key Status ─────────────────────────────────────── */
.rd-key-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.rd-key-loading {
  color: var(--text-muted);
  background: var(--bg-tertiary);
}
.rd-key-ok {
  color: var(--success);
  background: rgba(5,150,105,.06);
  border: 1px solid rgba(5,150,105,.15);
}
.rd-key-ok .rd-btn-icon {
  margin-left: auto;
  font-size: 14px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.rd-key-ok .rd-btn-icon:hover {
  background: rgba(0,0,0,.06);
  color: var(--text-primary);
}
.rd-key-source {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}
.rd-key-form {
  margin-bottom: 12px;
}
.rd-key-form .rd-field {
  margin-bottom: 8px;
}
.rd-key-form input[type="password"] {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color .15s;
}
.rd-key-form input[type="password"]:focus {
  border-color: var(--accent);
}
.rd-error-sm {
  margin-top: 6px;
  padding: 8px 12px;
  font-size: 12px;
}

/* ── Document Mode Toggle ───────────────────────────────── */
.rd-tab-infobar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  background: var(--accent-bg);
  border-left: 3px solid var(--accent);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.rd-tab-infobar-icon {
  flex-shrink: 0;
  font-size: 16px;
}
.rd-mode-toggle {
  display: flex;
  gap: 0;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}
.rd-mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: all .15s;
}
.rd-mode-btn:hover { color: var(--text-primary); }
.rd-mode-btn.active {
  background: var(--bg-secondary);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ── Upload Zone ────────────────────────────────────────── */
.rd-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 32px;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: border-color .2s, background .2s;
  text-align: center;
}
.rd-upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.rd-upload-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .8;
}
.rd-upload-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.rd-upload-formats {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: .3px;
}

/* Upload Zone – busy state */
.rd-upload-zone-busy {
  border-color: var(--accent);
  background: var(--accent-bg);
  cursor: default;
  pointer-events: none;
}
.rd-upload-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}
.rd-spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}
.rd-upload-status {
  font-size: 14px;
  color: var(--text-secondary);
  word-break: break-all;
  text-align: center;
  margin: 0;
}
.rd-upload-bar-track {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.rd-upload-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s ease;
}
.rd-upload-counter {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin: 0;
}

/* ── Text Input Zone ────────────────────────────────────── */
.rd-text-input-zone {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

/* ── Document Layout (2-column) ──────────────────────────── */
.rd-doc-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}
.rd-doc-input-area {
  min-width: 0;
}
.rd-doc-list-area {
  min-width: 0;
}

/* ── Document List ───────────────────────────────────────── */
.rd-doc-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rd-doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: border-color .15s, background .4s, box-shadow .4s;
}
.rd-doc-item:hover { border-color: var(--border-light); }
.rd-doc-item.rd-doc-new {
  animation: rd-doc-flash .7s ease;
}
@keyframes rd-doc-flash {
  0%   { background: rgba(13,148,136,.25); box-shadow: 0 0 0 3px rgba(13,148,136,.2); transform: translateX(8px); opacity: 0; }
  40%  { background: rgba(13,148,136,.12); transform: translateX(0); opacity: 1; }
  100% { background: var(--bg-secondary); box-shadow: none; }
}

/* ── Document Empty State ────────────────────────────────── */
.rd-doc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  text-align: center;
}
.rd-doc-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: .5;
}
.rd-doc-empty p {
  font-size: 15px;
  color: var(--text-muted);
}
.rd-doc-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rd-doc-name {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rd-doc-meta {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Chunk Cards ─────────────────────────────────────────── */
.rd-chunk-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.rd-chunk-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.rd-chunk-card-clickable {
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.rd-chunk-card-clickable:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(13,148,136,.1);
  background: var(--bg-tertiary);
}
.rd-chunk-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.rd-chunk-id {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.rd-chunk-size {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}
.rd-chunk-preview {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.rd-chunk-content {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-tertiary);
  padding: 14px;
  border-radius: 6px;
  margin: 0;
}
.rd-results-header {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

/* ── Query Form ──────────────────────────────────────────── */
.rd-query-form {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.rd-query-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
.rd-query-summary strong { color: var(--text-primary); }

/* ── Scores Table ────────────────────────────────────────── */
.rd-scores-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.rd-scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.rd-scores-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.rd-scores-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}
.rd-scores-table tbody tr { cursor: pointer; transition: background .15s; }
.rd-scores-table tbody tr:hover { background: var(--bg-tertiary); }
.rd-scores-table tbody tr.rd-row-selected {
  background: rgba(13,148,136,.14) !important;
  box-shadow: inset 4px 0 0 var(--accent), 0 0 0 1px rgba(13,148,136,.2);
}
.rd-scores-table tbody tr.rd-row-selected td {
  color: var(--text-primary);
  font-weight: 500;
}
.rd-rank {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.rd-score-cell {
  position: relative;
  font-family: var(--font-mono);
  white-space: nowrap;
  width: 100px;
}
.rd-score-cell span {
  position: relative;
  z-index: 1;
}
.rd-score-bar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: rgba(13,148,136,.08);
  pointer-events: none;
}
.rd-flags {
  white-space: nowrap;
}
.rd-flag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  margin-right: 4px;
}
.rd-flag-topk {
  background: rgba(13,148,136,.1);
  color: var(--accent);
}
.rd-flag-target {
  background: rgba(5,150,105,.1);
  color: var(--success);
}
.rd-flag-filtered {
  background: rgba(225,29,72,.06);
  color: var(--danger);
}
.rd-preview {
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rd-row-target td { background: rgba(5,150,105,.06) !important; }
.rd-row-dim td { opacity: .55; }

/* ── Detail Modal ─────────────────────────────────────────── */
.rd-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(4px);
  animation: rd-fade-in .2s ease;
}
@keyframes rd-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.rd-modal {
  width: min(720px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: rd-modal-pop .25s ease;
}
@keyframes rd-modal-pop {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.rd-modal-footer {
  display: flex;
  justify-content: flex-end;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.rd-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  background: var(--accent-bg);
  border-bottom: 1px solid var(--border);
}
.rd-detail-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.rd-detail-rank {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.rd-detail-score-badge {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-secondary);
  padding: 4px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.rd-detail-score-bar-wrap {
  position: relative;
  height: 28px;
  background: var(--bg-tertiary);
  overflow: hidden;
}
.rd-detail-score-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(13,148,136,.15), rgba(13,148,136,.3));
  transition: width .4s ease;
}
.rd-detail-score-label {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.rd-detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.rd-detail-meta-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 22px;
  background: var(--bg-secondary);
}
.rd-detail-meta-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.rd-detail-meta-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}
.rd-mono {
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
}
.rd-detail-section {
  padding: 18px 22px;
  border-top: 1px solid var(--border);
}
.rd-detail-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--accent);
  margin-bottom: 12px;
}
.rd-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.rd-meta-tag {
  display: inline-block;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.rd-detail-content {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-tertiary);
  padding: 18px;
  border-radius: var(--radius);
  margin: 0;
}

/* ── Diagnostics
.rd-diag-section {
  margin-bottom: 32px;
}
.rd-diag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.rd-diag-header .rd-panel-title { margin-bottom: 0; }

/* Health Check Items */
.rd-health-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.rd-health-summary strong { color: var(--text-primary); }
.rd-health-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rd-health-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg-secondary);
  border-left: 4px solid var(--border);
}
.rd-health-pass  { border-left-color: var(--success); }
.rd-health-warning { border-left-color: var(--warning); }
.rd-health-fail  { border-left-color: var(--danger); }
.rd-health-info  { border-left-color: var(--accent); }
.rd-health-icon {
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
.rd-health-cat {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 120px;
  flex-shrink: 0;
}
.rd-health-msg { color: var(--text-secondary); word-break: break-word; }

/* WhyMissing */
.rd-missing-result { margin-top: 20px; }
.rd-missing-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
.rd-missing-header strong { color: var(--text-primary); }
.rd-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rd-step {
  padding: 16px 20px;
  border-radius: var(--radius);
  border-left: 4px solid var(--border);
  background: var(--bg-secondary);
}
.rd-step-pass    { border-left-color: var(--success); }
.rd-step-warning { border-left-color: var(--warning); }
.rd-step-fail    { border-left-color: var(--danger); }
.rd-step-info    { border-left-color: var(--accent); }
.rd-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 16px;
}
.rd-step-icon { font-size: 18px; }
.rd-step-msg {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding-left: 26px;
  white-space: pre-wrap;
  word-break: break-word;
}
.rd-step-suggestion {
  font-size: 14px;
  color: var(--accent);
  padding-left: 26px;
  margin-top: 6px;
}
.rd-suggestions {
  margin-top: 20px;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: rgba(13,148,136,.04);
  border: 1px solid rgba(13,148,136,.1);
}
.rd-suggestions h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}
.rd-suggestions ol {
  padding-left: 22px;
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ── Pipeline Steps ──────────────────────────────────────── */
.rd-pipeline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 14px 32px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rd-pipeline-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  transition: all .25s;
}
.rd-pipeline-step.active {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: rgba(13,148,136,.2);
}
.rd-pipeline-step.done {
  color: var(--success);
  background: rgba(5,150,105,.06);
  border-color: rgba(5,150,105,.15);
}
.rd-pipeline-num {
  font-size: 15px;
}
.rd-pipeline-arrow {
  padding: 0 14px;
  color: var(--border-light);
  font-size: 18px;
  font-weight: 300;
}

/* ── CTA Card (Build Prompt) ─────────────────────────────── */
.rd-cta-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 32px;
  margin-top: 28px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--accent);
  background: var(--accent-bg);
}
.rd-cta-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.rd-cta-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.rd-cta-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ── Success Card ────────────────────────────────────────── */
.rd-success-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 32px;
  margin-top: 28px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(5,150,105,.2);
  background: rgba(5,150,105,.04);
}
.rd-success-card .rd-cta-icon { color: var(--success); }
.rd-success-card .rd-cta-title {
  color: var(--success);
  margin-bottom: 16px;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.18); }

/* ── Vector Space Universe ───────────────────────────────── */
.rd-panel.rd-panel-universe {
  background: #000000;
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  max-width: none;
  width: 100%;
}
.rd-panel-title-light { color: #e2e8f0; }
.rd-hint-light { color: #94a3b8; }

.rd-universe-header { margin-bottom: 16px; }

.rd-universe-body {
  display: flex;
  gap: 0;
}
.rd-universe-body-split {
  gap: 16px;
}
.rd-universe-main {
  flex: 1;
  min-width: 0;
}

.rd-universe-sidebar {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  overflow: hidden;
  transition: width .25s ease;
}
.rd-universe-sidebar-collapsed {
  width: 40px;
  min-width: 40px;
}
.rd-universe-sidebar-collapsed .rd-universe-sidebar-header {
  flex-direction: column;
  padding: 8px 4px;
  gap: 0;
}
.rd-universe-sidebar-collapsed .rd-universe-sidebar-header > span {
  display: none;
}
.rd-universe-sidebar-collapsed .rd-universe-sidebar-scroll {
  display: none;
}
.rd-btn-sidebar-toggle {
  margin-left: auto;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 6px;
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
}
.rd-btn-sidebar-toggle:hover {
  background: rgba(255,255,255,.12);
  color: #e2e8f0;
}
.rd-universe-sidebar-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 14px;
  font-size: 12px;
  color: #94a3b8;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.rd-universe-sidebar-header strong { color: #e2e8f0; }
.rd-universe-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  max-height: 520px;
}

/* Dark variant of scores table for universe sidebar */
.rd-scores-table-dark {
  color: #cbd5e1;
}
.rd-scores-table-dark thead th {
  background: rgba(255,255,255,.04);
  color: #94a3b8;
  border-bottom-color: rgba(255,255,255,.08);
}
.rd-scores-table-dark tbody tr {
  border-bottom-color: rgba(255,255,255,.05);
  cursor: pointer;
  transition: background .15s;
}
.rd-scores-table-dark tbody tr:hover {
  background: rgba(255,255,255,.06);
}
.rd-scores-table-dark tbody tr.rd-row-selected {
  background: rgba(0,255,204,.1);
  box-shadow: inset 3px 0 0 #00ffcc;
}
.rd-scores-table-dark .rd-score-cell {
  color: #e2e8f0;
}
.rd-scores-table-dark .rd-score-bar {
  background: rgba(68,136,255,.3);
}
.rd-scores-table-dark .rd-preview {
  color: #94a3b8;
}
.rd-scores-table-dark .rd-rank {
  color: #64748b;
}
.rd-scores-table-dark .rd-row-dim {
  opacity: 0.5;
}
.rd-scores-table-dark .rd-row-dim:hover {
  opacity: 0.8;
}

.rd-universe-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.rd-universe-controls .rd-field {
  flex: 1;
  margin-bottom: 0;
}
.rd-field-dark input[type="text"] {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  width: 100%;
}
.rd-field-dark input[type="text"]::placeholder { color: #64748b; }
.rd-field-dark input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}
.rd-btn-ghost-light {
  background: transparent;
  color: #94a3b8;
  border: 1px solid rgba(255,255,255,.15);
}
.rd-btn-ghost-light:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }

.rd-universe-canvas {
  width: 100%;
  height: 520px;
  min-height: 400px;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: #000000;
  border: 1px solid rgba(255,255,255,.04);
}

/* Fullscreen mode */
.rd-universe-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  max-width: none;
  border-radius: 0;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rd-universe-fullscreen .rd-universe-canvas {
  flex: 1;
  height: auto;
  min-height: 0;
  border-radius: 0;
  border: none;
}
.rd-universe-fullscreen .rd-universe-body {
  flex: 1;
  min-height: 0;
}
.rd-universe-fullscreen .rd-universe-main {
  display: flex;
  flex-direction: column;
}
.rd-universe-fullscreen .rd-universe-sidebar {
  max-height: none;
}
.rd-universe-fullscreen .rd-universe-sidebar-scroll {
  max-height: none;
  flex: 1;
}
.rd-universe-fullscreen .rd-universe-header { margin-bottom: 10px; }
.rd-universe-fullscreen .rd-universe-legend { margin-top: 10px; padding: 6px 0; }

/* Fullscreen icon button */
.rd-btn-icon-dark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  transition: all .2s;
}
.rd-btn-icon-dark:hover {
  background: rgba(255,255,255,.12);
  color: #e2e8f0;
}

.rd-universe-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
  padding: 10px 0;
}

/* MinScore slider */
.rd-universe-minscore {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
}
.rd-minscore-label {
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.rd-minscore-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #4488ff;
  min-width: 36px;
  text-align: right;
}
.rd-universe-minscore input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.rd-universe-minscore input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4488ff;
  border: 2px solid #000;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(68,136,255,.5);
}
.rd-universe-minscore input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4488ff;
  border: 2px solid #000;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(68,136,255,.5);
}
.rd-btn-minscore-clear {
  background: transparent;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 4px;
  color: #64748b;
  font-size: 13px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
}
.rd-btn-minscore-clear:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }
.rd-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: #94a3b8;
}
.rd-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.rd-legend-line {
  width: 18px;
  height: 0;
  border-top: 2px dashed #66eecc;
  flex-shrink: 0;
}

/* Three.js tooltip */
.vu-tooltip {
  position: absolute;
  z-index: 100;
  pointer-events: none;
  background: rgba(10,14,30,.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 300px;
  font-size: 13px;
  color: #e2e8f0;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.vu-tt-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #64748b;
  margin-bottom: 4px;
  word-break: break-all;
}
.vu-tt-src {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
}
.vu-tt-coords {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #8b9fc4;
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}
.vu-tt-score {
  position: relative;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  background: rgba(255,255,255,.06);
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 5px;
  overflow: hidden;
}
.vu-tt-score-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(68,136,255,.25);
  border-radius: 4px;
}
.vu-tt-preview {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Navigation HUD */
.vu-hud {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(148,163,184,.7);
}
.vu-hud span {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 4px;
  padding: 3px 8px;
}
.vu-hud-speed { color: #4488ff; }
.vu-hud-hint { color: rgba(148,163,184,.45); font-size: 10px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1100px) {
  .rd-doc-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .rd-body { grid-template-columns: 1fr; }
  .rd-sidebar { display: none; }
}
