/* ==========================================================================
   Authentication Portal
   All brand colours, gradients and typography come from the System Settings
   theme variables (--nile-*) served by /api/v1/settings/theme.css.
   ========================================================================== */

:root {
  /* Derived tokens (computed from the settings palette) */
  --a-primary: var(--nile-primary);
  --a-primary-hover: var(--nile-primary-hover, var(--nile-primary));
  --a-accent: var(--nile-accent, var(--nile-primary));
  --a-secondary: var(--nile-secondary, var(--nile-primary));
  --a-card: var(--nile-card-bg, #fff);
  --a-bg: var(--nile-body-bg, #f1f5f9);
  --a-grad: var(--nile-gradient-primary, var(--nile-primary));
  --a-text: var(--nile-sidebar-bg, #0f172a);
  --a-muted: color-mix(in srgb, var(--a-text) 58%, var(--a-card));
  --a-line: color-mix(in srgb, var(--a-text) 14%, var(--a-card));
  --a-soft: color-mix(in srgb, var(--a-primary) 7%, var(--a-card));
  --a-ring: color-mix(in srgb, var(--a-primary) 24%, transparent);
  --a-danger: #dc2626;
  --a-warn: #d97706;
  --a-on-primary: #fff;
  --a-font: var(--nile-font-family, 'Inter', system-ui, sans-serif);
  --a-radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--a-font);
  color: var(--a-text);
  background:
    radial-gradient(900px 500px at 8% -10%, color-mix(in srgb, var(--a-primary) 16%, transparent), transparent 60%),
    radial-gradient(800px 500px at 100% 110%, color-mix(in srgb, var(--a-accent) 16%, transparent), transparent 60%),
    var(--a-bg);
  -webkit-font-smoothing: antialiased;
  transition: opacity .35s ease;
}
body.is-loading { opacity: 0; }

[hidden] { display: none !important; }
.hidden { display: none !important; }
:empty:where([data-brand]) { display: none; }

/* ---------- Layout ---------- */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.auth-shell {
  width: 90vw;
  max-width: 1500px;
  min-height: 90vh;
  min-height: 90dvh;
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  background: var(--a-card);
  border-radius: 28px;
  overflow: hidden;
  box-shadow:
    0 1px 2px color-mix(in srgb, var(--a-text) 8%, transparent),
    0 30px 70px -20px color-mix(in srgb, var(--a-primary) 38%, transparent);
  animation: shellIn .6s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes shellIn { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }
/* Desktop: the sign-in card fills 80% of the screen (tablets & phones keep their own layout below) */
@media (min-width: 881px) {
  .auth-shell { width: 80vw; max-width: 1720px; min-height: 80vh; min-height: 80dvh; }
}
/* Desktop "80% fit": everything inside the card is drawn at 80% scale (like 80% browser zoom), while the card
   itself still spans 80% of the screen. Zoom also scales vw/vh lengths, so they are divided by .8 first. */
@supports (zoom: 1) {
  @media (min-width: 881px) {
    .auth-shell {
      zoom: .8;
      width: calc(80vw / .8);
      max-width: calc(1720px / .8);
      min-height: calc(80vh / .8);
      min-height: calc(80dvh / .8);
    }
  }
}

/* ---------- Brand panel ---------- */
.brand-panel {
  position: relative;
  background: var(--a-grad);
  color: var(--a-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 44px;
  overflow: hidden;
  isolation: isolate;
}
.brand-panel-inner { position: relative; z-index: 2; text-align: center; max-width: 340px; }
.orb { position: absolute; border-radius: 50%; z-index: 1; background: rgba(255,255,255,.09); }
.orb-1 { width: 320px; height: 320px; top: -110px; right: -110px; }
.orb-2 { width: 240px; height: 240px; bottom: -90px; left: -80px; background: rgba(255,255,255,.07); animation: float 9s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-16px); } }

/* Logo tile adapts to the logo's real proportions (square crest, wide wordmark or tall mark).
   brand_logo_fit.js trims empty margins and sets data-logo-shape on the tile. */
.logo-tile {
  --tile-h: 112px;
  --tile-max-w: 260px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--tile-h);
  width: auto;
  min-width: var(--tile-h);
  max-width: min(100%, var(--tile-max-w));
  /* No tile behind the logo: the crest sits directly on the panel (soft shadow keeps it crisp) */
  background: transparent;
  box-shadow: none;
}
.logo-tile img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.28));
}
.logo-tile-lg { --tile-h: 136px; --tile-max-w: 300px; padding: 14px; border-radius: 30px; margin-bottom: 26px; }
.logo-tile-lg[data-logo-shape="wide"] { --tile-h: 104px; padding: 14px 20px; border-radius: 24px; }
.logo-tile-lg[data-logo-shape="tall"] { --tile-h: 150px; }
.logo-tile-md { --tile-h: 96px; --tile-max-w: 240px; padding: 11px; border-radius: 24px; margin-bottom: 16px; box-shadow: none; }
.logo-tile-md[data-logo-shape="wide"] { --tile-h: 76px; padding: 10px 16px; border-radius: 20px; }
.logo-tile-md[data-logo-shape="tall"] { --tile-h: 108px; }
/* No background behind the logo, whatever its colours: it sits directly on the page */
.logo-tile[data-logo-tone="light"] {
  background: transparent;
  box-shadow: none;
}
/* On light surfaces (the phone header) brand_logo_fit.js repaints white logos in the theme colour */
.mobile-brand .logo-tile img[data-logo-recolored] { filter: none; }

