/**
 * VABA Theme Switcher System
 * Light/Dark mode with smooth transitions and system preference detection
 * Version: 1.0.0
 */

/* ==============================
   LIGHT THEME (Default)
   ============================== */
:root,
[data-theme="light"] {
  /* === Background Colors === */
  --theme-bg-primary: #ffffff;
  --theme-bg-secondary: #f8f9fc;
  --theme-bg-tertiary: #f1f3f9;
  --theme-bg-elevated: #ffffff;
  --theme-bg-hover: #f3f4f6;
  --theme-bg-active: #e5e7eb;
  
  /* === Surface Colors === */
  --theme-surface-primary: #ffffff;
  --theme-surface-secondary: #f8f9fc;
  --theme-surface-elevated: #ffffff;
  --theme-surface-hover: #f3f4f6;
  --theme-surface-active: #e5e7eb;
  
  /* === Text Colors === */
  --theme-text-primary: #111827;
  --theme-text-secondary: #374151;
  --theme-text-tertiary: #6b7280;
  --theme-text-muted: #9ca3af;
  --theme-text-inverse: #ffffff;
  
  /* === Border Colors === */
  --theme-border-subtle: #e5e7eb;
  --theme-border-medium: #d1d5db;
  --theme-border-strong: #9ca3af;
  --theme-border-focus: #C9A962;
  
  /* === Brand Colors (consistent across themes) === */
  --theme-brand-gold: #C9A962;
  --theme-brand-gold-hover: #D4B978;
  --theme-brand-gold-muted: rgba(201, 169, 98, 0.15);
  
  /* === Status Colors === */
  --theme-success: #16a34a;
  --theme-success-bg: #dcfce7;
  --theme-success-border: #86efac;
  --theme-warning: #d97706;
  --theme-warning-bg: #fef3c7;
  --theme-warning-border: #fcd34d;
  --theme-danger: #dc2626;
  --theme-danger-bg: #fee2e2;
  --theme-danger-border: #fca5a5;
  --theme-info: #0284c7;
  --theme-info-bg: #e0f2fe;
  --theme-info-border: #7dd3fc;
  
  /* === Shadow Colors === */
  --theme-shadow-color: rgba(0, 0, 0, 0.1);
  --theme-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --theme-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --theme-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --theme-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --theme-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);
  
  /* === Component-Specific === */
  --theme-header-bg: #ffffff;
  --theme-sidebar-bg: #f8f9fc;
  --theme-card-bg: #ffffff;
  --theme-modal-bg: #ffffff;
  --theme-modal-overlay: rgba(0, 0, 0, 0.5);
  --theme-input-bg: #ffffff;
  --theme-input-border: #d1d5db;
  --theme-table-header-bg: #f3f4f6;
  --theme-table-row-hover: #f9fafb;
  --theme-scrollbar-track: #f1f3f9;
  --theme-scrollbar-thumb: #d1d5db;
  --theme-scrollbar-thumb-hover: #9ca3af;
  
  /* === Code/Log Colors === */
  --theme-code-bg: #f3f4f6;
  --theme-code-text: #1f2937;
  
  /* === Accent RGB for glows === */
  --theme-accent-rgb: 201, 169, 98;
}

/* ==============================
   DARK THEME
   ============================== */
[data-theme="dark"] {
  /* === Background Colors === */
  --theme-bg-primary: #0d0f11;
  --theme-bg-secondary: #141618;
  --theme-bg-tertiary: #1a1d21;
  --theme-bg-elevated: #1f2328;
  --theme-bg-hover: #272b30;
  --theme-bg-active: #32383f;
  
  /* === Surface Colors === */
  --theme-surface-primary: #0d0f11;
  --theme-surface-secondary: #141618;
  --theme-surface-elevated: #1a1d21;
  --theme-surface-hover: #272b30;
  --theme-surface-active: #32383f;
  
  /* === Text Colors === */
  --theme-text-primary: #f9fafb;
  --theme-text-secondary: #d1d5db;
  --theme-text-tertiary: #9ca3af;
  --theme-text-muted: #6b7280;
  --theme-text-inverse: #111827;
  
  /* === Border Colors === */
  --theme-border-subtle: #27272a;
  --theme-border-medium: #3f3f46;
  --theme-border-strong: #52525b;
  --theme-border-focus: #C9A962;
  
  /* === Status Colors === */
  --theme-success: #22c55e;
  --theme-success-bg: rgba(34, 197, 94, 0.15);
  --theme-success-border: rgba(34, 197, 94, 0.3);
  --theme-warning: #f59e0b;
  --theme-warning-bg: rgba(245, 158, 11, 0.15);
  --theme-warning-border: rgba(245, 158, 11, 0.3);
  --theme-danger: #ef4444;
  --theme-danger-bg: rgba(239, 68, 68, 0.15);
  --theme-danger-border: rgba(239, 68, 68, 0.3);
  --theme-info: #3b82f6;
  --theme-info-bg: rgba(59, 130, 246, 0.15);
  --theme-info-border: rgba(59, 130, 246, 0.3);
  
  /* === Shadow Colors === */
  --theme-shadow-color: rgba(0, 0, 0, 0.4);
  --theme-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --theme-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --theme-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --theme-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
  --theme-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);
  
  /* === Component-Specific === */
  --theme-header-bg: #0d0f11;
  --theme-sidebar-bg: #141618;
  --theme-card-bg: #1a1d21;
  --theme-modal-bg: #1a1d21;
  --theme-modal-overlay: rgba(0, 0, 0, 0.75);
  --theme-input-bg: #1a1d21;
  --theme-input-border: #3f3f46;
  --theme-table-header-bg: #1a1d21;
  --theme-table-row-hover: #272b30;
  --theme-scrollbar-track: #1a1d21;
  --theme-scrollbar-thumb: #3f3f46;
  --theme-scrollbar-thumb-hover: #52525b;
  
  /* === Code/Log Colors === */
  --theme-code-bg: #1a1d21;
  --theme-code-text: #e5e7eb;
}

