/* ==========================================================================
   Portal sign-in (portal.html)
   A quiet, light layout: one column on phones, a centred card on tablets,
   and a full-screen split (brand left, form right) on laptops and desktops.
   ========================================================================== */

:root {
  /* Same palette and type as the public site (assets/site.css) */
  --a-ink: #14231D;
  --a-ink-2: #43524B;
  --a-ink-3: #6B7770;
  --a-line: #DCD3BF;
  --a-line-soft: #ECE5D5;
  --a-bg: #FBF8F1;
  --a-bg-alt: #F4EEE1;
  --a-surface: #ffffff;
  --a-accent: #123B2E;
  --a-accent-hover: #1D5743;
  --a-link: #1D5743;
  --a-accent-tint: rgba(29, 87, 67, 0.12);
  --a-gold: #C9A13B;
  --a-gold-ink: #7D6119;
  --a-error: #B3261E;
  --a-error-tint: #FCEEEC;
  --a-success: #1D6B45;
  --a-success-tint: #EAF4EE;
  --a-radius: 12px;
  --a-orange: #b64400;
  --a-font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --a-font-display: "Newsreader", Georgia, "Times New Roman", serif;
  color-scheme: light only;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body.auth-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--a-surface);
  color: var(--a-ink);
  font-family: var(--a-font);
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }

/* ── Top bar ─────────────────────────────────────────────────── */

.auth-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 52px;
  padding: 0 max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.8);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--a-ink);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-brand img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.auth-nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.auth-nav .portal-back-link {
  color: var(--a-ink-2);
  text-decoration: none;
  font-size: 14px;
}

.auth-nav .portal-back-link:hover { color: var(--a-ink); }

/* Language toggle (button injected by lang.js) — restyled for a light bar */
.auth-nav .lang-toggle-btn {
  background: transparent;
  border: 1px solid var(--a-line);
  color: var(--a-ink);
  font-family: var(--a-font);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  padding: 4px 12px 4px 9px;
}

.auth-nav .lang-toggle-btn:hover {
  background: var(--a-bg);
  border-color: var(--a-line);
  transform: none;
}

/* ── Layout shell ────────────────────────────────────────────── */

.auth-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.auth-hero { display: none; }

.auth-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-crest {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 18px;
}

.auth-title {
  font-family: var(--a-font-display);
  font-size: 32px;
  line-height: 1.125;
  font-weight: 600;
  letter-spacing: 0.004em;
  text-align: center;
  margin: 0 0 24px;
}

.auth-lead {
  color: var(--a-ink-2);
  font-size: 15px;
  text-align: center;
  margin: 0 0 22px;
}

/* ── Segmented control (Sign in / Register) ──────────────────── */

.auth-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--a-bg-alt);
  border-radius: 12px;
  margin: 0 0 22px;
}

.auth-segment button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--a-ink-2);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.auth-segment button.active {
  background: var(--a-surface);
  color: var(--a-ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 1px rgba(0, 0, 0, 0.04);
}

/* ── Flows ───────────────────────────────────────────────────── */

.portal-flow { display: none; }
.portal-flow.active { display: block; animation: auth-fade 0.25s ease; }

@keyframes auth-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ── Fields ──────────────────────────────────────────────────── */

.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--a-ink-2);
  padding-left: 2px;
}

.portal-input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border: 1px solid var(--a-line);
  border-radius: var(--a-radius);
  background: var(--a-surface);
  font-size: 17px; /* 16px+ keeps iOS from zooming on focus */
  color: var(--a-ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.portal-input::placeholder { color: var(--a-ink-3); }

.portal-input:focus {
  border-color: var(--a-accent);
  box-shadow: 0 0 0 4px var(--a-accent-tint);
}

.portal-input.error {
  border-color: var(--a-error);
  box-shadow: 0 0 0 4px rgba(215, 0, 21, 0.1);
}

.portal-input.mono {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
}

.password-wrap { position: relative; }
.password-wrap .portal-input { padding-right: 50px; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--a-ink-3);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.password-toggle:hover { color: var(--a-ink); background: var(--a-bg); }
.password-toggle svg { width: 18px; height: 18px; display: block; pointer-events: none; }

/* Remember me */
.auth-check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 4px;
  font-size: 15px;
  color: var(--a-ink);
  cursor: pointer;
  user-select: none;
}

.auth-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--a-accent);
  cursor: pointer;
}