.brand-institution { margin: 0; font-size: 1.65rem; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
.brand-subtitle { margin: 8px 0 0; font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; opacity: .8; font-weight: 600; }
.brand-divider { width: 44px; height: 3px; border-radius: 3px; background: rgba(255,255,255,.55); margin: 26px auto; }
.brand-divider:has(+ .brand-banner:empty) { display: none; }
.brand-banner { margin: 0; font-size: .98rem; line-height: 1.65; opacity: .92; }

/* ---------- Form pane ---------- */
.form-pane { display: flex; flex-direction: column; padding: 48px 52px 28px; background: var(--a-card); }
.form-inner { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 400px; margin: 0 auto; }

.mobile-brand { display: none; text-align: center; margin-bottom: 26px; }
.mobile-institution { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
.mobile-app { margin: 5px 0 0; font-size: .85rem; color: var(--a-muted); }

.auth-view { display: none; }
.auth-view.active { display: block; animation: viewIn .4s ease both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.view-header { margin-bottom: 26px; }
.view-header h1 { margin: 0 0 8px; font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.view-header p { margin: 0; color: var(--a-muted); font-size: .95rem; line-height: 1.55; }
.view-header strong { color: var(--a-text); word-break: break-all; }

.btn-back-step {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 16px -4px; padding: 6px 10px 6px 6px;
  background: none; border: 0; border-radius: 8px; color: var(--a-primary); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: background .2s;
}
.btn-back-step:hover { background: var(--a-soft); }

/* ---------- Fields ---------- */
.form-group { margin-bottom: 18px; }
label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 7px; }
.label-split { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.label-split label { margin: 0; }
.link-subtle { font-size: .83rem; font-weight: 600; color: var(--a-primary); text-decoration: none; }
.link-subtle:hover { text-decoration: underline; }

.input-wrapper { position: relative; }
.input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: flex; color: var(--a-muted); pointer-events: none; transition: color .2s; }
.input-wrapper input {
  width: 100%; height: 52px; padding: 0 46px 0 44px;
  font: inherit; font-size: 1rem; color: var(--a-text);
  background: var(--a-soft); border: 1.5px solid var(--a-line); border-radius: var(--a-radius);
  outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
.input-wrapper input::placeholder { color: color-mix(in srgb, var(--a-muted) 80%, transparent); }
.input-wrapper input:hover { border-color: color-mix(in srgb, var(--a-primary) 40%, var(--a-line)); }
.input-wrapper input:focus { background: var(--a-card); border-color: var(--a-primary); box-shadow: 0 0 0 4px var(--a-ring); }
.input-wrapper:focus-within .input-icon { color: var(--a-primary); }

.btn-toggle-pwd {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center; background: none; border: 0; border-radius: 10px;
  color: var(--a-muted); cursor: pointer; transition: color .2s, background .2s;
}
.btn-toggle-pwd:hover { color: var(--a-primary); background: var(--a-soft); }

/* Checkbox */
.custom-checkbox { display: flex; align-items: center; gap: 10px; margin: 2px 0 22px; cursor: pointer; font-weight: 500; user-select: none; }
.custom-checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.checkbox-box {
  flex: none; width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--a-line); background: var(--a-card);
  display: grid; place-items: center; transition: all .2s;
}
.checkbox-box::after {
  content: ''; width: 5px; height: 10px; margin-top: -2px; border: solid var(--a-on-primary); border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0); transition: transform .18s;
}
.custom-checkbox input:checked + .checkbox-box { background: var(--a-primary); border-color: var(--a-primary); }
.custom-checkbox input:checked + .checkbox-box::after { transform: rotate(45deg) scale(1); }
.custom-checkbox input:focus-visible + .checkbox-box { box-shadow: 0 0 0 4px var(--a-ring); }
.checkbox-label { font-size: .9rem; color: var(--a-muted); }

/* Primary button */
.auth-btn {
  position: relative; width: 100%; height: 54px; display: flex; align-items: center; justify-content: center; gap: 10px;
  font: inherit; font-size: 1rem; font-weight: 700; letter-spacing: .01em; color: var(--a-on-primary);
  background: var(--a-grad); border: 0; border-radius: var(--a-radius); cursor: pointer; overflow: hidden;
  box-shadow: 0 12px 24px -10px color-mix(in srgb, var(--a-primary) 70%, transparent);
  transition: transform .2s, box-shadow .2s, filter .2s;
}
.auth-btn::after { content: ''; position: absolute; inset: 0; background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.22) 50%, transparent 70%); transform: translateX(-120%); transition: transform .7s; }
.auth-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 28px -10px color-mix(in srgb, var(--a-primary) 75%, transparent); }
.auth-btn:hover:not(:disabled)::after { transform: translateX(120%); }
.auth-btn:hover:not(:disabled) .btn-arrow { transform: translateX(4px); }
.auth-btn:active:not(:disabled) { transform: translateY(0) scale(.99); }
.auth-btn:focus-visible { outline: 0; box-shadow: 0 0 0 4px var(--a-ring); }
.auth-btn:disabled { cursor: not-allowed; filter: saturate(.7) brightness(.95); }
.btn-arrow { transition: transform .2s; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite; }
.auth-btn.loading .btn-arrow { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.view-footer { margin: 22px 0 0; text-align: center; font-size: .9rem; color: var(--a-muted); }
.view-footer-tight { margin-top: 10px; }
.activate-hint {
  margin: 18px 0 0; padding: 12px 14px; border-radius: 12px; font-size: .88rem; line-height: 1.5;
  color: var(--a-text); background: color-mix(in srgb, var(--a-primary) 8%, var(--a-card));
  border: 1px solid color-mix(in srgb, var(--a-primary) 28%, transparent);
  animation: hintIn .35s ease both;
}
.activate-hint strong { display: block; margin-bottom: 2px; }
.activate-hint[hidden] { display: none; }
@keyframes hintIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .activate-hint { animation: none; } }
.btn-text-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--a-primary); cursor: pointer; text-decoration: none; }
.btn-text-link:hover { text-decoration: underline; }

