/* Auth + first-run setup overlays (js/auth.js, js/setup.js).
   Reuses the custom properties and .btn styles from css/base.css, so both
   overlays follow the light/dark theming automatically. */

.auth-overlay,
.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  /* Brand navy, not a generic dark scrim — same rail colors used everywhere
     else in the app, so the login screen reads as this product rather than
     a modal dropped on a blank page. A soft accent glow anchors the card
     without competing with it. */
  background:
    radial-gradient(1100px circle at 18% 15%, rgba(99, 164, 255, 0.16), transparent 55%),
    radial-gradient(900px circle at 85% 88%, rgba(99, 164, 255, 0.10), transparent 55%),
    linear-gradient(160deg, var(--rail) 0%, var(--rail-2) 55%, var(--rail) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  overflow-y: auto;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.28);
  padding: var(--sp-6);
  width: 100%;
  margin: auto 0; /* keeps a tall card scrollable inside the overlay */
}
.setup-card { max-width: 560px; }

/* ---- sign-in: a plain column on the overlay, no box around it. Light text
   on the navy background; the inputs and buttons keep their base styles. ---- */
.auth-panel {
  width: 100%;
  max-width: 360px;
  margin: 0 0 auto;
  color: #fff;
}
/* Top-anchored (issue #16 F-59): a centred panel jumped 74px each time an
   error line or the code step changed its height. */
