/* ============================================================
   Auth screens — "Great Circle"
   Shared by #/login, #/signup and #/team-login. The globe itself is
   drawn by js/components/authGlobe.js, which reads the --ag-* canvas
   tokens below so both themes stay in one place.
   ============================================================ */

.ag {
  /* Dawn (light) */
  --ag-sky: linear-gradient(180deg, #D3E4F2 0%, #E4EEF6 55%, #EFEBE6 84%, #F2D8BE 100%);
  --ag-ink: #0C2340;
  --ag-muted: #3C5A76;
  --ag-line: #B4C8DA;
  --ag-line-hover: #7F9DB8;
  --ag-field: rgba(255, 255, 255, 0.86);
  --ag-accent: #0369A1;
  /* Gold is sampled from the logo (assets/logo.png): midtone #CE9857, highlight #F5E1A1 */
  --ag-amber: #D9A650;
  --ag-amber-hover: #E2B568;
  --ag-on-amber: #1A1206;
  --ag-warn: #B3261E;
  --ag-panel: #F4F8FB;
  --ag-mono-bg: rgba(3, 105, 161, 0.10);
  --ag-danger: #C62828;
  --ag-danger-hover: #B71C1C;
  --ag-danger-ink: #B3261E;

  /* Canvas */
  --ag-sea-hi: #DDEBF6;
  --ag-sea-lo: #A3C4E0;
  --ag-land-rgb: 12, 35, 64;
  --ag-land-alpha: 0.42;
  --ag-grid: rgba(12, 35, 64, 0.07);
  --ag-atm-rgb: 2, 132, 199;
  --ag-arc: #0369A1;
  --ag-arc-faint: rgba(3, 105, 161, 0.16);
  --ag-head-rgb: 2, 132, 199;
  --ag-city: #B27135;
  --ag-hub: #9C5F24;
  --ag-label: #0C2340;
  --ag-fail: #C2410C;

  position: relative;
  min-height: 100dvh;
  overflow: clip;
  color: var(--ag-ink);
  background: var(--ag-sky);
  font-family: 'Sora', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html.dark .ag {
  /* Night */
  --ag-sky: linear-gradient(180deg, #040C1A 0%, #0A1D3A 58%, #15284A 80%, #3A3748 92%, #7E5541 100%);
  --ag-ink: #EAF0F6;
  --ag-muted: #A3B6C9;
  --ag-line: #2B4466;
  --ag-line-hover: #43648F;
  --ag-field: rgba(5, 14, 30, 0.78);
  --ag-accent: #38BDF8;
  --ag-amber: #E2B568;
  --ag-amber-hover: #EBC585;
  --ag-warn: #FF8A65;
  --ag-panel: #0B1B35;
  --ag-mono-bg: rgba(56, 189, 248, 0.12);
  --ag-danger-hover: #D32F2F;
  --ag-danger-ink: #FF8A65;

  --ag-sea-hi: #12375F;
  --ag-sea-lo: #061329;
  --ag-land-rgb: 128, 190, 235;
  --ag-land-alpha: 0.62;
  --ag-grid: rgba(163, 182, 201, 0.08);
  --ag-atm-rgb: 56, 189, 248;
  --ag-arc: #38BDF8;
  --ag-arc-faint: rgba(56, 189, 248, 0.14);
  --ag-head-rgb: 186, 230, 253;
  --ag-city: #F5E1A1;
  --ag-hub: #E2B568;
  --ag-label: #EAF0F6;
  --ag-fail: #FF8A65;
}

.ag .hidden, .ag [hidden] { display: none !important; }

.ag-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* ── Top bar ─────────────────────────────────────────────── */
.ag-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 6vw, 96px);
}
/* app-theme.css / dark-theme.css paint every <header> as a frosted sticky bar
   with !important; this bar sits directly on the sky. */
.ag .ag-top {
  background: none !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  border-bottom: 0 !important;
  box-shadow: none !important;
}
.ag-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 4px;
  border-radius: 8px;
  color: var(--ag-muted);
  font-size: 14px;
  text-decoration: none;
  transition: color .15s ease-out;
}
.ag-home:hover { color: var(--ag-ink); }
.ag-home svg { width: 16px; height: 16px; }
.ag-icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: var(--ag-field);
  color: var(--ag-muted);
  cursor: pointer;
  transition: color .15s ease-out, border-color .15s ease-out;
}
.ag-icon-btn:hover { color: var(--ag-ink); border-color: var(--ag-line-hover); }
.ag-icon-btn svg { width: 20px; height: 20px; }

