/**
 * Stargazer — Unified Theme Engine Stylesheet (theme.css)
 * =========================================================
 * Strict Zero-Inline CSP Architecture: Externalized, no inline styles.
 *
 * INDEPENDENCE CONTRACT:
 *   This file has zero awareness of any specific page layout (portal, admin,
 *   updates, gizi, etc.). It only styles the reusable theme engine components:
 *     - Option 2B: Compact Single-Button Cycler (.theme-cycler)
 *     - Icon slot visibility driven by data-theme-pref on <html>
 *     - Smooth global theme transitions
 *
 *   Page-specific positioning of the theme button (e.g. .portal-theme-bar,
 *   .nav-header, .header .btn-group) belongs in each page's own stylesheet.
 *
 * Usage:
 *   1. Load /static/js/theme.js synchronously in <head> (Zero FOUC).
 *   2. Load this file via <link rel="stylesheet" href="...theme.css">.
 *   3. Place a .theme-cycler button anywhere on the page.
 */

/* -------------------------------------------------------------
   Option 2B: Compact Single-Button Cycler Component
   ------------------------------------------------------------- */
.theme-cycler {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9999px;
  padding: 0.4rem 0.85rem;
  min-height: 38px;
  color: #f8fafc;
  font-family: inherit;
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  line-height: 1;
  text-decoration: none;
  z-index: 50;
}

.theme-cycler:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transform: translateY(-1px);
}

.theme-cycler:active {
  transform: scale(0.96);
}

/* Light mode adaptation for general .theme-cycler */
html[data-theme="light"] .theme-cycler:not(header .theme-cycler) {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(148, 163, 184, 0.35);
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .theme-cycler:not(header .theme-cycler):hover {
  background: #ffffff;
  border-color: rgba(148, 163, 184, 0.6);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
}

/* -------------------------------------------------------------
   Header Specific: Perfect Uniform 36px (h-9) Rounded-XL Button
   Matches header glassmorphism in both dark & light themes.
   ------------------------------------------------------------- */
header .theme-cycler {
  min-height: 36px !important;
  height: 36px !important;
  width: 36px !important;
  padding: 0 !important;
  border-radius: 0.75rem !important; /* rounded-xl */
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
  box-shadow: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transform: none !important;
  flex-shrink: 0 !important;
}

header .theme-cycler:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  color: #ffffff !important;
  box-shadow: none !important;
  transform: none !important;
}

header .theme-cycler:active {
  transform: scale(0.95) !important;
}

html[data-theme="light"] header .theme-cycler {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
  box-shadow: none !important;
}

html[data-theme="light"] header .theme-cycler:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

/* Icon Slots — Visibility controlled by data-theme-pref on <html> */
.theme-icon {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.theme-icon svg {
  display: block;
}

/* Active State Icons & Distinct Accents */
html[data-theme-pref="dark"] .theme-icon-dark {
  display: inline-flex;
  color: #38bdf8; /* Sky-400 */
}

html[data-theme-pref="dark"] .theme-cycler:hover {
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.25);
}

html[data-theme-pref="light"] .theme-icon-light {
  display: inline-flex;
  color: #f59e0b; /* Amber-400 */
}

html[data-theme-pref="light"] .theme-cycler:hover {
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.25);
}

html[data-theme-pref="auto"] .theme-icon-auto {
  display: inline-flex;
  color: #a855f7; /* Violet-500 */
}

html[data-theme-pref="auto"] .theme-cycler:hover {
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.25);
}

