/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --border-light: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;

  --emotion-color: #a78bfa;
  --emotion-bg: rgba(167, 139, 250, 0.12);
  --distortion-color: #fb923c;
  --distortion-bg: rgba(251, 146, 60, 0.12);
  --empathy-color: #34d399;
  --empathy-bg: rgba(52, 211, 153, 0.12);
  --highlight-color: #fbbf24;

  --speaker-bg: #1a2332;
  --speaker-border: #1d4ed8;
  --listener-bg: #1a2b1f;
  --listener-border: #16a34a;

  /* Highlight colors for evidence quotes */
  --hl-distortion-1: rgba(251, 146, 60, 0.25);
  --hl-distortion-2: rgba(248, 113, 113, 0.25);
  --hl-distortion-3: rgba(251, 191, 36, 0.25);

  --hl-empathy-concern: rgba(96, 165, 250, 0.22);
  --hl-empathy-expressiveness: rgba(167, 139, 250, 0.22);
  --hl-empathy-resonate: rgba(52, 211, 153, 0.22);
  --hl-empathy-warmth: rgba(251, 191, 36, 0.22);
  --hl-empathy-attuned: rgba(251, 146, 60, 0.22);
  --hl-empathy-cognitive: rgba(248, 113, 113, 0.22);
  --hl-empathy-feelings: rgba(129, 140, 248, 0.22);
  --hl-empathy-acceptance: rgba(45, 212, 191, 0.22);
  --hl-empathy-responsiveness: rgba(232, 121, 249, 0.22);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.3);

  --header-h: 60px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Header ===== */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(13, 17, 23, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 100;
}
.header-inner {
  max-width: 100%;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--empathy-color));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.header-logo h1 { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.header-logo p { font-size: 0.75rem; color: var(--text-muted); }
.header-controls { display: flex; align-items: center; gap: 12px; }

.file-upload-area {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.file-upload-area:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-hover); }
.file-upload-area input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
}
.sample-counter {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.sample-counter #currentIdx { color: var(--accent); font-weight: 600; }

/* ===== Welcome Screen ===== */
.welcome-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 50;
  padding: 20px;
}
.welcome-card {
  max-width: 480px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow);
}
.welcome-icon {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, rgba(88,166,255,0.15), rgba(52,211,153,0.15));
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 24px;
  color: var(--accent);
}
.welcome-card h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 10px; }
.welcome-card p { color: var(--text-secondary); line-height: 1.6; margin-bottom: 28px; }
.welcome-features {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 32px;
  text-align: left;
}
.feature-item {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.875rem; color: var(--text-secondary);
}
.feature-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.welcome-upload-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--accent), #388bfd);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
  font-size: 0.9rem;
}
.welcome-upload-btn:hover { opacity: 0.9; transform: translateY(-1px); }

/* ===== Main Layout ===== */
.main-layout {
  position: fixed;
  inset: 0;
  top: var(--header-h);
  display: grid;
  grid-template-columns: 200px 1fr 480px;
  overflow: hidden;
}

/* ===== Nav Panel ===== */
.nav-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.nav-panel-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-panel-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.search-box {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 0.8rem; width: 100%;
}
.search-box input::placeholder { color: var(--text-muted); }

.sample-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sample-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.sample-item:hover { background: var(--bg-hover); }
.sample-item.active {
  background: rgba(88,166,255,0.1);
  border-color: rgba(88,166,255,0.3);
}
.sample-item-idx {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 2px;
}
.sample-item-emotion {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 2px;
}
.sample-item-problem {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Conversation Panel ===== */
.conversation-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}
.conv-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg-secondary);
}
.conv-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meta-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.legend { display: flex; align-items: center; gap: 14px; }
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.75rem; color: var(--text-muted);
}
.legend-dot {
  width: 8px; height: 8px; border-radius: 2px;
}
.legend-dot.speaker { background: var(--speaker-border); }
.legend-dot.listener { background: var(--listener-border); }

