/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #293548;
  --border:      #334155;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --primary:     #3b82f6;
  --primary-h:   #2563eb;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --record:      #dc2626;
  --record-h:    #b91c1c;
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ─────────────────────────────────────────────── */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 20px;
}
.nav-brand { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -.3px; }
.nav-brand span { color: var(--primary); }
.nav-links { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav-links a, .nav-btn {
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-links a:hover, .nav-btn:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-user { color: var(--text); font-size: 14px; }

/* ── Layout ──────────────────────────────────────────── */
.page { max-width: 900px; margin: 0 auto; padding: 40px 20px; }
.page-narrow { max-width: 480px; margin: 0 auto; padding: 60px 20px; }
.page-wide { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover:not(:disabled)   { background: var(--primary-h); }

.btn-success   { background: var(--success);  color: #fff; }
.btn-success:hover:not(:disabled)   { background: #16a34a; }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled)    { background: #dc2626; }

.btn-record    { background: var(--record);   color: #fff; }
.btn-record:hover:not(:disabled)    { background: var(--record-h); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--border); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 13px 28px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 15px;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }

/* ── Alerts ──────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 7px;
  font-size: 14px;
  margin-bottom: 18px;
  border-left: 4px solid;
}
.alert-error   { background: rgba(239,68,68,.12);  border-color: var(--danger);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.12);  border-color: var(--success); color: #86efac; }
.alert-info    { background: rgba(59,130,246,.12); border-color: var(--primary); color: #93c5fd; }

/* ── Auth pages ──────────────────────────────────────── */
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 28px; font-weight: 700; }
.auth-logo h1 span { color: var(--primary); }
.auth-logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted); }

/* ── Dashboard ───────────────────────────────────────── */
.dashboard-header { display: flex; align-items: center; gap: 20px; margin-bottom: 32px; flex-wrap: wrap; }
.rank-badge {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  border-radius: 12px;
  padding: 16px 24px;
  text-align: center;
  min-width: 160px;
}
.rank-badge .rank-icon { font-size: 32px; }
.rank-badge .rank-name { font-size: 16px; font-weight: 700; margin-top: 4px; }
.rank-badge .rank-pts  { font-size: 12px; opacity: .8; }

.progress-bar-wrap { background: var(--bg); border-radius: 99px; height: 8px; overflow: hidden; margin: 6px 0; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }

.cases-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.case-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color .15s, transform .15s;
}
.case-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.case-card h3 { font-size: 16px; font-weight: 600; }
.case-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-muted);
}
.tag-beginner     { background: rgba(34,197,94,.15);  color: #86efac; }
.tag-intermediate { background: rgba(245,158,11,.15); color: #fcd34d; }
.tag-advanced     { background: rgba(239,68,68,.15);  color: #fca5a5; }
.tag-lang { background: rgba(59,130,246,.15); color: #93c5fd; }

/* ── Session page ────────────────────────────────────── */
.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.session-progress { font-size: 13px; color: var(--text-muted); }

.segment-panel { display: flex; flex-direction: column; gap: 20px; }

.speaker-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .05em;
}
.speaker-a { background: rgba(59,130,246,.2); color: #93c5fd; border: 1px solid rgba(59,130,246,.3); }
.speaker-b { background: rgba(168,85,247,.2); color: #d8b4fe; border: 1px solid rgba(168,85,247,.3); }

.audio-player {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.audio-player audio { display: none; }
.play-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.play-btn:hover { background: var(--primary-h); }
.play-btn:active { transform: scale(.93); }
.audio-info { flex: 1; }
.audio-info p { font-size: 14px; color: var(--text-muted); }
.audio-status { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.record-panel {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.record-panel h4 { font-size: 15px; color: var(--text-muted); }

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--record);
  font-weight: 600;
  font-size: 14px;
}
.rec-dot {
  width: 10px; height: 10px;
  background: var(--record);
  border-radius: 50%;
  animation: blink 1s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }

.timer { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

.transcript-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.7;
  min-height: 80px;
  width: 100%;
}
.transcript-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }

.state-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.state-idle     { background: var(--surface2); color: var(--text-muted); }
.state-playing  { background: rgba(59,130,246,.2); color: #93c5fd; }
.state-recording{ background: rgba(220,38,38,.2); color: #fca5a5; }
.state-processing{ background: rgba(245,158,11,.2); color: #fcd34d; }
.state-done     { background: rgba(34,197,94,.2); color: #86efac; }

/* ── Feedback page ───────────────────────────────────── */
.feedback-header { text-align: center; margin-bottom: 32px; }
.score-display {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.score-label { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.segment-result {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.segment-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface2);
  cursor: pointer;
  user-select: none;
}
.segment-result-body { padding: 18px; display: none; }
.segment-result-body.open { display: block; }

.text-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 600px) { .text-compare { grid-template-columns: 1fr; } }

.text-block {
  background: var(--bg);
  border-radius: 7px;
  padding: 12px;
}
.text-block-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 6px; }

.error-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.error-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 7px;
}
.error-minor    { background: rgba(245,158,11,.1); }
.error-major    { background: rgba(239,68,68,.1); }
.error-critical { background: rgba(220,38,38,.15); border: 1px solid rgba(239,68,68,.3); }
.error-type {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
.praise-box {
  background: rgba(34,197,94,.1);
  border: 1px solid rgba(34,197,94,.25);
  border-radius: 7px;
  padding: 12px 14px;
  color: #86efac;
  font-size: 14px;
  margin-top: 10px;
}

/* ── Admin ───────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

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

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; background: var(--surface2); }
tr:hover td { background: var(--surface2); }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone.dragging { border-color: var(--primary); background: rgba(59,130,246,.05); }
.drop-zone input { display: none; }
.drop-zone p { margin-top: 8px; font-size: 14px; }

/* ── Language selector ───────────────────────────────── */
.lang-grid { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; padding-right: 4px; }
.lang-group-header { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; padding: 8px 0 4px; }
.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .1s;
  border: 1px solid transparent;
}
.lang-option:hover { background: var(--surface2); }
.lang-option.selected { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.35); }
.lang-option input[type=checkbox] { display: none; }
.lang-check { width: 18px; height: 18px; border: 2px solid var(--border); border-radius: 4px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 11px; }
.lang-option.selected .lang-check { background: var(--primary); border-color: var(--primary); }
.lang-name { flex: 1; font-size: 14px; }
.lang-prof-select { padding: 3px 8px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 12px; display: none; }
.lang-option.selected .lang-prof-select { display: block; }

.prof-pill {
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
}
.prof-pill:hover { border-color: var(--primary); color: var(--text); }
.prof-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.selected-langs-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; min-height: 28px; }
.lang-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(59,130,246,.15);
  border: 1px solid rgba(59,130,246,.3);
  font-size: 13px;
  color: #93c5fd;
}

/* ── RTL support ─────────────────────────────────────── */
[dir="rtl"] .nav-links { margin-left: unset; margin-right: auto; }
[dir="rtl"] .nav { flex-direction: row-reverse; }
[dir="rtl"] .dashboard-header { flex-direction: row-reverse; }
[dir="rtl"] .lang-dir { flex-direction: row-reverse; }
[dir="rtl"] .segment-result-header { flex-direction: row-reverse; }
[dir="rtl"] .text-compare { direction: rtl; }
[dir="rtl"] .error-item { flex-direction: row-reverse; text-align: right; }
[dir="rtl"] .alert { border-left: none; border-right: 4px solid; }

/* ── Misc helpers ────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }
