/* ─────────────────────────────────────────────────────────────────────────────
   Broker auth pages (server-rendered Jinja2 templates: base.html, error.html,
   wayf.html, claim_success.html) — same design system as the React console
   (apps/web/src/styles/global.css). Token values and component
   patterns (panel/notice/btn/field) are kept in sync by hand across the two
   files; there's no shared build step between the SPA and these templates.
   Login/signup, workspace-picking and link-a-site no longer render here at
   all — see app.broker.oauth_as.authorize_org's module docstring for why.
───────────────────────────────────────────────────────────────────────────── */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

:root {
  --sans: 'IBM Plex Sans', Helvetica, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;

  --bg: #F7F7F8;
  --surface: #FFFFFF;
  --surface-sunk: #FBFBFC;
  --surface-tint: #F3F3F5;

  --fg-1: #101012;
  --fg-2: #5A5A63;
  --fg-3: #6B6B73;
  --fg-4: #8A8A93;
  --fg-5: #A5A5AD;
  --fg-6: #B5B5BC;

  --border: #E5E5E8;
  --border-subtle: #EFEFF1;
  --border-faint: #F3F3F5;
  --border-solid-1: #C9C9CF;

  --accent: #1F5AE0;
  --accent-hover: #17439F;
  --accent-tint-bg: #EDF2FE;

  --dark: #101012;
  --dark-hover: #2A2A30;

  --green: #0F7A4F;
  --green-bg: #EDF6F1;
  --green-fg: #0F5C3E;
  --green-border: #CBE6D9;

  --amber: #A96A00;
  --amber-bg: #FBF4E8;
  --amber-fg: #7A4E00;
  --amber-border: #F0E2C6;

  --red: #B02A1F;
  --red-bg: #FDF4F3;
  --red-fg: #8A3A31;
  --red-border: #E0C3BE;

  --radius-sm: 4px;
  --radius-md: 5px;
  --radius-lg: 6px;
  --radius-xl: 8px;

  --shadow-card: 0 14px 34px rgba(16,16,18,0.07);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg-1);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input { font: inherit; color: inherit; }

@keyframes shIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
@keyframes spin { to { transform: rotate(360deg) } }

/* ── page shell ──────────────────────────────────────────────────────────── */
.auth-page { min-height: 100%; display: flex; flex-direction: column; align-items: center; }

.auth-topbar { width: 100%; padding: 18px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.auth-topbar__brand { display: flex; align-items: center; gap: 9px; max-width: 480px; margin: 0 auto; }
.auth-topbar__logo { width: 20px; height: 20px; flex: 0 0 auto; }
.auth-topbar__product { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }

.auth-tagline { margin: 22px 0 28px; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-5); }

/* ── card ────────────────────────────────────────────────────────────────── */
.auth-card {
  width: 100%; max-width: 440px; margin: 40px auto 0; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card); animation: shIn .2s ease both;
}
.auth-center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 12px 4px; }

.auth-section-header { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 20px; }
.auth-icon-wrap {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: var(--radius-md);
  background: var(--accent-tint-bg); display: flex; align-items: center; justify-content: center; font-size: 15px;
}

.auth-status-icon {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: #fff;
}
.auth-status-icon--red { background: var(--red); }
.auth-status-icon--green { background: var(--green); }

.auth-title { font-size: 15.5px; font-weight: 600; letter-spacing: -0.012em; line-height: 1.35; }
.auth-sub { margin-top: 4px; font-size: 12.5px; line-height: 1.5; color: var(--fg-3); }
.auth-hint { font-size: 12.5px; line-height: 1.55; color: var(--fg-3); }

/* ── forms ───────────────────────────────────────────────────────────────── */
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 7px; }
.auth-label { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-5); }
.auth-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: 0; font-size: 13px; font-family: var(--sans); background: var(--surface-sunk);
  transition: border-color .12s ease, background .12s ease;
}
.auth-input:focus { border-color: var(--accent); background: #fff; }

.auth-error {
  padding: 10px 12px; background: var(--red-bg); border: 1px solid var(--red-border);
  border-radius: var(--radius-md); font-size: 12px; line-height: 1.5; color: var(--red-fg);
}
.auth-warning {
  padding: 10px 12px; background: var(--amber-bg); border: 1px solid var(--amber-border);
  border-radius: var(--radius-md); font-size: 12px; line-height: 1.5; color: var(--amber-fg);
}

.auth-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }

