/* ==============================================
   SSO — Auth Pages Stylesheet (Admin UI-Kit aligned)
   Shared by /login (OAuth flow), /admin/login (admin auth-error
   screen), /admin/error/403, /consent, /organization-select.
   Class names preserved for backward compatibility; colours,
   spacing, radii and typography pulled from admin design tokens
   (web/static/css/admin/tokens.css).
   ==============================================
   Sections:
     1. Base / Reset
     2. Login Card
     3. Auth Container (consent/logout)
     4. Consent Page
     5. Error Page (auth-card variant)
     6. Animations & Responsive
     7. Dark Theme (driven by tokens, only delta tweaks here)
   ============================================== */

/* Pull design tokens for both light and dark themes. On /admin/* pages
   tokens.css is already loaded via admin.css, but pure auth pages
   (/login, /consent, /organization-select, /oauth/error) only load
   login.css — without this @import the dark-theme variables stay
   undefined and `var(--fg-0, #0f172a)` etc. fall back to light values
   on every theme, so dark theme appears half-applied. */
@import url("admin/tokens.css");

/* ---------- 1. Base / Reset ---------- */

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

body {
  font-family: var(--font-sans, "Inter", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif);
  background:
    radial-gradient(
      ellipse 60% 60% at 10% 10%,
      rgba(16, 185, 129, 0.18),
      transparent 70%
    ),
    radial-gradient(
      ellipse 50% 50% at 90% 90%,
      rgba(153, 69, 255, 0.12),
      transparent 70%
    ),
    var(--bg-0, #f0f2f5);
  color: var(--fg-0, #0f172a);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow-x: hidden;
}

/* ---------- 2. Login Card ---------- */

/* Background glows + grid (same look as admin .brand-surface) */
.auth-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.auth-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 1;
  transition: opacity 0.3s;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(
    ellipse 80% 70% at 50% 50%,
    black 20%,
    transparent 70%
  );
  -webkit-mask-image: radial-gradient(
    ellipse 80% 70% at 50% 50%,
    black 20%,
    transparent 70%
  );
}

.auth-bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 1;
  transition:
    opacity 0.3s,
    filter 0.3s,
    background 0.3s;
}

.auth-bg-glow--tl {
  width: 600px;
  height: 600px;
  top: -10%;
  left: -10%;
  background: radial-gradient(
    circle,
    rgba(16, 185, 129, 0.3) 0%,
    transparent 70%
  );
}

.auth-bg-glow--br {
  width: 500px;
  height: 500px;
  bottom: -20%;
  right: -10%;
  background: radial-gradient(
    circle,
    rgba(153, 69, 255, 0.2) 0%,
    transparent 70%
  );
}

/* Card — glass-panel-equivalent for auth pages */
.auth-card {
  position: relative;
  z-index: 1;
  width: 400px;
  padding: 40px;
  background: var(--bg-1, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: var(--r-lg, 16px);
  box-shadow:
    var(--shadow-card, 0 1px 2px rgba(15, 23, 42, 0.04)),
    0 8px 24px -12px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
}

/* Green accent line at top */
.auth-card-glow {
  position: absolute;
  top: -1px;
  left: 1px;
  right: 1px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent-ring, rgba(16, 185, 129, 0.5)) 50%,
    transparent
  );
  border-radius: var(--r-lg, 16px) var(--r-lg, 16px) 0 0;
  opacity: 1;
  transition: opacity 0.3s;
}

/* Card header: logo + controls */
.auth-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

/* Logo */
.auth-logo {
  width: 32px;
  height: 32px;
  background: var(--accent, #10b981);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px var(--accent-ring, rgba(16, 185, 129, 0.3));
  flex-shrink: 0;
  overflow: hidden;
}

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--bg-1, #ffffff);
}