/* Secondary buttons: passkey sign-in (outlined) and ghost */
.auth-btn-passkey, .auth-btn-ghost {
  color: var(--a-primary); background: var(--a-card); border: 1.5px solid color-mix(in srgb, var(--a-primary) 45%, var(--a-line));
  box-shadow: none;
}
.auth-btn-passkey .spinner, .auth-btn-ghost .spinner { border-color: var(--a-ring); border-top-color: var(--a-primary); }
.auth-btn-passkey:hover:not(:disabled), .auth-btn-ghost:hover:not(:disabled) { background: var(--a-soft); box-shadow: none; }
.auth-btn-passkey.is-unsupported { opacity: .6; }

.auth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--a-muted); font-size: .8rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--a-line); }

/* Student / Staff selector */
.field-label { display: block; margin-bottom: 7px; font-weight: 600; font-size: .9rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: var(--a-radius); background: var(--a-soft); border: 1px solid var(--a-line); }
.segmented-opt { position: relative; cursor: pointer; }
.segmented-opt input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-opt span { display: block; text-align: center; padding: 10px 8px; border-radius: 10px; font-weight: 700; font-size: .92rem; color: var(--a-muted); transition: background .2s, color .2s, box-shadow .2s; }
.segmented-opt input:checked + span { background: var(--a-card); color: var(--a-primary); box-shadow: 0 2px 8px -3px color-mix(in srgb, var(--a-text) 30%, transparent); }
.segmented-opt input:focus-visible + span { box-shadow: 0 0 0 3px var(--a-ring); }

