/* ===== Variables ===== */
:root {
  --primary: #1a5276;
  --primary-light: #2471a3;
  --accent: #e67e22;
  --success: #27ae60;
  --danger: #e74c3c;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #dce1e7;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Sarabun', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

/* ===== Layout ===== */
.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 480px; margin: 0 auto; padding: 0 20px; }
.container-lg { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ===== Navbar ===== */
.navbar {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  position: sticky; top: 0; z-index: 100;
}
.navbar-brand { font-size: 1.2rem; font-weight: 700; }
.navbar-brand span { color: var(--accent); }
.navbar-right { display: flex; align-items: center; gap: 16px; }
.navbar-user { font-size: 0.9rem; opacity: 0.9; }
.btn-logout {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}
.card-sm { padding: 24px; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-align: center;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #d35400; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #1e8449; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-lg { padding: 14px 32px; font-size: 1.1rem; }
.btn-block { display: block; width: 100%; }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a5276 0%, #2980b9 100%);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo-icon {
  width: 72px; height: 72px;
  background: var(--primary);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 16px;
}
.login-logo h1 { font-size: 1.3rem; color: var(--primary); font-weight: 700; }
.login-logo p { font-size: 0.9rem; color: var(--text-muted); margin-top: 4px; }
.login-error {
  background: #fdecea;
  color: var(--danger);
  border: 1px solid #f5c6cb;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: none;
}

/* ===== Dashboard ===== */
.dashboard-hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 40px 0;
  margin-bottom: 32px;
}
.dashboard-hero h2 { font-size: 1.8rem; margin-bottom: 8px; }
.dashboard-hero p { opacity: 0.85; font-size: 1rem; }
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }

.exam-sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}
.exam-set-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}
.exam-set-card:hover { transform: translateY(-3px); box-shadow: 0 8px 30px rgba(0,0,0,0.15); }
.exam-set-card.completed { border-color: var(--success); }
.exam-set-card.passed .status-badge { background: var(--success); }
.exam-set-card.failed .status-badge { background: var(--danger); }
.exam-set-num {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.exam-set-title { font-weight: 600; margin: 8px 0 4px; font-size: 0.95rem; }
.exam-set-meta { font-size: 0.82rem; color: var(--text-muted); }
.status-badge {
  position: absolute; top: 16px; right: 16px;
  background: var(--text-muted);
  color: #fff;
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.exam-set-score { margin-top: 12px; font-size: 0.9rem; }
.exam-set-score strong { color: var(--primary); }

/* ===== Exam Page ===== */
.exam-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.exam-header h3 { font-size: 1rem; }
.exam-timer {
  background: rgba(255,255,255,0.15);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.exam-timer.warning { background: #e67e22; }
.exam-timer.danger { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.7; } }
.exam-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.2);
}
.exam-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.exam-body { padding: 24px; max-width: 860px; margin: 0 auto; }
.question-block { margin-bottom: 32px; }
.question-num {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.7;
}
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.choice-label:hover { border-color: var(--primary); background: #f0f4f8; }
.choice-label.selected { border-color: var(--primary); background: #ebf5fb; }
.choice-label input[type="radio"] { margin-top: 3px; accent-color: var(--primary); flex-shrink: 0; }
.choice-letter {
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  min-width: 20px;
}

.exam-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: #fff;
  border-top: 1px solid var(--border);
  position: sticky; bottom: 0;
}
.question-dots {
  display: flex; flex-wrap: wrap; gap: 6px; max-width: 600px;
}
.q-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-muted);
}
.q-dot.answered { background: var(--primary); color: #fff; }
.q-dot.current { background: var(--accent); color: #fff; }

/* ===== Results ===== */
.result-hero {
  text-align: center;
  padding: 48px 24px;
}
.result-circle {
  width: 140px; height: 140px;
  border-radius: 50%;
  margin: 0 auto 24px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: #fff;
}
.result-circle.pass { background: var(--success); }
.result-circle.fail { background: var(--danger); }
.result-circle .result-label { font-size: 0.75rem; font-weight: 600; opacity: 0.9; }
.result-verdict { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.result-verdict.pass { color: var(--success); }
.result-verdict.fail { color: var(--danger); }
.result-detail { color: var(--text-muted); font-size: 1rem; }

.result-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin: 24px 0;
}
.breakdown-item {
  text-align: center;
  padding: 16px;
  background: var(--bg);
  border-radius: 10px;
}
.breakdown-num { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.breakdown-label { font-size: 0.82rem; color: var(--text-muted); }

.review-list { margin-top: 24px; }
.review-item {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  border-left: 4px solid var(--border);
}
.review-item.correct { border-color: var(--success); }
.review-item.wrong { border-color: var(--danger); }
.review-q { font-weight: 600; margin-bottom: 8px; font-size: 0.95rem; }
.review-answer { font-size: 0.88rem; }
.review-answer .user-ans { color: var(--danger); }
.review-answer .correct-ans { color: var(--success); }

/* ===== History ===== */
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.history-table th { background: var(--bg); font-weight: 600; color: var(--text-muted); }
.badge-pass { background: #d5f5e3; color: var(--success); padding: 3px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }
.badge-fail { background: #fadbd8; color: var(--danger); padding: 3px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: 600; }

/* ===== Section Title ===== */
.section-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.section-sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }

/* ===== Utilities ===== */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.flex { display: flex; } .gap-8 { gap: 8px; } .gap-16 { gap: 16px; }
.hidden { display: none !important; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
}
.modal-box h3 { font-size: 1.3rem; margin-bottom: 12px; }
.modal-box p { color: var(--text-muted); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }

/* Responsive */
@media (max-width: 600px) {
  .login-box { padding: 32px 24px; }
  .exam-sets-grid { grid-template-columns: 1fr; }
  .navbar-brand { font-size: 1rem; }
  .exam-header h3 { font-size: 0.85rem; }
}