/* ==============================
   SYSTEM PREFERENCE DETECTION
   ============================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* Inherit dark theme when no explicit preference is set */
    --theme-bg-primary: #0d0f11;
    --theme-bg-secondary: #141618;
    --theme-bg-tertiary: #1a1d21;
    --theme-bg-elevated: #1f2328;
    --theme-bg-hover: #272b30;
    --theme-bg-active: #32383f;
    --theme-surface-primary: #0d0f11;
    --theme-surface-secondary: #141618;
    --theme-surface-elevated: #1a1d21;
    --theme-surface-hover: #272b30;
    --theme-surface-active: #32383f;
    --theme-text-primary: #f9fafb;
    --theme-text-secondary: #d1d5db;
    --theme-text-tertiary: #9ca3af;
    --theme-text-muted: #6b7280;
    --theme-text-inverse: #111827;
    --theme-border-subtle: #27272a;
    --theme-border-medium: #3f3f46;
    --theme-border-strong: #52525b;
    --theme-header-bg: #0d0f11;
    --theme-sidebar-bg: #141618;
    --theme-card-bg: #1a1d21;
    --theme-modal-bg: #1a1d21;
    --theme-input-bg: #1a1d21;
    --theme-input-border: #3f3f46;
    --theme-table-header-bg: #1a1d21;
    --theme-table-row-hover: #272b30;
    --theme-scrollbar-track: #1a1d21;
    --theme-scrollbar-thumb: #3f3f46;
    --theme-scrollbar-thumb-hover: #52525b;
    --theme-code-bg: #1a1d21;
    --theme-code-text: #e5e7eb;
    --theme-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --theme-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --theme-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --theme-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --theme-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);
  }
}

/* ==============================
   SMOOTH TRANSITION FOR THEME CHANGE
   ============================== */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: 
    background-color 0.3s ease,
    border-color 0.3s ease,
    color 0.2s ease,
    box-shadow 0.3s ease !important;
}

/* ==============================
   THEME TOGGLE BUTTON STYLES
   ============================== */
.theme-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--theme-bg-tertiary);
  border: 1px solid var(--theme-border-subtle);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--theme-text-secondary);
}

.theme-toggle:hover {
  background: var(--theme-bg-hover);
  border-color: var(--theme-border-medium);
  color: var(--theme-text-primary);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--theme-brand-gold);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

.theme-toggle .icon-sun {
  position: absolute;
  opacity: 1;
  transform: rotate(0deg);
}

.theme-toggle .icon-moon {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg);
}

[data-theme="dark"] .theme-toggle .icon-sun {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="dark"] .theme-toggle .icon-moon {
  opacity: 1;
  transform: rotate(0deg);
}

/* Compact toggle for header */
.theme-toggle-compact {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.theme-toggle-compact svg {
  width: 18px;
  height: 18px;
}

/* ==============================
   THEME DROPDOWN STYLES
   ============================== */
.theme-dropdown {
  position: relative;
}

.theme-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--theme-card-bg);
  border: 1px solid var(--theme-border-subtle);
  border-radius: 12px;
  box-shadow: var(--theme-shadow-lg);
  padding: 6px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.theme-dropdown.open .theme-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--theme-text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-option:hover {
  background: var(--theme-bg-hover);
  color: var(--theme-text-primary);
}

.theme-option.active {
  background: var(--theme-brand-gold-muted);
  color: var(--theme-brand-gold);
}

.theme-option svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ==============================
   BASE ELEMENT THEMING
   ============================== */
body {
  background: var(--theme-bg-primary) !important;
  color: var(--theme-text-primary);
}

/* Header theming */
.header,
header,
[class*="header"] {
  background: var(--theme-header-bg) !important;
  border-color: var(--theme-border-subtle) !important;
}

.header h1,
.header h2,
.header h3 {
  color: var(--theme-text-primary);
}

