/* Koder ID — Auth UI Styles
 * Zero-dependency SSR stylesheet. Design tokens inlined for portability.
 *
 * Palette = Verge v0 (KDS canonical visual language, Adwaita 1:1), per
 * meta/docs/stack/specs/themes/verge.kmd §R4. Source of truth for the
 * values below is koder_web_kit's [data-style="verge"] block; they are
 * inlined here to keep this OAuth login surface dependency-free (no FOUC,
 * no 19-preset bundle on the critical sign-in path). Drift is guarded by
 * tests/regression/176_authui_verge_tokens_test.go — if Verge diverges
 * from Adwaita (owner-ratified per-token, §R3/§R6), update both. */

/* ═══════════════════════════════════════════════════
   Design Tokens — Verge v0 (themes/verge.kmd §R4)
   ═══════════════════════════════════════════════════ */

:root {
  /* Brand — Verge accent (Adwaita blue #3584E4), §R4.1 */
  --color-primary: #3584E4;
  --color-primary-hover: #1C71D8;
  --color-primary-active: #1A5FB4;
  --color-primary-bg: rgba(53, 132, 228, 0.08);
  --color-primary-ring: rgba(53, 132, 228, 0.25);
  --color-danger: #dc3545;
  --color-danger-bg: rgba(220, 53, 69, 0.08);
  --color-success: #28a745;
  --color-success-bg: rgba(40, 167, 69, 0.08);
  --color-warning: #f0ad4e;
  --color-warning-bg: rgba(240, 173, 78, 0.08);
  --color-info: #17a2b8;

  /* Surface — Light (Verge v0 / Adwaita neutrals) */
  --bg: #FAFAFA;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f0f0f0;
  --bg-active: #e4e4e4;
  --border: #c0c0c0;
  --border-focus: var(--color-primary);
  --text: #2e3436;
  --text-secondary: #5e6772;
  --text-muted: #828b94;
  --text-inverse: #ffffff;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.10);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);

  /* Radius — tightened toward Adwaita ("minimally rounded squares", §R4) */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.625rem;
  --text-3xl: 2rem;
  --lh-tight: 1.25;
  --lh-normal: 1.5;
  --lh-relaxed: 1.75;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;

  color-scheme: light dark;
}

[data-theme="dark"] {
  /* Verge v0 dark (Adwaita neutrals), §R4.2 — accent stays #3584E4 (Adwaita
     uses the same accent in dark; not overridden here). */
  --bg: #242424;
  --bg-card: #303030;
  --bg-input: #303030;
  --bg-hover: #3a3a3a;
  --bg-active: #424242;
  --border: #1b1b1b;
  --border-focus: var(--color-primary);
  --text: #ffffff;
  --text-secondary: #cccccc;
  --text-muted: #999999;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════════
   Reset & Base
   ═══════════════════════════════════════════════════ */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100svh;
}

/* ═══════════════════════════════════════════════════
   Shell Layout
   ═══════════════════════════════════════════════════ */

.auth-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  min-height: 100svh;
  padding: var(--sp-4);
  padding-top: var(--sp-10);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--sp-6);
}

/* ═══════════════════════════════════════════════════
   Logo
   ═══════════════════════════════════════════════════ */

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--sp-6);
}

.auth-logo-img {
  max-height: 48px;
  width: auto;
  object-fit: contain;
}

.auth-logo-text {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.02em;
}

/* ═══════════════════════════════════════════════════
   Typography
   ═══════════════════════════════════════════════════ */

.auth-title {
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: var(--lh-tight);
  text-align: center;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--sp-8);
  line-height: var(--lh-normal);
}

.auth-subtitle strong {
  color: var(--text);
  font-weight: 600;
}

.auth-error-code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--sp-2);
}

.auth-legal {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
  margin-top: var(--sp-4);
  line-height: var(--lh-normal);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-muted {
  color: var(--text-muted);
}

.text-sm {
  font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════
   Alerts
   ═══════════════════════════════════════════════════ */

.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--lh-normal);
  margin-bottom: var(--sp-6);
}

.alert-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(220, 53, 69, 0.15);
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid rgba(40, 167, 69, 0.15);
}

/* ═══════════════════════════════════════════════════
   Form
   ═══════════════════════════════════════════════════ */

.auth-form {
  width: 100%;
}

/* ═══════════════════════════════════════════════════
   Field Groups
   ═══════════════════════════════════════════════════ */

.field-group {
  margin-bottom: var(--sp-5);
}

.field-group-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.field-input {
  display: block;
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-sans);
  font-size: 1rem; /* 16px min — prevents iOS Safari auto-zoom on focus */
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.field-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

@media (hover: hover) {
  .field-input:hover {
    border-color: var(--text-muted);
  }
}

.field-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.field-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: var(--sp-1);
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

