/* ============================================================================
   Boston Study Speaking Club — shared design system
   Used by index.html, student.html and admin.html.
   Page-specific layout lives inline in each page; everything reusable is here.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Brand */
  --navy: #16264e;
  --navy-900: #0e1a38;
  --navy-800: #16264e;
  --blue: #2447b5;
  --blue-700: #1b3694;
  --blue-100: #e8edfb;
  --red: #c92735;
  --red-700: #a81d2a;
  --red-100: #fdecee;
  --gold: #b7791f;

  /* Surfaces */
  --paper: #f7f8fc;
  --paper-warm: #fcfcff;
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --surface-3: #e9edf6;

  /* Text */
  --ink: #101a33;
  --ink-2: #2a3a5c;
  --muted: #5b6b85;
  --muted-2: #7b89a1;

  /* Lines */
  --line: #e2e7f0;
  --line-strong: #cfd7e6;

  /* Status */
  --ok: #0f7a4d;
  --ok-bg: #e6f6ee;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --bad: #b01724;
  --bad-bg: #fdecee;
  --info: #1d4ed8;
  --info-bg: #e9efff;

  /* Type */
  --sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;

  /* Shape & depth */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(16, 26, 51, .06);
  --shadow-sm: 0 1px 3px rgba(16, 26, 51, .07), 0 4px 12px -6px rgba(16, 26, 51, .12);
  --shadow-md: 0 12px 28px -14px rgba(16, 26, 51, .28), 0 2px 6px rgba(16, 26, 51, .05);
  --shadow-lg: 0 30px 70px -30px rgba(16, 26, 51, .45), 0 8px 20px -12px rgba(16, 26, 51, .2);
  --ring: 0 0 0 3px rgba(36, 71, 181, .35);
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 { line-height: 1.15; text-wrap: balance; }
p { text-wrap: pretty; }
img, svg, video { max-width: 100%; height: auto; display: block; }
a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-700); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

::selection { background: #c9d6fb; color: var(--navy-900); }

:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
  border-radius: 4px;
}

[hidden] { display: none !important; }

/* --- Accessibility helpers ------------------------------------------------ */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform .18s ease;
}
.skip-link:focus { transform: translateY(0); color: #fff; }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--blue);
  --btn-fg: #fff;
  --btn-border: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--btn-border);
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.btn:hover { background: var(--blue-700); color: #fff; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .6; pointer-events: none; }

.btn--primary { --btn-bg: var(--blue); }
.btn--accent { --btn-bg: var(--red); }
.btn--accent:hover { background: var(--red-700); }
.btn--ok { --btn-bg: var(--ok); }
.btn--ok:hover { background: #0b5f3c; }
.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-border: var(--line-strong);
}
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--soft { --btn-bg: var(--blue-100); --btn-fg: var(--blue); }
.btn--soft:hover { background: #d8e2fb; color: var(--blue-700); }
.btn--danger { --btn-bg: var(--bad-bg); --btn-fg: var(--bad); }
.btn--danger:hover { background: #fbd8dc; color: var(--bad); }
.btn--sm { min-height: 34px; padding: 6px 12px; font-size: 12px; gap: 6px; }
.btn--lg { min-height: 52px; padding: 14px 26px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { min-height: 40px; width: 40px; padding: 0; border-radius: 50%; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: bsc-spin .6s linear infinite;
}
.btn--ghost.is-loading::after, .btn--soft.is-loading::after, .btn--danger.is-loading::after { color: var(--ink); }
@keyframes bsc-spin { to { transform: rotate(360deg); } }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.link-btn:hover { color: var(--red); text-decoration: underline; }

/* --- Badges & chips ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.4;
  white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }
.badge--info { background: var(--info-bg); color: var(--info); }
.badge--muted { background: var(--surface-2); color: var(--muted); }
.badge--brand { background: var(--blue-100); color: var(--blue); }
.badge--gold { background: #fdf3dd; color: var(--gold); }
.badge--dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xs);
}
.card__pad { padding: 22px; }
.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px 22px 0;
}
.card__title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.card__desc { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* --- Forms ---------------------------------------------------------------- */
.field { display: grid; gap: 6px; margin: 0 0 16px; }
.field > label, .field__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: .01em;
}
.field__hint { margin: 0; color: var(--muted); font-size: 12px; }
.input, .select, .textarea, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea, .textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:hover, .select:hover, .field input:hover, .field select:hover, .field textarea:hover { border-color: #b9c4d8; }
.input:focus, .select:focus, .textarea:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--ring);
}
.input[aria-invalid="true"], .field input[aria-invalid="true"], .field textarea[aria-invalid="true"] {
  border-color: var(--bad);
}
.form-error {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--bad);
  font-size: 12px;
  font-weight: 600;
}
.form-error--ok { color: var(--ok); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.check input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--blue); flex: none; }

/* --- Dialogs -------------------------------------------------------------- */
dialog {
  width: min(560px, calc(100% - 28px));
  max-height: min(90dvh, 860px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.wide { width: min(820px, calc(100% - 28px)); }
dialog.narrow { width: min(440px, calc(100% - 28px)); }
dialog::backdrop { background: rgba(10, 18, 38, .62); backdrop-filter: blur(4px); }
dialog[open] { animation: bsc-dialog-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes bsc-dialog-in { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

.dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.dialog__title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.dialog__desc { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.dialog__body { padding: 22px; overflow-y: auto; max-height: calc(88dvh - 150px); }
.dialog__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.dialog__foot--split { justify-content: space-between; }
.dialog__close {
  flex: none;
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  margin: -4px -6px 0 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.dialog__close:hover { background: var(--surface-2); color: var(--ink); }

/* --- Toast ---------------------------------------------------------------- */
.bsc-toast {
  position: fixed;
  z-index: 900;
  right: 18px;
  bottom: 18px;
  left: 18px;
  width: fit-content;
  max-width: min(440px, calc(100% - 36px));
  margin-left: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--navy-900);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  transform: translateY(140%);
  opacity: 0;
  pointer-events: none;
  transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .24s ease;
}
.bsc-toast.is-visible { transform: none; opacity: 1; }
.bsc-toast--ok { background: #0c5c3b; }
.bsc-toast--bad { background: #8f1220; }
.bsc-toast__icon { flex: none; font-size: 15px; line-height: 1.4; }

/* --- Boot screen ---------------------------------------------------------- */
.boot-screen {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 72px 20px;
  text-align: center;
}
.boot-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: bsc-spin .8s linear infinite;
}
.boot-screen h1 { margin: 4px 0 0; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.boot-screen p { max-width: 430px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.boot-screen .btn { margin-top: 6px; }

/* --- Empty / loading states ---------------------------------------------- */
.empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 38px 20px;
  text-align: center;
  color: var(--muted);
}
.empty__icon { font-size: 30px; line-height: 1; }
.empty__title { color: var(--ink); font-size: 15px; font-weight: 700; }
.empty__text { max-width: 380px; margin: 0; font-size: 13px; }

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: transparent !important;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .65), transparent);
  animation: bsc-shimmer 1.4s infinite;
}
@keyframes bsc-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* --- Tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
table.data td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafbfe; }

/* --- Misc ---------------------------------------------------------------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 18px 0; }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .dialog__body { padding: 18px; }
  .dialog__head { padding: 18px 18px 14px; }
  .dialog__foot { padding: 12px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
