/* ============================================================
   ExamPortal — Main Stylesheet
   Mobile-first, responsive, no external dependencies
   ============================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  --primary:      #4f46e5;
  --primary-dark: #4338ca;
  --primary-light:#ede9fe;
  --secondary:    #6b7280;
  --success:      #059669;
  --success-light:#d1fae5;
  --danger:       #dc2626;
  --danger-light: #fee2e2;
  --warning:      #d97706;
  --warning-light:#fef3c7;
  --info:         #0284c7;
  --info-light:   #e0f2fe;
  --purple:       #7c3aed;
  --purple-light: #ede9fe;
  --gray:         #9ca3af;
  --gray-light:   #f3f4f6;
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e5e7eb;
  --text:         #1f2937;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    14px;
  --shadow:       0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
  --navbar-h:     60px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
img  { max-width: 100%; height: auto; display: block; }
a    { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { padding-left: 1.4rem; }

/* ── Typography ─────────────────────────────────────────────── */
h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 700; color: var(--text); }
h2 { font-size: clamp(1.1rem, 2.5vw, 1.4rem); font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
small { font-size: .8rem; }
code { background: var(--gray-light); padding: .1em .35em; border-radius: 4px; font-size: .875rem; font-family: 'Courier New', monospace; }
p { margin-bottom: .75rem; }
p:last-child { margin-bottom: 0; }

/* ── Utility ────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-center  { text-align: center; }
.text-danger  { color: var(--danger); }
.mt-1 { margin-top: .75rem; }
.mt-2 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1.5rem; }
.empty-state  { padding: 2rem; text-align: center; color: var(--text-muted); font-style: italic; }

/* ── Navbar ─────────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--navbar-h);
  background: var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
.navbar-brand a { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; white-space: nowrap; }
.navbar-menu { display: flex; align-items: center; gap: .25rem; list-style: none; margin: 0; padding: 0; }
.navbar-menu a { color: rgba(255,255,255,.88); font-size: .9rem; padding: .45rem .75rem; border-radius: var(--radius-sm); transition: background .2s; text-decoration: none; white-space: nowrap; }
.navbar-menu a:hover { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.navbar-user { display: flex; align-items: center; gap: .5rem; padding-left: .75rem; border-left: 1px solid rgba(255,255,255,.2); }
.navbar-user span { color: rgba(255,255,255,.8); font-size: .85rem; white-space: nowrap; }
.navbar-toggle { display: none; background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; padding: .3rem; }

@media (max-width: 768px) {
  .navbar { flex-wrap: wrap; height: auto; padding: .5rem 1rem; gap: .5rem; }
  .navbar-brand { flex: 1; }
  .navbar-toggle { display: block; }
  .navbar-menu { display: none; flex-direction: column; align-items: stretch; width: 100%; background: var(--primary-dark); border-radius: var(--radius-sm); padding: .5rem; gap: .1rem; }
  .navbar-menu.open { display: flex; }
  .navbar-menu a { padding: .6rem .9rem; }
  .navbar-user { border-left: none; border-top: 1px solid rgba(255,255,255,.2); padding-top: .5rem; padding-left: 0; flex-wrap: wrap; }
}

/* ── Main Content ───────────────────────────────────────────── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }

/* ── Page Header ────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
.page-header h1 { margin: 0; }

/* ── Cards ──────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

/* ── Stats Grid ─────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow); border: 1px solid var(--border); border-left: 4px solid var(--primary); }
.stat-blue   { border-left-color: var(--primary); }
.stat-green  { border-left-color: var(--success); }
.stat-purple { border-left-color: var(--purple); }
.stat-orange { border-left-color: var(--warning); }
.stat-icon  { font-size: 2rem; line-height: 1; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .2rem; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1.1rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; transition: background .18s, border-color .18s, opacity .18s; white-space: nowrap; text-decoration: none; line-height: 1.4; }
.btn:hover { text-decoration: none; opacity: .88; }
.btn-primary   { background: var(--primary);   color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); opacity: 1; }
.btn-secondary { background: var(--surface);   color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--gray-light); opacity: 1; }
.btn-danger    { background: var(--danger);    color: #fff; border-color: var(--danger); }
.btn-warning   { background: var(--warning);   color: #fff; border-color: var(--warning); }
.btn-sm   { padding: .3rem .65rem; font-size: .8rem; }
.btn-full { width: 100%; }
.btn-group { display: flex; flex-wrap: wrap; gap: .35rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-row   { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: .2rem; }
label { display: block; font-size: .875rem; font-weight: 600; color: var(--text); margin-bottom: .35rem; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=file], select, textarea {
  width: 100%; padding: .6rem .85rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: .95rem; font-family: var(--font); color: var(--text); background: var(--surface);
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
input:disabled, select:disabled { background: var(--gray-light); cursor: not-allowed; color: var(--text-muted); }
textarea { resize: vertical; min-height: 100px; }
.input-group { display: flex; gap: .5rem; }
.input-group input { flex: 1; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.form-label-heading { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-weight: 400; cursor: pointer; padding: .2rem 0; }
.checkbox-label input[type=checkbox] { width: auto; margin: 0; cursor: pointer; accent-color: var(--primary); }
.permissions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .4rem; padding: .9rem; background: var(--gray-light); border-radius: var(--radius-sm); margin-bottom: 1rem; }
.inline-form { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.inline-form label { margin: 0; white-space: nowrap; }
.inline-form select { width: auto; min-width: 220px; }
.option-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.option-row input { flex: 1; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { background: var(--gray-light); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .7rem .9rem; text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { padding: .75rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-light); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .2em .55em; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-red    { background: var(--danger-light);  color: var(--danger); }
.badge-blue   { background: var(--info-light);    color: var(--info); }
.badge-purple { background: var(--purple-light);  color: var(--purple); }
.badge-orange { background: var(--warning-light); color: var(--warning); }
.badge-gray   { background: var(--gray-light);    color: var(--secondary); }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert { padding: .85rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; }
.alert ul { margin: .4rem 0 0 1rem; }
.alert-success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--info-light);    color: #075985; border-color: #7dd3fc; }

/* ── Filter Bar ─────────────────────────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }

/* ── Auth Pages ─────────────────────────────────────────────── */
.auth-page { background: linear-gradient(135deg, #ede9fe 0%, #dbeafe 100%); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-container { width: 100%; max-width: 420px; }
.auth-card { background: var(--surface); border-radius: var(--radius-lg); padding: 2.25rem; box-shadow: var(--shadow-lg); }
.auth-logo  { font-size: 2.5rem; text-align: center; margin-bottom: .5rem; }
.auth-title { text-align: center; font-size: 1.5rem; margin-bottom: .25rem; }
.auth-sub   { text-align: center; color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.auth-form .form-group { margin-bottom: 1rem; }
.auth-footer { text-align: center; font-size: .85rem; color: var(--text-muted); margin-top: 1.25rem; }

/* ── Instructions / Notice ──────────────────────────────────── */
.instructions-box { background: var(--info-light); border-left: 3px solid var(--info); padding: .85rem 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-bottom: 1.2rem; font-size: .9rem; }
.exam-notice { background: var(--warning-light); border: 1px solid #fcd34d; border-radius: var(--radius-sm); padding: .85rem 1rem; margin: 1rem 0; font-size: .875rem; }
.exam-notice ul { margin-top: .4rem; }

/* ── Exam Link Box ──────────────────────────────────────────── */
.exam-link-box { background: var(--info-light); border-radius: var(--radius-sm); padding: .85rem 1rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; font-size: .875rem; }
.exam-link-box code { flex: 1; font-size: .82rem; word-break: break-all; }

/* ── Result Pages ───────────────────────────────────────────── */
.result-header-card { background: var(--primary); color: #fff; border-radius: var(--radius-lg); padding: 2rem; text-align: center; margin-bottom: 1.25rem; }
.result-header-card h1 { color: #fff; margin-bottom: .25rem; }
.result-header-card p  { color: rgba(255,255,255,.8); margin-bottom: .5rem; }
.result-check      { font-size: 3rem; margin-bottom: .5rem; }
.result-score-big  { font-size: 2.5rem; font-weight: 800; margin: .5rem 0; }
.result-pct        { font-size: 1.2rem; opacity: .8; }
.result-answer-row { padding: 1rem; border-bottom: 1px solid var(--border); }
.result-answer-row:last-child { border-bottom: none; }
.result-q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .5rem; font-size: .85rem; }
.ans-correct { border-left: 3px solid var(--success); padding-left: .85rem; }
.ans-wrong   { border-left: 3px solid var(--danger);  padding-left: .85rem; }
.ans-theory  { border-left: 3px solid var(--purple);  padding-left: .85rem; }

/* ── Result Detail (admin) ──────────────────────────────────── */
.result-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.detail-row:last-child { border-bottom: none; }
.detail-row span { color: var(--text-muted); }
.score-big { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.answer-row { padding: 1rem; border-bottom: 1px solid var(--border); }
.answer-row:last-child { border-bottom: none; }
.answer-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .5rem; font-size: .85rem; }
.ans-verdict { font-weight: 700; }

/* ── Theory Grading ─────────────────────────────────────────── */
.grade-q-header { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; font-size: .9rem; }
.grade-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: .75rem 0; }
@media (max-width: 600px) { .grade-split { grid-template-columns: 1fr; } }
.answer-box { background: var(--gray-light); border-radius: var(--radius-sm); padding: .75rem; font-size: .9rem; min-height: 80px; white-space: pre-wrap; }
.answer-box.model { background: #f0fdf4; border: 1px solid #86efac; }
.grade-input-row { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; }
.grade-input-row label { margin: 0; white-space: nowrap; font-size: .875rem; }
.grade-input-row input { width: 90px; }

/* ── Submission Confirmation ────────────────────────────────── */
.success-icon { font-size: 3.5rem; color: var(--success); text-align: center; margin-bottom: .5rem; }
.submission-info { background: var(--gray-light); border-radius: var(--radius-sm); padding: .85rem 1rem; margin: 1rem 0; text-align: left; }
.submission-info p { margin-bottom: .3rem; }
.result-notice { background: var(--warning-light); border: 1px solid #fcd34d; border-radius: var(--radius-sm); padding: .85rem 1rem; margin-bottom: 1rem; font-size: .9rem; }

/* ── Help List ──────────────────────────────────────────────── */
.help-list { font-size: .9rem; }
.help-list li { margin-bottom: .35rem; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--gray-light); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }