/**
 * Family Calendar Global Design Tokens
 * Centralized Design System: Colors, Typography, Spacing, Radii, Elevation & Dark Mode
 */

:root {
  /* Brand & Primary Colors */
  --fc-primary: #007aff;
  --fc-primary-hover: #0056b3;
  --fc-primary-light: #e8f2ff;
  --fc-primary-rgb: 0, 122, 255;
  --fc-secondary: #4f8fe7;
  --fc-secondary-hover: #3a7bd5;

  /* Semantic Feedback Colors */
  --fc-success: #10b981;
  --fc-success-light: #ecfdf5;
  --fc-success-text: #065f46;
  --fc-warning: #f59e0b;
  --fc-warning-light: #fffbeb;
  --fc-warning-text: #92400e;
  --fc-danger: #ef4444;
  --fc-danger-light: #fef2f2;
  --fc-danger-text: #991b1b;
  --fc-info: #0284c7;
  --fc-info-light: #f0f9ff;

  /* Neutrals & Surfaces (Default Light) */
  --fc-bg: #f8fafc;
  --fc-bg-alt: #f1f5f9;
  --fc-surface: #ffffff;
  --fc-surface-subtle: #f8fafc;
  --fc-surface-elevated: #ffffff;
  --fc-border: #e2e8f0;
  --fc-border-subtle: #edf2f7;
  --fc-border-strong: #cbd5e1;

  /* Typography Colors */
  --fc-text-primary: #0f172a;
  --fc-text-secondary: #334155;
  --fc-text-muted: #64748b;
  --fc-text-subtle: #94a3b8;
  --fc-text-inverse: #ffffff;

  /* Typography Families */
  --fc-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fc-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Border Radii */
  --fc-radius-xs: 4px;
  --fc-radius-sm: 8px;
  --fc-radius-md: 12px;
  --fc-radius-lg: 16px;
  --fc-radius-xl: 20px;
  --fc-radius-2xl: 24px;
  --fc-radius-pill: 9999px;

  /* Shadows & Elevation */
  --fc-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --fc-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --fc-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --fc-shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.10);
  --fc-shadow-xl: 0 20px 40px rgba(15, 23, 42, 0.14);

  /* Animation & Transitions */
  --fc-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --fc-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --fc-transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout Constants */
  --fc-header-height: 42px;
  --fc-sidebar-width: 260px;
  --fc-container-max: 1400px;

  /* Universal Aliases for Peripheral Pages */
  --primary: var(--fc-primary);
  --primary-hover: var(--fc-primary-hover);
  --primary-light: var(--fc-primary-light);
  --surface: var(--fc-surface);
  --border: var(--fc-border);
  --text: var(--fc-text-primary);
  --muted: var(--fc-text-muted);
  --radius: var(--fc-radius-lg);
  --success: var(--fc-success);
  --warning: var(--fc-warning);
  --danger: var(--fc-danger);

  /* Admin Portal Variables (Light Mode Default) */
  --bg-dark: #0a0a1a;
  --bg-card: rgba(18, 18, 35, 0.92);
  --card: var(--fc-surface);
  --bg: var(--fc-bg);
  --border-glow: rgba(0, 122, 255, 0.12);
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-glow: 0 0 20px rgba(0, 122, 255, 0.2);
  --gradient-primary: linear-gradient(135deg, #007aff 0%, #4f8fe7 100%);
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-text: #0f172a;
}

/* Explicit Dark Theme and System Preference */
:root[data-theme="dark"],
[data-theme="dark"],
body.dark-theme {
  --fc-bg: #0b1120;
  --fc-bg-alt: #0f172a;
  --fc-surface: #1e293b;
  --fc-surface-subtle: #182234;
  --fc-surface-elevated: #243248;
  --fc-border: #334155;
  --fc-border-subtle: #243248;
  --fc-border-strong: #475569;

  --fc-text-primary: #f8fafc;
  --fc-text-secondary: #cbd5e1;
  --fc-text-muted: #94a3b8;
  --fc-text-subtle: #64748b;
  --fc-text-inverse: #0f172a;

  --fc-primary-light: rgba(0, 122, 255, 0.22);
  --fc-secondary: #3b82f6;

  --fc-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --fc-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --fc-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --fc-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.55);

  --surface: var(--fc-surface);
  --border: var(--fc-border);
  --text: var(--fc-text-primary);
  --muted: var(--fc-text-muted);

  /* Admin Portal Dark Parity Overrides */
  --bg-dark: #0a0e1a;
  --bg-card: #141b2d;
  --card: #1e293b;
  --bg: #0b1120;
  --border-glow: rgba(99, 102, 241, 0.25);
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --input-bg: #1e293b;
  --input-border: #334155;
  --input-text: #f8fafc;
}

