/**
 * 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)
 *     - Option 2A: Segmented Switcher (.theme-switcher) — disabled display
 *     - Icon slot visibility driven by data-theme-pref on <html>
 *     - Admin Dashboard & Updates header integration hooks
 *     - Smooth global theme transitions
 *
 *   Page-specific positioning of the theme button (e.g. .portal-theme-bar)
 *   belongs in each page's own stylesheet (portal.css, admin.css, etc.).
 *
 * Usage:
 *   1. Load /js/theme.js synchronously in <head> (Zero FOUC).
 *   2. Load this file via <link rel="stylesheet" href="/css/theme.css">.
 *   3. Place a .theme-cycler button anywhere on the page.
 */

/* -------------------------------------------------------------
   Modern Web Guidance: Native color-scheme and scrollbars
   ------------------------------------------------------------- */
:root {
  color-scheme: dark light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  scrollbar-color: rgba(148, 163, 184, 0.4) transparent;
}

html[data-theme="light"] {
  color-scheme: light;
  scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}

html {
  scrollbar-width: thin;
}

.theme-switcher {
  display: none !important;
}

/* -------------------------------------------------------------
   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 .theme-cycler */
html[data-theme="light"] .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:hover {
  background: #ffffff;
  border-color: rgba(148, 163, 184, 0.6);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
}

/* 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;
}

/* -------------------------------------------------------------
   Admin Dashboard & Updates Header Integration
   (Generic hooks — work on any page with .nav-header or .header .btn-group)
   ------------------------------------------------------------- */
.nav-header .theme-cycler {
  margin: 0;
}

.nav-header:not(:has(.nav-left)) .theme-cycler {
  margin-left: auto;
  margin-right: 1rem;
}

@media (max-width: 768px) {
  .nav-header .theme-cycler .theme-cycler-label {
    display: none;
  }
  .nav-header .theme-cycler {
    padding: 0.4rem 0.55rem;
  }
}

.header .btn-group .theme-cycler {
  display: inline-flex;
  align-self: center;
  flex-shrink: 0;
}

@media (max-width: 680px) {
  .header .btn-group .theme-cycler .theme-cycler-label {
    display: none;
  }
  .header .btn-group .theme-cycler {
    padding: 0;
    width: 38px;
    height: 38px;
    min-height: 38px;
    border-radius: 9999px;
    justify-content: center;
  }
}

/* -------------------------------------------------------------
   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;
}