/* Gender: a small segmented choice */
.gender-picker-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gender-pill {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border: 1px solid var(--a-line);
  border-radius: 10px;
  font-size: 15px;
  color: var(--a-ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.gender-pill input { position: absolute; opacity: 0; pointer-events: none; }

.gender-pill.active {
  border-color: var(--a-accent);
  background: var(--a-accent-tint);
  font-weight: 600;
}

.gender-pill:focus-within { box-shadow: 0 0 0 4px var(--a-accent-tint); }

/* Class list (rows rendered by portal.js) */
.portal-class-scroll-picker {
  max-height: 232px;
  overflow-y: auto;
  border: 1px solid var(--a-line);
  border-radius: var(--a-radius);
  outline: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.portal-class-scroll-picker:focus-visible { box-shadow: 0 0 0 4px var(--a-accent-tint); }

.portal-class-option-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--a-line-soft);
  cursor: pointer;
  transition: background 0.12s;
}

.portal-class-option-card:last-child { border-bottom: 0; }
.portal-class-option-card:hover { background: var(--a-bg); }
.portal-class-option-card:focus-visible { outline: none; background: var(--a-bg); }
.portal-class-option-card.selected { background: var(--a-accent-tint); }

.portal-class-option-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.portal-class-option-icon { font-size: 18px; line-height: 1; }

.portal-class-option-name {
  font-size: 15px;
  color: var(--a-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-class-option-card.selected .portal-class-option-name { font-weight: 600; }

/* Schedule / room lines and code badge are noise at sign-up time */
.portal-class-option-sub,
.portal-class-option-badge { display: none; }

.portal-class-radio-indicator {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--a-line);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.portal-class-option-card.selected .portal-class-radio-indicator {
  border-color: var(--a-accent);
  background: var(--a-accent);
  box-shadow: inset 0 0 0 4px var(--a-surface);
}

/* Live invite-code check */
.invite-code-preview {
  font-size: 13px;
  line-height: 1.4;
  color: var(--a-ink-2);
}

.invite-code-preview:empty { display: none; }
.invite-code-preview.valid { color: var(--a-success); }
.invite-code-preview.invalid { color: var(--a-error); }
.invite-code-preview code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.invite-badge-icon { font-weight: 700; }

/* ── Messages ────────────────────────────────────────────────── */

.portal-error-msg,
.teacher-error-msg {
  display: none;
  margin: 14px 0 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--a-error-tint);
  color: var(--a-error);
  font-size: 14px;
  line-height: 1.4;
}

.portal-error-msg.visible,
.teacher-error-msg.visible { display: block; }

/* ── Buttons ─────────────────────────────────────────────────── */

.auth-btn {
  width: 100%;
  height: 50px;
  margin-top: 20px;
  border: 0;
  border-radius: 999px;
  background: var(--a-accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.auth-btn:hover { background: var(--a-accent-hover); }
.auth-btn:active { transform: scale(0.985); }
.auth-btn:disabled { opacity: 0.6; cursor: default; }
.auth-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--a-accent-tint); }
.auth-btn .btn-arrow { display: none; }

.auth-btn.secondary {
  background: var(--a-bg);
  color: var(--a-ink);
}

.auth-btn.secondary:hover { background: var(--a-bg-alt); }

.auth-switch {
  margin: 22px 0 0;
  text-align: center;
  font-size: 15px;
  color: var(--a-ink-2);
}

.auth-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0 0 0 4px;
  color: var(--a-link);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
}

.auth-link:hover { text-decoration: underline; }

/* ── Registration success ────────────────────────────────────── */

.auth-success-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--a-success-tint);
  color: var(--a-success);
  display: grid;
  place-items: center;
}

.auth-success-title {
  font-family: var(--a-font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  text-align: center;
  margin: 0 0 6px;
}

.auth-creds {
  margin: 0;
  border: 1px solid var(--a-line-soft);
  border-radius: var(--a-radius);
  background: var(--a-bg);
  overflow: hidden;
}

.auth-creds-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--a-line-soft);
  font-size: 15px;
}

.auth-creds-row:last-child { border-bottom: 0; }
.auth-creds-row dt { color: var(--a-ink-2); margin: 0; }
.auth-creds-row dd { margin: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.auth-creds-row.key dd { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-weight: 600; }

.auth-copy {
  display: block;
  margin: 12px auto 0;
}

/* ── Faculty sign in ─────────────────────────────────────────── */

.auth-faculty {
  width: 100%;
  max-width: 400px;
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--a-line-soft);
}

