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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232733;
  --border: #2e3344;
  --text: #e1e4ed;
  --text-dim: #8b8fa3;
  --accent: #4f8ff7;
  --accent-dim: #2a4a8a;
  --danger: #e55c5c;
  --danger-dim: #5c2a2a;
  --warning: #e5a84f;
  --warning-dim: #5c4a2a;
  --success: #4fc78e;
  --success-dim: #2a5c4a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Setup Screen ── */
.setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  max-width: 460px;
  width: 100%;
}

.setup-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.setup-card .subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
  line-height: 1.5;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-group .hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 12px;
}

.btn-primary:hover {
  background: #3a7ae0;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

/* Language selector */
.language-selector {
  display: flex;
  gap: 8px;
}

.lang-btn {
  padding: 8px 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lang-btn.lang-active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.sup-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s;
}

.sup-link:hover {
  color: var(--accent);
}

/* ── Chat Screen ── */
.chat-screen {
  display: none;
  height: 100vh;
  flex-direction: column;
}

.chat-screen.active {
  display: flex;
}

.setup-screen.hidden {
  display: none;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header h2 {
  font-size: 16px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.badge-returning {
  background: var(--warning-dim);
  color: var(--warning);
}

.badge-new {
  background: var(--success-dim);
  color: var(--success);
}

.volunteer-tag {
  color: var(--text-dim);
  font-size: 13px;
}

/* Header right group */
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Session timer */
.session-timer {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Main content area */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Chat panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-caller {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.message-volunteer {
  align-self: flex-end;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
}

.message-system {
  align-self: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
}

.message .sender {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.typing-indicator {
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 14px;
  display: none;
}

.typing-indicator.visible {
  display: block;
}

/* Reply suggestions */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 24px 0;
  min-height: 0;
}

.suggestions:empty {
  display: none;
}

.suggestion-chip {
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  max-width: 100%;
  text-align: left;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
}

.suggestion-chip:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

/* Input area */
.input-area {
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.input-area input {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.input-area input:focus {
  border-color: var(--accent);
}

.btn-send {
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-send:hover {
  background: #3a7ae0;
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-mic {
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.btn-mic.mic-active {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: var(--danger);
  animation: micPulse 1.5s ease infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 92, 92, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(229, 92, 92, 0); }
}

/* Context sidebar */
.context-panel {
  width: 360px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 20px;
}

.context-panel h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

/* Session diff block */
.session-diff {
  background: var(--danger-dim);
  border: 1px solid rgba(229, 92, 92, 0.3);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
  animation: fadeIn 0.3s ease;
}

.diff-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--danger);
  margin-bottom: 8px;
}

.diff-item {
  font-size: 12px;
  line-height: 1.5;
  padding: 4px 0;
  font-weight: 600;
}

.diff-escalation {
  color: var(--danger);
}

.diff-new {
  color: var(--warning);
}

.diff-strategy {
  color: var(--success);
}

/* Briefing block */
.briefing-block {
  background: var(--warning-dim);
  border: 1px solid rgba(229, 168, 79, 0.3);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-line;
}

/* Live context sections */
.context-section {
  margin-bottom: 20px;
}

.context-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.context-section-title.danger {
  color: var(--danger);
}

.context-section-title.warning {
  color: var(--warning);
}

.context-section-title.success {
  color: var(--success);
}

.context-section-title.info {
  color: var(--accent);
}

.context-list {
  list-style: none;
  padding: 0;
}

.context-list li {
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 4px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
}

.risk-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.risk-low {
  background: var(--success-dim);
  color: var(--success);
}

.risk-moderate {
  background: var(--warning-dim);
  color: var(--warning);
}

.risk-high {
  background: var(--danger-dim);
  color: var(--danger);
}

.context-section-title.addressed {
  color: var(--text-dim);
  opacity: 0.6;
}

.context-addressed {
  opacity: 0.5;
  transition: opacity 0.3s ease;
}

.context-addressed:hover {
  opacity: 0.8;
}

.context-item-faded {
  text-decoration: line-through;
  opacity: 0.6;
}

.mood-text {
  font-size: 13px;
  color: var(--text-dim);
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  line-height: 1.4;
}

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
}

/* Risk escalation alert */
.risk-alert {
  background: var(--danger);
  color: white;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  animation: alertFlash 0.6s ease;
}

.risk-alert-icon {
  font-size: 16px;
}

.risk-alert-dismiss {
  opacity: 0;
  transition: opacity 0.5s ease;
}

@keyframes alertFlash {
  0%, 50%, 100% { opacity: 1; }
  25%, 75% { opacity: 0.5; }
}

/* Coaching tips */
.coaching-tip {
  align-self: flex-end;
  max-width: 75%;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
  transition: opacity 0.5s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.coaching-tip.coaching-fade {
  opacity: 0.3;
}

.coaching-good {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(79, 199, 142, 0.2);
}

.coaching-needs_improvement {
  background: var(--warning-dim);
  color: var(--warning);
  border: 1px solid rgba(229, 168, 79, 0.2);
}

.coaching-caution {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(229, 92, 92, 0.2);
}

.coaching-icon {
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.coaching-technique {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.7;
  margin-left: 4px;
}

/* Export button */
.btn-secondary {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

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

/* End session bar */
.session-bar {
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

/* Extraction overlay */
.extraction-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 100;
  overflow-y: auto;
  padding: 40px 20px;
}

.extraction-overlay.visible {
  display: flex;
}

.extraction-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  max-height: 80vh;
  overflow-y: auto;
}

.extraction-card h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.extraction-card p {
  color: var(--text-dim);
  margin-bottom: 8px;
  text-align: left;
}

.extraction-card ul {
  text-align: left;
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}

.extraction-card ul li {
  padding: 4px 10px;
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 4px;
  line-height: 1.4;
}

.extraction-card h4 {
  margin-bottom: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

/* ── Memory Timeline ── */
.timeline {
  position: relative;
  margin: 0 0 20px 0;
  padding: 0;
}

.timeline-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.timeline-header::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* Vertical line running behind the nodes */
.timeline-track {
  position: relative;
  padding-left: 20px;
}

.timeline-track::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

/* Individual session node */
.timeline-node {
  position: relative;
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

/* The dot on the vertical line */
.timeline-node::before {
  content: "";
  position: absolute;
  left: -20px;
  top: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--accent);
  z-index: 1;
}

/* Risk-colored dot variants */
.timeline-node.risk-high::before {
  border-color: var(--danger);
  background: var(--danger-dim);
  box-shadow: 0 0 6px rgba(229, 92, 92, 0.4);
}

.timeline-node.risk-moderate::before {
  border-color: var(--warning);
  background: var(--warning-dim);
}

.timeline-node.risk-low::before {
  border-color: var(--success);
  background: var(--success-dim);
}

/* Session card */
.timeline-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

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

.timeline-session-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.timeline-risk-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.timeline-risk-badge.risk-low {
  background: var(--success-dim);
  color: var(--success);
}

.timeline-risk-badge.risk-moderate {
  background: var(--warning-dim);
  color: var(--warning);
}

.timeline-risk-badge.risk-high {
  background: var(--danger-dim);
  color: var(--danger);
}

.timeline-risk-badge.risk-unknown {
  background: var(--surface);
  color: var(--text-dim);
}

.timeline-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
  line-height: 1.4;
}

.timeline-summary {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 8px;
  border-left: 2px solid var(--border);
  padding-left: 8px;
}

/* Diff items */
.timeline-diff-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline-diff-list li {
  font-size: 11px;
  line-height: 1.5;
  padding: 3px 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.timeline-diff-list li::before {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 11px;
  margin-top: 1px;
}

/* New info: green plus */
.timeline-diff-new li {
  color: var(--success);
}

.timeline-diff-new li::before {
  content: "+";
  color: var(--success);
}

/* Escalations: red arrow up */
.timeline-diff-escalation li {
  color: var(--danger);
}

.timeline-diff-escalation li::before {
  content: "\2191";
  color: var(--danger);
}

/* Resolved: dimmed with checkmark */
.timeline-diff-resolved li {
  color: var(--text-dim);
}

.timeline-diff-resolved li::before {
  content: "\2713";
  color: var(--success);
}

/* Connector line at the very bottom after last node */
.timeline-track .timeline-node:last-child {
  margin-bottom: 0;
}

/* Collapse/expand toggle */
.timeline-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
  display: block;
  width: 100%;
  text-align: center;
}

.timeline-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

/* ── Emergency Protocol Overlay ── */
.emergency-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(92, 20, 20, 0.85);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 40px 20px;
  animation: alertFlash 0.6s ease;
}

.emergency-overlay.visible {
  display: flex;
}

.emergency-card {
  background: var(--surface);
  border: 2px solid var(--danger);
  border-radius: 16px;
  padding: 36px;
  max-width: 520px;
  width: 90%;
}

.emergency-header {
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--danger);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.emergency-header::before {
  content: "\26A0";
  font-size: 20px;
}

.emergency-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.emergency-checklist {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 0 0 24px 0;
}

.emergency-checklist li {
  counter-increment: step;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.emergency-checklist li::before {
  content: counter(step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--danger-dim);
  color: var(--danger);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.emergency-checklist label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  flex: 1;
}

.emergency-checklist input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--danger);
  flex-shrink: 0;
}

.emergency-card .btn-danger {
  width: 100%;
  margin-top: 4px;
}

/* ── Mood Arc (Risk Sparkline) ── */
.mood-arc-svg {
  display: block;
  margin-top: 4px;
}

#mood-arc {
  margin-top: 16px;
}

/* ── Volunteer Performance Summary ── */
.performance-summary {
  text-align: left;
  margin: 16px 0;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.performance-summary h5 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 12px;
}

.perf-stat {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
  color: var(--text-dim);
}

.perf-stat .perf-value {
  color: var(--text);
  font-weight: 600;
}

.perf-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0 4px;
  background: var(--surface);
}

.perf-bar-good {
  background: var(--success);
}

.perf-bar-improve {
  background: var(--warning);
}

.perf-bar-caution {
  background: var(--danger);
}

.perf-techniques {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.perf-technique-tag {
  padding: 3px 8px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
  .context-panel {
    display: none;
  }
}
