/* public/css/style.css — mobile-first, shared across all Bliss CBT pages.
   Breakpoints: base = mobile (~375px+), 768px = tablet, 1280px = desktop. */

:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-primary: #1a56db;
  --color-primary-dark: #123a99;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --radius: 10px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --touch-target: 44px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; display: block; }
a { color: var(--color-primary); }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-3);
}

/* ── Layout shell ─────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header h1 { font-size: 1.1rem; margin: 0; }
.app-header .brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; }

.nav-toggle {
  display: inline-flex;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1.3rem;
}

.app-nav {
  display: none;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3) var(--space-3);
}
.app-nav.open { display: flex; }
.app-nav a {
  display: block;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
}
.app-nav a.active, .app-nav a:hover { background: var(--color-bg); color: var(--color-primary); }

@media (min-width: 768px) {
  .nav-toggle { display: none; }
  .app-nav {
    display: flex;
    flex-direction: row;
    border-bottom: none;
    padding: 0;
    background: none;
  }
  .app-header { flex-wrap: wrap; }
}

.main-content { padding: var(--space-3); max-width: 1200px; margin: 0 auto; width: 100%; }

/* ── Cards / surfaces ─────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.card h2, .card h3 { margin-top: 0; }

.grid { display: grid; gap: var(--space-3); grid-template-columns: 1fr; }
@media (min-width: 768px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

/* ── Forms ────────────────────────────────────────────────── */
label { display: block; font-weight: 600; margin-bottom: var(--space-1); font-size: 0.9rem; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  min-height: var(--touch-target);
}
textarea { min-height: 88px; }
.field { margin-bottom: var(--space-3); }
.field-row { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.field-row > .field { flex: 1 1 200px; }

/* ── Buttons ──────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch-target);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
button:hover, .btn:hover { background: var(--color-primary-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); }
.btn-success { background: var(--color-success); border-color: var(--color-success); }
.btn-warning { background: var(--color-warning); border-color: var(--color-warning); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ── Tables ───────────────────────────────────────────────── */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 520px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 0.92rem; }
th { color: var(--color-text-muted); font-weight: 600; white-space: nowrap; }

/* ── Badges / status ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ── Alerts / toasts ──────────────────────────────────────── */
.alert { padding: var(--space-2) var(--space-3); border-radius: var(--radius); margin-bottom: var(--space-3); font-size: 0.92rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.toast-stack { position: fixed; bottom: var(--space-3); right: var(--space-3); left: var(--space-3); z-index: 100; display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end; }
@media (min-width: 768px) { .toast-stack { left: auto; } }
.toast { background: var(--color-text); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 0.9rem; box-shadow: 0 4px 14px rgba(0,0,0,0.2); max-width: 360px; }
.toast.toast-error { background: var(--color-danger); }
.toast.toast-success { background: var(--color-success); }

.muted { color: var(--color-text-muted); }
.center { text-align: center; }
.spacer { height: var(--space-4); }
.hidden { display: none !important; }

/* ── Login page ───────────────────────────────────────────── */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-3); }
.login-card { width: 100%; max-width: 420px; }
.login-card h1 { text-align: center; margin-bottom: var(--space-1); }
.login-card p.muted { text-align: center; margin-top: 0; margin-bottom: var(--space-4); }

/* ── Exam-taking page (highest mobile priority) ──────────── */
.exam-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.exam-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.exam-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--color-bg);
}
.exam-timer.low-time { background: #fee2e2; color: var(--color-danger); }

.exam-body { flex: 1; display: flex; flex-direction: column; }
.exam-main { flex: 1; padding: var(--space-3); }

.question-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-3); }
.question-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-3); flex-wrap: wrap; gap: var(--space-2); }
.question-text { font-size: 1.05rem; margin-bottom: var(--space-3); white-space: pre-wrap; }

.option-list { display: flex; flex-direction: column; gap: var(--space-2); }
.option-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: var(--touch-target);
  cursor: pointer;
}
.option-item input { width: 20px; height: 20px; flex-shrink: 0; margin-top: 2px; }
.option-item.selected { border-color: var(--color-primary); background: #eff6ff; }
.option-item.correct { border-color: var(--color-success); background: #f0fdf4; }
.option-item.incorrect { border-color: var(--color-danger); background: #fef2f2; }
.option-letter { font-weight: 700; margin-right: 4px; }

.exam-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.exam-actions .btn { flex: 1 1 130px; }

/* Palette: collapsible/toggleable on mobile, always visible sidebar on desktop */
.palette-toggle { display: inline-flex; margin: 0 var(--space-3) var(--space-2); }
.palette-panel {
  display: none;
  padding: var(--space-3);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.palette-panel.open { display: block; }
.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; max-height: 260px; overflow-y: auto; }
.palette-btn {
  min-height: 40px;
  min-width: 40px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
}
.palette-btn.answered { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.palette-btn.flagged { background: var(--color-warning); color: #fff; border-color: var(--color-warning); }
.palette-btn.current { outline: 3px solid var(--color-primary); outline-offset: 1px; }
.palette-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-2); font-size: 0.8rem; }
.palette-legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

@media (min-width: 1024px) {
  .exam-body { flex-direction: row; }
  .exam-main { flex: 1; }
  .palette-toggle { display: none; }
  .palette-panel { display: block !important; width: 300px; flex-shrink: 0; border-top: none; border-left: 1px solid var(--color-border); }
}

/* On-screen calculator */
.calculator { max-width: 280px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-2); margin-top: var(--space-3); }
.calc-display { background: var(--color-bg); border-radius: 8px; padding: 10px; text-align: right; font-size: 1.4rem; font-variant-numeric: tabular-nums; margin-bottom: 8px; min-height: 44px; overflow-x: auto; white-space: nowrap; }
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-grid button { min-height: 48px; padding: 0; font-size: 1.1rem; border-color: var(--color-border); background: var(--color-bg); color: var(--color-text); }
.calc-grid button.op { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Stat tiles ───────────────────────────────────────────── */
.stat-tile { text-align: center; padding: var(--space-3); }
.stat-tile .value { font-size: 1.8rem; font-weight: 800; color: var(--color-primary); }
.stat-tile .label { color: var(--color-text-muted); font-size: 0.85rem; }

/* ── Progress bars (weak-topic view) ─────────────────────── */
.bar-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.bar-label { flex: 0 0 140px; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 10px; background: var(--color-bg); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--color-primary); }
.bar-fill.weak { background: var(--color-danger); }
.bar-fill.medium { background: var(--color-warning); }
.bar-fill.strong { background: var(--color-success); }
.bar-pct { flex: 0 0 40px; text-align: right; font-size: 0.85rem; font-weight: 700; }

/* Utility for full-screen prompts */
.fullscreen-prompt { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 200; padding: var(--space-3); }
.fullscreen-prompt .card { max-width: 400px; }
