/* CSS Variables System */
:root {
  /* === Color System === */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  
  --accent-green: #22c55e;
  --accent-green-hover: #16a34a;
  
  /* Modern Gradient Colors */
  --gradient-blue: linear-gradient(135deg, #3b82f6, #1e40af, #1e3a8a);
  --gradient-green: linear-gradient(135deg, #22c55e, #16a34a, #15803d);
  --gradient-cyan: linear-gradient(135deg, #06b6d4, #0891b2, #0e7490);
  --gradient-teal: linear-gradient(135deg, #14b8a6, #0d9488, #0f766e);
  --gradient-red: linear-gradient(135deg, #ef4444, #dc2626, #b91c1c);
  --gradient-purple: linear-gradient(135deg, #8b5cf6, #7c3aed, #6d28d9);
  --gradient-pink: linear-gradient(135deg, #ec4899, #db2777, #be185d);
  
  --border-color: #dee2e6;
  --border-focus: #22c55e;
  
  /* === Spacing System === */
  --spacing-xs: 0.25rem;    /* 4px */
  --spacing-sm: 0.5rem;     /* 8px */
  --spacing-md: 1rem;       /* 16px */
  --spacing-lg: 1.5rem;     /* 24px */
  --spacing-xl: 2rem;       /* 32px */
  
  /* === Typography === */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  
  /* === Borders & Shadows === */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
}

/* Dark Theme Override - Modern Deep Backgrounds */
[data-theme="dark"] {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2d2d2d;
  
  --text-primary: #ffffff;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  
  --border-color: #404040;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
}

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* Custom Tailwind Classes */
.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-tertiary { background-color: var(--bg-tertiary); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

.border-tertiary { border-color: var(--bg-tertiary); }
.border-color { border-color: var(--border-color); }
.border-focus { border-color: var(--border-focus); }

.bg-accent-green { background-color: var(--accent-green); }
.hover\:bg-accent-green:hover { background-color: var(--accent-green); }

/* Modern Gradient Button Classes */
.btn-gradient-blue { background: var(--gradient-blue); }
.btn-gradient-green { background: var(--gradient-green); }
.btn-gradient-cyan { background: var(--gradient-cyan); }
.btn-gradient-teal { background: var(--gradient-teal); }
.btn-gradient-red { background: var(--gradient-red); }
.btn-gradient-purple { background: var(--gradient-purple); }
.btn-gradient-pink { background: var(--gradient-pink); }

/* Theme Toggle */
[data-theme="dark"] #theme-slider {
  transform: translateX(1.5rem);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-green);
}

/* Mobile-First Responsive Design */
@media (max-width: 768px) {
  #app main {
    flex-direction: column !important;
  }
  
  #appLeft,
  #appRight {
    width: 100% !important;
    height: auto !important;
    min-height: 300px;
  }
  
  #divider {
    display: none;
  }
}

@media (max-width: 1024px) {
  #app main {
    flex-direction: column;
  }
  
  #left-panel,
  #right-panel {
    width: 100%;
    height: 50%;
  }
  
  #divider {
    width: 100%;
    height: 4px;
    cursor: row-resize;
  }
}

@media (max-width: 768px) {
  /* Header compact for mobile */
  #app-header {
    height: 3rem;
    padding: 0 1rem;
  }
  
  #app-header .text-lg {
    font-size: 1rem;
  }
  
  /* Main layout improvements */
  #appLeft {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
  }
  
  #appRight {
    padding: 0;
  }
  
  /* Touch-friendly input areas */
  #input-editor {
    min-height: 140px !important;
    padding: 16px !important;
    font-size: 16px !important; /* Prevent zoom on iOS */
    line-height: 1.5 !important;
    border-radius: 8px !important;
  }
  
  /* Character count better visibility */
  .character-count {
    font-size: 14px !important;
    padding: 8px 12px !important;
    background: rgba(0,0,0,0.15) !important;
    border-radius: 6px !important;
    font-weight: 600 !important;
  }
  
  /* Output area text wrapping */
  .output-text {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: pre-wrap !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding: 16px !important;
  }
  
  /* Function navigator mobile adjustments */
  .function-navigator {
    border-radius: 8px 8px 0 0;
  }
  
  /* Result display mobile adjustments */
  .result-display-container {
    padding: 1rem !important;
  }
  
  /* Footer status */
  footer {
    height: 2.5rem;
    font-size: 12px;
    padding: 0 1rem;
  }
  
  /* Mobile-specific button improvements */
  button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
}

/* Focus States */
#input-editor:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}

select:focus,
button:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Animation Classes */
.transition-theme {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Loading States */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--bg-tertiary);
  border-top: 2px solid var(--accent-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

/* Mobile Collapse Styles */
@media (max-width: 768px) {
  .collapse-header {
    transition: background-color 0.2s ease;
  }
  
  .collapse-header:hover {
    background-color: var(--bg-tertiary);
  }
  
  .collapse-btn {
    transition: transform 0.2s ease;
    user-select: none;
  }
}