.faculty-toggle {
  appearance: none;
  width: 100%;
  border: 0;
  background: none;
  padding: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--a-ink-2);
  font-size: 14px;
  cursor: pointer;
}

.faculty-toggle:hover { color: var(--a-ink); }

.faculty-toggle .chev {
  width: 12px;
  height: 12px;
  transition: transform 0.2s;
}

.faculty-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.faculty-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.faculty-panel > form {
  overflow: hidden;
  min-height: 0;
}

.faculty-panel:not(.open) > form { visibility: hidden; }

.faculty-panel.open { grid-template-rows: 1fr; }

.faculty-panel.open > form { padding-top: 14px; }

/* ── Footer ──────────────────────────────────────────────────── */

.auth-footer {
  padding: 18px 20px max(18px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--a-ink-3);
}

/* ── Shake on wrong password ─────────────────────────────────── */

.shake { animation: auth-shake 0.4s ease; }

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .portal-flow.active, .shake { animation: none; }
  .faculty-panel, .faculty-toggle .chev { transition: none; }
}

/* ── Tablet: centred card on a soft grey page ────────────────── */

@media (min-width: 640px) {
  body.auth-page { background: var(--a-bg); }
  .auth-nav { background: rgba(245, 245, 247, 0.8); }
  .auth-panel { justify-content: center; padding: 48px 32px; }

  .auth-card {
    max-width: 460px;
    padding: 40px 44px 36px;
    background: var(--a-surface);
    border-radius: 22px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(0, 0, 0, 0.06);
  }

  .auth-faculty {
    max-width: 460px;
    border-top: 0;
    margin-top: 16px;
    padding-top: 0;
  }

  .faculty-panel.open > form {
    margin-top: 10px;
    padding: 24px 28px 28px;
    background: var(--a-surface);
    border-radius: 18px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(0, 0, 0, 0.06);
  }
}

/* ── Laptop & desktop: full-screen split ─────────────────────── */

@media (min-width: 1024px) {
  body.auth-page { background: var(--a-surface); }
  .auth-nav { background: rgba(255, 255, 255, 0.72); }

  .auth-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(480px, 1fr);
    min-height: calc(100vh - 52px);
    min-height: calc(100dvh - 52px);
  }

  .auth-hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 64px clamp(48px, 7vw, 120px);
    background: var(--a-bg);
  }

  .auth-hero-crest {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 36px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  }

  .auth-hero h2 {
    font-family: var(--a-font-display);
    font-size: clamp(44px, 4.6vw, 72px);
    line-height: 1.05;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin: 0 0 20px;
    max-width: 12ch;
  }

  .auth-hero p {
    font-size: clamp(19px, 1.5vw, 24px);
    line-height: 1.4;
    color: var(--a-ink-2);
    margin: 0;
    max-width: 30ch;
  }

  .auth-panel {
    justify-content: center;
    padding: 56px clamp(40px, 5vw, 96px);
  }

  .auth-card {
    max-width: 400px;
    padding: 0;
    background: none;
    box-shadow: none;
    border-radius: 0;
  }

  .auth-card .auth-crest { display: none; }
  .auth-title { text-align: left; font-size: 40px; margin-bottom: 28px; }
  .auth-lead { text-align: left; }

  .auth-faculty {
    max-width: 400px;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--a-line-soft);
  }

  .faculty-toggle { justify-content: flex-start; }

  .faculty-panel.open > form {
    margin-top: 0;
    padding: 14px 0 0;
    background: none;
    box-shadow: none;
    border-radius: 0;
  }

  .auth-footer { display: none; }
}

@media (min-width: 1600px) {
  .auth-card, .auth-faculty { max-width: 440px; }
}

/* Narrow phones: keep the top bar on one line */
.auth-brand span,
.auth-nav .portal-back-link { white-space: nowrap; }

@media (max-width: 400px) {
  .auth-nav .portal-back-link { display: none; }
}

/* Short landscape phones: keep everything reachable */
@media (max-height: 520px) and (orientation: landscape) {
  .auth-crest { display: none; }
  .auth-panel { padding-top: 16px; }
}

/* ══════════════════════════════════════════════════════════════════
   BRAND — crest, Oxford green and gold, as on the public site
   ══════════════════════════════════════════════════════════════════ */

