/* Load after palettes.css and legacy application CSS. Only variable-based colors here.
   data-theme/data-color-theme identify a FAMILY; data-mode alone identifies light/dark. */
:root, :root[data-color-theme="golden-black"] {
  --family-light-primary: var(--palette-golden-black-light-primary);
  --family-light-hover: var(--palette-golden-black-light-hover);
  --family-light-active: var(--palette-golden-black-light-active);
  --family-light-page: var(--palette-golden-black-light-page);
  --family-light-surface: var(--palette-golden-black-light-surface);
  --family-light-secondary: var(--palette-golden-black-light-secondary);
  --family-light-elevated: var(--palette-golden-black-light-elevated);
  --family-dark-primary: var(--palette-golden-black-dark-primary);
  --family-dark-hover: var(--palette-golden-black-dark-hover);
  --family-dark-active: var(--palette-golden-black-dark-active);
  --family-dark-page: var(--palette-golden-black-dark-page);
  --family-dark-surface: var(--palette-golden-black-dark-surface);
  --family-dark-secondary: var(--palette-golden-black-dark-secondary);
  --family-dark-elevated: var(--palette-golden-black-dark-elevated);
}
:root[data-color-theme="default"] {
  --family-light-primary: var(--palette-default-light-primary);
  --family-light-hover: var(--palette-default-light-hover);
  --family-light-active: var(--palette-default-light-active);
  --family-light-page: var(--palette-default-light-page);
  --family-light-surface: var(--palette-default-light-surface);
  --family-light-secondary: var(--palette-default-light-secondary);
  --family-light-elevated: var(--palette-default-light-elevated);
  --family-dark-primary: var(--palette-default-dark-primary);
  --family-dark-hover: var(--palette-default-dark-hover);
  --family-dark-active: var(--palette-default-dark-active);
  --family-dark-page: var(--palette-default-dark-page);
  --family-dark-surface: var(--palette-default-dark-surface);
  --family-dark-secondary: var(--palette-default-dark-secondary);
  --family-dark-elevated: var(--palette-default-dark-elevated);
}
:root[data-color-theme="purple"] {
  --family-light-primary: var(--palette-purple-light-primary);
  --family-light-hover: var(--palette-purple-light-hover);
  --family-light-active: var(--palette-purple-light-active);
  --family-light-page: var(--palette-purple-light-page);
  --family-light-surface: var(--palette-purple-light-surface);
  --family-light-secondary: var(--palette-purple-light-secondary);
  --family-light-elevated: var(--palette-purple-light-elevated);
  --family-dark-primary: var(--palette-purple-dark-primary);
  --family-dark-hover: var(--palette-purple-dark-hover);
  --family-dark-active: var(--palette-purple-dark-active);
  --family-dark-page: var(--palette-purple-dark-page);
  --family-dark-surface: var(--palette-purple-dark-surface);
  --family-dark-secondary: var(--palette-purple-dark-secondary);
  --family-dark-elevated: var(--palette-purple-dark-elevated);
}
:root[data-color-theme="maroon"] {
  --family-light-primary: var(--palette-maroon-light-primary);
  --family-light-hover: var(--palette-maroon-light-hover);
  --family-light-active: var(--palette-maroon-light-active);
  --family-light-page: var(--palette-maroon-light-page);
  --family-light-surface: var(--palette-maroon-light-surface);
  --family-light-secondary: var(--palette-maroon-light-secondary);
  --family-light-elevated: var(--palette-maroon-light-elevated);
  --family-dark-primary: var(--palette-maroon-dark-primary);
  --family-dark-hover: var(--palette-maroon-dark-hover);
  --family-dark-active: var(--palette-maroon-dark-active);
  --family-dark-page: var(--palette-maroon-dark-page);
  --family-dark-surface: var(--palette-maroon-dark-surface);
  --family-dark-secondary: var(--palette-maroon-dark-secondary);
  --family-dark-elevated: var(--palette-maroon-dark-elevated);
}
:root[data-color-theme="gray-technology"] {
  --family-light-primary: var(--palette-gray-technology-light-primary);
  --family-light-hover: var(--palette-gray-technology-light-hover);
  --family-light-active: var(--palette-gray-technology-light-active);
  --family-light-page: var(--palette-gray-technology-light-page);
  --family-light-surface: var(--palette-gray-technology-light-surface);
  --family-light-secondary: var(--palette-gray-technology-light-secondary);
  --family-light-elevated: var(--palette-gray-technology-light-elevated);
  --family-dark-primary: var(--palette-gray-technology-dark-primary);
  --family-dark-hover: var(--palette-gray-technology-dark-hover);
  --family-dark-active: var(--palette-gray-technology-dark-active);
  --family-dark-page: var(--palette-gray-technology-dark-page);
  --family-dark-surface: var(--palette-gray-technology-dark-surface);
  --family-dark-secondary: var(--palette-gray-technology-dark-secondary);
  --family-dark-elevated: var(--palette-gray-technology-dark-elevated);
}
:root[data-color-theme="modern-earth"] {
  --family-light-primary: var(--palette-modern-earth-light-primary);
  --family-light-hover: var(--palette-modern-earth-light-hover);
  --family-light-active: var(--palette-modern-earth-light-active);
  --family-light-page: var(--palette-modern-earth-light-page);
  --family-light-surface: var(--palette-modern-earth-light-surface);
  --family-light-secondary: var(--palette-modern-earth-light-secondary);
  --family-light-elevated: var(--palette-modern-earth-light-elevated);
  --family-dark-primary: var(--palette-modern-earth-dark-primary);
  --family-dark-hover: var(--palette-modern-earth-dark-hover);
  --family-dark-active: var(--palette-modern-earth-dark-active);
  --family-dark-page: var(--palette-modern-earth-dark-page);
  --family-dark-surface: var(--palette-modern-earth-dark-surface);
  --family-dark-secondary: var(--palette-modern-earth-dark-secondary);
  --family-dark-elevated: var(--palette-modern-earth-dark-elevated);
}
:root[data-color-theme="old-photograph"] {
  --family-light-primary: var(--palette-old-photograph-light-primary);
  --family-light-hover: var(--palette-old-photograph-light-hover);
  --family-light-active: var(--palette-old-photograph-light-active);
  --family-light-page: var(--palette-old-photograph-light-page);
  --family-light-surface: var(--palette-old-photograph-light-surface);
  --family-light-secondary: var(--palette-old-photograph-light-secondary);
  --family-light-elevated: var(--palette-old-photograph-light-elevated);
  --family-dark-primary: var(--palette-old-photograph-dark-primary);
  --family-dark-hover: var(--palette-old-photograph-dark-hover);
  --family-dark-active: var(--palette-old-photograph-dark-active);
  --family-dark-page: var(--palette-old-photograph-dark-page);
  --family-dark-surface: var(--palette-old-photograph-dark-surface);
  --family-dark-secondary: var(--palette-old-photograph-dark-secondary);
  --family-dark-elevated: var(--palette-old-photograph-dark-elevated);
}
:root[data-color-theme="neutral-elegance"] {
  --family-light-primary: var(--palette-neutral-elegance-light-primary);
  --family-light-hover: var(--palette-neutral-elegance-light-hover);
  --family-light-active: var(--palette-neutral-elegance-light-active);
  --family-light-page: var(--palette-neutral-elegance-light-page);
  --family-light-surface: var(--palette-neutral-elegance-light-surface);
  --family-light-secondary: var(--palette-neutral-elegance-light-secondary);
  --family-light-elevated: var(--palette-neutral-elegance-light-elevated);
  --family-dark-primary: var(--palette-neutral-elegance-dark-primary);
  --family-dark-hover: var(--palette-neutral-elegance-dark-hover);
  --family-dark-active: var(--palette-neutral-elegance-dark-active);
  --family-dark-page: var(--palette-neutral-elegance-dark-page);
  --family-dark-surface: var(--palette-neutral-elegance-dark-surface);
  --family-dark-secondary: var(--palette-neutral-elegance-dark-secondary);
  --family-dark-elevated: var(--palette-neutral-elegance-dark-elevated);
}