/* ── buttons ─────────────────────────────────────────────────────────────── */
.auth-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.auth-btn--primary { background: var(--accent); color: #fff; }
.auth-btn--primary:hover { background: var(--accent-hover); }
.auth-btn--ghost { background: #fff; color: var(--fg-1); border-color: var(--border-solid-1); }
.auth-btn--ghost:hover { border-color: var(--dark); background: var(--surface-sunk); }

/* ── permission / step lists ─────────────────────────────────────────────── */
.auth-perms { margin: 16px 0; padding: 14px; background: var(--surface-sunk); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); }
.auth-perms__label { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-5); margin-bottom: 10px; }
.auth-perms__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.auth-perm-item { display: flex; align-items: flex-start; gap: 10px; font-size: 12.5px; line-height: 1.5; color: var(--fg-2); }
.auth-perm-check {
  flex: 0 0 auto; width: 17px; height: 17px; border-radius: 50%; background: var(--dark); color: #fff;
  display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 9.5px; font-weight: 600;
}

/* ── Contact Support launcher (templates/_support.html, behaviour in support.js) ─ */
.auth-textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.auth-required { color: var(--red); }
.auth-success {
  padding: 10px 12px; background: var(--green-bg); border: 1px solid var(--green-border);
  border-radius: var(--radius-md); font-size: 12px; line-height: 1.5; color: var(--green-fg);
}

/* z-index 35: the console also loads this file — keep the launcher above its sticky topbar (5)
   and dropdowns (30) but under its modals (40) and toasts (60). */
.mo-help {
  position: fixed; right: 24px; bottom: 24px; z-index: 35;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}
.mo-help__fab-wrap { position: relative; display: inline-flex; align-items: center; }
.mo-help__fab {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff;
  box-shadow: 0 6px 20px rgba(31,90,224,0.35), 0 2px 6px rgba(16,16,18,0.12);
  transition: transform .16s ease, background .16s ease;
}
.mo-help__fab:hover { background: var(--accent-hover); transform: translateY(-1px); }
.mo-help__fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mo-help__bubble {
  position: absolute; right: calc(100% + 12px); top: 50%; transform: translateY(-50%);
  white-space: nowrap; background: var(--surface); color: var(--fg-1);
  border-radius: 9px; padding: 7px 13px; font-size: 13px; font-weight: 600; letter-spacing: -0.01em;
  box-shadow: 0 4px 14px rgba(16,16,18,0.14), 0 0 0 1px var(--border-subtle);
}
.mo-help__bubble::after {
  content: ""; position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  border: 6px solid transparent; border-left-color: var(--surface);
}
.mo-help__popover[hidden] { display: none; }
.mo-help__popover {
  width: 360px; max-width: calc(100vw - 48px); max-height: calc(100vh - 120px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: 0 16px 48px rgba(16,16,18,0.16), 0 2px 8px rgba(16,16,18,0.08);
  overflow: hidden; transform-origin: bottom right; animation: mo-help-pop .14s ease;
}
@keyframes mo-help-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) { .mo-help__popover { animation: none; } }
.mo-help__popover-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0;
}
.mo-help__popover-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--fg-1); letter-spacing: -0.012em; line-height: 1.3; }
.mo-help__popover-desc { margin: 3px 0 0; font-size: 12.5px; color: var(--fg-3); }
.mo-help__popover-close {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; color: var(--fg-3); border-radius: var(--radius-sm); flex-shrink: 0;
}
.mo-help__popover-close:hover { background: var(--surface-tint); color: var(--fg-1); }
.mo-help__popover-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.mo-help__hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 480px) {
  .mo-help { right: 16px; bottom: 16px; }
  .mo-help__popover { max-width: calc(100vw - 32px); }
  .mo-help__bubble { display: none; }
}

/* The signed-out pages (ConnectFrame) tag the body "mo-help-centered". There the round launcher is
   never shown (even if something nudges it): help is the "Contact support" links, which open the form
   as a centred dialog over a dimmed page, not a popover in a corner. A click on the dimmed page, Esc
   or the X closes it. */
body.mo-help-centered .mo-help__fab-wrap { display: none; }
.mo-help.mo-help--dialog {
  inset: 0; z-index: 50; align-items: center; justify-content: center; padding: 24px;
  background: rgba(16, 16, 18, 0.42); animation: mo-help-fade .14s ease;
}
.mo-help--dialog .mo-help__fab-wrap { display: none; }
.mo-help--dialog .mo-help__popover { width: 400px; max-width: 100%; max-height: calc(100vh - 48px); transform-origin: center; }
@keyframes mo-help-fade { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 480px) {
  .mo-help.mo-help--dialog { padding: 16px; }
  .mo-help--dialog .mo-help__popover { max-height: calc(100vh - 32px); }
}
@media (prefers-reduced-motion: reduce) { .mo-help.mo-help--dialog { animation: none; } }

/* Nudged: the visitor looks stuck. The label shows (even on a phone) and the button pulses a few
   times, then rests. */
