/**
 * Unified Theme System - Botify ModBot Mini-App
 * ================================================
 *
 * SINGLE SOURCE OF TRUTH for all design tokens.
 * All pages should reference these variables.
 *
 * Note: Core tokens are defined in _tokens.css
 * This file extends those tokens with application-specific values.
 *
 * SECTIONS:
 * A) Color System - Primary, semantic, backgrounds, text, borders
 * B) Typography - Font families, sizes, weights, line heights
 * C) Spacing - 4px base unit scale (rem values)
 * D) Border Radius - Consistent corner radii
 * E) Shadows & Glows - Elevation and accent effects
 * F) Transitions - Animation timing
 * G) Z-Index Scale - Layering system
 * H) Telegram Integration - WebApp variable fallbacks
 * I) Layout - Container widths, safe areas
 *
 * Token Count: 150+ design tokens
 * Default Theme: Dark mode (Telegram native)
 */

:root {
  /* ============================================
   * A) COLOR SYSTEM
   * ============================================ */

  /* A.1 Brand Colors - Primary (Cyan) */
  --color-primary-50: #e6feff;
  --color-primary-100: #b3fcff;
  --color-primary-200: #80faff;
  --color-primary-300: #4df7ff;
  --color-primary-400: #26f4ff;
  --color-primary-500: #00f0ff;  /* Primary action color */
  --color-primary-600: #00c4d4;  /* Primary hover */
  --color-primary-700: #0098a8;
  --color-primary-800: #006d7d;
  --color-primary-900: #004251;

  /* A.2 Secondary Colors - Purple */
  --color-secondary-50: #f3e8ff;
  --color-secondary-100: #e4d0ff;
  --color-secondary-200: #c9a1ff;
  --color-secondary-300: #ae72ff;
  --color-secondary-400: #9a4bff;
  --color-secondary-500: #8a2be2;  /* Secondary action */
  --color-secondary-600: #7023b8;
  --color-secondary-700: #561b8f;
  --color-secondary-800: #3d1365;
  --color-secondary-900: #230b3c;

  /* A.3 Accent Colors - Green */
  --color-accent-50: #e6fff5;
  --color-accent-100: #b3ffe1;
  --color-accent-200: #80ffcc;
  --color-accent-300: #4dffb8;
  --color-accent-400: #26ffa3;
  --color-accent-500: #00ff88;  /* Accent/success highlight */
  --color-accent-600: #00d470;
  --color-accent-700: #00a858;
  --color-accent-800: #007d40;
  --color-accent-900: #005228;

  /* A.4 Semantic Colors - Success (Green) */
  --color-success-50: #f0fdf4;
  --color-success-100: #dcfce7;
  --color-success-200: #bbf7d0;
  --color-success-300: #86efac;
  --color-success-400: #4ade80;
  --color-success-500: #22c55e;
  --color-success-600: #16a34a;
  --color-success-700: #15803d;
  --color-success-800: #166534;
  --color-success-900: #14532d;

  /* A.5 Semantic Colors - Warning (Amber) */
  --color-warning-50: #fffbeb;
  --color-warning-100: #fef3c7;
  --color-warning-200: #fde68a;
  --color-warning-300: #fcd34d;
  --color-warning-400: #fbbf24;
  --color-warning-500: #f59e0b;
  --color-warning-600: #d97706;
  --color-warning-700: #b45309;
  --color-warning-800: #92400e;
  --color-warning-900: #78350f;

  /* A.6 Semantic Colors - Danger (Red) */
  --color-danger-50: #fef2f2;
  --color-danger-100: #fee2e2;
  --color-danger-200: #fecaca;
  --color-danger-300: #fca5a5;
  --color-danger-400: #f87171;
  --color-danger-500: #ef4444;
  --color-danger-600: #dc2626;
  --color-danger-700: #b91c1c;
  --color-danger-800: #991b1b;
  --color-danger-900: #7f1d1d;

  /* A.7 Semantic Colors - Info (Blue) */
  --color-info-50: #eff6ff;
  --color-info-100: #dbeafe;
  --color-info-200: #bfdbfe;
  --color-info-300: #93c5fd;
  --color-info-400: #60a5fa;
  --color-info-500: #3b82f6;
  --color-info-600: #2563eb;
  --color-info-700: #1d4ed8;
  --color-info-800: #1e40af;
  --color-info-900: #1e3a8a;

  /* A.8 Background Colors (Dark Mode Default) */
  --bg-page: #0a0e27;
  --bg-surface: rgba(10, 14, 39, 0.95);
  --bg-surface-solid: #0d1230;
  --bg-elevated: #151a3d;
  --bg-hover: rgba(0, 240, 255, 0.05);
  --bg-active: rgba(0, 240, 255, 0.1);
  --bg-overlay: rgba(0, 0, 0, 0.8);
  --bg-overlay-light: rgba(0, 0, 0, 0.5);
  --bg-gradient: linear-gradient(135deg, var(--bg-page) 0%, #1a1a2e 50%, var(--bg-page) 100%);
  --bg-card-gradient: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));

  /* A.9 Text Colors */
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.85);
  --text-muted: rgba(255, 255, 255, 0.6);
  --text-disabled: rgba(255, 255, 255, 0.4);
  --text-placeholder: rgba(255, 255, 255, 0.4);
  --text-inverse: #0a0e27;
  --text-link: var(--color-primary-500);
  --text-link-hover: var(--color-primary-400);
  --text-on-primary: #000000;

  /* A.10 Border Colors */
  --border-default: rgba(0, 240, 255, 0.3);
  --border-subtle: rgba(0, 240, 255, 0.15);
  --border-strong: rgba(0, 240, 255, 0.5);
  --border-focus: var(--color-primary-500);
  --border-error: var(--color-danger-500);
  --border-success: var(--color-success-500);

  /* ============================================
   * B) TYPOGRAPHY
   * ============================================ */

  /* B.1 Font Families */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* B.2 Font Sizes */
  --font-size-xs: 0.6875rem;   /* 11px */
  --font-size-sm: 0.75rem;     /* 12px */
  --font-size-base: 0.875rem;  /* 14px */
  --font-size-lg: 1rem;        /* 16px */
  --font-size-xl: 1.25rem;     /* 20px */
  --font-size-2xl: 1.5rem;     /* 24px */
  --font-size-3xl: 1.75rem;    /* 28px */
  --font-size-4xl: 2rem;       /* 32px */

  /* B.3 Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* B.4 Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* B.5 Letter Spacing */
  --letter-spacing-tight: -0.025em;
  --letter-spacing-normal: 0;
  --letter-spacing-wide: 0.025em;
  --letter-spacing-wider: 0.05em;

  /* ============================================
   * C) SPACING SCALE (4px base)
   * ============================================ */

  --space-0: 0;
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */

  /* ============================================
   * D) BORDER RADIUS
   * ============================================ */

  --radius-none: 0;
  --radius-sm: 0.375rem;  /* 6px */
  --radius-md: 0.5rem;    /* 8px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-xl: 1rem;      /* 16px */
  --radius-2xl: 1.25rem;  /* 20px */
  --radius-full: 9999px;

  /* ============================================
   * E) SHADOWS & GLOWS
   * ============================================ */

  /* E.1 Standard Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.5);

  /* E.2 Accent Glows */
  --glow-primary: 0 0 20px rgba(0, 240, 255, 0.3);
  --glow-primary-strong: 0 0 30px rgba(0, 240, 255, 0.5);
  --glow-secondary: 0 0 20px rgba(138, 43, 226, 0.3);
  --glow-accent: 0 0 20px rgba(0, 255, 136, 0.3);
  --glow-danger: 0 0 15px rgba(239, 68, 68, 0.4);
  --glow-danger-muted: 0 0 8px rgba(136, 8, 8, 0.8);
  --glow-success: 0 0 15px rgba(34, 197, 94, 0.4);

  /* Danger background variants */
  --color-danger-bg: rgba(136, 8, 8, 0.1);
  --color-danger-bg-subtle: rgba(170, 10, 10, 0.05);

  /* E.3 Card Hover Effect */
  --shadow-card-hover: 0 8px 25px rgba(0, 240, 255, 0.2);

  /* ============================================
   * F) TRANSITIONS
   * ============================================ */

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

  --duration-instant: 100ms;
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;

  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --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);

  /* ============================================
   * G) Z-INDEX SCALE
   * ============================================ */

  --z-base: 0;
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-notification: 1080;

  /* ============================================
   * H) TELEGRAM INTEGRATION
   * ============================================ */

  /* Telegram WebApp theme variables with fallbacks */
  --tg-bg: var(--tg-theme-bg-color, var(--bg-page));
  --tg-text: var(--tg-theme-text-color, var(--text-primary));
  --tg-hint: var(--tg-theme-hint-color, var(--text-muted));
  --tg-link: var(--tg-theme-link-color, var(--color-primary-500));
  --tg-button: var(--tg-theme-button-color, var(--color-primary-500));
  --tg-button-text: var(--tg-theme-button-text-color, var(--text-on-primary));
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, var(--bg-surface-solid));

  /* Safe Area Insets (iOS notch support) */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);

  /* ============================================
   * I) LAYOUT
   * ============================================ */

  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;

  --header-height: 60px;
  --nav-height: 56px;
  --footer-height: 60px;

  /* Touch targets (accessibility minimum) */
  --touch-target-min: 44px;

  /* ============================================
   * LEGACY ALIASES
   * For backward compatibility with existing code
   * ============================================ */

  /* Map old variable names to new tokens */
  --primary: var(--color-primary-500);
  --secondary: var(--color-secondary-500);
  --accent: var(--color-accent-500);
  --danger: var(--color-danger-500);
  --warning: var(--color-warning-500);
  --success: var(--color-success-500);
  --info: var(--color-info-500);
  --bg-dark: var(--bg-page);
  --bg-card: var(--bg-surface);
  --border: var(--border-default);
  --text: var(--text-primary);
}