.field-hint { margin: 6px 2px 0; font-size: .78rem; line-height: 1.45; color: var(--a-muted); }
.code-input { letter-spacing: .18em; font-family: 'JetBrains Mono', ui-monospace, monospace; text-transform: uppercase; }

.status-badge { width: 54px; height: 54px; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; color: var(--a-primary); background: var(--a-soft); border: 1px solid var(--a-line); }
#viewMessage .view-header p { white-space: pre-line; }

/* OTP */
.otp-inputs-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp-digit {
  width: 100%; height: 56px; padding: 0; text-align: center; font: inherit; font-size: 1.4rem; font-weight: 700; color: var(--a-text);
  background: var(--a-soft); border: 1.5px solid var(--a-line); border-radius: 12px; outline: none; transition: all .2s;
}
.otp-digit:focus { background: var(--a-card); border-color: var(--a-primary); box-shadow: 0 0 0 4px var(--a-ring); }

/* Footer */
.auth-footer { margin-top: 28px; text-align: center; font-size: .78rem; color: var(--a-muted); line-height: 1.6; }
.auth-footer p { margin: 0; }
.auth-footer p:empty { display: none; }
.auth-support a { color: var(--a-primary); text-decoration: none; font-weight: 600; }
.auth-support a:hover { text-decoration: underline; }
.auth-support .sep { margin: 0 8px; opacity: .5; }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast-card {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 14px;
  background: var(--a-card); border: 1px solid var(--a-line); border-left: 4px solid var(--a-primary);
  box-shadow: 0 18px 40px -16px color-mix(in srgb, var(--a-text) 45%, transparent); animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
}
.toast-icon { flex: none; display: flex; color: var(--a-primary); margin-top: 1px; }
.toast-body { flex: 1; font-size: .9rem; line-height: 1.45; word-break: break-word; }
.toast-close { flex: none; background: none; border: 0; font-size: 1.3rem; line-height: 1; color: var(--a-muted); cursor: pointer; padding: 0 2px; }
.toast-success { border-left-color: var(--a-secondary); } .toast-success .toast-icon { color: var(--a-secondary); }
.toast-error { border-left-color: var(--a-danger); } .toast-error .toast-icon { color: var(--a-danger); }
.toast-warning { border-left-color: var(--a-warn); } .toast-warning .toast-icon { color: var(--a-warn); }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes toastSlideOut { to { opacity: 0; transform: translateX(24px); } }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 880px) {
  .auth-shell { grid-template-columns: 1fr; width: 90vw; max-width: none; margin: auto; border-radius: 22px; }
  .auth-shell::before { content: ''; display: block; height: 6px; background: var(--a-grad); }
  .brand-panel { display: none; }          /* mobile: login only */
  .mobile-brand { display: block; }
  .form-pane { padding: 28px 24px 20px; }
  .form-inner { max-width: 440px; }
  .view-header h1 { font-size: 1.35rem; }
}