.mo-help--nudge .mo-help__bubble { display: block; }
.mo-help--nudge .mo-help__fab { animation: mo-help-nudge 1.6s ease-in-out 3; }
@keyframes mo-help-nudge {
  0%, 100% { box-shadow: 0 0 0 0 rgba(31, 90, 224, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(31, 90, 224, 0); }
}
@media (prefers-reduced-motion: reduce) { .mo-help--nudge .mo-help__fab { animation: none; } }

/* Phone input: [ country code | number ] sharing one border */
.mo-phone { position: relative; }
.mo-phone__row {
  display: flex; align-items: stretch; height: 38px;
  background: var(--surface-sunk); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; transition: border-color .12s ease, background .12s ease;
}
.mo-phone__row:focus-within { border-color: var(--accent); background: #fff; }
.mo-phone__country {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; flex-shrink: 0;
  background: var(--surface-tint); border-right: 1px solid var(--border);
  color: var(--fg-2); font-size: 13px; white-space: nowrap;
}
.mo-phone__country:hover { background: var(--border); }
.mo-phone__number {
  flex: 1; min-width: 0; padding: 0 12px; border: none; outline: none; background: transparent;
  font: inherit; font-size: 13px; color: var(--fg-1);
}
.mo-phone__number::placeholder { color: var(--fg-4); }
.mo-phone__iso { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; color: var(--fg-2); }
.mo-phone__dial { color: var(--fg-2); font-variant-numeric: tabular-nums; }
.mo-phone__menu {
  position: fixed; z-index: 10000; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
  box-shadow: 0 16px 48px rgba(16,16,18,0.16), 0 2px 8px rgba(16,16,18,0.08);
}
.mo-phone__search {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle); color: var(--fg-3);
}
.mo-phone__search input {
  flex: 1; border: none; outline: none; background: transparent; font: inherit; font-size: 13px; color: var(--fg-1);
}
.mo-phone__list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; }
.mo-phone__option {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px;
  text-align: left; font-size: 13px; color: var(--fg-1);
}
.mo-phone__option:hover, .mo-phone__option.is-selected { background: var(--surface-tint); }
.mo-phone__option .mo-phone__name { flex: 1; }
.mo-phone__option .mo-phone__dial, .mo-phone__option .mo-phone__iso { color: var(--fg-3); }
.mo-phone__option .mo-phone__iso { min-width: 22px; }
.mo-phone__empty { padding: 12px 10px; text-align: center; font-size: 13px; color: var(--fg-3); }

/* ── spinner ─────────────────────────────────────────────────────────────── */
.auth-spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--accent); animation: spin .7s linear infinite;
}

/* ── Problem card (templates/_problem.html, static/problem.js) ────────────────
   What went wrong and how to fix it, in the approved words of app/broker/problems.py. Ported from
   the standalone broker's stylesheet with its tokens mapped onto this one's. */
.mo-problem { display: flex; flex-direction: column; gap: 18px; }
.mo-problem__head { margin-bottom: 0; }
.mo-problem__icon { width: 36px; height: 36px; flex-shrink: 0; font-size: 15px; }
.mo-problem--site .mo-problem__icon {
  background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red-fg);
}
.mo-problem--flow .mo-problem__icon,
.mo-problem--ours .mo-problem__icon {
  background: var(--amber-bg); border: 1px solid var(--amber-border); color: var(--amber-fg);
}
.mo-problem__title { font-size: 16px; outline: none; }
.mo-problem__what { font-size: 13px; color: var(--fg-2); margin-top: 6px; line-height: 1.55; }

.mo-problem__steps { list-style: none; display: flex; flex-direction: column; gap: 10px; padding: 0; margin: 0; }
.mo-problem__step { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; color: var(--fg-2); line-height: 1.5; }
.mo-problem__step .auth-perm-check { margin-top: 1px; }
.mo-problem__step-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.mo-ips { display: flex; flex-direction: column; gap: 6px; }
.mo-ips__list { display: flex; flex-wrap: wrap; gap: 6px; }
.mo-ips__ip {
  font-family: var(--mono); font-size: 12px;
  padding: 3px 8px; border-radius: 999px;
  background: var(--surface-tint); border: 1px solid var(--border-solid-1); color: var(--fg-1);
  user-select: all;
}
.mo-ips__actions { display: flex; flex-wrap: wrap; gap: 4px 14px; }

.mo-link-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--accent); font-size: 12.5px; font-weight: 500; padding: 2px 0;
  text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--accent-tint-bg);
}
.mo-link-btn:hover { text-decoration-color: currentColor; }
.mo-link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.mo-link-btn.is-copied { color: var(--green-fg); text-decoration: none; }

.mo-problem__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mo-problem__actions .auth-btn--primary { flex: 0 1 auto; min-width: 140px; }
.mo-problem__help { margin-left: auto; }
.mo-problem__ref {
  font-size: 11.5px; color: var(--fg-4); border-top: 1px solid var(--border-solid-1);
  padding-top: 12px; overflow-wrap: anywhere;
}
.mo-problem__ref code { font-family: var(--mono); font-size: 11px; color: var(--fg-3); }

@media (max-width: 480px) {
  .mo-problem__actions .auth-btn { flex: 1 1 100%; }
  .mo-problem__help { margin-left: 0; }
}