.field-input.is-error {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15);
}

/* Password strength bar */
.password-strength {
  margin-top: var(--sp-2);
}

.password-strength-bar {
  height: 3px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.password-strength-fill {
  height: 100%;
  border-radius: var(--radius-full);
  width: 0;
  transition: width var(--duration-normal) var(--ease-out),
              background var(--duration-normal) var(--ease-out);
}

.password-strength-fill[data-strength="1"] { width: 25%; background: var(--color-danger); }
.password-strength-fill[data-strength="2"] { width: 50%; background: var(--color-warning); }
.password-strength-fill[data-strength="3"] { width: 75%; background: #5bc0de; }
.password-strength-fill[data-strength="4"] { width: 100%; background: var(--color-success); }

.password-strength-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

/* OTP input */
.field-input-otp {
  max-width: 200px;
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.35em;
  padding: var(--sp-4);
}

/* ═══════════════════════════════════════════════════
   Password Toggle
   ═══════════════════════════════════════════════════ */

.password-wrapper {
  position: relative;
}

.password-wrapper .field-input {
  padding-right: var(--sp-12);
}

.password-toggle {
  position: absolute;
  right: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) {
  .password-toggle:hover {
    color: var(--text);
  }
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle.is-visible .icon-eye {
  display: none;
}

.password-toggle.is-visible .icon-eye-off {
  display: block;
}

/* ═══════════════════════════════════════════════════
   Checkboxes & Field Rows
   ═══════════════════════════════════════════════════ */

.field-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  user-select: none;
}

.checkbox-row-muted {
  margin-bottom: var(--sp-5);
}

.checkbox-input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-3) var(--sp-6);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: var(--lh-normal);
  text-decoration: none;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  outline: none;
  transition: all var(--duration-fast) var(--ease-out);
  user-select: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

.btn:disabled,
.btn.is-loading {
  opacity: 0.65;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn.is-loading::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
  opacity: 0.8;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--text-inverse);
  border-color: var(--color-primary);
  margin-bottom: var(--sp-3);
}

.btn-primary:active {
  background: var(--color-primary-active);
  border-color: var(--color-primary-active);
  transform: scale(0.99);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  margin-bottom: var(--sp-3);
}

.btn-secondary:active {
  background: var(--bg-active);
  transform: scale(0.99);
}

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: transparent;
  font-weight: 500;
  margin-bottom: var(--sp-3);
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
  }
  .btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
  }
  .btn-ghost:hover {
    background: var(--color-primary-bg);
  }
}

.btn-row {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.btn-row .btn {
  margin-bottom: 0;
}

/* ═══════════════════════════════════════════════════
   Social Login
   ═══════════════════════════════════════════════════ */

.divider {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin: var(--sp-6) 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  font-size: var(--text-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.social-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
}

.btn-social {
  width: auto;
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  padding: var(--sp-3);
  font-size: var(--text-sm);
  font-weight: 500;
}

@media (hover: hover) {
  .btn-social:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
  }
}

.btn-social:active {
  background: var(--bg-active);
  transform: scale(0.98);
}

.btn-social svg {
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════
   Scope List (Consent)
   ═══════════════════════════════════════════════════ */

.scope-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-5);
  overflow: hidden;
}

.scope-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}

.scope-item:last-child {
  border-bottom: none;
}

@media (hover: hover) {
  .scope-item:hover {
    background: var(--bg-hover);
  }
}

.scope-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.scope-info {
  flex: 1;
  min-width: 0;
}

.scope-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.scope-desc {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 1px;
}

.scope-badge {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════
   Links
   ═══════════════════════════════════════════════════ */

.link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: color var(--duration-fast) var(--ease-out);
}

.link:hover {
  text-decoration: underline;
}

.link-sm {
  font-size: var(--text-xs);
}

.auth-alt-actions {
  text-align: center;
  margin-top: var(--sp-5);
}

.auth-alt-actions .btn {
  margin-bottom: var(--sp-3);
}

/* ═══════════════════════════════════════════════════
   Footer
   ═══════════════════════════════════════════════════ */

.auth-footer {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-8);
}

.auth-footer-text {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

@media (hover: hover) {
  .theme-toggle:hover {
    color: var(--text);
    border-color: var(--text-muted);
    background: var(--bg-hover);
  }
}

/* In dark mode: show sun, hide moon */
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: block; }

/* In light mode: show moon, hide sun */
:root .icon-sun         { display: none; }
:root .icon-moon        { display: block; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ═══════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════ */

@media (min-width: 768px) {
  .auth-shell {
    justify-content: center;
    padding: var(--sp-6);
  }

  .auth-card {
    padding: var(--sp-10);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
  }

  .auth-title {
    font-size: var(--text-2xl);
  }

  .social-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .field-row {
    flex-direction: row;
    align-items: center;
  }
}