/* Sidebar theming */
.sidebar,
[class*="sidebar"],
nav[class*="nav"] {
  background: var(--theme-sidebar-bg);
  border-color: var(--theme-border-subtle);
}

/* Card theming */
.card,
[class*="card"],
.panel,
[class*="panel"] {
  background: var(--theme-card-bg) !important;
  border-color: var(--theme-border-subtle) !important;
  box-shadow: var(--theme-shadow-sm);
}

.card h2,
.card h3,
.card h4 {
  color: var(--theme-text-primary);
}

.card p,
.card span:not(.badge):not(.pill):not(.status) {
  color: var(--theme-text-secondary);
}

/* Table theming */
table,
.table,
[class*="table"] {
  background: var(--theme-card-bg);
}

th,
.table th,
[class*="table"] th {
  background: var(--theme-table-header-bg) !important;
  color: var(--theme-text-secondary);
  border-color: var(--theme-border-subtle) !important;
}

td,
.table td,
[class*="table"] td {
  color: var(--theme-text-primary);
  border-color: var(--theme-border-subtle) !important;
}

tbody tr:hover,
.table tbody tr:hover {
  background: var(--theme-table-row-hover);
}

/* Form elements theming */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  background: var(--theme-input-bg) !important;
  border-color: var(--theme-input-border) !important;
  color: var(--theme-text-primary) !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--theme-brand-gold) !important;
  box-shadow: 0 0 0 3px var(--theme-brand-gold-muted) !important;
}

input::placeholder,
textarea::placeholder {
  color: var(--theme-text-muted) !important;
}

/* Button secondary theming */
.btn-secondary,
[class*="btn-secondary"],
[class*="btn"][class*="outline"] {
  background: var(--theme-bg-tertiary);
  color: var(--theme-text-secondary);
  border-color: var(--theme-border-medium);
}

.btn-secondary:hover {
  background: var(--theme-bg-hover);
  color: var(--theme-text-primary);
}

/* Modal theming */
.modal,
[class*="modal"],
.dialog,
[class*="dialog"] {
  background: var(--theme-modal-bg);
  border-color: var(--theme-border-subtle);
}

.modal-overlay,
[class*="overlay"] {
  background: var(--theme-modal-overlay);
}

/* Code/pre elements */
pre,
code,
.code,
[class*="log"],
[class*="results"] {
  background: var(--theme-code-bg) !important;
  color: var(--theme-code-text);
  border-color: var(--theme-border-subtle) !important;
}

/* Links */
a:not(.btn):not([class*="btn"]) {
  color: var(--theme-brand-gold);
}

a:not(.btn):not([class*="btn"]):hover {
  color: var(--theme-brand-gold-hover);
}

/* Scrollbar theming */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--theme-scrollbar-thumb);
  border-radius: 6px;
  border: 2px solid var(--theme-scrollbar-track);
}

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

/* ==============================
   STATUS PILLS WITH THEME SUPPORT
   ============================== */
.status-success,
.status-completed {
  background: var(--theme-success-bg) !important;
  color: var(--theme-success) !important;
  border-color: var(--theme-success-border) !important;
}

.status-warning,
.status-pending,
.status-processing {
  background: var(--theme-warning-bg) !important;
  color: var(--theme-warning) !important;
  border-color: var(--theme-warning-border) !important;
}

.status-danger,
.status-error,
.status-failed {
  background: var(--theme-danger-bg) !important;
  color: var(--theme-danger) !important;
  border-color: var(--theme-danger-border) !important;
}

.status-info {
  background: var(--theme-info-bg) !important;
  color: var(--theme-info) !important;
  border-color: var(--theme-info-border) !important;
}

/* ==============================
   UTILITY CLASSES
   ============================== */
.text-primary { color: var(--theme-text-primary) !important; }
.text-secondary { color: var(--theme-text-secondary) !important; }
.text-tertiary { color: var(--theme-text-tertiary) !important; }
.text-muted { color: var(--theme-text-muted) !important; }

.bg-primary { background: var(--theme-bg-primary) !important; }
.bg-secondary { background: var(--theme-bg-secondary) !important; }
.bg-tertiary { background: var(--theme-bg-tertiary) !important; }
.bg-elevated { background: var(--theme-bg-elevated) !important; }

.border-subtle { border-color: var(--theme-border-subtle) !important; }
.border-medium { border-color: var(--theme-border-medium) !important; }
.border-strong { border-color: var(--theme-border-strong) !important; }

/* ==============================
   DARK MODE SPECIFIC ADJUSTMENTS
   ============================== */
[data-theme="dark"] img:not([src*=".svg"]) {
  /* Slightly reduce brightness of non-SVG images in dark mode */
  filter: brightness(0.95);
}

[data-theme="dark"] .logo,
[data-theme="dark"] [class*="logo"] {
  filter: none; /* Keep logos at full brightness */
}

/* Invert dark illustrations/diagrams in dark mode */
[data-theme="dark"] .invertable {
  filter: invert(1) hue-rotate(180deg);
}
