/**
 * UBMS Public Theme — Shared Design Tokens
 *
 * Canonical source for all public-facing pages (besichtigung, selbstauskunft,
 * pwa, pwa-protokoll). Variable names follow the UBMS main app convention.
 *
 * Default: dark theme. Light theme via [data-theme="light"] on <html>.
 * Pair with auto-theme.js for automatic sunrise/sunset switching.
 *
 * Location: webserver-deployment/ubms/shared/public-theme.css
 */

/* ========================================
   Dark Theme (default)
   ======================================== */
:root {
  /* Primary / Accent */
  --color-primary-400: #58a3c8;
  --color-primary-500: #3b8cb5;
  --color-primary-600: #307394;
  --color-primary-700: #275e79;

  /* Primary subtle backgrounds */
  --color-primary-bg-subtle: rgba(59, 140, 181, 0.15);

  /* Secondary */
  --color-secondary-400: #60a5fa;
  --color-secondary-500: #3b82f6;

  /* Surfaces */
  --color-background: #0f1117;
  --color-background-gradient: linear-gradient(135deg, #0f1117 0%, #0c1020 100%);
  --color-surface-primary: #1a1d27;
  --color-surface-secondary: #22263a;
  --color-surface-elevated: #2d3148;

  /* Neutral scale */
  --color-neutral-100: #f1f5f9;
  --color-neutral-200: #e2e8f0;
  --color-neutral-300: #cbd5e1;
  --color-neutral-400: #94a3b8;
  --color-neutral-500: #64748b;
  --color-neutral-600: #475569;
  --color-neutral-700: #334155;
  --color-neutral-800: #1e293b;
  --color-neutral-900: #0f172a;

  /* Text */
  --color-text-primary: #e4e7ef;
  --color-text-secondary: #b0b4c0;
  --color-text-muted: #8b90a0;
  --color-text-inverse: #1a1d27;

  /* Borders */
  --color-border-default: #2d3148;
  --color-border-subtle: #3a3f58;
  --color-border-input: #3a3f58;
  --color-border-focus: #5b6af5;

  /* Status */
  --color-success-500: #22c55e;
  --color-success-600: #16a34a;
  --color-success-bg-subtle: rgba(34, 197, 94, 0.15);
  --color-warning-500: #f59e0b;
  --color-warning-600: #d97706;
  --color-danger-500: #ef4444;
  --color-danger-600: #dc2626;
  --color-danger-bg-subtle: rgba(239, 68, 68, 0.12);
  --color-info-500: #3b82f6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);

  /* Overlay */
  --color-overlay: rgba(0, 0, 0, 0.6);

  /* ── Non-themed tokens ───────────────── */

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;
  --radius-base: 0.375rem; /* 6px — default control radius (matches UBMS forms) */

  /* Form / input support — consumed by the shared components/forms.css (parity with UBMS).
     primary-border-subtle uses color-mix so it tracks whichever --color-primary-500 the
     app sets (teal in the PWAs, emerald in the frontend). */
  --color-input-hover-ring: color-mix(in srgb, var(--color-text-primary) 16%, transparent);
  --color-primary-border-subtle: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
  --color-shadow-subtle: #0000001a; /* black @ 10% — inset field shadow */
  --color-text-tertiary: #666666;   /* most-muted text */

  /* Button support — consumed by the shared components/buttons.css (parity with UBMS).
     Values copied from frontend tokens.css; color-mix ones track --color-primary-500. */
  --color-primary-800: #204c62;
  --color-primary-surface: color-mix(in srgb, var(--color-primary-500) 14%, var(--color-surface-primary));
  --color-primary-on-surface: color-mix(in srgb, var(--color-primary-500) 50%, var(--color-text-primary));
  --color-surface-tertiary: #26262f;
  --color-danger-100: #fee2e2;
  --color-highlight-lighter: #ffffff0d; /* white @ 5% — subtle raise on dark surfaces */
  --color-highlight-subtle: #ffffff1a;  /* white @ 10% */
  --color-shadow-light: #00000033;      /* black @ 20% */
  --color-shadow-medium: #0000004d;     /* black @ 30% */
  --icon-lg: 1.5rem;                    /* 24px (frontend --size-6) */
  --leading-tight: 1.25;

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

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Courier New', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease-out;

  /* Z-Index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-toast: 600;
}

/* ========================================
   Light Theme
   ======================================== */
[data-theme="light"] {
  /* Surfaces */
  --color-background: #f0f2f5;
  --color-background-gradient: linear-gradient(135deg, #f0f2f5 0%, #e2e5ed 100%);
  --color-surface-primary: #ffffff;
  --color-surface-secondary: #f5f6f8;
  --color-surface-elevated: rgba(255, 255, 255, 0.95);

  /* Neutral scale (inverted for light) */
  --color-neutral-100: #1e293b;
  --color-neutral-200: #334155;
  --color-neutral-300: #475569;
  --color-neutral-400: #64748b;
  --color-neutral-500: #94a3b8;
  --color-neutral-600: #e2e8f0;
  --color-neutral-700: #f1f5f9;
  --color-neutral-800: #ffffff;
  --color-neutral-900: #f8fafc;

  /* Text */
  --color-text-primary: #1a1d27;
  --color-text-secondary: #475569;
  --color-text-muted: #64748b;
  --color-text-tertiary: #999999;   /* light-mode most-muted text (dark default in :root) */
  --color-text-inverse: #ffffff;
  --color-surface-tertiary: #f0f0f0; /* light-mode tertiary surface (dark default in :root) */
  /* highlight-lighter/subtle stay white-alpha (subtle on light too); shadow-* are black-alpha,
     fine in both themes — matching frontend tokens.css (no light override there). */

  /* Borders */
  --color-border-default: #d8dbe3;
  --color-border-subtle: #e2e5ed;
  --color-border-input: #cbd5e1;
  --color-border-focus: #4a58e0;

  /* Adjusted accent for light bg contrast */
  --color-primary-500: #307394;
  --color-primary-600: #275e79;
  --color-primary-bg-subtle: rgba(48, 115, 148, 0.1);

  /* Status (slightly darker for light bg) */
  --color-success-500: #16a34a;
  --color-success-600: #15803d;
  --color-success-bg-subtle: rgba(22, 163, 74, 0.1);
  --color-danger-500: #dc2626;
  --color-danger-600: #b91c1c;
  --color-danger-bg-subtle: rgba(220, 38, 38, 0.08);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);

  /* Overlay */
  --color-overlay: rgba(0, 0, 0, 0.4);
}

/* =====================================================================
   Shared mobile login screen
   Component styles for pwa-shared/js/login-screen.js, used by pwa (Foto-Upload)
   and pwa-protokoll. Scoped under #login-screen so they never affect other
   screens; declarations mirror pwa-protokoll's base.css/screens.css login look.
   Visibility of #login-screen is owned by each app (pwa toggles display;
   pwa-protokoll uses its .screen router) — do NOT set display/position here.
   ===================================================================== */

#login-screen .login-form-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

#login-screen .login-header {
  text-align: center;
  margin-bottom: var(--space-6);
}

#login-screen .app-logo {
  width: 2.5rem;
  height: 2.5rem;
  background: linear-gradient(135deg, var(--color-primary-400), var(--color-secondary-500));
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin: 0 auto var(--space-4);
}

