/**
 * @oneos/ui Theme
 * Complete theme bundle including tokens and default themes
 */

/* ========================================
   Typography Tokens
   ======================================== */

:root {
  /* Font Families */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-serif: Georgia, Cambria, 'Times New Roman', Times, serif;
  --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;

  --font-body: var(--font-sans);
  --font-heading: var(--font-sans);
  --font-code: var(--font-mono);

  /* Font Sizes */
  --text-xs: 0.75rem;     /* 12px */
  --text-sm: 0.875rem;    /* 14px */
  --text-base: 1rem;      /* 16px */
  --text-lg: 1.125rem;    /* 18px */
  --text-xl: 1.25rem;     /* 20px */
  --text-2xl: 1.5rem;     /* 24px */
  --text-3xl: 1.875rem;   /* 30px */
  --text-4xl: 2.25rem;    /* 36px */
  --text-5xl: 3rem;       /* 48px */

  /* Font Weights */
  --font-thin: 100;
  --font-light: 300;
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* Line Heights */
  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  --leading-loose: 2;

  /* Letter Spacing */
  --tracking-tighter: -0.05em;
  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;
  --tracking-wider: 0.05em;
  --tracking-widest: 0.1em;
}

/* ========================================
   Spacing Tokens
   ======================================== */

:root {
  --space-0: 0;
  --space-px: 1px;
  --space-0-5: 0.125rem;  /* 2px */
  --space-1: 0.25rem;     /* 4px */
  --space-1-5: 0.375rem;  /* 6px */
  --space-2: 0.5rem;      /* 8px */
  --space-2-5: 0.625rem;  /* 10px */
  --space-3: 0.75rem;     /* 12px */
  --space-3-5: 0.875rem;  /* 14px */
  --space-4: 1rem;        /* 16px */
  --space-5: 1.25rem;     /* 20px */
  --space-6: 1.5rem;      /* 24px */
  --space-7: 1.75rem;     /* 28px */
  --space-8: 2rem;        /* 32px */
  --space-9: 2.25rem;     /* 36px */
  --space-10: 2.5rem;     /* 40px */
  --space-11: 2.75rem;    /* 44px */
  --space-12: 3rem;       /* 48px */
  --space-14: 3.5rem;     /* 56px */
  --space-16: 4rem;       /* 64px */
  --space-20: 5rem;       /* 80px */
  --space-24: 6rem;       /* 96px */
  --space-28: 7rem;       /* 112px */
  --space-32: 8rem;       /* 128px */
  --space-36: 9rem;       /* 144px */
  --space-40: 10rem;      /* 160px */
  --space-44: 11rem;      /* 176px */
  --space-48: 12rem;      /* 192px */
  --space-52: 13rem;      /* 208px */
  --space-56: 14rem;      /* 224px */
  --space-60: 15rem;      /* 240px */
  --space-64: 16rem;      /* 256px */
}

/* ========================================
   Border Radius Tokens
   ======================================== */

:root {
  --radius-none: 0;
  --radius-sm: 0.125rem;    /* 2px */
  --radius-md: 0.375rem;    /* 6px */
  --radius-lg: 0.5rem;      /* 8px */
  --radius-xl: 0.75rem;     /* 12px */
  --radius-2xl: 1rem;       /* 16px */
  --radius-3xl: 1.5rem;     /* 24px */
  --radius-full: 9999px;
}

/* ========================================
   Shadow Tokens
   ======================================== */

:root {
  --shadow-none: none;
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);

  /* Focus ring */
  --shadow-focus: 0 0 0 3px var(--color-primary-muted);
  --shadow-focus-danger: 0 0 0 3px var(--theme-danger-muted, rgb(239 68 68 / 0.3));
}

/* ========================================
   Animation Tokens
   ======================================== */

:root {
  /* Durations */
  --duration-instant: 0ms;
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 500ms;
  --duration-slowest: 700ms;

  /* Easings */
  --ease-linear: linear;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);

  /* Common transitions */
  --transition-colors: color var(--duration-fast) var(--ease-out),
                       background-color var(--duration-fast) var(--ease-out),
                       border-color var(--duration-fast) var(--ease-out);
  --transition-opacity: opacity var(--duration-normal) var(--ease-out);
  --transition-transform: transform var(--duration-normal) var(--ease-out);
  --transition-all: all var(--duration-normal) var(--ease-out);
}

