/* ============================================================
   GARI Corporate App — Dark/Light Theme System
   ============================================================
   Include this file on every page to enable theme switching.
   Default theme is dark (matches the existing design).
   ============================================================ */

/* ----------------------------------------------------------
   1. CSS Custom Properties — Dark Theme (default)
   ---------------------------------------------------------- */
:root,
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: rgba(30, 41, 59, 0.8);
  --bg-glass: rgba(15, 23, 42, 0.8);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --border-default: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.2);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.3);

  --input-bg: rgba(30, 41, 59, 0.6);
  --input-border: rgba(255, 255, 255, 0.15);
  --input-text: #e2e8f0;

  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

/* ----------------------------------------------------------
   2. CSS Custom Properties — Light Theme
   ---------------------------------------------------------- */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-glass: rgba(248, 250, 252, 0.9);

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  --border-default: rgba(0, 0, 0, 0.1);
  --border-hover: rgba(0, 0, 0, 0.2);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);

  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-text: #1f2937;

  --accent-primary: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #059669;
  --warning: #d97706;
  --error: #dc2626;
}

/* ----------------------------------------------------------
   3. System Preference Detection (fallback when no
      data-theme attribute is set)
   ---------------------------------------------------------- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-glass: rgba(248, 250, 252, 0.9);

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --border-default: rgba(0, 0, 0, 0.1);
    --border-hover: rgba(0, 0, 0, 0.2);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);

    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --input-text: #1f2937;

    --accent-primary: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
  }
}

/* ----------------------------------------------------------
   4. Smooth Theme Transitions
   ---------------------------------------------------------- */
body,
body *,
body *::before,
body *::after {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

/* Opt-out class — add to elements where transitions cause
   jank (e.g. canvas wrappers, heavy animations).            */
.no-theme-transition,
.no-theme-transition *,
.no-theme-transition *::before,
.no-theme-transition *::after {
  transition: none !important;
}

/* ----------------------------------------------------------
   5. Theme Toggle Button Component
   ---------------------------------------------------------- */
.theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;

  border: 1px solid var(--border-default);
  border-radius: 9999px;            /* pill / circle */
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);

  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;

  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl);
  border-color: var(--border-hover);
}

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

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

/* Icon container — holds both icons stacked */
.theme-toggle__icons {
  position: relative;
  width: 24px;
  height: 24px;
}

/* Shared icon base */
.theme-toggle__icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    opacity 0.35s ease,
    transform 0.35s ease;
}

/* Moon icon — visible in dark mode */
.theme-toggle__icon--moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Sun icon — visible in light mode */
.theme-toggle__icon--sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* When light theme is active, swap visibility */
[data-theme="light"] .theme-toggle__icon--moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

[data-theme="light"] .theme-toggle__icon--sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* System-preference fallback for icon swap */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .theme-toggle__icon--moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
  }
  :root:not([data-theme]) .theme-toggle__icon--sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* SVG colour inherits from text */
.theme-toggle__icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--text-primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ----------------------------------------------------------
   6. Utility Classes
   ---------------------------------------------------------- */

/* Background that follows the primary theme colour */
.theme-aware-bg {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* Card surface with border & shadow */
.theme-aware-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
}

.theme-aware-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
}

/* Text that adapts to the current theme */
.theme-aware-text {
  color: var(--text-primary);
}

.theme-aware-text--secondary {
  color: var(--text-secondary);
}

.theme-aware-text--muted {
  color: var(--text-muted);
}

/* Themed input field */
.theme-aware-input {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--input-text);
  padding: 10px 14px;
  font-size: 0.9375rem;
  outline: none;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.3s ease;
}

.theme-aware-input::placeholder {
  color: var(--text-muted);
}

.theme-aware-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.theme-aware-input:hover:not(:focus) {
  border-color: var(--border-hover);
}