#login-screen .app-logo.large {
  width: 4rem;
  height: 4rem;
}

#login-screen .login-header h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

#login-screen .login-header p {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

#login-screen .login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

#login-screen .form-group {
  margin-bottom: 0;
}

#login-screen .form-group label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

#login-screen .input-field {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-secondary);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  font-size: var(--text-base);
  transition: var(--transition-fast);
}

#login-screen .input-field:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary-500) 20%, transparent);
}

#login-screen .input-field::placeholder {
  color: var(--color-text-muted);
}

#login-screen .password-input {
  position: relative;
}

#login-screen .password-input .input-field {
  padding-right: var(--space-10);
}

#login-screen .password-toggle {
  position: absolute;
  top: 50%;
  right: var(--space-3);
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  color: var(--color-text-muted);
  cursor: pointer;
}

#login-screen .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface-secondary);
  border: none;
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
}

#login-screen .btn:hover {
  background: var(--color-surface-elevated);
}

#login-screen .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#login-screen .btn-primary {
  background: var(--color-primary-500);
  color: #fff;
}

#login-screen .btn-primary:hover {
  background: var(--color-primary-400);
}

#login-screen .btn-secondary {
  background: var(--color-surface-secondary);
  border: 1px solid var(--color-border-default);
}

#login-screen .btn-large {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
  width: 100%;
}

/* Keyfile "file selected" success state (mirrors screens.css override). */
#login-screen .btn-success {
  background: color-mix(in srgb, var(--color-success-500) 15%, transparent);
  border: 1px solid var(--color-success-500);
  color: var(--color-success-500);
}

#login-screen .btn-success:hover {
  background: color-mix(in srgb, var(--color-success-500) 25%, transparent);
}

#login-screen .login-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
  gap: var(--space-3);
}

#login-screen .trust-device-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
}

#login-screen .trust-device-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary-500);
  cursor: pointer;
  flex-shrink: 0;
}

#login-screen .forgot-password-link {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  white-space: nowrap;
}

#login-screen .forgot-password-link:hover {
  color: var(--color-text-secondary);
}

#login-screen .totp-input {
  text-align: center;
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: 0.5em;
  padding: var(--space-4);
}

/* MFA method selection (TOTP + keyfile). */
#login-screen .mfa-methods {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

#login-screen .mfa-method {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

#login-screen .mfa-method-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
}

#login-screen .mfa-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

#login-screen .mfa-divider::before,
#login-screen .mfa-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-surface-elevated);
}

#login-screen .keyfile-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

#login-screen .keyfile-select-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-4);
  font-size: var(--text-base);
}

/* Device pending-approval state. */
#login-screen .approval-info {
  margin: var(--space-4) 0;
}

#login-screen .info-card {
  display: flex;
  gap: var(--space-3);
  background: var(--color-surface-primary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

#login-screen .info-card strong {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
}

#login-screen .info-card p {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* Inline button spinner. */
#login-screen .spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: login-spin 0.7s linear infinite;
}

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