/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #252837; --border: #2e3148;
  --accent: #6c63ff; --accent-hover: #5a52e0; --green: #22c55e;
  --yellow: #f59e0b; --red: #ef4444; --text: #e2e8f0; --muted: #94a3b8;
  --radius: 10px; --font: 'Segoe UI', system-ui, sans-serif;
}
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { padding-left: 1.2rem; } li { margin-bottom: .3rem; }
code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-size: .85rem; }

.navbar { display: flex; align-items: center; justify-content: space-between; padding: .85rem 2rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-brand { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { color: var(--muted); font-size: .95rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

.btn { display: inline-block; padding: .6rem 1.2rem; border-radius: var(--radius); font-size: .95rem; font-weight: 600; border: none; cursor: pointer; transition: background .15s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }
.btn-sm { padding: .3rem .75rem; font-size: .85rem; }
.btn-mic { width: 56px; height: 56px; border-radius: 50%; font-size: 1.4rem; background: var(--accent); color: #fff; border: none; cursor: pointer; transition: background .15s, box-shadow .15s; flex-shrink: 0; }
.btn-mic.recording { background: var(--red); box-shadow: 0 0 0 6px rgba(239,68,68,.25); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{box-shadow:0 0 0 6px rgba(239,68,68,.25)} 50%{box-shadow:0 0 0 12px rgba(239,68,68,.08)} }

.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.badge-live { background: rgba(34,197,94,.15); color: var(--green); }
.badge-active { background: rgba(245,158,11,.15); color: var(--yellow); }
.badge-completed { background: rgba(108,99,255,.15); color: var(--accent); }

.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: 1.9rem; margin-bottom: .4rem; }
.page-header p { color: var(--muted); }

.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; transition: border-color .2s, transform .2s; }
.job-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.job-card h2 { font-size: 1.15rem; }
.job-card p { color: var(--muted); font-size: .9rem; flex: 1; }

.room-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; height: calc(100vh - 120px); }
.room-main { display: flex; flex-direction: column; gap: 1rem; overflow: hidden; }
.room-header { display: flex; align-items: center; gap: 1rem; }
.room-header h1 { font-size: 1.4rem; }

.transcript { flex: 1; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.static-transcript { height: auto; max-height: 500px; }
.turn { display: flex; flex-direction: column; gap: .3rem; max-width: 85%; }
.turn-interviewer { align-self: flex-start; }
.turn-candidate { align-self: flex-end; }
.turn-label { font-size: .75rem; color: var(--muted); font-weight: 600; }
.turn-label small { font-weight: 400; margin-left: .5rem; }
.turn-interviewer p, .turn-candidate p {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.turn-interviewer p { background: var(--surface2); border: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: .75rem 1rem; }
.turn-candidate p { background: rgba(108,99,255,.18); border: 1px solid rgba(108,99,255,.3); border-radius: var(--radius) 0 var(--radius) var(--radius); padding: .75rem 1rem; }

.input-area { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.status-bar { font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
.controls { display: flex; gap: .75rem; align-items: flex-end; }
textarea { flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius); padding: .6rem .8rem; font-family: var(--font); font-size: .95rem; resize: none; }
textarea:focus { outline: none; border-color: var(--accent); }

.panel-sidebar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; overflow-y: auto; }
.panel-sidebar h3 { font-size: .95rem; margin-bottom: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.panel-section { margin-bottom: 1rem; }
.panel-section strong { font-size: .8rem; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: .35rem; }
.panel-section ul { padding-left: 1rem; }
.panel-section li, .panel-section p { font-size: .85rem; color: var(--text); }
.panel-empty { font-size: .85rem; color: var(--muted); }

.result-layout { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 2rem; }
.result-header h1 { font-size: 2rem; }
.result-header h2 { color: var(--accent); font-size: 1.3rem; margin-top: .25rem; }
.result-meta { color: var(--muted); font-size: .85rem; margin-top: .5rem; }
.eval-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; display: grid; grid-template-columns: 110px 1fr; gap: 1.5rem; }
.score-ring { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100px; height: 100px; border-radius: 50%; border: 4px solid var(--accent); background: rgba(108,99,255,.1); }
.score-number { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.score-label { font-size: .8rem; color: var(--muted); }
.eval-details { display: flex; flex-direction: column; gap: 1rem; }
.eval-section h3 { font-size: 1rem; margin-bottom: .5rem; }
.eval-summary p { color: var(--muted); font-size: .95rem; }
.transcript-section h2 { font-size: 1.4rem; margin-bottom: 1rem; }
.result-actions { display: flex; gap: 1rem; }

.filter-form { margin-top: .75rem; }
.filter-form select { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .75rem; margin-left: .5rem; cursor: pointer; }
.history-table-wrap { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; }
.history-table th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.history-table tr:hover td { background: var(--surface2); }
.empty-row { text-align: center; color: var(--muted); padding: 2rem; }

/* ── Video Mode Styles ── */
.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  border: 2px solid var(--border);
  transition: all 0.3s ease;
}

.video-container.hidden {
  display: none;
}

.video-container.active {
  display: block;
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(108,99,255,0.3);
}

#userVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  transform: scaleX(-1); /* Mirror effect like Zoom */
}

/* Loading spinner for camera initialization */
.video-container::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 1;
}

.video-container.active::before {
  display: none;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Video toggle button active state */
#videoToggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Analytics Styles ── */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.analytics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.analytics-card h3 {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.chart-container {
  position: relative;
  height: 300px;
  margin-top: 1rem;
}

.topic-tag {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  margin: 0.25rem;
  background: rgba(108, 99, 255, 0.15);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid rgba(108, 99, 255, 0.3);
}

.ratio-bar {
  display: flex;
  height: 40px;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 1rem 0;
}

.ratio-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s;
}

.ratio-candidate {
  background: rgba(108, 99, 255, 0.3);
  color: var(--accent);
}

.ratio-interviewer {
  background: var(--surface2);
  color: var(--muted);
}

.ratio-legend {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.ratio-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ratio-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.ratio-dot.candidate {
  background: rgba(108, 99, 255, 0.5);
}

.ratio-dot.interviewer {
  background: var(--surface2);
}

@media (max-width: 768px) {
  .room-layout { grid-template-columns: 1fr; height: auto; }
  .panel-sidebar { order: -1; max-height: 200px; }
  .eval-card { grid-template-columns: 1fr; }
  .score-ring { margin: 0 auto; }
  .video-container { aspect-ratio: 4 / 3; }
  .analytics-grid { grid-template-columns: 1fr; }
}