/* ── Panel ───────────────────────────────────────────────── */
.ag-ui {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 440px);
  align-content: center;
  min-height: calc(100dvh - 76px);
  padding: 24px clamp(16px, 6vw, 96px) 96px;
}
.ag-panel { display: grid; gap: 24px; }
.ag-brand { display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 600; }
.ag-brand img { width: 40px; height: 40px; object-fit: contain; }
.ag-title {
  margin: 0;
  font-weight: 300;
  font-size: clamp(34px, 4.4vw, 56px);
  line-height: 1.04;
  letter-spacing: -0.03em;
}
.ag-sub { margin: 12px 0 0; max-width: 40ch; color: var(--ag-muted); font-size: 16px; line-height: 1.6; }

.ag-tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--ag-line); }
.ag-tab {
  position: relative;
  min-height: 44px;
  padding: 12px 0;
  border: 0;
  background: none;
  color: var(--ag-muted);
  font: 500 16px/1 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: color .15s ease-out;
}
.ag-tab:hover, .ag-tab.active { color: var(--ag-ink); }
.ag-tab::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--ag-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .2s cubic-bezier(.2, .8, .2, 1);
}
.ag-tab.active::after { transform: scaleX(1); }

.ag-form, .ag-stack { display: flex; flex-direction: column; gap: 16px; }
.ag-field label { display: block; margin-bottom: 8px; color: var(--ag-muted); font-size: 14px; }
.ag-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: var(--ag-field);
  color: var(--ag-ink);
  font: 400 16px/1 'Sora', system-ui, sans-serif;
  transition: border-color .12s ease-out;
}
.ag-input:hover { border-color: var(--ag-line-hover); }
.ag-input[aria-invalid="true"] { border-color: var(--ag-warn); }
.ag-pw { position: relative; }
.ag-pw .ag-input { padding-right: 56px; }
.ag-eye {
  position: absolute;
  top: 50%;
  right: 4px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ag-muted);
  cursor: pointer;
  transform: translateY(-50%);
}
.ag-eye:hover { color: var(--ag-ink); }
.ag-eye svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ag-hint { margin: 8px 0 0; color: var(--ag-muted); font-size: 14px; line-height: 1.5; }

