:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* HEADER */
.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.25rem; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 16px; }
.header-user { font-size: 0.875rem; opacity: 0.9; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-white { background: white; color: var(--primary); }
.btn-white:hover { background: #f8fafc; }
.btn-ghost { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-ghost:hover { background: rgba(255,255,255,0.25); }

/* CARDS */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-title { font-size: 1.125rem; font-weight: 700; }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.9375rem;
  transition: border-color 0.2s;
  background: white;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
select.form-control { appearance: auto; }
textarea.form-control { min-height: 100px; resize: vertical; font-family: inherit; }

/* LAYOUT */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap { display: flex; gap: 8px; align-items: center; }
.text-center { text-align: center; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }

/* AUTH PAGE */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
  padding: 20px;
}
.auth-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}
.auth-card h1 {
  text-align: center;
  font-size: 1.75rem;
  margin-bottom: 8px;
  color: var(--primary);
}
.auth-card .subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 32px;
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  border: none;
  background: transparent;
}
.auth-tab.active { background: white; box-shadow: var(--shadow); color: var(--primary); }

/* EXAM CARD */
.exam-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.2s;
  background: white;
}
.exam-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); }
.exam-card h3 { margin-bottom: 8px; font-size: 1.1rem; }
.exam-meta { font-size: 0.8rem; color: var(--text-light); display: flex; gap: 16px; margin: 8px 0; }
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fef2f2; color: #991b1b; }
.badge-specialty { background: #ede9fe; color: #5b21b6; }
.badge-violated { background: #fef2f2; color: #dc2626; }
.badge-completed { background: #dcfce7; color: #166534; }

/* EXAM TAKING */
.exam-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 20px 24px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.exam-timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.exam-timer.warning { color: #fbbf24; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.question-card {
  background: white;
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  max-width: 800px;
  margin: 0 auto;
}
.question-number {
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 12px;
}
.question-text {
  font-size: 1.1rem;
  line-height: 1.7;
  margin-bottom: 24px;
  white-space: pre-wrap;
}
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 20px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.5;
  width: 100%;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #eff6ff;
}
.option-btn:disabled { cursor: default; }
.option-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--bg);
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
}
.option-btn.correct { border-color: var(--success); background: #f0fdf4; }
.option-btn.correct .option-letter { background: var(--success); color: white; }
.option-btn.wrong { border-color: var(--danger); background: #fef2f2; }
.option-btn.wrong .option-letter { background: var(--danger); color: white; }
.option-btn.selected { border-color: var(--primary); background: #eff6ff; }
.option-btn.selected .option-letter { background: var(--primary); color: white; }

.explanation-box {
  margin-top: 16px;
  padding: 16px;
  background: #f0fdf4;
  border-left: 4px solid var(--success);
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
  line-height: 1.6;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 20px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  border-radius: 3px;
  transition: width 0.3s;
}

/* SCORE SCREEN */
.score-container {
  text-align: center;
  max-width: 500px;
  margin: 40px auto;
}
.score-circle {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  font-size: 2.5rem;
  font-weight: 800;
  color: white;
}
.score-high { background: linear-gradient(135deg, #16a34a, #22c55e); }
.score-mid { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.score-low { background: linear-gradient(135deg, #dc2626, #ef4444); }

/* VIOLATION OVERLAY */
.violation-overlay {
  position: fixed;
  inset: 0;
  background: rgba(220, 38, 38, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  text-align: center;
  padding: 40px;
}
.violation-overlay h2 { font-size: 2rem; margin-bottom: 16px; }
.violation-overlay p { font-size: 1.1rem; opacity: 0.9; margin-bottom: 24px; }

/* STATS */
.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-light); margin-top: 4px; }

/* TABLE */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 0.8rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; }
td { font-size: 0.9rem; }
tr:hover td { background: #f8fafc; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal h2 { margin-bottom: 20px; }

/* NAV TABS */
.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
  overflow-x: auto;
}
.nav-tab {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.nav-tab.active { background: white; color: var(--primary); box-shadow: var(--shadow); }
.nav-tab:hover:not(.active) { background: rgba(255,255,255,0.5); }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 9999;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* RESPONSIVE */
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .card { padding: 16px; }
  .question-card { padding: 20px; }
  .auth-card { padding: 24px; }
  .header h1 { font-size: 1rem; }
  .exam-header { flex-direction: column; gap: 12px; text-align: center; }
  .nav-tabs { padding: 2px; }
  .nav-tab { padding: 8px 12px; font-size: 0.8rem; }
}

.hidden { display: none !important; }

/* Loading spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