:root, :root[data-mode="light"] {
  color-scheme: light;
  --color-page-background: var(--family-light-page);
  --color-surface: var(--family-light-surface);
  --color-surface-secondary: var(--family-light-secondary);
  --color-surface-elevated: var(--family-light-elevated);
  --color-text-primary: var(--palette-light-text);
  --color-text-secondary: var(--palette-light-muted);
  --color-text-muted: var(--palette-light-muted);
  --color-text-inverse: var(--palette-white);
  --color-primary: var(--family-light-primary);
  --color-primary-hover: var(--family-light-hover);
  --color-primary-active: var(--family-light-active);
  --color-primary-contrast: var(--palette-white);
  --color-border: var(--palette-light-border);
  --color-border-strong: var(--palette-light-border-strong);
  --color-success: var(--palette-light-success);
  --color-warning: var(--palette-light-warning);
  --color-error: var(--palette-light-error);
  --color-info: var(--palette-light-info);
  --color-overlay: var(--palette-light-overlay);
  --shadow-color: var(--palette-light-shadow);
}
:root[data-mode="dark"] {
  color-scheme: dark;
  --color-page-background: var(--family-dark-page);
  --color-surface: var(--family-dark-surface);
  --color-surface-secondary: var(--family-dark-secondary);
  --color-surface-elevated: var(--family-dark-elevated);
  --color-text-primary: var(--palette-dark-text);
  --color-text-secondary: var(--palette-dark-muted);
  --color-text-muted: var(--palette-dark-muted);
  --color-text-inverse: var(--palette-black);
  --color-primary: var(--family-dark-primary);
  --color-primary-hover: var(--family-dark-hover);
  --color-primary-active: var(--family-dark-active);
  --color-primary-contrast: var(--palette-black);
  --color-border: var(--palette-dark-border);
  --color-border-strong: var(--palette-dark-border-strong);
  --color-success: var(--palette-dark-success);
  --color-warning: var(--palette-dark-warning);
  --color-error: var(--palette-dark-error);
  --color-info: var(--palette-dark-info);
  --color-overlay: var(--palette-dark-overlay);
  --shadow-color: var(--palette-dark-shadow);
}