/* ============================================
 * THEME VARIANTS
 * Apply via data-theme-variant attribute
 * ============================================ */

/* Neon Purple Theme */
[data-theme-variant="neon-purple"] {
  --color-primary-500: #bd00ff;
  --color-primary-600: #a400dd;
  --color-primary-400: #d433ff;
  --border-default: rgba(189, 0, 255, 0.3);
  --glow-primary: 0 0 20px rgba(189, 0, 255, 0.3);
}

/* Deep Red Theme */
[data-theme-variant="deep-red"] {
  --color-primary-500: #880808;
  --color-primary-600: #660606;
  --color-primary-400: #aa0a0a;
  --border-default: rgba(136, 8, 8, 0.3);
  --glow-primary: 0 0 20px rgba(136, 8, 8, 0.4);
}

/* Halloween Theme */
[data-theme-variant="halloween"] {
  --color-primary-500: #ff9900;
  --color-primary-600: #ee8800;
  --color-primary-400: #ffaa33;
  --bg-page: #0f0a05;
  --border-default: rgba(255, 153, 0, 0.3);
  --glow-primary: 0 0 20px rgba(255, 153, 0, 0.4);
}

/* Telegram Blue Theme */
[data-theme-variant="telegram-blue"] {
  --color-primary-500: #4a9eff;
  --color-primary-600: #2987ee;
  --color-primary-400: #6bb0ff;
  --border-default: rgba(74, 158, 255, 0.3);
  --glow-primary: 0 0 20px rgba(74, 158, 255, 0.3);
}

