/* Calcuflow identity provider — Material-inspired, branded, accessible auth pages. */

:root {
  --brand: #006492;          /* Calcuflow primary (logo) */
  --brand-strong: #00567d;
  --brand-ink: #102336;      /* Calcuflow deep navy */
  --brand-tint: #e3f2fb;

  --bg: #f5f8fb;
  --bg-grad-1: #eaf3f9;
  --bg-grad-2: #f6f8fb;
  --surface: #ffffff;
  --on-surface: #1b2430;
  --muted: #5b6772;
  --outline: #c4ccd6;
  --outline-strong: #9aa6b3;

  --error: #ba1a1a;
  --success: #18794e;

  --radius: 14px;
  --field-radius: 10px;
  --shadow: 0 10px 28px rgba(16, 35, 54, 0.10), 0 2px 6px rgba(16, 35, 54, 0.06);
  --focus-ring: 0 0 0 3px rgba(0, 100, 146, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #5bb8e6;
    --brand-strong: #7cc8f0;
    --brand-ink: #cfe6f4;
    --brand-tint: #0d2230;
    --bg: #0e151c;
    --bg-grad-1: #0c1820;
    --bg-grad-2: #0e151c;
    --surface: #161f29;
    --on-surface: #e6edf4;
    --muted: #9fb0bf;
    --outline: #36434f;
    --outline-strong: #51606d;
    --error: #ffb4ab;
    --success: #6dd29c;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --focus-ring: 0 0 0 3px rgba(91, 184, 230, 0.4);
  }
}

* { box-sizing: border-box; }

html { background: var(--bg); height: 100%; }
/* body must NOT be height:100% — that would pin it to the viewport and let the card
   overflow the fixed box (clipping the bottom gap). min-height fills short pages while
   letting body grow with a tall card. Because body grows, justify-content:center never
   has overflow to clip; it just centers the card + legal footer on short pages. */

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px 16px;
  color: var(--on-surface);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  /* fixed attachment anchors the gradient to the viewport, so it stays consistent
     instead of stretching with the page height when content overflows/scrolls. */
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--brand-tint), transparent 60%),
    linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
}

.card {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  padding: 36px 32px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: card-in 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.brand { text-align: center; margin-bottom: 22px; }
.brand img { height: 44px; width: auto; }

h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}

.subtitle {
  margin: 0 0 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ---- Material-style outlined text fields (CSS-only floating label) ---- */
form { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.field { position: relative; }

.field input {
  width: 100%;
  height: 56px;
  /* symmetric padding keeps the value vertically centered; the label floats up
     onto the border rather than needing room inside the field. */
  padding: 0 14px;
  font-size: 1rem;
  color: var(--on-surface);
  background: transparent;
  border: 1.5px solid var(--outline);
  border-radius: var(--field-radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}

.field input:hover { border-color: var(--outline-strong); }

.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.field label {
  position: absolute;
  left: 12px;
  top: 28px; /* vertical center of the 56px input (independent of any .hint below) */
  transform: translateY(-50%);
  transform-origin: left center;
  padding: 0 4px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  pointer-events: none;
  background: var(--surface);
  transition: top 0.15s ease, transform 0.15s ease, color 0.15s ease;
}

.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  top: 0;
  transform: translateY(-50%) scale(0.78);
  color: var(--brand);
}

.field input:not(:focus):not(:placeholder-shown) + label { color: var(--muted); }

.field .hint { display: block; margin: 6px 4px 0; font-size: 0.8rem; color: var(--muted); }

/* ---- Inline validation feedback ----
   Forms use `novalidate`, so the browser never blocks submit or shows its own bubbles
   (the server stays the source of truth). These rules only add styling. We key off
   :user-invalid rather than :invalid so a field is flagged only after it has been edited
   and blurred — empty required fields aren't marked red on initial page load. The `pattern`
   attribute on email inputs mirrors the server regex in RegistrationService. */
.field input:user-invalid { border-color: var(--error); }
.field input:user-invalid:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 28%, transparent);
}
.field input:user-invalid + label { color: var(--error); }

.field-error {
  display: none;
  margin: 6px 4px 0;
  font-size: 0.8rem;
  color: var(--error);
}
.field input:user-invalid ~ .field-error { display: block; }

/* A field with a persistent .hint (e.g. the password rule) recolors the hint when invalid
   instead of stacking a second message beneath it. */
.field input:user-invalid ~ .hint { color: var(--error); }

/* ---- Buttons ---- */
.btn {
  height: 48px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }

/* ---- Messages ---- */
.alert {
  /* a normal block: must NOT be flex, or inline content (text + the <strong> email)
     gets split into separate flex items and stacks into broken columns. */
  padding: 12px 14px; border-radius: 10px; font-size: 0.9rem; line-height: 1.45;
}
.alert-error { background: color-mix(in srgb, var(--error) 12%, transparent); color: var(--error); }
.alert-info  { background: var(--brand-tint); color: var(--brand-strong); }
.alert-success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }

.foot {
  margin-top: 20px; text-align: center; color: var(--muted); font-size: 0.92rem;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }

.link-row { display: flex; justify-content: flex-end; align-items: center; margin-top: -6px; }

/* ---- Legal footer (imprint / privacy) — shown under the card on every page ---- */
.legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 12px;
  font-size: 0.82rem;
  color: var(--muted);
}
.legal a { color: var(--muted); }
.legal a:hover { color: var(--brand); }

/* ---- Proof-of-work captcha widget ---- */
.pow-captcha {
  --pc-accent: var(--brand);
  border: 1.5px solid var(--outline);
  border-radius: var(--field-radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: color-mix(in srgb, var(--brand-tint) 40%, var(--surface));
}

.pow-captcha__button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 44px;
  background: var(--surface);
  border: 1.5px solid var(--outline);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.95rem; color: var(--on-surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pow-captcha__button:hover { border-color: var(--brand); }
.pow-captcha__button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.pow-captcha__button:disabled { cursor: default; }

.pow-captcha__check {
  width: 26px; height: 26px; flex: 0 0 26px;
  border: 2px solid var(--outline-strong);
  border-radius: 50%;
  display: inline-grid; place-items: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.pow-captcha__check svg { width: 16px; height: 16px; }
.pow-captcha__check path {
  stroke: #fff; stroke-width: 3; fill: none;
  stroke-dasharray: 24; stroke-dashoffset: 24;
}

/* spinner shown while solving */
.pow-captcha__spinner {
  width: 22px; height: 22px; flex: 0 0 22px;
  border: 2.5px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  display: none;
  animation: pc-spin 0.7s linear infinite;
}

.pow-captcha__bar {
  height: 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 18%, transparent);
  overflow: hidden;
  display: none;
}
.pow-captcha__bar-fill {
  height: 100%; width: 0%;
  background: var(--brand);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.pow-captcha__status { font-size: 0.82rem; color: var(--muted); min-height: 1em; }

/* state machine */
.pow-captcha[data-state="solving"] .pow-captcha__check { display: none; }
.pow-captcha[data-state="solving"] .pow-captcha__spinner { display: block; }
.pow-captcha[data-state="solving"] .pow-captcha__bar { display: block; }

.pow-captcha[data-state="verified"] {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
}
.pow-captcha[data-state="verified"] .pow-captcha__button {
  border-color: var(--success); pointer-events: none;
}
.pow-captcha[data-state="verified"] .pow-captcha__check {
  border-color: var(--success); background: var(--success);
}
.pow-captcha[data-state="verified"] .pow-captcha__check path {
  animation: pc-check 0.4s ease forwards;
}
.pow-captcha[data-state="verified"] .pow-captcha__spinner,
.pow-captcha[data-state="verified"] .pow-captcha__bar { display: none; }
.pow-captcha[data-state="verified"] .pow-captcha__status { color: var(--success); }

.pow-captcha[data-state="error"] { border-color: var(--error); }
.pow-captcha[data-state="error"] .pow-captcha__status { color: var(--error); }
.pow-captcha[data-state="error"] .pow-captcha__spinner,
.pow-captcha[data-state="error"] .pow-captcha__bar { display: none; }

@keyframes pc-spin { to { transform: rotate(360deg); } }
@keyframes pc-check { to { stroke-dashoffset: 0; } }

/* ---- Motion & responsive ---- */
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  .pow-captcha__spinner { animation-duration: 1.4s; }
  .pow-captcha__check path { animation: none !important; stroke-dashoffset: 0; }
  * { transition-duration: 0.001ms !important; }
}

@media (max-width: 480px) {
  .card { padding: 28px 20px 24px; border-radius: 12px; box-shadow: none; }
  body { padding: 0 0 24px; align-items: stretch; background: var(--surface); }
  .legal { text-align: center; } /* footer keeps its 24px bottom gap on phones */
  .row { flex-direction: column; gap: 18px; }
  h1 { font-size: 1.35rem; }
}
