/* ==========================================================================
   Base: design tokens, reset and shared components used by every page.
   Page-specific layout lives in login.css, admin.css and quiz.css.
   ========================================================================== */

:root {
  /* Blue: the main color */
  --blue-900: #132a6b;
  --blue-800: #1a37a0;
  --blue-700: #1f3fb8;
  --blue-600: #2b50d6;
  --blue-500: #4a6ee6;
  --blue-300: #9db4f5;
  --blue-200: #c9d7fb;
  --blue-100: #e3eafd;
  --blue-50: #f1f5fe;

  /* Red: small accents only (wrong answers, timer warning, delete) */
  --red-600: #d64545;
  --red-500: #ee6b6b;
  --red-300: #f6a9a9;
  --red-100: #fdeeee;

  /* Green: right answers in result lists */
  --green-700: #1b7a52;
  --green-500: #2fae74;
  --green-100: #e4f6ec;

  /* Neutrals */
  --bg: #f3f6fb;
  --surface: #ffffff;
  --text: #18223d;
  --text-2: #4b5675;
  --muted: #7c869f;
  --border: #e2e7f1;
  --border-strong: #cfd7e6;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 2px rgba(19, 42, 107, 0.06);
  --shadow: 0 1px 2px rgba(19, 42, 107, 0.05), 0 10px 30px -14px rgba(19, 42, 107, 0.18);
  --shadow-lg: 0 24px 60px -20px rgba(19, 42, 107, 0.35);
  --focus-ring: 0 0 0 3px rgba(43, 80, 214, 0.22);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------- Reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 1rem; font-weight: 600; }

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-lg { width: 26px; height: 26px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--blue-600); color: #fff; box-shadow: 0 6px 16px -8px rgba(43, 80, 214, 0.7); }
.btn-primary:hover:not(:disabled) { background: var(--blue-700); }

.btn-soft { background: var(--blue-100); color: var(--blue-700); }
.btn-soft:hover:not(:disabled) { background: var(--blue-200); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-200); }

.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c03a3a; }

.btn-danger-text { color: var(--red-600); }
.btn-danger-text:hover:not(:disabled) { background: var(--red-100); color: var(--red-600); border-color: var(--red-300); }

.btn-sm { min-height: 34px; padding: 0 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--blue-50); color: var(--blue-700); }
.icon-btn.is-danger:hover { background: var(--red-100); color: var(--red-600); }

/* ---------- Forms ---------- */

.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }

.input, .select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus { outline: none; border-color: var(--blue-500); box-shadow: var(--focus-ring); }
.input::placeholder { color: #a6aec2; }
.input-lg { min-height: 54px; font-size: 1.1rem; text-align: center; letter-spacing: 0.04em; }

.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c869f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

.input-group { display: flex; gap: 8px; align-items: center; }
.input-group .input { flex: 1; }

.hint { font-size: 0.8rem; color: var(--muted); }
.form-error { font-size: 0.85rem; color: var(--red-600); }

/* Segmented pill toggle */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  max-width: 100%;
  overflow-x: auto;
}
.segmented button {
  min-height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--blue-700); }
.segmented button.is-active { background: var(--blue-700); color: #fff; font-weight: 600; }

/* Count bubble inside a segmented tab: "Wrong (3)" */
.tab-count:not(:empty) {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--blue-100);
  color: var(--blue-700);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.segmented button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.segmented button.is-active .tab-count { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* Result lists (teacher detail + student result), filtered by the Right / Wrong boxes */
.answer-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.answer-item { display: grid; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.answer-item.is-right { border-color: #bfe8d2; }
.answer-prompt { overflow-wrap: anywhere; }
.answer { display: flex; gap: 10px; align-items: baseline; padding: 7px 12px; border-radius: 10px; font-size: 0.92rem; overflow-wrap: anywhere; }
.answer-label { flex: none; width: 58px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.answer-given { background: var(--red-100); color: var(--red-600); }
.answer-given.is-empty { font-style: italic; }
.answer-correct { background: var(--blue-50); color: var(--blue-800); }
.answer-right { background: var(--green-100); color: var(--green-700); font-weight: 600; }
.answer-right .icon { width: 16px; height: 16px; align-self: center; color: var(--green-500); }
.list-note { display: flex; align-items: center; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--blue-50); color: var(--blue-700); font-weight: 600; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.92rem; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative;
  width: 40px;
  height: 24px;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 0.2s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease);
}
.switch input:checked + .switch-track { background: var(--blue-600); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }

/* ---------- Surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.card-title { margin-bottom: 18px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--blue-100);
  color: var(--blue-700);
  white-space: nowrap;
}
.badge-grey { background: #eef0f5; color: var(--muted); }
.badge-red { background: var(--red-100); color: var(--red-600); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--blue-300); }
.chip.is-active { background: var(--blue-50); border-color: var(--blue-500); color: var(--blue-700); font-weight: 600; }
.chip-count { font-size: 0.75rem; color: var(--muted); }
.chip.is-active .chip-count { color: var(--blue-600); }

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--blue-50);
  color: var(--blue-800);
  font-size: 0.9rem;
}
.notice-red { background: var(--red-100); color: var(--red-600); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--blue-100);
  border-top-color: var(--blue-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dialog ---------- */

.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(19, 42, 107, 0.35); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop 0.2s var(--ease); }
.dialog-body { padding: 26px 26px 8px; display: grid; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 26px 24px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  display: grid;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--blue-900);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s var(--ease);
  transition: opacity 0.3s, transform 0.3s;
}
.toast-error { background: var(--red-600); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