@media (max-width: 480px) {
  .auth-shell { display: flex; flex-direction: column; border-radius: 18px; }
  .form-pane { flex: 1; padding: 22px 16px 16px; }
  .mobile-brand { margin-bottom: 18px; }
  .logo-tile-md { --tile-h: 76px; --tile-max-w: 200px; padding: 9px; border-radius: 20px; margin-bottom: 10px; }
  .logo-tile-md[data-logo-shape="wide"] { --tile-h: 60px; padding: 8px 12px; border-radius: 16px; }
  .logo-tile-md[data-logo-shape="tall"] { --tile-h: 88px; }
  .mobile-institution { font-size: 1.02rem; }
  .mobile-app { font-size: .74rem; }
  .view-header { margin-bottom: 18px; }
  .view-header h1 { font-size: 1.2rem; margin-bottom: 5px; }
  .view-header p { font-size: .8rem; }
  .form-group { margin-bottom: 13px; }
  label { font-size: .75rem; margin-bottom: 5px; }
  .link-subtle { font-size: .74rem; }
  .input-wrapper input { height: 42px; padding: 0 40px 0 38px; font-size: .85rem; border-radius: 11px; }
  .input-icon { left: 12px; } .input-icon svg { width: 16px; height: 16px; }
  .btn-toggle-pwd { width: 34px; height: 34px; }
  .checkbox-box { width: 17px; height: 17px; border-radius: 5px; }
  .checkbox-label { font-size: .78rem; }
  .custom-checkbox { margin-bottom: 16px; }
  .auth-btn { height: 44px; font-size: .88rem; border-radius: 11px; }
  .view-footer { font-size: .78rem; }
  .otp-inputs-grid { gap: 5px; }
  .otp-digit { height: 44px; font-size: 1.05rem; border-radius: 10px; }
  .auth-footer { font-size: .68rem; margin-top: 18px; }
  .toast-container { right: 12px; left: 12px; width: auto; }
  .toast-body { font-size: .8rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .auth-page { align-items: flex-start; }
  .mobile-brand { margin-bottom: 14px; }
  .logo-tile-md { --tile-h: 64px; margin-bottom: 8px; }
  .logo-tile-md[data-logo-shape="wide"] { --tile-h: 52px; }
  .logo-tile-md[data-logo-shape="tall"] { --tile-h: 72px; }
}

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

/* ---------- Verify it's you (new device) ---------- */
.verify-prompt { border: 1px solid color-mix(in srgb, var(--a-primary) 22%, transparent); background: color-mix(in srgb, var(--a-primary) 5%, #fff);
  border-radius: 14px; padding: 16px; margin-bottom: 18px; text-align: center; }
.verify-prompt-title { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.verify-prompt p { margin: 0 0 8px; font-size: .84rem; opacity: .85; }
.verify-number { font: 800 2.6rem/1 'Inter', system-ui, sans-serif; color: var(--a-primary); letter-spacing: .04em; margin: 6px 0 10px; }
.verify-waiting { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; opacity: .8; }
.verify-waiting .spinner { width: 14px; height: 14px; border-width: 2px; }
.verify-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: .76rem; opacity: .85; }
.verify-meta a { font-weight: 600; color: var(--a-primary); text-decoration: none; }
.verify-meta a[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.verify-note { font-size: .74rem; opacity: .7; margin: 12px 0 0; line-height: 1.5; }
.verify-waiting .spinner { border-color: rgba(15,23,42,.15); border-top-color: var(--a-primary); }