.auth-nav { background: rgba(251, 248, 241, 0.88); border-bottom-color: var(--a-line-soft); }
.auth-brand { font-family: var(--a-font-display); font-size: 18px; letter-spacing: -0.01em; }
.auth-brand em { font-style: italic; color: var(--a-accent-hover); }
.auth-brand img { width: 32px; height: 32px; }
.auth-nav .lang-toggle-btn:hover { background: var(--a-surface); border-color: var(--a-accent); color: var(--a-accent); }
.auth-nav .portal-back-link:hover { color: var(--a-accent); }

body.auth-page { background: var(--a-bg); }
body.auth-page :focus-visible { outline: 3px solid var(--a-gold); outline-offset: 2px; }

.auth-title { font-family: var(--a-font-display); font-weight: 600; letter-spacing: -0.01em; color: var(--a-ink); }
.auth-crest { box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--a-line), 0 10px 24px -10px rgba(8, 30, 23, 0.4); }
.auth-label { font-weight: 600; color: var(--a-ink-2); }
.portal-input { border-color: var(--a-line); }
.portal-input:hover { border-color: #c9bea4; }
.portal-input:focus { border-color: var(--a-accent-hover); }
.auth-btn { box-shadow: 0 8px 20px -10px rgba(18, 59, 46, 0.7); }
.auth-btn.secondary { box-shadow: none; }
.auth-link { font-weight: 600; }
.auth-check input, .gender-pill input { accent-color: var(--a-accent); }

/* Short list of what parents find inside (phones and tablets: under the title) */
.auth-perks {
  list-style: none;
  margin: 0 0 22px;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  background: var(--a-bg-alt);
  border-radius: 14px;
  font-size: 14px;
  color: var(--a-ink-2);
}
.auth-perks li { display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; }
.auth-perks svg { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--a-gold-ink); }
/* Only on the Sign in / Register screens, not once registration is done */
.auth-card:has(#portalSuccessFlow.active) .auth-perks { display: none; }

@media (min-width: 640px) {
  .auth-panel { background: radial-gradient(800px 380px at 50% -120px, #efe3c4 0%, rgba(239, 227, 196, 0) 70%); }
  .auth-card { border: 1px solid var(--a-line-soft); box-shadow: 0 2px 6px rgba(20, 35, 29, 0.04), 0 24px 48px -24px rgba(20, 35, 29, 0.25); }
  .faculty-panel.open > form { border: 1px solid var(--a-line-soft); }
}

@media (min-width: 1024px) {
  body.auth-page { background: var(--a-bg); }
  .auth-panel { background: var(--a-bg); }
  .auth-card { border: 0; background: none; box-shadow: none; }
  .auth-perks { display: none; }

  /* Brand side: the study-house photo under a deep green wash */
  .auth-hero {
    position: relative;
    isolation: isolate;
    color: #fff;
    background:
      linear-gradient(160deg, rgba(13, 45, 35, 0.94) 0%, rgba(18, 59, 46, 0.86) 55%, rgba(8, 30, 23, 0.95) 100%),
      url("images/kids-studyhouse.jpg") center / cover no-repeat,
      #123B2E;
  }
  .auth-hero::after {
    content: "";
    position: absolute;
    inset: 24px;
    border: 1px solid rgba(230, 203, 128, 0.28);
    border-radius: 22px;
    pointer-events: none;
  }
  .auth-hero-crest { box-shadow: 0 0 0 3px rgba(230, 203, 128, 0.7), 0 18px 40px rgba(0, 0, 0, 0.35); }
  .auth-hero .auth-hero-eyebrow {
    margin: 0 0 16px;
    line-height: 1.3;
    max-width: none;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #E6CB80;
  }
  .auth-hero h2 { font-family: var(--a-font-display); font-weight: 600; color: #fff; letter-spacing: -0.015em; }
  .auth-hero h2 em { font-style: italic; color: #E6CB80; }
  .auth-hero p { color: rgba(255, 255, 255, 0.82); }
  .auth-hero-list {
    list-style: none;
    margin: 36px 0 0;
    padding: 0;
    display: grid;
    gap: 14px;
    max-width: 40ch;
    font-size: 17px;
    color: rgba(255, 255, 255, 0.9);
  }
  .auth-hero-list li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.45; }
  .auth-hero-list svg {
    flex: none;
    width: 22px;
    height: 22px;
    padding: 4px;
    border-radius: 50%;
    background: rgba(230, 203, 128, 0.16);
    color: #E6CB80;
    margin-top: 1px;
  }
  .auth-nav { background: rgba(251, 248, 241, 0.9); }
}