.conversation-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  font-size: 0.875rem;
  line-height: 1.6;
  position: relative;
  transition: all 0.2s;
}
.message-bubble.speaker {
  background: var(--speaker-bg);
  border-color: var(--speaker-border);
  align-self: flex-end;
  border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius);
}
.message-bubble.listener {
  background: var(--listener-bg);
  border-color: var(--listener-border);
  align-self: flex-start;
  border-radius: var(--radius) var(--radius) var(--radius) var(--radius-sm);
}
.message-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  opacity: 0.7;
}
.message-bubble.speaker .message-label { color: #60a5fa; }
.message-bubble.listener .message-label { color: #4ade80; }

/* Highlighted evidence text */
mark.evidence-hl {
  background: transparent;
  border-radius: 3px;
  padding: 1px 0;
  cursor: pointer;
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
  position: relative;
}
mark.evidence-hl:hover { filter: brightness(1.3); }
mark.evidence-pulse {
  animation: evidence-glow 0.6s ease-in-out 3;
  border-radius: 4px;
}
@keyframes evidence-glow {
  0%, 100% { box-shadow: none; filter: brightness(1); }
  50% { box-shadow: 0 0 12px 4px rgba(251, 191, 36, 0.5); filter: brightness(1.5); }
}

/* Distortion highlights */
mark.dist-hl-0 { background: var(--hl-distortion-1); border-bottom-color: #fb923c; color: inherit; }
mark.dist-hl-1 { background: var(--hl-distortion-2); border-bottom-color: #f87171; color: inherit; }
mark.dist-hl-2 { background: var(--hl-distortion-3); border-bottom-color: #fbbf24; color: inherit; }

/* Empathy dimension highlights */
mark.emp-hl-0 { background: var(--hl-empathy-concern); border-bottom-color: #60a5fa; color: inherit; }
mark.emp-hl-1 { background: var(--hl-empathy-expressiveness); border-bottom-color: #a78bfa; color: inherit; }
mark.emp-hl-2 { background: var(--hl-empathy-resonate); border-bottom-color: #34d399; color: inherit; }
mark.emp-hl-3 { background: var(--hl-empathy-warmth); border-bottom-color: #fbbf24; color: inherit; }
mark.emp-hl-4 { background: var(--hl-empathy-attuned); border-bottom-color: #fb923c; color: inherit; }
mark.emp-hl-5 { background: var(--hl-empathy-cognitive); border-bottom-color: #f87171; color: inherit; }
mark.emp-hl-6 { background: var(--hl-empathy-feelings); border-bottom-color: #818cf8; color: inherit; }
mark.emp-hl-7 { background: var(--hl-empathy-acceptance); border-bottom-color: #2dd4bf; color: inherit; }
mark.emp-hl-8 { background: var(--hl-empathy-responsiveness); border-bottom-color: #e879f9; color: inherit; }

/* ===== Annotation Panel ===== */
.annotation-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  min-height: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.anno-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: visible;
  flex-shrink: 0;
  transition: border-color 0.2s;
}
.anno-card:hover { border-color: var(--border-light); }
.anno-card-header {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.anno-card-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  flex: 1;
}
.anno-card-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.emotion-icon { background: var(--emotion-bg); color: var(--emotion-color); }
.distortion-icon { background: var(--distortion-bg); color: var(--distortion-color); }
.empathy-icon { background: var(--empathy-bg); color: var(--empathy-color); }

.anno-content { padding: 14px 16px; }

/* Emotion */
.emotion-primary {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.emotion-comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.emotion-comparison-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.025);
}
.emotion-comparison-label {
  margin-bottom: 7px;
  color: var(--text-muted);
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.emotion-comparison-item .emotion-badge {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emotion-unavailable { opacity: 0.55; }
.emotion-prediction-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.emotion-match-status {
  padding: 4px 9px;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 700;
}
.emotion-match-status.is-match {
  color: #34d399;
  background: rgba(52,211,153,0.12);
  border-color: rgba(52,211,153,0.3);
}
.emotion-match-status.is-different {
  color: #fbbf24;
  background: rgba(251,191,36,0.12);
  border-color: rgba(251,191,36,0.3);
}
.emotion-badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--emotion-bg);
  color: var(--emotion-color);
  border: 1px solid rgba(167,139,250,0.3);
}
.intensity-badge {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid;
}
.intensity-high { background: rgba(248,113,113,0.15); color: #f87171; border-color: rgba(248,113,113,0.3); }
.intensity-medium { background: rgba(251,191,36,0.15); color: #fbbf24; border-color: rgba(251,191,36,0.3); }
.intensity-low { background: rgba(52,211,153,0.15); color: #34d399; border-color: rgba(52,211,153,0.3); }
.emotion-reasoning {
  font-size: 0.83rem;
  color: var(--text-secondary);
  line-height: 1.7;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--emotion-color);
}
.specific-term {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.specific-term span { color: var(--emotion-color); font-weight: 600; }

.emotion-reasoning-block { margin-top: 8px; }
.reasoning-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 5px;
}

/* Distortions */
.distortion-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.distortion-item:last-child { margin-bottom: 0; }
.distortion-item:hover { border-color: var(--distortion-color); background: var(--distortion-bg); }
.distortion-item.active { border-color: var(--distortion-color); background: var(--distortion-bg); }
.distortion-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--distortion-color);
  margin-bottom: 7px;
  display: flex; align-items: center; gap: 8px;
}
.dist-color-dot {
  width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0;
}
.distortion-quote {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 7px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
  border-left: 3px solid;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.5;
}
.distortion-reasoning {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.no-distortions {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.no-distortions svg { margin: 0 auto 6px; display: block; opacity: 0.4; }

/* Empathy */
.overall-score {
  margin-left: auto;
  padding: 3px 10px;
  background: var(--empathy-bg);
  color: var(--empathy-color);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid rgba(52,211,153,0.3);
}
.empathy-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.empathy-item:last-child { margin-bottom: 0; }
.empathy-item:hover { border-color: rgba(52,211,153,0.4); background: rgba(52,211,153,0.06); }
.empathy-item.active { border-color: rgba(52,211,153,0.5); background: rgba(52,211,153,0.08); }
.empathy-item-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.emp-color-dot {
  width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0;
}
.empathy-name {
  font-size: 0.82rem;
  font-weight: 600;
  flex: 1;
  color: var(--text-primary);
}
.score-bar-container {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.score-bar {
  width: 80px; height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.score-value {
  font-size: 0.78rem;
  font-weight: 700;
  width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.empathy-quote {
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: 5px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
  border-left: 3px solid;
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 6px;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}
.empathy-reasoning {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  display: none;
}
.empathy-item.active .empathy-reasoning { display: block; }

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 320px;
}
.tooltip.visible { opacity: 1; pointer-events: auto; }
.tooltip-content {
  background: #1c2128;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  font-size: 0.78rem;
  line-height: 1.6;
}
.tooltip-title {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 0.82rem;
}
.tooltip-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 3px;
  margin-top: 8px;
}
.tooltip-text { color: var(--text-secondary); }
.tooltip-score {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.75rem;
}

/* ===== Nav Arrows ===== */
.nav-arrows {
  position: fixed;
  bottom: 24px;
  right: 500px;
  display: flex;
  gap: 8px;
  z-index: 200;
}
.nav-btn {
  width: 40px; height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.nav-btn:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== Emotion colors by type ===== */
.emotion-fear { background: rgba(248,113,113,0.15); color: #f87171; border-color: rgba(248,113,113,0.3); }
.emotion-sadness { background: rgba(96,165,250,0.15); color: #60a5fa; border-color: rgba(96,165,250,0.3); }
.emotion-anger { background: rgba(251,146,60,0.15); color: #fb923c; border-color: rgba(251,146,60,0.3); }
.emotion-joy { background: rgba(251,191,36,0.15); color: #fbbf24; border-color: rgba(251,191,36,0.3); }
.emotion-anxiety { background: rgba(167,139,250,0.15); color: #a78bfa; border-color: rgba(167,139,250,0.3); }
.emotion-shame { background: rgba(232,121,249,0.15); color: #e879f9; border-color: rgba(232,121,249,0.3); }
.emotion-depression { background: rgba(99,102,241,0.15); color: #818cf8; border-color: rgba(99,102,241,0.3); }
.emotion-default { background: var(--emotion-bg); color: var(--emotion-color); border: 1px solid rgba(167,139,250,0.3); }

/* Problem type badge */
.problem-badge {
  padding: 3px 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  color: var(--text-muted);
}
.experience-badge {
  padding: 3px 8px;
  background: rgba(88,166,255,0.08);
  border: 1px solid rgba(88,166,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  color: var(--accent);
}
