/*
 * Shared stylesheet for the standalone auth screens (login, forgot
 * password, reset password) — styled as a school letterhead document
 * rather than a generic SaaS auth panel. Each page defines
 * --brand-primary / --brand-primary-dark inline (from school_settings(),
 * see App/core/functions.php) before this file's selectors ever read
 * them, same pattern as App/views/layout/header.view.php uses for the
 * rest of the portal — one hex color drives both.
 */

:root {
  --paper: #EEF1EA;
  --sheet: #FBFBF6;
  --sheet-edge: #D7DECF;
  --ink: #1B2620;
  --ink-muted: #5E6B5F;
  --rule: #B9C3B0;

  /* Brand-derived: darker shade for headings/button fill, the
     configured color itself for links/focus, dark shade again (at low
     opacity via the seal's own alpha) for the corner seal. */
  --forest: var(--brand-primary-dark, #123A25);
  --forest-soft: var(--brand-primary, #1C8A4C);
  --seal: var(--brand-primary-dark, #A9382A);
  --focus-ring: color-mix(in srgb, var(--brand-primary, #1C8A4C) 28%, transparent);

  /* Errors stay a fixed, recognizable red regardless of brand color —
     semantic color, not the brand accent. */
  --danger: #A9382A;
  --danger-bg: #F6E7E1;
  --danger-border: #E3C3B4;

  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Noto Serif', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0B120D;
    --sheet: #121A14;
    --sheet-edge: #26332A;
    --ink: #E9EEE6;
    --ink-muted: #9CAB9E;
    --rule: #33452F;

    /* Brightened against the dark ground rather than the raw configured
       color, which can read too dark/muddy on a near-black page. */
    --forest: color-mix(in srgb, var(--brand-primary, #1C8A4C) 70%, white);
    --forest-soft: color-mix(in srgb, var(--brand-primary, #1C8A4C) 55%, white);
    --seal: color-mix(in srgb, var(--brand-primary, #1C8A4C) 70%, white);

    --danger: #E2694F;
    --danger-bg: #2A1712;
    --danger-border: #4A2A21;
  }
}

:root[data-theme="dark"] {
  --paper: #0B120D;
  --sheet: #121A14;
  --sheet-edge: #26332A;
  --ink: #E9EEE6;
  --ink-muted: #9CAB9E;
  --rule: #33452F;

  --forest: color-mix(in srgb, var(--brand-primary, #1C8A4C) 70%, white);
  --forest-soft: color-mix(in srgb, var(--brand-primary, #1C8A4C) 55%, white);
  --seal: color-mix(in srgb, var(--brand-primary, #1C8A4C) 70%, white);

  --danger: #E2694F;
  --danger-bg: #2A1712;
  --danger-border: #4A2A21;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.page {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: clamp(18px, 5vw, 56px) clamp(14px, 4vw, 24px);
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: fit-content;
  background: var(--sheet);
  border: 1px solid var(--sheet-edge);
  box-shadow: 0 1px 2px rgba(18, 30, 20, 0.06), 0 12px 28px -20px rgba(18, 30, 20, 0.4);
  padding: clamp(22px, 5vw, 34px) clamp(20px, 5vw, 36px) clamp(26px, 5vw, 32px);
  overflow: hidden;
  opacity: 0;
  animation: settle 0.45s ease-out forwards;
}

@keyframes settle {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; opacity: 1; transform: none; }
  .line-field input, .link-btn, .btn-seal { transition: none !important; }
}

/* ---------- Letterhead ---------- */

.letterhead {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
}

.crest {
  flex: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
}

.school-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.05rem, 4vw, 1.22rem);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.school-sub {
  margin: 2px 0 0;
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.rule-thick {
  height: 2px;
  background: var(--forest);
  margin-top: 16px;
}

.rule-thin {
  height: 1px;
  background: var(--rule);
  margin-top: 3px;
  margin-bottom: 22px;
}

/* ---------- Body ---------- */

.doc-title {
  margin: 0 0 22px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.3rem, 5vw, 1.5rem);
  letter-spacing: -0.005em;
  text-wrap: balance;
}

.doc-lead {
  margin: -14px 0 22px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.alert {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  line-height: 1.4;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.alert.alert-success {
  background: color-mix(in srgb, var(--forest-soft) 16%, var(--sheet));
  color: var(--forest);
  border-color: color-mix(in srgb, var(--forest-soft) 40%, var(--sheet-edge));
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
}

.line-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.line-field input {
  appearance: none;
  width: 100%;
  min-height: 30px;
  padding: 2px 2px 8px;
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.line-field input::placeholder { color: var(--ink-muted); opacity: 0.65; }

.line-field input:focus {
  outline: none;
  border-bottom: 1px solid var(--forest-soft);
  box-shadow: 0 1px 0 0 var(--forest-soft);
}

.line-field input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.btn-seal {
  appearance: none;
  border: 1px solid var(--forest);
  background: var(--forest);
  color: var(--sheet);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-height: 46px;
  padding: 0 22px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-seal:hover { background: transparent; color: var(--forest); }
.btn-seal:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.btn-seal:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-seal:disabled:hover { background: var(--forest); color: var(--sheet); }

.field-feedback {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: -8px;
  min-height: 1.2em;
}

.text-success { color: var(--forest); }
.text-danger { color: var(--danger); }

.link-btn {
  background: none;
  border: none;
  padding: 8px 0;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--ink-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  white-space: nowrap;
}

.link-btn:hover, .link-btn:focus-visible { color: var(--forest-soft); }

.doc-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.doc-footer .ref {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

/* ---------- Seal ---------- */

.seal {
  position: absolute;
  right: 22px;
  bottom: 78px;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 1.5px solid var(--seal);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-11deg);
  opacity: 0.55;
  pointer-events: none;
}

.seal::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--seal);
  border-radius: 50%;
}

.seal span {
  font-family: var(--font-display);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--seal);
  text-align: center;
  line-height: 1.35;
}

@media (max-width: 420px) {
  .seal { right: 16px; bottom: 122px; width: 60px; height: 60px; opacity: 0.45; }
  .seal span { font-size: 0.46rem; }
  .form-row { flex-direction: column; align-items: stretch; }
  .link-btn { text-align: center; }
}