:root {
  --app-font-scale: 1;
  --font: "Segoe UI Variable", "Segoe UI", "Aptos", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --color-black: var(--palette-black);
  --color-white: var(--palette-white);
  --color-transparent: var(--palette-transparent);
  --color-divider: var(--color-border);
  --color-link: var(--color-primary);
  --color-link-hover: var(--color-primary-hover);
  --color-focus: var(--color-primary);
  --color-focus-ring: var(--color-focus);
  --color-icon-muted: var(--color-text-muted);
  --color-selection: var(--color-active);
  --scrollbar-track: var(--color-transparent);
  --scrollbar-thumb: var(--color-border-strong);
  --scrollbar-thumb-hover: var(--color-primary);
  --shadow-small: var(--shadow-sm);
  --shadow-medium: var(--shadow-md);
  --shadow-large: var(--shadow-lg);
  --gradient-brand: var(--gradient-primary);
  --color-hover: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface));
  --color-active: color-mix(in srgb, var(--color-primary) 14%, var(--color-surface));
  --color-accent: var(--color-primary);
  --color-secondary: var(--color-text-secondary);
  --color-icon: var(--color-primary);
  --color-icon-active: var(--color-primary-active);
  --color-header-background: var(--color-surface-secondary);
  --color-header-text: var(--color-text-primary);
  --color-header-border: var(--color-border);
  --color-greeting-background: var(--family-dark-page);
  --color-greeting-text: var(--palette-dark-text);
  --greeting-gradient: var(--color-greeting-background);
  --tile-border-width: 1px;
  --tile-border-color: var(--color-border-strong);
  --tile-background: var(--color-surface-secondary);
  --tile-pending-background: color-mix(in srgb, var(--color-primary) 18%, var(--color-surface));
  --tile-meetings-background: color-mix(in srgb, var(--color-primary) 14%, var(--color-surface));
  --color-focus-callout-background: color-mix(in srgb, var(--color-primary) 16%, var(--color-surface-secondary));
  --color-disabled-background: var(--color-surface-secondary);
  --color-disabled-text: var(--color-text-muted);
  --color-disabled-border: var(--color-border);
  --color-success-background: color-mix(in srgb, var(--color-success) 8%, var(--color-surface));
  --color-success-text: var(--color-success);
  --color-success-border: var(--color-success);
  --color-warning-background: color-mix(in srgb, var(--color-warning) 8%, var(--color-surface));
  --color-warning-text: var(--color-warning);
  --color-warning-border: var(--color-warning);
  --color-error-background: color-mix(in srgb, var(--color-error) 8%, var(--color-surface));
  --color-error-text: var(--color-error);
  --color-error-border: var(--color-error);
  --color-info-background: color-mix(in srgb, var(--color-info) 8%, var(--color-surface));
  --color-info-text: var(--color-info);
  --color-info-border: var(--color-info);
  --color-calendar-busy-background: var(--color-error-background);
  --color-calendar-busy-text: var(--color-error-text);
  --color-calendar-busy-border: var(--color-error-border);
  --color-calendar-free-background: var(--color-success-background);
  --color-calendar-free-text: var(--color-success-text);
  --color-calendar-free-border: var(--color-success-border);
  --color-calendar-tentative-background: var(--color-warning-background);
  --color-calendar-tentative-text: var(--color-warning-text);
  --color-calendar-tentative-border: var(--color-warning-border);
  --color-calendar-poll-background: var(--color-info-background);
  --color-calendar-poll-text: var(--color-info-text);
  --color-calendar-poll-border: var(--color-info-border);
  --color-chat-user-background: var(--color-primary);
  --color-chat-user-text: var(--color-primary-contrast);
  --color-chat-user-border: var(--color-primary);
  --color-chat-assistant-background: var(--color-surface-secondary);
  --color-chat-assistant-text: var(--color-text-primary);
  --color-chat-assistant-border: var(--color-border);
  --color-logo-primary: var(--color-primary);
  --color-logo-secondary: var(--color-primary-hover);
  --color-mascot-primary: var(--color-primary);
  --color-mascot-secondary: var(--color-primary-hover);
  --color-mascot-shell: var(--color-surface-elevated);
  --color-mascot-visor: var(--color-text-primary);
  --brand-logo-filter: none;
  --gradient-primary: linear-gradient(135deg, var(--color-primary), var(--color-primary-active));
  --gradient-header: linear-gradient(135deg, var(--color-header-background), var(--color-surface));
  --gradient-surface: linear-gradient(135deg, var(--color-surface), var(--color-surface-secondary));
  --shadow-sm: 0 1px 2px var(--shadow-color);
  --shadow-md: 0 6px 20px var(--shadow-color);
  --shadow-lg: 0 14px 34px var(--shadow-color);

  /* Existing public compatibility contract. No separate legacy palette values. */
  --color-bg: var(--color-page-background);
  --color-text: var(--color-text-primary);
  --color-header: var(--color-header-background);
  --color-sidebar: var(--color-surface);
  --color-card: var(--color-surface);
  --color-input: var(--color-surface);
  --bg: var(--color-page-background);
  --card: var(--color-surface);
  --border: var(--color-border);
  --border-soft: var(--color-divider);
  --text: var(--color-text-primary);
  --text-dim: var(--color-text-secondary);
  --text-muted: var(--color-text-muted);
  --text-faint: var(--color-text-muted);
  --blue: var(--color-primary);
  --blue-dark: var(--color-primary-hover);
  --blue-mid: var(--color-primary);
  --blue-soft: var(--color-active);
  --mrcl: var(--color-primary);
  --mrcl-soft: var(--color-active);
  --green: var(--color-success);
  --green-soft: var(--color-success-background);
  --amber: var(--color-warning);
  --amber-soft: var(--color-warning-background);
  --red: var(--color-error);
  --red-soft: var(--color-error-background);
  --violet: var(--color-info);
  --theme-primary: var(--color-primary);
  --theme-primary-hover: var(--color-primary-hover);
  --theme-primary-active: var(--color-primary-active);
  --theme-text-on-primary: var(--color-primary-contrast);
  --theme-text: var(--color-text-primary);
  --theme-text-muted: var(--color-text-muted);
  --theme-bg-secondary: var(--color-surface-secondary);
  --theme-accent-soft: var(--color-active);
  --theme-header-bg: var(--color-header-background);
  --theme-surface: var(--color-surface);
  --theme-border: var(--color-border);
  --theme-surface-hover: var(--color-hover);
  --theme-brand-logo-filter: var(--brand-logo-filter);
  --theme-mascot-primary: var(--color-mascot-primary);
  --theme-mascot-secondary: var(--color-mascot-secondary);
  --theme-mascot-shell: var(--color-mascot-shell);
  --theme-mascot-visor: var(--color-mascot-visor);
  --theme-name: var(--theme-selected);
  --color-theme-name: var(--theme-name);
  --scheduler-title: var(--color-text-primary);
  --scheduler-text: var(--color-text-primary);
  --scheduler-secondary: var(--color-text-secondary);
  --scheduler-time: var(--color-link);
}

/* Original-style surfaces, not a component palette. Other families keep their geometry. */
:root[data-color-theme="default"] {
  --color-border: var(--palette-default-light-border);
  --color-header-background: var(--palette-default-light-header);
  --color-greeting-background: var(--palette-default-greeting-start);
  --color-greeting-text: var(--palette-white);
  --greeting-gradient: linear-gradient(120deg, var(--palette-default-greeting-start), var(--palette-default-greeting-end));
  --tile-border-width: 1px;
  --tile-border-color: var(--color-border);
  --tile-background: var(--color-surface);
  --tile-pending-background: color-mix(in srgb, var(--color-warning) 14%, var(--color-surface-secondary));
  --tile-meetings-background: color-mix(in srgb, var(--color-info) 14%, var(--color-surface-secondary));
}
:root[data-color-theme="default"][data-mode="dark"] {
  --color-border: var(--palette-default-dark-border);
  --color-header-background: var(--color-surface);
}