/* ------------------------------------------------------------------ */
/* Design Tokens                                                       */
/* ------------------------------------------------------------------ */

:root,
:root[data-theme="dark"] {
  /* Backgrounds */
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-raised: #334155;
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --bg-overlay-heavy: rgba(0, 0, 0, 0.85);
  --bg-canvas: #1a1a2e;
  --bg-input: #1e293b;
  --bg-hover: #334155;
  --bg-active: #1e3a5f;

  /* Status backgrounds */
  --bg-error: #7f1d1d;
  --bg-error-subtle: #450a0a;
  --bg-warning: #451a03;
  --bg-success: #14532d;
  --bg-info: #1e1b4b;

  /* Text */
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --text-inverse: #0f172a;
  --text-link: #60a5fa;
  --text-error: #fca5a5;
  --text-warning: #fbbf24;
  --text-success: #86efac;

  /* Borders */
  --border-subtle: #1e293b;
  --border-default: #334155;
  --border-strong: #475569;
  --border-focus: #3b82f6;

  /* Accent / brand */
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-secondary: #8b5cf6;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-success: #4ade80;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  /* Typography */
  --font-family: system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 14px;
  --font-size-lg: 16px;
  --font-size-xl: 18px;
  --font-size-2xl: 24px;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Z-indices */
  --z-canvas: 0;
  --z-panel: 10;
  --z-toolbar: 20;
  --z-overlay: 30;
  --z-modal: 40;
  --z-toast: 50;

  /* Layout */
  --toolbar-height: 48px;
  --statusbar-height: 28px;
  --sidebar-width: 260px;
  --panel-width: 320px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

:root[data-theme="light"] {
  /* Backgrounds */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-raised: #f1f5f9;
  --bg-overlay: rgba(0, 0, 0, 0.4);
  --bg-overlay-heavy: rgba(0, 0, 0, 0.6);
  --bg-canvas: #f0f4f8;
  --bg-input: #ffffff;
  --bg-hover: #e2e8f0;
  --bg-active: #dbeafe;

  /* Status backgrounds */
  --bg-error: #fef2f2;
  --bg-error-subtle: #fee2e2;
  --bg-warning: #fffbeb;
  --bg-success: #f0fdf4;
  --bg-info: #eef2ff;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --text-inverse: #f8fafc;
  --text-link: #2563eb;
  --text-error: #dc2626;
  --text-warning: #d97706;
  --text-success: #16a34a;

  /* Borders */
  --border-subtle: #e2e8f0;
  --border-default: #cbd5e1;
  --border-strong: #94a3b8;
  --border-focus: #3b82f6;

  /* Accent / brand - keep consistent */
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-secondary: #7c3aed;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-success: #22c55e;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ------------------------------------------------------------------ */
/* Reset & Base                                                        */
/* ------------------------------------------------------------------ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body, #root {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-app);
}

/* ------------------------------------------------------------------ */
/* Scrollbar styling                                                   */
/* ------------------------------------------------------------------ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ------------------------------------------------------------------ */
/* Focus styles                                                        */
/* ------------------------------------------------------------------ */

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

/* ------------------------------------------------------------------ */
/* Theme transition                                                    */
/* ------------------------------------------------------------------ */

html {
  transition: background-color var(--transition-normal),
              color var(--transition-normal);
}

/* ------------------------------------------------------------------ */
/* Responsive overrides                                                */
/* ------------------------------------------------------------------ */

/* Tablet: 640px - 1023px */
@media (max-width: 1023px) {
  :root {
    --sidebar-width: 220px;
    --panel-width: 280px;
    --toolbar-height: 44px;
  }
}

/* Mobile: < 640px */
@media (max-width: 639px) {
  :root {
    --sidebar-width: 100%;
    --panel-width: 100%;
    --toolbar-height: 44px;
    --font-size-2xl: 20px;
  }
}

/* ------------------------------------------------------------------ */
/* Mobile panel overlay                                                */
/* ------------------------------------------------------------------ */

.panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.panel-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ------------------------------------------------------------------ */
/* Mobile slide-in panel                                               */
/* ------------------------------------------------------------------ */

.slide-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-width);
  max-width: 100vw;
  z-index: calc(var(--z-overlay) + 1);
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  background: var(--bg-app);
  overflow-y: auto;
}

.slide-panel.open {
  transform: translateX(0);
}

.slide-panel-left {
  left: 0;
  right: auto;
  transform: translateX(-100%);
}

.slide-panel-left.open {
  transform: translateX(0);
}

/* ------------------------------------------------------------------ */
/* Mobile-specific utilities                                           */
/* ------------------------------------------------------------------ */

@media (max-width: 639px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 640px) {
  .hide-desktop {
    display: none !important;
  }
}

@media (max-width: 1023px) {
  .hide-tablet-down {
    display: none !important;
  }
}

/* ------------------------------------------------------------------ */
/* Mobile dialog                                                       */
/* ------------------------------------------------------------------ */

@media (max-width: 639px) {
  .mobile-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
}

/* ------------------------------------------------------------------ */
/* Responsive typography                                               */
/* ------------------------------------------------------------------ */

@media (max-width: 639px) {
  :root {
    --font-size-xs: 10px;
    --font-size-sm: 12px;
    --font-size-base: 13px;
    --font-size-lg: 15px;
    --font-size-xl: 17px;
  }
}
