/* Shared visual theme for the unauthenticated pages (login, server-starting).
   Self-contained on purpose — kept out of style.css so it never interacts
   with the per-entity --entity-bg-color theming used everywhere else. */

:root {
  --ink: #24262a;
  --ink-2: #2f3236;
  --paper: #f5f4f1;
  --paper-2: #eae8e3;
  --accent-default: #d3d5d8;
  --slate: #5a5e63;
  --slate-soft: #8a8e93;
  --line-light: #e0ded8;
  --line-dark: #3a3d41;
  --danger: #b3452f;

  --surface: var(--paper);
  --surface-panel: var(--ink);
  --text: #202325;
  --text-muted: var(--slate);
  --on-panel: #eef0ef;
  --on-panel-muted: #a3a8ac;
  --border: var(--line-light);
  --border-panel: var(--line-dark);
  /* --entity-bg-color/--entity-font-color, when present, are stamped onto <html> by
     sendHtmlPage() for the Entity of whoever last logged in on THIS browser (see the
     last_login_entity cookie in server.js's GET /login and POST /api/auth/login) — falls
     back to the neutral light-grey/dark-ink pair below until this browser has logged in. */
  --accent: var(--entity-bg-color, var(--accent-default));
  --accent-strong: color-mix(in srgb, var(--accent) 80%, black);
  --accent-on: var(--entity-font-color, #24262a);
  --field-bg: #ffffff;
  --shadow: 0 24px 60px -28px rgba(20, 21, 23, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #19191a;
    --surface-panel: #131314;
    --text: #ececea;
    --text-muted: #9b9c9d;
    --on-panel: #ececea;
    --on-panel-muted: #9b9c9d;
    --border: #333333;
    --border-panel: #2a2a2b;
    --field-bg: #202021;
    --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --surface: #19191a;
  --surface-panel: #131314;
  --text: #ececea;
  --text-muted: #9b9c9d;
  --on-panel: #ececea;
  --on-panel-muted: #9b9c9d;
  --border: #333333;
  --border-panel: #2a2a2b;
  --field-bg: #202021;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.6);
}

.authpage, .authpage *, .authpage *::before, .authpage *::after { box-sizing: border-box; }
.authpage h1, .authpage h2, .authpage p, .authpage form { margin: 0; padding: 0; }

.authpage .d-none { display: none !important; }
.authpage .mb-3 { margin-bottom: 1rem !important; }

body.authpage {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.authpage .brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--on-panel-muted);
}

.authpage .brand-mark .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.authpage .btn-primary {
  width: 100%;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-on);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 13px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s ease, transform .1s ease;
}
.authpage .btn-primary:hover { background: var(--accent-strong); }
.authpage .btn-primary:active { transform: translateY(1px); }
.authpage .btn-primary:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 3px; }
.authpage .btn-primary:disabled { opacity: 0.7; cursor: default; }

.authpage .field { margin-bottom: 18px; }

.authpage .field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--text);
}

.authpage .field-control {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--field-bg);
  padding: 0 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.authpage .field-control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.authpage .field-control svg { flex-shrink: 0; color: var(--text-muted); }
.authpage .field-control:focus-within svg { color: var(--accent-strong); }

.authpage .field-control input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  padding: 11px 0;
  min-width: 0;
}

.authpage .field-control input::placeholder { color: var(--slate-soft); }

.authpage .toggle-visibility {
  border: none;
  background: none;
  padding: 4px;
  display: flex;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
}
.authpage .toggle-visibility:hover { color: var(--accent-strong); }
.authpage .toggle-visibility:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.authpage .alert-danger {
  background: rgba(179, 69, 47, 0.1);
  border: 1px solid rgba(179, 69, 47, 0.35);
  color: var(--danger);
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: 8px;
}

/* ---------- Login: split-panel shell ---------- */

.authpage .shell {
  width: 100%;
  max-width: 1040px;
  margin: clamp(0px, 4vw, 56px) auto;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 620px;
}