.ag-btn {
  height: 52px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--ag-amber);
  color: var(--ag-on-amber);
  font: 600 16px/1 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: background .15s ease-out, transform .1s ease-out;
}
.ag-btn:hover { background: var(--ag-amber-hover); }
.ag-btn:active { transform: scale(.98); }
.ag-btn:disabled { opacity: .72; cursor: progress; transform: none; }
.ag-btn-ghost {
  height: 52px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: transparent;
  color: var(--ag-ink);
  font: 500 16px/1 'Sora', system-ui, sans-serif;
  cursor: pointer;
  transition: border-color .15s ease-out;
}
.ag-btn-ghost:hover { border-color: var(--ag-line-hover); }
.ag-btn-sm { height: 40px; padding: 0 16px; font-size: 14px; }
.ag-btn, .ag-btn-ghost { white-space: nowrap; }
.ag-btn svg, .ag-btn-ghost svg { width: 20px; height: 20px; flex: none; }
.ag-btn-sm svg { width: 16px; height: 16px; }
.ag-btn-wide { width: 100%; }
.ag-btn-danger { background: var(--ag-danger); color: #FFFFFF; }
.ag-btn-danger:hover { background: var(--ag-danger-hover); }
.ag-row { display: flex; gap: 12px; }
.ag-row .ag-btn { flex: 1; }
.ag-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.ag-alt { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--ag-muted); font-size: 14px; }
.ag-link {
  min-height: 44px;
  padding: 12px 0;
  border: 0;
  background: none;
  color: var(--ag-ink);
  font: 500 14px/1.3 'Sora', system-ui, sans-serif;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.ag-link:hover { color: var(--ag-accent); }

.ag-err { margin: 0; color: var(--ag-warn); font-size: 14px; line-height: 1.5; }
.ag-notice {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: var(--ag-field);
  color: var(--ag-ink);
  font-size: 14px;
  line-height: 1.5;
}
.ag-err:empty, .ag-notice:empty { display: none; }

.ag-workspace {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: var(--ag-field);
}
.ag-workspace svg { width: 20px; height: 20px; flex: none; color: var(--ag-accent); }
.ag-workspace div { min-width: 0; }
.ag-workspace small { display: block; color: var(--ag-muted); font-size: 12px; }
.ag-workspace strong { display: block; overflow: hidden; font-size: 16px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }

.ag-install { align-items: center; flex-wrap: wrap; gap: 12px; }
.ag-install p { margin: 0; color: var(--ag-muted); font-size: 14px; }

/* ── Organization picker ─────────────────────────────────── */
.ag-top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ag-who {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  color: var(--ag-muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ag-who:empty { display: none; }

.ag-orgs { display: flex; flex-direction: column; gap: 12px; }
.ag-orgs.is-ready > * { animation: ag-fade .18s ease-out both; }
/* The enter button spans the whole row; owner actions overlay it in column 2,
   left of the plane, over a matching .ag-org-spacer inside the button. */
.ag-org {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 68px;
  border: 1px solid var(--ag-line);
  border-radius: 12px;
  background: var(--ag-field);
  transition: border-color .15s ease-out;
}
.ag-org:hover, .ag-org:focus-within { border-color: var(--ag-line-hover); }
.ag-org-enter {
  grid-area: 1 / 1 / 2 / 3;
  min-width: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ag-mono {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--ag-mono-bg);
  color: var(--ag-ink);
  font-size: 16px;
  font-weight: 600;
}
.ag-org-text { flex: 1; min-width: 0; display: grid; gap: 4px; }
.ag-org-name { overflow: hidden; font-size: 16px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.ag-org-role { color: var(--ag-muted); font-size: 14px; }
.ag-org-go {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--ag-muted);
  transform: rotate(90deg);
  transition: transform .2s cubic-bezier(.2, .8, .2, 1), color .15s ease-out;
}
.ag-org-enter:hover .ag-org-go,
.ag-org-enter:focus-visible .ag-org-go,
.ag-org.is-opening .ag-org-go { color: var(--ag-accent); transform: translateX(3px) rotate(90deg); }
.ag-org.is-opening .ag-org-enter { cursor: progress; }
/* 52px = button padding (16) + plane (20) + flex gap (16); 84px = two 40px buttons + 4px gap */
.ag-org-actions { grid-area: 1 / 2; z-index: 1; display: flex; gap: 4px; margin-right: 52px; }
.ag-org-spacer { flex: none; width: 84px; }
.ag-icon-sm { width: 40px; height: 40px; border-color: transparent; background: transparent; }
.ag-icon-sm:hover { border-color: var(--ag-line); }
.ag-icon-danger:hover { color: var(--ag-danger-ink); }
.ag-icon-sm svg { width: 16px; height: 16px; }
.ag-skel { height: 68px; border: 1px solid var(--ag-line); border-radius: 12px; background: var(--ag-field); opacity: .55; }
.ag-empty { padding: 4px 0; }
.ag-empty-title { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.ag-empty-sub { margin: 0; color: var(--ag-muted); font-size: 14px; line-height: 1.6; }
.ag-field-err { margin-top: 8px; }

/* ── Dialogs (native <dialog>, rendered in the top layer) ── */
.ag-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--ag-line);
  border-radius: 16px;
  background: var(--ag-panel);
  color: var(--ag-ink);
  font-family: 'Sora', system-ui, sans-serif;
  box-shadow: 0 24px 64px -24px rgba(4, 12, 26, .55);
}
.ag-dialog::backdrop { background: rgba(4, 12, 26, .55); }
.ag-dialog[open] { animation: ag-pop .22s cubic-bezier(.2, .8, .2, 1); }
.ag-dialog-body { display: grid; gap: 20px; padding: 24px; }
.ag-dialog-title { margin: 0; font-size: 20px; font-weight: 400; letter-spacing: -.02em; }
.ag-dialog-sub { margin: 8px 0 0; color: var(--ag-muted); font-size: 14px; line-height: 1.6; }
.ag-dialog-sub strong, .ag-dialog label strong { color: var(--ag-ink); font-weight: 600; }
.ag-dialog-danger .ag-dialog-title { color: var(--ag-danger-ink); }
.ag-input[readonly] { opacity: .7; }

@keyframes ag-fade { from { opacity: 0; } }
@keyframes ag-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.ag-route {
  position: absolute;
  z-index: 1;
  right: clamp(16px, 6vw, 96px);
  bottom: 32px;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  color: var(--ag-muted);
  font-size: 14px;
}
.ag-route b { color: var(--ag-ink); font-weight: 600; }

/* Focus: one visible ring everywhere, never obscured */
.ag a:focus-visible,
.ag button:focus-visible,
.ag-input:focus-visible {
  outline: 2px solid var(--ag-accent);
  outline-offset: 2px;
}
.ag-input:focus-visible { border-color: var(--ag-accent); }
.ag-eye:focus-visible, .ag-org-enter:focus-visible { outline-offset: -2px; }
.ag-btn:focus-visible { outline-offset: 3px; }

@media (max-width: 819px) {
  .ag-ui {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    min-height: 0;
    padding-top: var(--ag-top, 300px);
  }
  .ag-route {
    top: calc(var(--ag-top, 300px) + var(--ag-bar, 76px) - 44px);
    bottom: auto;
    left: 16px;
    right: 16px;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ag *, .ag *::after { transition-duration: .01ms !important; }
  .ag-orgs.is-ready > * { animation: none; }
  .ag-dialog[open] { animation: ag-fade .15s ease-out; }
}
