:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --bg-input: #2a2e3d;
  --text-primary: #e4e6ed;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --user-bubble: #4f46e5;
  --assistant-bubble: #2a2e3d;
  --border: #374151;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

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

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

/* ─── Entry Screen ─── */

.entry-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  padding: 20px;
}

.entry-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.entry-card .logo {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent);
}

.entry-card .subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 32px;
  line-height: 1.5;
}

.entry-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

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

.entry-card input::placeholder {
  color: var(--text-muted);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Chat Screen ─── */

.chat-screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

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

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

.chat-header .name {
  font-weight: 600;
  font-size: 16px;
}

.chat-header .status {
  color: var(--success);
  font-size: 13px;
}

.btn-end {
  padding: 8px 16px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* ─── Messages ─── */

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

.message {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 15px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message .time {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  margin-top: 4px;
  display: block;
}

.message.assistant .time {
  color: var(--text-muted);
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  max-width: 100%;
  text-align: center;
  padding: 8px 16px;
  border-radius: 8px;
}

.message.system .time {
  display: none;
}

/* ─── Markdown in messages ─── */

.md-content { line-height: 1.6; }
.md-content p { margin: 0 0 8px 0; }
.md-content p:last-child { margin-bottom: 0; }
.md-content strong { color: #c4b5fd; }
.md-content h2, .md-content h3, .md-content h4 {
  margin: 12px 0 6px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-hover);
}
.md-content h2 { font-size: 16px; }
.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.md-content ul {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}
.md-content li {
  margin-bottom: 4px;
}
.md-content em { font-style: italic; color: var(--text-secondary); }

.typing-indicator {
  align-self: flex-start;
  background: var(--assistant-bubble);
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: none;
}

.typing-indicator.active { display: flex; gap: 4px; }

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ─── Input Area ─── */

.chat-input {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 48px;
  max-height: 120px;
}

.chat-input textarea:focus { border-color: var(--accent); }
.chat-input textarea::placeholder { color: var(--text-muted); }

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

.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Session End ─── */

.session-ended {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.session-ended h3 { margin-bottom: 8px; color: var(--text-primary); }

/* ─── Tabs ─── */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  padding: 10px 24px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Modal ─── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 440px;
  width: 100%;
}

.modal-card h3 { margin-bottom: 20px; }

.modal-card-wide {
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-card input, .modal-card select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}

.modal-card input:focus, .modal-card select:focus { border-color: var(--accent); }
.modal-card select { appearance: auto; }

.modal-card textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
  resize: vertical;
  min-height: 80px;
}

.modal-card textarea:focus { border-color: var(--accent); }
.modal-card textarea::placeholder { color: var(--text-muted); }

.modal-textarea-mono {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  min-height: 200px;
}

.modal-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.modal-row {
  display: flex;
  gap: 12px;
  margin-bottom: 0;
}

.modal-field {
  flex: 1;
}

.modal-checkbox-group {
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.modal-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

.modal-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-bottom: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

.copied-tooltip {
  position: absolute;
  background: var(--success);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  transform: translateY(-100%);
  margin-top: -6px;
}

.users-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

/* ─── Admin Styles ─── */

.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  height: 100vh;
  overflow-y: auto;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.admin-header h1 {
  font-size: 24px;
  font-weight: 700;
}

.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  flex: 1;
  text-align: center;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.filters input, .filters select {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

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

.session-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
}

.session-table th, .session-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.session-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.session-table tr:hover { background: var(--bg-tertiary); }

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

.badge.active { background: rgba(34,197,94,0.15); color: var(--success); }
.badge.completed { background: rgba(99,102,241,0.15); color: var(--accent); }
.badge.abandoned { background: rgba(245,158,11,0.15); color: var(--warning); }

.btn-view {
  padding: 6px 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}

.btn-view:hover { background: var(--accent-hover); }

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
}

.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination button.active { background: var(--accent); border-color: var(--accent); }

/* ─── Admin Login ─── */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.login-card h2 { margin-bottom: 24px; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

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

.error-msg {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}

/* ─── Transcript View ─── */

.transcript-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.transcript-header .back {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

.transcript-meta {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

.transcript-meta .field {
  display: flex;
  flex-direction: column;
}

.transcript-meta .field .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.transcript-meta .field .value {
  font-size: 15px;
  font-weight: 600;
}

.transcript-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 0;
}

/* ─── Simulation Feedback Components (shared by sim + admin) ─── */

.sim-outcome-banner {
  text-align: center;
  padding: 24px;
  border-radius: 16px;
  margin-bottom: 24px;
}

.sim-outcome-banner.outcome-set {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.sim-outcome-banner.outcome-declined {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.sim-outcome-banner.outcome-died {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.sim-outcome-banner.outcome-gaveup {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.sim-outcome-banner .outcome-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.sim-outcome-banner .outcome-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.sim-outcome-banner.outcome-set .outcome-text { color: var(--success); }
.sim-outcome-banner.outcome-declined .outcome-text { color: var(--warning); }
.sim-outcome-banner.outcome-died .outcome-text { color: var(--danger); }
.sim-outcome-banner.outcome-gaveup .outcome-text { color: rgb(148, 163, 184); }

.outcome-corrected-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: -16px;
  margin-bottom: 24px;
}

.sim-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.sim-stats-row .sim-stat-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.sim-stat-item .sim-stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.sim-stat-item .sim-stat-desc {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.sim-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  margin-top: 4px;
}

.sim-score-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.sim-score-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.sim-score-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.sim-score-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.sim-score-card-weight {
  font-size: 11px;
  color: var(--text-muted);
}

.sim-score-card-value {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.sim-score-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.sim-score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

.sim-feedback-list {
  margin-bottom: 24px;
}

.sim-feedback-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
}

.sim-feedback-item .sim-fb-why {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.5;
}

.sim-feedback-item .sim-fb-reinforcement {
  font-size: 13px;
  color: var(--accent-hover);
  line-height: 1.5;
}

.sim-violation-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.sim-violation-label.type-violation {
  color: var(--danger);
}

.sim-violation-label.type-strength {
  color: var(--success);
}

.sim-coaching {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.sim-coaching .sim-coaching-text {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Admin results-specific */

.admin-results-inner {
  max-width: 720px;
  padding: 20px 0;
}

.admin-results-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.admin-results-empty h3 {
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-size: 18px;
}

.admin-results-empty p {
  font-size: 14px;
}

.admin-timeline-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-timeline-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
}

.admin-timeline-item.coaching {
  border-left-color: var(--warning);
}

.admin-timeline-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.admin-timeline-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-timeline-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 4px;
  padding: 3px 8px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.admin-timeline-badge.process {
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
}

.admin-timeline-badge.coaching {
  background: rgba(255, 193, 7, 0.16);
  color: var(--warning);
}

.admin-timeline-time,
.admin-timeline-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.admin-timeline-title {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.admin-timeline-message,
.admin-timeline-payload {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.admin-timeline-payload {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.admin-commitment {
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.admin-commitment h4 {
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 8px;
}

.admin-commitment .commitment-text {
  color: var(--text-primary);
  font-size: 14px;
  font-style: italic;
  line-height: 1.6;
}

.admin-commitment .commitment-time {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 8px;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .message { max-width: 85%; }
  .entry-card { padding: 32px 24px; }
  .stats-bar { flex-wrap: wrap; }
  .stat-card { min-width: 140px; }
  .filters { flex-wrap: wrap; }
  .transcript-meta { gap: 16px; }
  .sim-score-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .message { max-width: 90%; }
  .chat-input { padding: 12px; }
}