.authpage .brand {
  background:
    radial-gradient(120% 140% at 15% -10%, #3a3d40 0%, transparent 55%),
    var(--surface-panel);
  color: var(--on-panel);
  padding: clamp(36px, 5vw, 64px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  border-right: 1px solid var(--border-panel);
}

.authpage .brand-copy h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(2.4rem, 4vw, 3.1rem);
  line-height: 1.05;
  margin: 22px 0 14px;
  text-wrap: balance;
  letter-spacing: -0.01em;
}

.authpage .brand-copy h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--accent);
}

.authpage .brand-copy p {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--on-panel-muted);
  max-width: 34ch;
  margin: 0;
}

.authpage .trend { margin-top: clamp(28px, 6vh, 56px); }

.authpage .trend-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--on-panel-muted);
  margin-bottom: 10px;
}

.authpage .trend-label strong {
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.authpage .trend svg { display: block; width: 100%; height: auto; }

.authpage .trend-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  animation: authTrendDraw 1.7s cubic-bezier(.4,0,.2,1) 0.2s forwards;
}

.authpage .trend-fill {
  opacity: 0;
  animation: authFadeIn 1.2s ease 1.1s forwards;
}

.authpage .trend-dot {
  fill: var(--accent);
  opacity: 0;
  animation: authFadeIn 0.5s ease 1.7s forwards, authPulse 2.6s ease-in-out 2.4s infinite;
  transform-origin: center;
}

/* Overrides the gradient <stop> elements' own stop-color attributes so the trend-fill
   gradient tracks --accent too, instead of staying pinned to the static teal underneath it. */
.authpage .trend-stop-start,
.authpage .trend-stop-end {
  stop-color: var(--accent);
}

.authpage .brand-foot {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border-panel);
  font-size: 0.8rem;
  color: var(--on-panel-muted);
}

@keyframes authTrendDraw { to { stroke-dashoffset: 0; } }
@keyframes authFadeIn { to { opacity: 1; } }
@keyframes authPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.6); }
}

@media (prefers-reduced-motion: reduce) {
  .authpage .trend-path, .authpage .trend-fill, .authpage .trend-dot {
    animation: none !important;
    opacity: 1 !important;
    stroke-dashoffset: 0 !important;
  }
}

.authpage .form-panel {
  background: var(--surface);
  padding: clamp(36px, 5vw, 64px);
  display: flex;
  align-items: center;
}

.authpage .form-inner { width: 100%; max-width: 360px; margin: 0 auto; }

.authpage .eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin: 0 0 10px;
}

.authpage .form-inner h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.authpage .form-inner > p.sub {
  margin: 0 0 30px;
  color: var(--text-muted);
  font-size: 0.925rem;
}

.authpage .helper {
  margin-top: 22px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}
.authpage .helper a { color: var(--accent-strong); text-decoration: none; }
.authpage .helper a:hover { text-decoration: underline; }

@media (max-width: 860px) {
  .authpage .shell {
    grid-template-columns: 1fr;
    margin: 0;
    border-radius: 0;
    min-height: 100vh;
    box-shadow: none;
  }
  .authpage .brand { border-right: none; border-bottom: 1px solid var(--border-panel); padding: 30px 26px; }
  .authpage .brand-copy h1 { font-size: 1.9rem; margin: 16px 0 10px; }
  .authpage .trend { margin-top: 22px; }
  .authpage .brand-foot { display: none; }
  .authpage .form-panel { padding: 34px 26px 48px; }
}

/* ---------- Server-starting: single centered card ---------- */

.authpage .status-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.authpage .status-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-panel);
  color: var(--on-panel);
  border: 1px solid var(--border-panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: clamp(28px, 5vw, 40px);
  text-align: center;
}

.authpage .status-card .brand-mark {
  justify-content: center;
  margin-bottom: 26px;
}

.authpage .status-spinner {
  width: 2.4rem;
  height: 2.4rem;
  margin: 0 auto 20px;
  border: 3px solid var(--border-panel);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: authSpin 0.8s linear infinite;
}

@keyframes authSpin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .authpage .status-spinner { animation-duration: 2.4s; }
}

.authpage .status-card h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.4rem;
  margin: 0 0 8px;
}

.authpage .status-card p {
  color: var(--on-panel-muted);
  font-size: 0.9rem;
  margin: 0 0 4px;
  line-height: 1.5;
}