/* Matrix Green Theme */
[data-theme-variant="matrix-green"] {
  --color-primary-500: #00ff00;
  --color-primary-600: #00cc00;
  --color-primary-400: #33ff33;
  --bg-page: #050f05;
  --border-default: rgba(0, 255, 0, 0.3);
  --glow-primary: 0 0 20px rgba(0, 255, 0, 0.4);
}

/* ============================================
 * LIGHT MODE THEME
 * Applied via data-theme="light" or Telegram's colorScheme
 * ============================================ */

[data-theme="light"],
.theme-light {
  /* Light mode backgrounds */
  --bg-page: #f5f5f7;
  --bg-surface: rgba(255, 255, 255, 0.95);
  --bg-surface-solid: #ffffff;
  --bg-elevated: #f0f0f5;
  --bg-hover: rgba(0, 122, 255, 0.08);
  --bg-active: rgba(0, 122, 255, 0.12);
  --bg-overlay: rgba(0, 0, 0, 0.5);
  --bg-overlay-light: rgba(0, 0, 0, 0.3);
  --bg-gradient: linear-gradient(135deg, #f5f5f7 0%, #e8e8ed 50%, #f5f5f7 100%);

  /* Light mode text */
  --text-primary: #1c1c1e;
  --text-secondary: rgba(0, 0, 0, 0.75);
  --text-muted: rgba(0, 0, 0, 0.5);
  --text-disabled: rgba(0, 0, 0, 0.3);
  --text-placeholder: rgba(0, 0, 0, 0.3);
  --text-inverse: #ffffff;
  --text-on-primary: #ffffff;

  /* Light mode borders */
  --border-default: rgba(0, 0, 0, 0.12);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.2);

  /* Light mode primary (iOS blue) */
  --color-primary-500: #007aff;
  --color-primary-600: #0056b3;
  --color-primary-400: #3395ff;

  /* Adjusted shadows for light mode */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  /* Adjusted glows for light mode */
  --glow-primary: 0 0 10px rgba(0, 122, 255, 0.2);
  --glow-primary-strong: 0 0 15px rgba(0, 122, 255, 0.3);

  /* Card gradient for light mode */
  --bg-card-gradient: linear-gradient(135deg, #007aff, #5856d6);
}

/* Use Telegram's theme variables when available */
body.tg-theme {
  --bg-page: var(--tg-theme-bg-color, var(--bg-page));
  --bg-surface-solid: var(--tg-theme-secondary-bg-color, var(--bg-surface-solid));
  --text-primary: var(--tg-theme-text-color, var(--text-primary));
  --text-muted: var(--tg-theme-hint-color, var(--text-muted));
  --color-primary-500: var(--tg-theme-button-color, var(--color-primary-500));
  --text-on-primary: var(--tg-theme-button-text-color, var(--text-on-primary));
  --text-link: var(--tg-theme-link-color, var(--color-primary-500));
}

/* ============================================
 * ACCESSIBILITY
 * ============================================ */

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast: 0ms;
    --transition-base: 0ms;
    --transition-slow: 0ms;
    --duration-instant: 0ms;
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --border-default: rgba(255, 255, 255, 0.5);
    --text-muted: rgba(255, 255, 255, 0.8);
  }
}

/* ============================================
 * BASE RESET & GLOBAL STYLES
 * ============================================ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background: var(--bg-gradient);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Selection styling */
::selection {
  background: var(--color-primary-500);
  color: var(--text-on-primary);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-surface-solid);
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}