/* Keyframe animations */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(-25%); animation-timing-function: cubic-bezier(0.8, 0, 1, 1); }
  50% { transform: translateY(0); animation-timing-function: cubic-bezier(0, 0, 0.2, 1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

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

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

@keyframes scale-in {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ========================================
   Component Tokens
   ======================================== */

:root {
  /* Interactive elements (buttons, links, etc.) */
  --radius-interactive: var(--radius-md);
  --spacing-interactive-x: var(--space-4);
  --spacing-interactive-y: var(--space-2);

  /* Cards and containers */
  --radius-card: var(--radius-lg);
  --spacing-card: var(--space-4);

  /* Badges and tags */
  --radius-badge: var(--radius-full);

  /* Form inputs */
  --radius-input: var(--radius-md);
  --spacing-input-x: var(--space-3);
  --spacing-input-y: var(--space-2);

  /* Small interactive elements */
  --spacing-interactive-sm-x: var(--space-2);
  --spacing-interactive-sm-y: var(--space-1);

  /* Large interactive elements */
  --spacing-interactive-lg-x: var(--space-6);
  --spacing-interactive-lg-y: var(--space-3);
}

/* ========================================
   Color Tokens (Semantic)
   ======================================== */

:root {
  /* Primary */
  --color-primary: var(--theme-primary);
  --color-primary-hover: var(--theme-primary-hover);
  --color-primary-active: var(--theme-primary-active);
  --color-primary-muted: var(--theme-primary-muted);

  /* Secondary */
  --color-secondary: var(--theme-secondary);
  --color-secondary-hover: var(--theme-secondary-hover);

  /* Semantic */
  --color-danger: var(--theme-danger);
  --color-danger-hover: var(--theme-danger-hover);
  --color-success: var(--theme-success);
  --color-success-hover: var(--theme-success-hover);
  --color-warning: var(--theme-warning);
  --color-warning-hover: var(--theme-warning-hover);
  --color-info: var(--theme-info);
  --color-info-hover: var(--theme-info-hover);

  /* Surfaces */
  --color-background: var(--theme-background);
  --color-surface: var(--theme-surface);
  --color-surface-secondary: var(--theme-surface-secondary);
  --color-surface-hover: var(--theme-surface-hover);
  --color-surface-active: var(--theme-surface-active);

  /* Text */
  --color-text: var(--theme-text);
  --color-text-secondary: var(--theme-text-secondary);
  --color-text-muted: var(--theme-text-muted);
  --color-text-disabled: var(--theme-text-disabled);
  --color-text-inverse: var(--theme-text-inverse);

  /* Borders */
  --color-border: var(--theme-border);
  --color-border-hover: var(--theme-border-hover);
  --color-border-focus: var(--theme-border-focus);

  /* On-colors (text/icons on colored backgrounds) */
  --color-on-primary: var(--theme-on-primary);
  --color-on-secondary: var(--theme-on-secondary);
  --color-on-danger: var(--theme-on-danger);
  --color-on-success: var(--theme-on-success);
  --color-on-warning: var(--theme-on-warning);
  --color-on-info: var(--theme-on-info);

  /* Shadows (tinted, never pure black) */
  --shadow-sm: var(--theme-shadow-sm);
  --shadow-md: var(--theme-shadow-md);
  --shadow-lg: var(--theme-shadow-lg);
  --shadow-xl: var(--theme-shadow-xl);

  /* Glass / Frosted panels */
  --glass-bg: var(--theme-glass-bg);
  --glass-blur: var(--theme-glass-blur);
  --glass-border: var(--theme-glass-border);

  /* Gradients */
  --gradient-primary: var(--theme-primary-gradient);
}

/* ========================================
   Light Theme (Default)
   ======================================== */

[data-theme='light'],
:root {
  /* ── Color Scales ── */
  --color-primary-50: #eff6ff;
  --color-primary-100: #dbeafe;
  --color-primary-200: #bfdbfe;
  --color-primary-300: #93c5fd;
  --color-primary-400: #60a5fa;
  --color-primary-500: #3b82f6;
  --color-primary-600: #2563eb;
  --color-primary-700: #1d4ed8;
  --color-primary-800: #1e40af;
  --color-primary-900: #1e3a8a;

  --color-slate-50: #f8fafc;
  --color-slate-100: #f1f5f9;
  --color-slate-200: #e2e8f0;
  --color-slate-300: #cbd5e1;
  --color-slate-400: #94a3b8;
  --color-slate-500: #64748b;
  --color-slate-600: #475569;
  --color-slate-700: #334155;
  --color-slate-800: #1e293b;
  --color-slate-900: #0f172a;
  --color-slate-950: #020617;

  /* ── Semantic Theme (Light — "Digital Architect") ── */

  /* Primary */
  --theme-primary: #2563eb;
  --theme-primary-hover: #1d4ed8;
  --theme-primary-active: #1e40af;
  --theme-primary-muted: rgb(37 99 235 / 0.15);
  --theme-primary-gradient: linear-gradient(135deg, #2563eb, #3b82f6);

  /* Secondary */
  --theme-secondary: #64748b;
  --theme-secondary-hover: #475569;

  /* Semantic — Danger (rose) */
  --theme-danger: #f43f5e;
  --theme-danger-hover: #e11d48;
  --theme-danger-muted: rgb(244 63 94 / 0.15);

  /* Semantic — Success (emerald) */
  --theme-success: #10b981;
  --theme-success-hover: #059669;

  /* Semantic — Warning (amber) */
  --theme-warning: #f59e0b;
  --theme-warning-hover: #d97706;

  /* Semantic — Info (sky) */
  --theme-info: #0ea5e9;
  --theme-info-hover: #0284c7;

  /* Surfaces — Tonal Layering */
  --theme-background: #f8fafc;
  --theme-surface: #ffffff;
  --theme-surface-secondary: #f1f5f9;
  --theme-surface-hover: #e2e8f0;
  --theme-surface-active: #cbd5e1;

  /* Text */
  --theme-text: #0f172a;
  --theme-text-secondary: #475569;
  --theme-text-muted: #94a3b8;
  --theme-text-disabled: #cbd5e1;
  --theme-text-inverse: #ffffff;

  /* Borders — Ghost Borders (prefer tonal shifts over lines) */
  --theme-border: #e2e8f0;
  --theme-border-hover: #cbd5e1;
  --theme-border-focus: #2563eb;

  /* Shadows — Tinted (never pure black) */
  --theme-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --theme-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --theme-shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.06);
  --theme-shadow-xl: 0 20px 40px rgba(15, 23, 42, 0.08);

  /* Glass */
  --theme-glass-bg: rgba(255, 255, 255, 0.6);
  --theme-glass-blur: 24px;
  --theme-glass-border: rgba(255, 255, 255, 0.3);

  /* On-colors */
  --theme-on-primary: #ffffff;
  --theme-on-secondary: #ffffff;
  --theme-on-danger: #ffffff;
  --theme-on-success: #ffffff;
  --theme-on-warning: #ffffff;
  --theme-on-info: #ffffff;
}

/* ========================================
   Dark Theme
   ======================================== */

[data-theme='dark'] {
  /* ── Semantic Theme (Dark — "Midnight Architect") ── */

  /* Primary — luminous blue on dark */
  --theme-primary: #3b82f6;
  --theme-primary-hover: #60a5fa;
  --theme-primary-active: #93c5fd;
  --theme-primary-muted: rgb(59 130 246 / 0.15);
  --theme-primary-gradient: linear-gradient(135deg, #adc6ff, #4d8eff);

  /* Secondary */
  --theme-secondary: #94a3b8;
  --theme-secondary-hover: #cbd5e1;

  /* Semantic — Danger */
  --theme-danger: #f43f5e;
  --theme-danger-hover: #fb7185;
  --theme-danger-muted: rgb(244 63 94 / 0.15);

  /* Semantic — Success */
  --theme-success: #22c55e;
  --theme-success-hover: #4ade80;

  /* Semantic — Warning (warm ember accent) */
  --theme-warning: #f59e0b;
  --theme-warning-hover: #fbbf24;

  /* Semantic — Info */
  --theme-info: #06b6d4;
  --theme-info-hover: #22d3ee;

  /* Surfaces — Midnight Architect Tonal Layering */
  --theme-background: #0b1326;
  --theme-surface: #131b2e;
  --theme-surface-secondary: #243044;
  --theme-surface-hover: #2d3a4f;
  --theme-surface-active: #2d3449;

  /* Text — Light on dark with hierarchy */
  --theme-text: #dae2fd;
  --theme-text-secondary: #c2c6d6;
  --theme-text-muted: #8c909f;
  --theme-text-disabled: #424754;
  --theme-text-inverse: #0b1326;

  /* Borders — Ghost Borders (barely visible) */
  --theme-border: rgba(66, 71, 84, 0.5);
  --theme-border-hover: #424754;
  --theme-border-focus: #adc6ff;

  /* Shadows — Midnight Glow (indigo-tinted, never pure black) */
  --theme-shadow-sm: 0 1px 3px rgba(6, 14, 32, 0.4);
  --theme-shadow-md: 0 4px 12px rgba(6, 14, 32, 0.5);
  --theme-shadow-lg: 0 12px 32px rgba(6, 14, 32, 0.6);
  --theme-shadow-xl: 0 20px 48px rgba(6, 14, 32, 0.7);
  --theme-shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  /* Glass — Frosted dark panels */
  --theme-glass-bg: rgba(11, 19, 38, 0.8);
  --theme-glass-blur: 20px;
  --theme-glass-border: rgba(255, 255, 255, 0.06);

  /* On-colors */
  --theme-on-primary: #002e6a;
  --theme-on-secondary: #0b1326;
  --theme-on-danger: #ffffff;
  --theme-on-success: #0b1326;
  --theme-on-warning: #0b1326;
  --theme-on-info: #0b1326;
}

/* ========================================
   Base Styles
   ======================================== */

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

html {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
}

/* Focus visible styles */
:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
}

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

/* SvelteFlow a11y description — its scoped display:none rule uses a
   svelte-hash class selector that doesn't survive our vendor
   bundling, so the description text (Press enter or space to
   select a node…) ends up visible. Force-hide globally. */
.a11y-hidden { display: none !important; }