.auth-overlay:has(> .auth-panel) {
  align-items: flex-start;
  padding-top: clamp(var(--sp-5), 18vh, 200px);
}
.auth-panel > .auth-error { margin-bottom: var(--sp-3); }
.auth-panel .auth-field label,
.auth-panel .auth-sub,
.auth-panel .auth-note,
.auth-panel .auth-consent { color: rgba(255, 255, 255, 0.78); }
/* The rule spans the panel, not just the title (issue #16 F-82). */
.auth-panel .auth-brand {
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}
.auth-panel .auth-brand h1 { font-size: var(--fs-xl); font-weight: 700; }
.auth-panel .auth-sub { margin: var(--sp-3) 0 var(--sp-5); }
.auth-panel .auth-field input { width: 100%; }
.auth-panel .auth-error { color: #ffb4b4; border-color: #ffb4b4; background: transparent; }
.auth-panel .auth-link { color: #fff; }
/* The UA focus ring is near-black, invisible on the navy panel. */
.auth-panel :is(.btn, .auth-link):focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---- shared: brand, forms, errors ---- */
.auth-brand { display: flex; align-items: center; gap: var(--sp-2); }
.auth-brand h1 { font-size: var(--fs-xl); font-weight: 700; }
.auth-sub { color: var(--text-muted); font-size: var(--fs-md); margin: var(--sp-1) 0 var(--sp-3); }
.auth-note { font-size: var(--fs-md); margin: 0; }
.auth-closed { font-weight: 600; }
.auth-consent { font-size: var(--fs-xs); line-height: var(--lh); margin: 0; }
/* Wraps rather than squeezing Resend to two lines on a phone (F-60). The
   rule is the theme border on the setup card; white only on the navy sign-in
   panel (F-83). */
.auth-step-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  row-gap: var(--sp-2);
  margin-top: var(--sp-1);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.auth-panel .auth-step-actions { border-top-color: rgba(255, 255, 255, 0.22); }
.auth-resend { white-space: nowrap; }
.auth-resend:disabled { opacity: 0.7; cursor: default; }
.auth-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: var(--fs-sm);
  text-decoration: underline;
  cursor: pointer;
}
.auth-back { min-height: 24px; }
/* The indent balances the tracking after the last digit, so the code sits
   on the centre line (F-87). */
.auth-field input[autocomplete="one-time-code"] {
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  font-size: var(--fs-xl);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.auth-form { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-field label { margin-bottom: var(--sp-1); }
.auth-submit { justify-content: center; margin-top: var(--sp-0); }
/* Account dialogs: the button sits at the form's end at its own width, not
   stretched across it with a left-aligned label (F-62). */
:is(.account-name-form, .account-delete-form) > .btn { align-self: flex-end; justify-content: center; }

/* ---- school typeahead ---- */
.school-picker { position: relative; }
.school-picker input { width: 100%; }

.school-options {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 244px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}
.school-options[hidden] { display: none; }

.school-option {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  font-size: var(--fs-md);
  border-bottom: 1px solid var(--border);
}
.school-option:last-child { border-bottom: 0; }
.school-option:hover,
.school-option.active { background: var(--accent-soft); }
.school-option.active .school-name { color: var(--accent); }

/* The name takes the row; a long state/country line wraps under it rather
   than squeezing the name into a narrow column. */
.school-name { flex: 1 1 60%; min-width: 0; }
@media (max-width: 560px) {
  .school-option { flex-direction: column; align-items: stretch; gap: var(--sp-0); }
}
.school-meta {
  flex-shrink: 1;
  min-width: 0;
  font-size: var(--fs-2xs);
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.auth-error {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 600;
  background: var(--surface-2);
}

/* ---- footer chip ---- */
.auth-chip {
  margin-top: var(--sp-4);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-3);
}

/* ---- setup wizard ---- */
.setup-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.setup-icon { font-size: 1.875rem; }
.setup-head h1 { font-size: var(--fs-xl); font-weight: 700; }
.setup-sub { color: var(--text-muted); font-size: var(--fs-md); }
.setup-lead { color: var(--text-muted); font-size: var(--fs-md); margin-bottom: var(--sp-3); }

.setup-rail {
  display: flex;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--sp-3);
}
/* Sized by its label (issue #16 F-84): four equal quarters cut "School &
   Canvas" and "Knowledge base" to an ellipsis on the 560px card. */
.setup-rail-step {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.setup-rail-dot {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-2xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.setup-rail-step.active { color: var(--accent); }
.setup-rail-step.active .setup-rail-dot {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.setup-rail-step.done { color: var(--success); }
.setup-rail-step.done .setup-rail-dot { border-color: var(--success); color: var(--success); }
.setup-rail-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.setup-body .auth-field { margin-bottom: var(--sp-3); }
/* Inside a form the form's gap spaces the fields, as on the sign-in panel
   (12px, not 24px; F-61). */
.setup-body .auth-form .auth-field { margin-bottom: 0; }
.setup-link { display: inline-block; margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--accent); }
.setup-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }

.setup-status { margin-top: var(--sp-3); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.setup-status:empty { display: none; }
.setup-status.ok { color: var(--success); }
.setup-status.err { color: var(--danger); }

/* ---- environment checklist ---- */
.setup-checks { display: flex; flex-direction: column; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }
.setup-check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.setup-check-mark {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  background: var(--surface-2);
}
.setup-check.ok .setup-check-mark { color: var(--success); }
.setup-check.err .setup-check-mark { color: var(--danger); }
.setup-check.skipped { opacity: 0.7; }
.setup-check-label { font-weight: 600; color: var(--text); font-size: var(--fs-sm); }
.setup-check-hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- knowledge-base build log ---- */
.setup-log {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--sp-2) var(--sp-3);
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-loose);
  color: var(--text-muted);
}
.setup-log:empty { display: none; }
.setup-log-line { word-break: break-word; }
.setup-log-line.stage { color: var(--accent); font-weight: 700; margin-top: var(--sp-1); }
.setup-log-line.err { color: var(--danger); }

@media (max-width: 560px) {
  .setup-rail-label { display: none; }
}

/* 561-760px: four steps leave each label about 90px, so a label wraps to a
   second line rather than ending in an ellipsis (issue #16 F-84). Under
   560px the labels are hidden above. */
@media (max-width: 760px) {
  .setup-rail-label { white-space: normal; overflow-wrap: anywhere; }
}