[data-theme="dark"] .brand-logo {
  color: var(--bg-0, #070b09);
}

/* Controls bar (lang + divider + theme) */
.auth-controls {
  display: flex;
  align-items: center;
  height: 38px;
  background: var(--bg-2, rgba(0, 0, 0, 0.04));
  border: 1px solid var(--line, rgba(0, 0, 0, 0.06));
  border-radius: 12px;
  padding: 0 5px;
}

.controls-divider {
  width: 1px;
  height: 14px;
  background: var(--line-strong, rgba(0, 0, 0, 0.1));
}

/* Heading */
.auth-heading {
  margin-bottom: 32px;
}

.auth-heading h1 {
  font-size: 30px;
  font-weight: 500;
  color: var(--fg-0, #0f172a);
  letter-spacing: -0.75px;
  line-height: 36px;
  margin-bottom: 8px;
}

.auth-heading p {
  font-size: 14px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  line-height: 22.75px;
}

.auth-heading-highlight {
  font-weight: 500;
  color: var(--fg-0, #0f172a);
}

/* Form fields */
#login-form-container {
  width: 100%;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-1, #475569);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-group label .required {
  color: var(--danger, #ef4444);
  margin-left: 2px;
}

.input-wrapper {
  position: relative;
  height: 42px;
}

/* Inline SVG icons (auth pages) — match the inline-block baseline alignment the
   iconify-icon web component used, so swapping to inline SVG keeps layout. */
.auth-ico {
  display: inline-block;
  vertical-align: -0.125em;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-3, #94a3b8);
  pointer-events: none;
  z-index: 1;
}

.input-wrapper input {
  width: 100%;
  height: 100%;
  padding: 0 16px 0 40px;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 300;
  font-family: inherit;
  color: var(--fg-0, #0f172a);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.input-wrapper input::placeholder {
  color: var(--fg-3, #94a3b8);
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--accent, #10b981);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(16, 185, 129, 0.1));
}

/* Password toggle */
.password-toggle {
  position: absolute;
  right: 0;
  top: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--fg-3, #94a3b8);
  cursor: pointer;
  transition: color 0.2s;
}

.password-toggle:hover {
  color: var(--fg-2, #64748b);
}

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

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

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

/* Checkbox + forgot link row */
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 4px;
  cursor: pointer;
  transition:
    background-color 0.2s,
    border-color 0.2s;
  flex-shrink: 0;
}

.checkbox-group input[type="checkbox"]:checked {
  background: var(--accent, #10b981);
  border-color: var(--accent, #10b981);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.checkbox-group label {
  font-size: 12px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  cursor: pointer;
  user-select: none;
}

.forgot-link {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent, #10b981);
  text-decoration: none;
  transition: color 0.2s;
  white-space: nowrap;
}

.forgot-link:hover {
  color: var(--accent-2, #059669);
}

/* Submit button */
.btn-submit {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
  background: var(--fg-0, #0f172a);
  color: var(--bg-1, white);
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition:
    background-color 0.3s,
    color 0.3s,
    box-shadow 0.3s;
}

.btn-submit:hover {
  background: var(--accent, #10b981);
  color: #ffffff;
}

.btn-submit:disabled {
  background: var(--fg-3, #94a3b8);
  cursor: not-allowed;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 32px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line, #e2e8f0);
}

.divider span {
  font-family: var(--font-mono, "Menlo", "Courier New", monospace);
  font-size: 12px;
  color: var(--fg-3, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
}

/* IDP buttons */
.idp-buttons {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 12px;
}

.btn-idp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  width: 100%;
  height: 48px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  background: var(--bg-2, #f8fafc);
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-1, #374151);
  cursor: pointer;
  transition:
    background-color 0.2s,
    border-color 0.2s;
  text-decoration: none;
}

.btn-idp:hover {
  background: var(--bg-3, #f1f5f9);
  border-color: var(--line-strong, #cbd5e1);
}

.idp-icon {
  height: 20px;
  width: auto;
  max-width: 80px;
  object-fit: contain;
  flex-shrink: 0;
}

/* "Use Login & Password" toggle button */
.btn-use-password {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px dashed var(--line-strong, #cbd5e1);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--fg-2, #64748b);
  cursor: pointer;
  transition:
    opacity 0.2s ease,
    background-color 0.2s,
    border-color 0.2s,
    color 0.2s;
  opacity: 1;
}

.btn-use-password.hidden {
  opacity: 0;
  pointer-events: none;
}

.btn-use-password.collapsed {
  display: none;
}

.btn-use-password:hover {
  background: var(--bg-2, #f8fafc);
  border-color: var(--fg-3, #94a3b8);
  color: var(--fg-1, #475569);
}

/* Password form collapse animation */
.password-form-collapse {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 1s ease,
    opacity 0.8s ease;
}

.password-form-collapse.open {
  max-height: 600px;
  opacity: 1;
}

/* Error */
.error {
  background: var(--danger-soft, #fef2f2);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: var(--danger, #dc2626);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  animation: fadeIn 0.3s ease-out;
}

/* Language dropdown */
.lang-dropdown {
  position: relative;
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--fg-2, #64748b);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: background-color 0.2s;
}

.lang-toggle:hover {
  background: var(--bg-2, rgba(0, 0, 0, 0.06));
}

.lang-code {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.lang-arrow {
  opacity: 0.5;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  background: var(--bg-1, #ffffff);
  border: 1px solid var(--line, transparent);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  width: max-content;
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition:
    opacity 0.2s,
    transform 0.2s,
    visibility 0.2s;
  z-index: 100;
}

.lang-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  transition: background-color 0.15s;
}

.lang-option:hover {
  background: var(--bg-3, #f1f5f9);
}

.lang-option.active {
  background: var(--accent-soft, #ecfdf5);
}

.lang-option .lang-native {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-0, #1f2937);
}

.lang-option .lang-name {
  font-size: 12px;
  color: var(--fg-2, #6b7280);
  margin-top: 2px;
}

.lang-option.active .lang-native {
  color: var(--accent, #10b981);
}

/* Theme toggle */
.theme-toggle {
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-2, #64748b);
  cursor: pointer;
  transition: background-color 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-2, rgba(0, 0, 0, 0.06));
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

/* HTMX loading state */
.htmx-request .btn-submit:not(.sync-status__refresh):not(.sync-status__link) {
  background: var(--fg-3, #94a3b8);
  cursor: wait;
  pointer-events: none;
}

/* ---------- 3. Auth Container (logout / admin) ---------- */

.auth-container {
  display: flex;
  background: var(--bg-1, white);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  max-width: 900px;
  width: 100%;
  min-height: 540px;
}

.auth-form-panel {
  flex: 1;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-decoration-panel {
  width: 400px;
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #3b82f6 100%);
  border-radius: 16px;
  margin: 12px;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 16px;
}

.panel-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Auth container theme & lang (for consent/logout/admin) */
.panel-controls .theme-toggle {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.panel-controls .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
}

.panel-controls .lang-toggle {
  height: 36px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.panel-controls .lang-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Auth container form styles */
.auth-container .auth-header {
  margin-bottom: 24px;
}

.auth-container .auth-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--fg-0, #1f2937);
  margin-bottom: 8px;
}

.auth-container .auth-header p {
  font-size: 14px;
  color: var(--fg-2, #6b7280);
}

.auth-container .form-group input[type="text"],
.auth-container .form-group input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 8px;
  font-size: 14px;
  color: var(--fg-0, #1f2937);
  background: var(--bg-1, white);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.auth-container .form-group input::placeholder {
  color: var(--fg-3, #9ca3af);
}

.auth-container .form-group input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.auth-container .btn-submit {
  height: auto;
  padding: 12px 16px;
  background: #3b82f6;
  border-radius: 8px;
  margin-top: 4px;
}

.auth-container .btn-submit:hover {
  background: #2563eb;
}

.auth-container .forgot-password {
  display: block;
  text-align: left;
  margin-top: 12px;
  margin-bottom: 20px;
}

.auth-container .forgot-password a {
  font-size: 14px;
  color: var(--fg-2, #6b7280);
  text-decoration: none;
  transition: color 0.2s;
}

.auth-container .forgot-password a:hover {
  color: #3b82f6;
  text-decoration: underline;
}

.auth-container .checkbox-group input[type="checkbox"] {
  appearance: auto;
  -webkit-appearance: auto;
  accent-color: #3b82f6;
}

.auth-container .divider::before,
.auth-container .divider::after {
  background: var(--line, #e5e7eb);
}

.auth-container .divider span {
  font-family: inherit;
  color: var(--fg-3, #9ca3af);
  letter-spacing: normal;
}

/* ---------- 4. Consent Page ---------- */

#consent-form-container {
  width: 100%;
}

/* "Requested Data" section divider */
.consent-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.consent-divider::before,
.consent-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line, #e2e8f0);
}

.consent-divider span {
  font-family: var(--font-mono, "Menlo", "Courier New", monospace);
  font-size: 11px;
  color: var(--fg-3, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 1.6px;
  white-space: nowrap;
}

/* Scrollable scopes container */
.consent-scopes-container {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 12px;
  padding: 16px;
  max-height: 224px;
  overflow-y: auto;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Custom scrollbar */
.consent-scopes-container::-webkit-scrollbar {
  width: 4px;
}

.consent-scopes-container::-webkit-scrollbar-track {
  background: transparent;
}

.consent-scopes-container::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 4px;
}

/* Scope item */
.consent-scope-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* Scope icon box */
.consent-scope-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-soft, #ecfdf5);
  color: var(--accent, #10b981);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

/* Scope text block */
.consent-scope-text {
  min-width: 0;
}

.consent-scope-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-1, #334155);
  line-height: 1;
  margin-bottom: 4px;
}

.consent-scope-desc {
  font-size: 12px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  line-height: 1.4;
}

/* Info text */
.consent-info-text {
  font-size: 12px;
  font-weight: 300;
  color: var(--fg-3, #94a3b8);
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

/* Button row */
.consent-actions {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

/* Cancel button */
.btn-cancel {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-1, white);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--fg-1, #475569);
  cursor: pointer;
  transition:
    background-color 0.2s,
    border-color 0.2s;
  order: 1;
}

.btn-cancel:hover {
  background: var(--bg-2, #f8fafc);
  border-color: var(--line-strong, #cbd5e1);
}

/* Authorize button */
.btn-authorize {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  background: var(--fg-0, #0f172a);
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--bg-1, white);
  cursor: pointer;
  transition: transform 0.1s;
  order: 2;
}

.btn-authorize:active {
  transform: scale(0.98);
}

.btn-authorize-label {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--bg-1, white);
  transition: color 0.3s;
}

.btn-authorize-gradient {
  position: absolute;
  inset: 0;
  background: var(--accent, #10b981);
  opacity: 0;
  transition: opacity 0.3s;
}

.btn-authorize:hover .btn-authorize-gradient {
  opacity: 1;
}

/* ---------- 4b. Organization Selection Cards ---------- */

.org-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 2px;
}

.org-list::-webkit-scrollbar {
  width: 4px;
}

.org-list::-webkit-scrollbar-track {
  background: transparent;
}

.org-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 4px;
}

.org-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    box-shadow 0.2s;
}

.org-card:hover {
  border-color: var(--line-strong, #cbd5e1);
  background: var(--bg-2, #fafbfc);
}

.org-card:has(.org-card-input:checked) {
  border-color: var(--accent, #10b981);
  background: var(--accent-soft, rgba(16, 185, 129, 0.04));
  box-shadow: inset 0 0 0 1px var(--accent, #10b981);
}

.org-card-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.org-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.org-card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-1, #334155);
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.org-card-role {
  font-size: 12px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  line-height: 1.4;
  margin-top: 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.org-card-radio {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong, #cbd5e1);
  border-radius: 50%;
  position: relative;
  transition:
    border-color 0.2s,
    background-color 0.2s;
}

.org-card-radio::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--accent, #10b981);
  opacity: 0;
  transform: scale(0);
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.org-card:has(.org-card-input:checked) .org-card-radio {
  border-color: var(--accent, #10b981);
}

.org-card:has(.org-card-input:checked) .org-card-radio::after {
  opacity: 1;
  transform: scale(1);
}

/* ---------- 4b-1. Patient (Child) Selection ---------- */

.patient-unavailable {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  background: var(--bg-2, #fafbfc);
}

.patient-unavailable__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-2, #64748b);
}

.patient-unavailable__text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 13px;
  font-weight: 300;
  line-height: 1.5;
  color: var(--fg-2, #64748b);
}

.patient-unavailable__actions {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 12px;
}

.patient-unavailable__actions form {
  flex: 1;
  display: flex;
  order: 2;
}

.patient-unavailable__retry {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  text-align: center;
}

/* ---------- 4c. Practitioner Data Sync Status ---------- */

.sync-status {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.sync-status__indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
}

.sync-status__spinner {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--line-strong, #cbd5e1);
  border-top-color: var(--accent, #10b981);
  animation: syncSpin 0.9s linear infinite;
}

.sync-status__state {
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-1, #475569);
  line-height: 1.5;
}

.sync-status__hint {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  line-height: 1.6;
}

.sync-status__refresh,
.sync-status__link {
  margin-top: 20px;
}

.sync-status__refresh {
  transition: opacity 0.2s ease;
}

.sync-status__refresh.htmx-request {
  opacity: 0.65;
  pointer-events: none;
}

.sync-status noscript .sync-status__link {
  display: flex;
}

/* ---------- 4d. QR Sign-In ---------- */

.qr-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.qr-block__title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--fg-0, #0f172a);
  text-align: center;
}

.qr-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 16px;
}

.qr-figure svg {
  width: 200px;
  height: 200px;
  max-width: 100%;
  display: block;
}

.qr-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
}

.qr-status__spinner {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--line-strong, #cbd5e1);
  border-top-color: var(--accent, #10b981);
  animation: syncSpin 0.9s linear infinite;
}

.qr-status__icon {
  flex-shrink: 0;
  color: var(--fg-2, #64748b);
}

.qr-status--scanned .qr-status__icon {
  color: var(--accent, #10b981);
}

.qr-status__text {
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-1, #475569);
  line-height: 1.5;
}

.qr-status__retry {
  margin-left: auto;
  font-family: var(--font-mono, "Menlo", "Courier New", monospace);
  font-size: 12px;
  color: var(--fg-2, #64748b);
  white-space: nowrap;
}

.qr-outcome {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
}

.qr-outcome__icon {
  flex-shrink: 0;
  color: var(--fg-2, #64748b);
}

.qr-outcome__text {
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-1, #475569);
  line-height: 1.5;
}

.qr-outcome__retry {
  margin-left: auto;
  font-family: var(--font-mono, "Menlo", "Courier New", monospace);
  font-size: 12px;
  color: var(--fg-2, #64748b);
  white-space: nowrap;
}

.qr-start-form {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.qr-start-form--auto {
  display: none;
}

.qr-retry {
  margin-top: 20px;
}

.btn-use-qr {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--fg-1, #475569);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s;
}

.btn-use-qr:hover {
  border-color: var(--accent, #10b981);
  color: var(--accent, #10b981);
}

/* ---------- 5. Error Page (auth-card variant) ---------- */

.error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Error icon box */
.error-icon-box {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.error-icon-box--danger {
  background: var(--danger-soft, rgba(239, 68, 68, 0.1));
  color: var(--danger, #ef4444);
  border: 1px solid rgba(239, 68, 68, 0.3);
  box-shadow: 0 0 48px rgba(239, 68, 68, 0.15);
}

.error-icon-box--warning {
  background: var(--warn-soft, rgba(245, 158, 11, 0.1));
  color: var(--warn, #f59e0b);
  border: 1px solid rgba(245, 158, 11, 0.3);
  box-shadow: 0 0 48px rgba(245, 158, 11, 0.15);
}

/* Error label ("ERROR 403") */
.error-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--danger, #ef4444);
  margin-bottom: 12px;
}

/* Error heading */
.auth-heading-title {
  font-size: 26px;
  font-weight: 500;
  color: var(--fg-0, #0f172a);
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-bottom: 12px;
}

/* Error description */
.error-description {
  font-size: 14px;
  font-weight: 300;
  color: var(--fg-2, #64748b);
  line-height: 1.6;
  max-width: 280px;
  margin-bottom: 24px;
}

.error-hint {
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 24px;
  max-width: 320px;
}

.error-hint p {
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-2, #64748b);
  line-height: 1.5;
  margin: 0;
}

/* User info card */
.error-user-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  margin-top: 8px;
}

.error-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-3, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-3, #94a3b8);
  flex-shrink: 0;
}

.error-user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
}

.error-user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-0, #0f172a);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.error-user-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-2, #64748b);
  margin-top: 2px;
}

.error-user-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent, #10b981);
  flex-shrink: 0;
}

/* Sign Out button */
.error-signout-btn,
.error-signin-another-btn {
  width: 100%;
  padding: 8px 20px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--fg-1, #475569);
  background: var(--bg-1, white);
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
  transition:
    background-color 0.2s,
    border-color 0.2s;
}

.error-signout-btn:hover,
.error-signin-another-btn:hover {
  background: var(--bg-3, #f1f5f9);
  border-color: var(--line-strong, #cbd5e1);
}

.error-signin-another-btn {
  margin-left: 0;
}

/* CTA button spacing inside error-content */
.error-content .btn-submit {
  margin-top: 8px;
}

/* Request ID block (shown under error messages across all SSO pages) */
.request-id {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 6px;
  margin-top: 20px;
  font-size: 12px;
  color: #64748b;
}

.request-id-label {
  font-weight: 500;
  flex-shrink: 0;
}

.request-id-value {
  flex: 1;
  min-width: 0;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  background: rgba(15, 23, 42, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  color: #0f172a;
  white-space: nowrap;
  overflow-x: auto;
}

.request-id-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  border-radius: 4px;
  font-family: inherit;
  line-height: 1;
  transition: background 0.15s ease;
}

.request-id-copy:hover {
  background: rgba(15, 23, 42, 0.08);
}

.request-id-copy:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 1px;
}

.request-id-copy--copied {
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

/* ---------- 6. Animations & Responsive ---------- */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .sync-status__spinner {
    animation-duration: 3s;
  }
}

@media (max-width: 768px) {
  .auth-container {
    max-width: 400px;
  }

  .auth-decoration-panel {
    display: none;
  }

  .auth-form-panel {
    padding: 32px 24px;
  }

  /* Error page responsive */
  .error-icon-box {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  .error-icon-box iconify-icon,
  .error-icon-box svg {
    width: 28px;
    height: 28px;
  }

  .auth-heading-title {
    font-size: 22px;
  }

  .error-description {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .auth-card {
    width: 100%;
    max-width: 400px;
    padding: 32px 24px;
  }

  .auth-heading h1 {
    font-size: 24px;
  }

  .auth-controls {
    padding: 0 3px;
  }

  /* Consent responsive: stack buttons vertically */
  .consent-actions {
    flex-direction: column;
  }

  .btn-cancel {
    order: 2;
  }

  .btn-authorize {
    order: 1;
  }

  .consent-scopes-container {
    max-height: 180px;
    padding: 12px;
  }

  /* Error page responsive */
  .error-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .error-icon-box iconify-icon,
  .error-icon-box svg {
    width: 24px;
    height: 24px;
  }

  .auth-heading-title {
    font-size: 20px;
  }

  .error-label {
    font-size: 10px;
    letter-spacing: 2px;
  }

  .error-user-card {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }

  .error-signout-btn {
    width: 100%;
    text-align: center;
    padding: 10px 20px;
  }
}

/* ---------- 7. Dark Theme deltas ---------- */
/* Most colours flip automatically through tokens. Only auth-page-
   specific tweaks (glows, decoration panel, blue OAuth submit)
   need explicit dark overrides. */

/* --- Body & Background glows (no token equivalent) --- */
[data-theme="dark"] body {
  background: var(--bg-0);
}

[data-theme="dark"] .auth-bg-glow {
  opacity: 1;
  filter: blur(80px);
}

[data-theme="dark"] .auth-bg-glow--tl {
  width: 700px;
  height: 700px;
  top: -15%;
  left: -10%;
  background: radial-gradient(
    circle,
    rgba(20, 241, 149, 0.15) 0%,
    transparent 70%
  );
}

[data-theme="dark"] .auth-bg-glow--br {
  width: 550px;
  height: 550px;
  bottom: -15%;
  right: -10%;
  background: radial-gradient(
    circle,
    rgba(153, 69, 255, 0.12) 0%,
    transparent 70%
  );
}

[data-theme="dark"] .auth-bg::before {
  opacity: 1;
  background-image:
    linear-gradient(rgba(20, 241, 149, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 241, 149, 0.04) 1px, transparent 1px);
}

/* --- Login Card — soft glass override (matches admin glass-panel feel) --- */
[data-theme="dark"] .auth-card {
  background: linear-gradient(
    180deg,
    rgba(11, 18, 16, 0.85) 0%,
    rgba(11, 18, 16, 0.65) 100%
  );
  border-color: var(--glass-border, rgba(255, 255, 255, 0.06));
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 20px 40px -10px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

[data-theme="dark"] .auth-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
  pointer-events: none;
}

/* --- Theme toggle (icon swap on dark) --- */
[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* --- Submit button — invert on dark --- */
[data-theme="dark"] .btn-submit {
  background: var(--fg-0);
  color: var(--bg-0);
}

[data-theme="dark"] .btn-submit:hover {
  background: var(--accent);
  color: var(--bg-0);
}

[data-theme="dark"] .btn-submit:disabled {
  background: var(--fg-3);
  color: var(--fg-2);
}

[data-theme="dark"] .htmx-request .btn-submit:not(.sync-status__refresh):not(.sync-status__link) {
  background: var(--fg-3);
  color: var(--fg-2);
}

/* --- IDP buttons --- */
[data-theme="dark"] .btn-idp .idp-icon {
  filter: brightness(0) invert(1);
}

/* --- Auth Container (consent/logout/admin) — keep blue accent palette --- */
[data-theme="dark"] .auth-container {
  background: var(--bg-1);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .auth-form-panel {
  background: var(--bg-1);
}

[data-theme="dark"] .auth-container .form-group input[type="text"],
[data-theme="dark"] .auth-container .form-group input[type="password"] {
  background: var(--bg-0);
  border-color: var(--line);
  color: var(--fg-0);
}

[data-theme="dark"] .auth-container .form-group input::placeholder {
  color: var(--fg-3);
}

[data-theme="dark"] .auth-container .form-group input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .auth-container .btn-submit {
  background: #3b82f6;
  color: white;
}

[data-theme="dark"] .auth-container .btn-submit:hover {
  background: #2563eb;
}

[data-theme="dark"] .auth-container .forgot-password a:hover {
  color: #60a5fa;
}

[data-theme="dark"] .auth-decoration-panel {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 50%, #60a5fa 100%);
}

/* --- Consent scopes container (semi-transparent background) --- */
[data-theme="dark"] .consent-scopes-container {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .consent-scopes-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

/* --- Authorize button --- */
[data-theme="dark"] .btn-authorize {
  background: var(--fg-0);
  color: var(--bg-0);
}

[data-theme="dark"] .btn-authorize-label {
  color: var(--bg-0);
}

[data-theme="dark"] .btn-authorize:hover .btn-authorize-label {
  color: var(--bg-0);
}

/* --- Organization cards — dark hover/focus refinements --- */
[data-theme="dark"] .org-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .org-card {
  background: transparent;
}

[data-theme="dark"] .org-card:hover {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .org-card:has(.org-card-input:checked) {
  border-color: #14f195;
  background: rgba(20, 241, 149, 0.06);
  box-shadow: inset 0 0 0 1px #14f195;
}

[data-theme="dark"] .patient-unavailable {
  border-color: rgba(148, 163, 184, 0.16);
  background: rgba(148, 163, 184, 0.06);
}

[data-theme="dark"] .patient-unavailable__text,
[data-theme="dark"] .patient-unavailable__icon {
  color: rgba(226, 232, 240, 0.66);
}

[data-theme="dark"] .org-card-name {
  color: #e2e8f0;
}

[data-theme="dark"] .org-card-role {
  color: #94a3b8;
}

[data-theme="dark"] .org-card-radio {
  border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .org-card:has(.org-card-input:checked) .org-card-radio {
  border-color: #14f195;
}

[data-theme="dark"]
  .org-card:has(.org-card-input:checked)
  .org-card-radio::after {
  background: #14f195;
}

/* --- Auth-card error page dark --- */
[data-theme="dark"] .error-icon-box--danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.15);
  box-shadow: 0 0 56px rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .error-icon-box--warning {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
  box-shadow: 0 0 56px rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .error-label {
  color: #f87171;
}

[data-theme="dark"] .auth-heading-title {
  color: white;
}

[data-theme="dark"] .error-description {
  color: #94a3b8;
}

/* --- Practitioner sync status on dark --- */
[data-theme="dark"] .sync-status__indicator {
  background: rgba(0, 0, 0, 0.25);
  border-color: var(--line);
}

[data-theme="dark"] .sync-status__spinner {
  border-color: rgba(255, 255, 255, 0.15);
  border-top-color: #14f195;
}

[data-theme="dark"] .sync-status__state {
  color: #e2e8f0;
}

[data-theme="dark"] .sync-status__hint {
  color: #94a3b8;
}

/* --- Error page hint/user-card on dark --- */
[data-theme="dark"] .error-hint {
  background: rgba(0, 0, 0, 0.25);
  border-color: var(--line);
}

[data-theme="dark"] .error-user-card {
  background: rgba(0, 0, 0, 0.25);
  border-color: var(--line);
}

[data-theme="dark"] .error-user-avatar {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-3);
}

[data-theme="dark"] .error-signout-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--fg-1);
}

[data-theme="dark"] .error-signout-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line-strong);
}

[data-theme="dark"] .request-id {
  color: #94a3b8;
}

[data-theme="dark"] .request-id-value {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

[data-theme="dark"] .request-id-copy:hover {
  background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .request-id-copy:focus-visible {
  outline-color: #60a5fa;
}