.theme-cycler-label {
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* -------------------------------------------------------------
   Smooth Global Theme Transitions
   Applies to any element across any page that uses this engine.
   ------------------------------------------------------------- */
body,
.card,
.section-card,
.auth-box,
.startup-panel,
.tab-bar,
.tab-btn,
.service-card,
.table-container,
.icon-wrapper,
.badge {
  transition: background-color 0.3s ease, background 0.3s ease,
              border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* =============================================================
   STARGAZER MEDIA PORTAL THEME COLOR PALETTE FOR Gizi App
   Eliminates all blinding white backgrounds in dark mode.
   Maps Tailwind utility classes to Media Portal's dark palette:
     - Surface Cards: Slate-800 (#1e293b) with 1px border (#334155 / rgba(255,255,255,0.1))
     - Main Canvas: Deep Midnight Slate (#0f172a with subtle twilight gradient)
     - Text Main: Crisp Slate-50 (#f8fafc) & Slate-100 (#f1f5f9)
     - Text Muted: Silver Slate-300 (#cbd5e1) & Slate-400 (#94a3b8)
     - Form Inputs: Slate-800 (#1e293b) with Slate-700 borders
     - Badges: Translucent colored pills (15% opacity + vibrant text)
   ============================================================= */

@media screen {
  /* 1. Main Canvas & Root Body */
  html[data-theme="dark"] body {
    background-color: #0f172a !important;
    color: #f1f5f9 !important;
  }

  html[data-theme="dark"] main {
    background: radial-gradient(circle at top right, rgba(30, 27, 75, 0.4), transparent 45%),
                linear-gradient(135deg, #0b1120 0%, #0f172a 100%) !important;
    color: #f1f5f9 !important;
  }

  /* 2. Surfaces & Containers — Converts all glaring bg-white to Slate-800 */
  html[data-theme="dark"] .bg-white {
    background-color: #1e293b !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #f8fafc;
  }

  html[data-theme="dark"] .bg-slate-50 {
    background-color: #0f172a !important;
  }

  html[data-theme="dark"] .bg-slate-100 {
    background-color: #1e293b !important;
    color: #e2e8f0;
  }

  html[data-theme="dark"] .bg-slate-100\/80,
  html[data-theme="dark"] .bg-slate-100\/90 {
    background-color: rgba(30, 41, 59, 0.85) !important;
  }

  html[data-theme="dark"] .bg-slate-200 {
    background-color: #334155 !important;
    color: #f1f5f9 !important;
  }

  /* 3. Borders & Dividers — Soft luminous borders like Media Portal */
  html[data-theme="dark"] .border-slate-100,
  html[data-theme="dark"] .border-slate-200,
  html[data-theme="dark"] .border-slate-300 {
    border-color: rgba(255, 255, 255, 0.1) !important;
  }

  html[data-theme="dark"] .divide-slate-100 > * + *,
  html[data-theme="dark"] .divide-slate-200 > * + * {
    border-color: rgba(255, 255, 255, 0.08) !important;
  }

  html[data-theme="dark"] .shadow-sm,
  html[data-theme="dark"] .shadow,
  html[data-theme="dark"] .shadow-md,
  html[data-theme="dark"] .shadow-lg {
    box-shadow: 0 4px 18px -2px rgba(0, 0, 0, 0.5) !important;
  }

  /* 4. Headings & High-Contrast Typography */
  html[data-theme="dark"] .text-slate-900,
  html[data-theme="dark"] .text-slate-800 {
    color: #f8fafc !important;
  }

  html[data-theme="dark"] .text-slate-700 {
    color: #e2e8f0 !important;
  }

  html[data-theme="dark"] .text-slate-600 {
    color: #cbd5e1 !important;
  }

  html[data-theme="dark"] .text-slate-500 {
    color: #94a3b8 !important;
  }

  html[data-theme="dark"] .text-slate-400 {
    color: #cbd5e1 !important; /* Lifts small uppercase labels and muted hints */
  }

  /* 5. Interactive Form Inputs, Selects, & Textareas */
  html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
  html[data-theme="dark"] select,
  html[data-theme="dark"] textarea {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
  }

  html[data-theme="dark"] input::placeholder,
  html[data-theme="dark"] textarea::placeholder {
    color: #64748b !important;
  }

  html[data-theme="dark"] input:focus,
  html[data-theme="dark"] select:focus,
  html[data-theme="dark"] textarea:focus {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3) !important;
    outline: none !important;
  }

  /* 6. Translucent Colored Badges & Icon Containers (Media Portal Style) */
  html[data-theme="dark"] .bg-emerald-50,
  html[data-theme="dark"] .bg-emerald-100 {
    background-color: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
  }

  html[data-theme="dark"] .text-emerald-700,
  html[data-theme="dark"] .text-emerald-800 {
    color: #34d399 !important;
  }

  html[data-theme="dark"] .bg-blue-50,
  html[data-theme="dark"] .bg-blue-100 {
    background-color: rgba(59, 130, 246, 0.15) !important;
    color: #60a5fa !important;
  }

  html[data-theme="dark"] .text-blue-700,
  html[data-theme="dark"] .text-blue-800 {
    color: #60a5fa !important;
  }

  html[data-theme="dark"] .bg-amber-50,
  html[data-theme="dark"] .bg-amber-100 {
    background-color: rgba(245, 158, 11, 0.15) !important;
    color: #fbbf24 !important;
  }

  html[data-theme="dark"] .text-amber-700,
  html[data-theme="dark"] .text-amber-800 {
    color: #fbbf24 !important;
  }

  html[data-theme="dark"] .bg-purple-50,
  html[data-theme="dark"] .bg-purple-100 {
    background-color: rgba(168, 85, 247, 0.15) !important;
    color: #c084fc !important;
  }

  html[data-theme="dark"] .text-purple-700,
  html[data-theme="dark"] .text-purple-800 {
    color: #c084fc !important;
  }

  html[data-theme="dark"] .bg-rose-50,
  html[data-theme="dark"] .bg-rose-100 {
    background-color: rgba(244, 63, 94, 0.15) !important;
    color: #fb7185 !important;
  }

  html[data-theme="dark"] .text-rose-700,
  html[data-theme="dark"] .text-rose-800 {
    color: #fb7185 !important;
  }

  /* 7. Tables & Data Grids */
  html[data-theme="dark"] table th {
    background-color: #1e293b !important;
    color: #94a3b8 !important;
    border-color: #334155 !important;
  }

  html[data-theme="dark"] table td {
    border-color: rgba(255, 255, 255, 0.08) !important;
  }

  html[data-theme="dark"] table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.04) !important;
  }

  /* 8. Modals, Native Dialogs, & Popups */
  html[data-theme="dark"] dialog {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
  }

  html[data-theme="dark"] dialog::backdrop {
    background-color: rgba(15, 23, 42, 0.8) !important;
    backdrop-filter: blur(8px);
  }

  /* 9. Interactive Hover States */
  html[data-theme="dark"] .hover\:bg-slate-50:hover,
  html[data-theme="dark"] .hover\:bg-slate-100:hover {
    background-color: rgba(255, 255, 255, 0.06) !important;
  }

  /* 10. Standard Scrollbar — dark mode color adaptation */
  html[data-theme="dark"] * {
    scrollbar-color: #475569 transparent;
  }
}

/* ==============================================================================
   CLS (Cumulative Layout Shift) Compliance & Visual Stability
   ============================================================================== */

/* 1. Stabilize Font Awesome icon sizing to avoid Cumulative Layout Shift (CLS) */
.fa, .fas, .fa-solid, .fa-regular, .fa-brands {
  display: inline-block;
  width: 1.25em;
  text-align: center;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  line-height: 1;
  vertical-align: -0.125em;
}

/* 2. Stabilize dynamic HTMX live summary calculation card */
#live-summary-container {
  min-height: 140px;
  contain: layout style;
  contain-intrinsic-size: auto 140px;
}

/* 3. Native dialog rendering containment */
dialog {
  contain: paint;
}

/* 4. Table containers responsive layout stabilization */
.table-responsive-container {
  min-height: 200px;
  contain: layout;
}