/* Explicit Light Theme Overrides (For pages with dark defaults) */
:root[data-theme="light"],
[data-theme="light"] {
  --fc-bg: #f8fafc;
  --fc-bg-alt: #f1f5f9;
  --fc-surface: #ffffff;
  --fc-surface-subtle: #f8fafc;
  --fc-surface-elevated: #ffffff;
  --fc-border: #e2e8f0;
  --fc-border-subtle: #edf2f7;
  --fc-border-strong: #cbd5e1;

  --fc-text-primary: #0f172a;
  --fc-text-secondary: #334155;
  --fc-text-muted: #64748b;
  --fc-text-subtle: #94a3b8;
  --fc-text-inverse: #ffffff;

  --surface: var(--fc-surface);
  --border: var(--fc-border);
  --text: var(--fc-text-primary);
  --muted: var(--fc-text-muted);

  --bg-dark: #0a0a1a;
  --bg-card: rgba(18, 18, 35, 0.92);
  --card: var(--fc-surface);
  --bg: var(--fc-bg);
  --border-glow: rgba(0, 122, 255, 0.12);
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-glow: 0 0 20px rgba(0, 122, 255, 0.2);
  --gradient-primary: linear-gradient(135deg, #007aff 0%, #4f8fe7 100%);
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-text: #0f172a;
}

/* Universal Dark Mode Form and Component Styles */
[data-theme="dark"] body {
  background-color: var(--fc-bg) !important;
  color: var(--fc-text-primary) !important;
}

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background-color: var(--input-bg) !important;
  color: var(--input-text) !important;
  border-color: var(--input-border) !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: #64748b !important;
}

[data-theme="dark"] .panel,
[data-theme="dark"] .card,
[data-theme="dark"] .step-card,
[data-theme="dark"] .summary-box,
[data-theme="dark"] .dashboard-header,
[data-theme="dark"] .modal-content {
  background-color: var(--fc-surface) !important;
  border-color: var(--fc-border) !important;
  color: var(--fc-text-primary) !important;
}

[data-theme="dark"] .btn.secondary,
[data-theme="dark"] button.secondary,
[data-theme="dark"] a.btn.secondary {
  background-color: #182234 !important;
  color: #cbd5e1 !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .btn.secondary:hover,
[data-theme="dark"] button.secondary:hover,
[data-theme="dark"] a.btn.secondary:hover {
  background-color: #243248 !important;
  color: #f8fafc !important;
  border-color: #475569 !important;
}

[data-theme="dark"] table {
  color: var(--fc-text-primary) !important;
}

[data-theme="dark"] th {
  background-color: #182234 !important;
  color: var(--fc-text-primary) !important;
  border-color: var(--fc-border) !important;
}

[data-theme="dark"] td {
  border-color: var(--fc-border) !important;
  color: var(--fc-text-secondary) !important;
}

[data-theme="dark"] .code,
[data-theme="dark"] pre,
[data-theme="dark"] code {
  background-color: #0f172a !important;
  color: #93c5fd !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .runner-status,
[data-theme="dark"] .job-progress {
  background: #141e33 !important;
  border-color: #294b78 !important;
  color: #93c5fd !important;
}

[data-theme="dark"] .pill {
  background-color: #243248 !important;
  color: #cbd5e1 !important;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fc-bg: #0b1120;
    --fc-bg-alt: #0f172a;
    --fc-surface: #1e293b;
    --fc-surface-subtle: #182234;
    --fc-surface-elevated: #243248;
    --fc-border: #334155;
    --fc-border-subtle: #243248;
    --fc-border-strong: #475569;

    --fc-text-primary: #f8fafc;
    --fc-text-secondary: #cbd5e1;
    --fc-text-muted: #94a3b8;
    --fc-text-subtle: #64748b;
    --fc-text-inverse: #0f172a;

    --fc-primary-light: rgba(0, 122, 255, 0.22);
    --fc-secondary: #3b82f6;

    --surface: var(--fc-surface);
    --border: var(--fc-border);
    --text: var(--fc-text-primary);
    --muted: var(--fc-text-muted);

    --bg-dark: #0a0e1a;
    --bg-card: #141b2d;
    --card: #1e293b;
    --bg: #0b1120;
    --border-glow: rgba(99, 102, 241, 0.25);
    --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --input-bg: #1e293b;
    --input-border: #334155;
    --input-text: #f8fafc;
  }
}
