/* ─── IELTS Platform Design System ─────────────────────────────────────────── */
:root {
  --red: #D0021B;
  --dark: #1a1a2e;
  --dark2: #16213e;
  --mid: #0f3460;
  --accent: #e94560;
  --light: #f8f9fa;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --success: #198754;
  --warning: #ffc107;
  --shadow: 0 2px 20px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: #f0f2f5; color: var(--text); line-height: 1.6; }

/* ─── IELTS Header Bar ─── */
.ielts-topbar {
  background: white;
  border-bottom: 3px solid #e0e0e0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.ielts-badge {
  background: var(--red);
  color: white;
  font-weight: 800;
  font-size: 18px;
  padding: 4px 14px;
  border-radius: 4px;
  letter-spacing: 1px;
}
.topbar-title { font-size: 15px; color: #444; font-weight: 500; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ─── Login Page ─── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--dark) 0%, var(--mid) 100%);
}
.login-box {
  background: white;
  border-radius: var(--radius);
  padding: 48px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .badge-big {
  background: var(--red);
  color: white;
  font-weight: 900;
  font-size: 28px;
  padding: 8px 24px;
  border-radius: 6px;
  display: inline-block;
  margin-bottom: 12px;
}
.login-logo h2 { font-size: 20px; color: var(--dark); }
.login-logo p { color: var(--muted); font-size: 14px; }

/* ─── Forms ─── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; color: #444; }
.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color 0.2s;
  outline: none;
}
.form-control:focus { border-color: var(--red); }
select.form-control { background: white; cursor: pointer; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary { background: var(--red); color: white; }
.btn-primary:hover { background: #b01818; }
.btn-dark { background: var(--dark); color: white; }
.btn-dark:hover { background: var(--mid); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #157347; }
.btn-outline { background: white; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--red); color: var(--red); }
.btn-danger { background: #dc3545; color: white; }
.btn-danger:hover { background: #bb2d3b; }
.btn-warning { background: var(--warning); color: #333; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ─── Alert ─── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-danger { background: #fdeaea; border: 1px solid #f5c6cb; color: #721c24; }
.alert-success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; }
.alert-info { background: #d1ecf1; border: 1px solid #bee5eb; color: #0c5460; }
.alert-warning { background: #fff3cd; border: 1px solid #ffc107; color: #856404; }

/* ─── Dashboard ─── */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--dark); margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.test-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.test-card:hover { border-color: var(--red); transform: translateY(-2px); }
.test-card-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 20px;
}
.type-listening { background: #e8f4fd; color: #0066cc; }
.type-reading { background: #fdf0e8; color: #cc5500; }
.test-card h3 { font-size: 17px; font-weight: 700; color: var(--dark); }
.test-card .meta { font-size: 13px; color: var(--muted); }
.score-badge { font-size: 16px; font-weight: 700; color: var(--success); }
.score-badge.partial { color: var(--warning); }

/* ─── Test Interface ─── */
.test-layout { display: flex; height: calc(100vh - 60px); overflow: hidden; }
.passage-panel {
  width: 50%;
  padding: 24px;
  overflow-y: auto;
  border-right: 2px solid var(--border);
  background: white;
}
.questions-panel {
  width: 50%;
  padding: 24px;
  overflow-y: auto;
  background: #fafafa;
}
.passage-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.passage-author { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.passage-text { font-size: 15px; line-height: 1.9; color: #333; text-align: justify; }
.passage-text p { margin-bottom: 16px; }

/* ─── Question Groups ─── */
.q-section { margin-bottom: 32px; }
.q-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.q-instruction {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #f0f2f5;
  border-left: 3px solid var(--red);
  border-radius: 0 6px 6px 0;
}
.question-item { margin-bottom: 20px; }
.q-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--dark);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}
.q-text { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 10px; display: flex; align-items: flex-start; }
.q-text span { flex: 1; }

/* TF / MCQ radios */
.radio-group, .checkbox-group { display: flex; flex-direction: column; gap: 8px; padding-left: 36px; }
.radio-opt, .check-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
}
.radio-opt:hover, .check-opt:hover { border-color: var(--red); background: #fef9f9; }
.radio-opt input, .check-opt input { accent-color: var(--red); width: 16px; height: 16px; }
.radio-opt.selected, .check-opt.selected { border-color: var(--red); background: #fef0f0; }

/* Fill-in inputs */
.fill-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-left: 36px;
  width: calc(100% - 36px);
}
.fill-input:focus { border-color: var(--red); outline: none; }

/* Matching */
.match-table { width: calc(100% - 36px); margin-left: 36px; border-collapse: collapse; }
.match-table th { background: var(--dark); color: white; padding: 8px 12px; font-size: 13px; }
.match-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.match-table td:first-child { width: 60%; }
.match-select { width: 100%; padding: 6px 10px; border: 2px solid var(--border); border-radius: 6px; font-size: 13px; }
.match-select:focus { border-color: var(--red); outline: none; }

/* ─── Listening Interface ─── */
.listening-layout { display: flex; flex-direction: column; height: calc(100vh - 60px); }
.listening-start {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dark);
}
.start-box {
  background: white;
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  max-width: 520px;
  width: 90%;
}
.headphone-icon { font-size: 80px; margin-bottom: 24px; color: var(--dark); }
.start-box h2 { font-size: 24px; font-weight: 700; margin-bottom: 12px; }
.start-box .warning { color: var(--muted); font-size: 14px; margin-bottom: 32px; line-height: 1.7; }
.btn-play {
  background: var(--dark);
  color: white;
  padding: 16px 40px;
  border-radius: 50px;
  font-size: 17px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
}
.btn-play:hover { background: var(--mid); transform: scale(1.03); }

.listening-active { display: none; flex: 1; overflow: hidden; }
.listening-active.visible { display: flex; }
.listen-questions { flex: 1; padding: 24px; overflow-y: auto; background: #fafafa; }
.audio-bar {
  background: var(--dark);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}
.audio-progress { display: flex; align-items: center; gap: 12px; flex: 1; margin: 0 24px; }
.progress-bar { flex: 1; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--red); transition: width 0.5s linear; width: 0; }

/* ─── Part Navigator ─── */
.part-nav {
  background: white;
  border-top: 2px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.part-item { display: flex; align-items: center; gap: 6px; }
.q-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.q-dot.answered { background: var(--dark); color: white; border-color: var(--dark); }
.q-dot.current { border-color: var(--red); color: var(--red); }

/* ─── Submit Bar ─── */
.submit-bar {
  position: sticky;
  bottom: 0;
  background: white;
  border-top: 2px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.answered-count { font-size: 13px; color: var(--muted); }

/* ─── Admin Panel ─── */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px;
  background: var(--dark);
  color: white;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo .badge { background: var(--red); padding: 4px 10px; border-radius: 4px; font-weight: 800; font-size: 16px; display: inline-block; margin-bottom: 4px; }
.sidebar-logo p { font-size: 11px; color: rgba(255,255,255,0.5); margin-top: 4px; }
.sidebar-nav { flex: 1; padding: 16px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.1); color: white; }
.nav-item .icon { font-size: 18px; width: 20px; }

.admin-content { flex: 1; padding: 32px; overflow-y: auto; background: #f0f2f5; }
.admin-header { margin-bottom: 28px; }
.admin-header h1 { font-size: 24px; font-weight: 700; color: var(--dark); }
.admin-header p { color: var(--muted); font-size: 14px; }

/* ─── Cards / Stats ─── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: white; border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }
.stat-card .num { font-size: 32px; font-weight: 800; color: var(--dark); }
.stat-card .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }

.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; }
.card-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 16px; font-weight: 700; }
.card-body { padding: 24px; }

/* ─── Table ─── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { background: #f8f9fa; font-weight: 600; padding: 10px 14px; text-align: left; border-bottom: 2px solid var(--border); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8f9fa; }

/* ─── Status badges ─── */
.badge-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #f8d7da; color: #721c24; }
.badge-submitted { background: #d1ecf1; color: #0c5460; }
.badge-pending { background: #fff3cd; color: #856404; }

/* ─── Question Builder ─── */
.q-builder { border: 2px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.q-builder-header {
  background: #f8f9fa;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
}
.q-builder-header:hover { background: #e9ecef; }
.q-builder-body { padding: 20px; display: none; }
.q-builder-body.open { display: block; }
.q-type-tag {
  background: var(--mid);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

/* Add question form */
.add-q-panel { background: white; border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }
.add-q-panel h3 { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.options-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.option-row { display: flex; gap: 8px; align-items: center; }
.option-row input { flex: 1; }
.option-row .btn-sm { padding: 8px 12px; }

/* ─── Results ─── */
.result-student { background: white; border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px; box-shadow: var(--shadow); }
.result-name { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.result-tests { display: flex; flex-wrap: wrap; gap: 12px; }
.result-test-item {
  background: #f8f9fa;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.result-test-item .score { font-weight: 700; font-size: 18px; color: var(--dark); }
.result-test-item .label { font-size: 12px; color: var(--muted); }
.result-test-item .date { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  display: none;
}
.modal-overlay.open { display: flex; }
.modal-box { background: white; border-radius: var(--radius); padding: 32px; width: 90%; max-width: 500px; }
.modal-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; justify-content: flex-end; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .test-layout { flex-direction: column; }
  .passage-panel, .questions-panel { width: 100%; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .admin-sidebar { display: none; }
}

/* ── Fix question number badge ─────────────────────────────────────────────── */
.qnum-badge {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  background: var(--mid) !important;
  color: white !important;
  border-radius: 50% !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  flex-shrink: 0 !important;
  line-height: 1 !important;
  padding: 0 !important;
}

/* Also fix .q-num used in student test */
.q-num {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  max-width: 28px !important;
  border-radius: 50% !important;
  flex-shrink: 0 !important;
  padding: 0 !important;
  line-height: 1 !important;
}

/* ── Highlighter toolbar ───────────────────────────────────────────────────── */
#highlightToolbar {
  position: fixed;
  background: var(--dark);
  border-radius: 8px;
  padding: 6px 8px;
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.hl-btn {
  border: none;
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.hl-btn:hover { opacity: .85; }
.hl-yellow { background: #FFE066; color: #333; }
.hl-green  { background: #6EE7B7; color: #1a472a; }
.hl-pink   { background: #FCA5A5; color: #7f1d1d; }
.hl-clear  { background: rgba(255,255,255,.15); color: white; font-size: 11px; }

/* highlighted text marks */
.hl-y { background: #FFE066; border-radius: 2px; }
.hl-g { background: #6EE7B7; border-radius: 2px; }
.hl-p { background: #FCA5A5; border-radius: 2px; }

/* ── Dropdown select question type (student view) ──────────────────────────── */
.inline-select-q {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}
.inline-select-q .q-num { margin-top: 2px; }
.inline-select-wrap {
  flex: 1;
}
.inline-select-wrap .q-stmt {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  line-height: 1.6;
}
.inline-select-wrap select {
  width: 100%;
  max-width: 300px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: white;
  cursor: pointer;
}
.inline-select-wrap select:focus { border-color: var(--red); outline: none; }
