/* ============================================
   Theme Manager v3 — JSON-driven Theme Engine
   Generic glassmorphism rules — NO hardcoded themes
   ============================================ */

/* --- Stacking & Background Engine --- */
html[class*="theme-"] {
  position: relative;
  z-index: 0;
  background: transparent !important;
  min-height: 100vh;
}

/* Wallpaper: background image with blur + brightness */
html[class*="theme-"]::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--theme-fallback, #1e293b) center/cover no-repeat;
  background-image: var(--theme-bg-image, none);
  background-attachment: scroll;
  filter: blur(var(--theme-blur, 3px)) brightness(var(--theme-brightness, 0.85)) saturate(0.85);
  pointer-events: none;
}

/* Dark overlay for readability */
html[class*="theme-"]::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, var(--theme-overlay, 0.55));
  pointer-events: none;
}

/* Body & wrapper transparent to reveal pseudo-elements */
html[class*="theme-"] body {
  background: transparent !important;
  min-height: 100vh;
}
html[class*="theme-"] #wrapper {
  background: transparent !important;
}

/* ============================================
   Glassmorphism — Sidebar
   ============================================ */
html[class*="theme-"] .sidebar {
  background: rgba(0, 0, 0, 0.15) !important;
  backdrop-filter: blur(24px) !important;
  -webkit-backdrop-filter: blur(24px) !important;
  border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
}
html[class*="theme-"].dark .sidebar {
  background: rgba(0, 0, 0, 0.3) !important;
}
html[class*="theme-"] .sidebar ul.nav li a {
  color: rgba(255, 255, 255, 0.8) !important;
}
html[class*="theme-"] .sidebar ul.nav li a i.menu-icon {
  color: rgba(255, 255, 255, 0.55) !important;
}
html[class*="theme-"] .sidebar ul.nav li.active > a,
html[class*="theme-"] .sidebar ul.nav > li > a:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.1) !important;
}
html[class*="theme-"] .sidebar ul.nav li.active > a .menu-icon,
html[class*="theme-"] .sidebar ul.nav > li > a:hover .menu-icon {
  color: #fff !important;
}
html[class*="theme-"] .sidebar .nav-second-level li a {
  color: rgba(255, 255, 255, 0.65) !important;
}
html[class*="theme-"] .sidebar-user-profile a {
  color: rgba(255, 255, 255, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}
html[class*="theme-"] .sidebar-user-profile a:hover {
  border-color: rgba(255, 255, 255, 0.25) !important;
}

/* ============================================
   Glassmorphism — Header
   ============================================ */
html[class*="theme-"] #header {
  background: rgba(255, 255, 255, var(--theme-glass, 0.7)) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}
html[class*="theme-"].dark #header {
  background: rgba(0, 0, 0, var(--theme-glass, 0.7)) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
}

/* ============================================
   Glassmorphism — Panels
   ============================================ */
html[class*="theme-"] .content {
  background: transparent !important;
}
html[class*="theme-"] .panel_s {
  background: rgba(255, 255, 255, var(--theme-glass, 0.7)) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08) !important;
  border-radius: 12px !important;
}
html[class*="theme-"].dark .panel_s {
  background: rgba(0, 0, 0, var(--theme-glass, 0.7)) !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
}
html[class*="theme-"] .panel-body {
  background: transparent !important;
}
html[class*="theme-"] .panel-heading,
html[class*="theme-"] .panel-footer {
  background: transparent !important;
  border-color: rgba(0, 0, 0, 0.06) !important;
}
html[class*="theme-"].dark .panel-heading,
html[class*="theme-"].dark .panel-footer {
  border-color: rgba(255, 255, 255, 0.06) !important;
}

/* ============================================
   Glassmorphism — Modals
   ============================================ */
html[class*="theme-"] .modal-content {
  background: rgba(255, 255, 255, var(--theme-glass, 0.7)) !important;
  backdrop-filter: blur(24px) !important;
  -webkit-backdrop-filter: blur(24px) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}
html[class*="theme-"].dark .modal-content {
  background: rgba(0, 0, 0, var(--theme-glass, 0.7)) !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
}
html[class*="theme-"] .modal-header,
html[class*="theme-"] .modal-footer {
  border-color: rgba(0, 0, 0, 0.06) !important;
}
html[class*="theme-"].dark .modal-header,
html[class*="theme-"].dark .modal-footer {
  border-color: rgba(255, 255, 255, 0.06) !important;
}

/* ============================================
   Glassmorphism — Dropdowns
   ============================================ */
html[class*="theme-"] .dropdown-menu {
  background: rgba(255, 255, 255, 0.8) !important;
  backdrop-filter: blur(24px) !important;
  -webkit-backdrop-filter: blur(24px) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}
html[class*="theme-"].dark .dropdown-menu {
  background: rgba(0, 0, 0, 0.8) !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
}

/* ============================================
   Glassmorphism — Cards, Kanban, Widgets
   ============================================ */
html[class*="theme-"] .widget,
html[class*="theme-"] .todo-item,
html[class*="theme-"] .kan-ban-col,
html[class*="theme-"] .kan-ban-card {
  background: rgba(255, 255, 255, var(--theme-glass, 0.7)) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
}
html[class*="theme-"].dark .widget,
html[class*="theme-"].dark .todo-item,
html[class*="theme-"].dark .kan-ban-col,
html[class*="theme-"].dark .kan-ban-card {
  background: rgba(0, 0, 0, var(--theme-glass, 0.7)) !important;
}

/* ============================================
   Glassmorphism — Tables
   ============================================ */
html[class*="theme-"] .table > tbody > tr {
  background: transparent !important;
}
html[class*="theme-"] .table > tbody > tr:hover {
  background: rgba(255, 255, 255, 0.15) !important;
}
html[class*="theme-"].dark .table > tbody > tr:hover {
  background: rgba(255, 255, 255, 0.05) !important;
}
html[class*="theme-"] .table > thead > tr {
  background: transparent !important;
}
html[class*="theme-"] .dataTables_wrapper .dataTables_filter input,
html[class*="theme-"] .dataTables_wrapper .dataTables_length select {
  background: rgba(255, 255, 255, 0.5) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

/* ============================================
   Glassmorphism — Nav tabs & Buttons
   ============================================ */
html[class*="theme-"] .nav-tabs > li > a:hover,
html[class*="theme-"] .nav-tabs > li.active > a {
  background: rgba(255, 255, 255, 0.2) !important;
  border-color: transparent !important;
}
html[class*="theme-"] .btn-default {
  background: rgba(255, 255, 255, 0.3) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  backdrop-filter: blur(8px) !important;
}
html[class*="theme-"].dark .btn-default {
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
}

/* ============================================
   Theme transition (300ms per spec)
   ============================================ */
html.theme-transitioning,
html.theme-transitioning body,
html.theme-transitioning #wrapper,
html.theme-transitioning .sidebar,
html.theme-transitioning #header,
html.theme-transitioning .panel_s,
html.theme-transitioning .modal-content,
html.theme-transitioning .dropdown-menu {
  transition: all 0.3s ease !important;
}
html.theme-transitioning::before {
  transition: filter 0.3s ease !important;
}
html.theme-transitioning::after {
  transition: background 0.3s ease !important;
}

/* ============================================
   Navbar Theme Switcher Dropdown
   ============================================ */
.theme-switcher-dropdown { width: 260px; padding: 8px 0; max-height: 70vh; overflow-y: auto; }
.theme-switcher-dropdown .dropdown-header { padding: 8px 16px 12px; font-weight: 600; color: #1e293b; }
.theme-switcher-item { display: flex !important; align-items: center; gap: 10px; padding: 6px 16px !important; transition: background 0.2s; }
.theme-switcher-item:hover { background: #f1f5f9 !important; }
.theme-switcher-item.active { background: #eef2ff !important; }
.theme-swatch { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.08); background-size: cover !important; background-position: center !important; }
.theme-swatch-none { display: inline-flex; align-items: center; justify-content: center; background: #e2e8f0 !important; font-size: 12px; color: #64748b; }
.theme-label { display: flex; flex-direction: column; line-height: 1.3; }
.theme-name { font-size: 13px; font-weight: 500; color: #1e293b; }
.theme-name-en { font-size: 10px; color: #94a3b8; }
.theme-active-icon { margin-left: auto; color: #6c5ce7; font-size: 12px; }
.dark .theme-switcher-dropdown .dropdown-header { color: #e2e8f0; }
.dark .theme-switcher-item:hover { background: #1e293b !important; }
.dark .theme-switcher-item.active { background: #1e293b !important; }
.dark .theme-name { color: #e2e8f0; }

/* ============================================
   Theme Gallery Page
   ============================================ */
.theme-grid {
  display: grid;
  gap: 20px;
}
@media (min-width: 640px) { .theme-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .theme-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .theme-grid { grid-template-columns: repeat(4, 1fr); } }

.theme-card {
  cursor: pointer;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid transparent;
  background: #fff;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
}
.theme-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 40px -8px rgba(0,0,0,0.15);
}
.theme-card.selected {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 3px rgba(108,92,231,0.25), 0 20px 60px rgba(0,0,0,0.12);
}
.theme-card-preview {
  position: relative;
  height: 150px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.theme-card:hover .theme-card-preview img {
  transform: scale(1.08);
}
.theme-card-preview .preview-fallback {
  width: 100%;
  height: 100%;
}
.theme-card-preview .preview-badge {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11px;
  color: rgba(255,255,255,0.9);
  font-weight: 500;
  pointer-events: none;
}
.theme-card-body {
  padding: 12px 14px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.theme-card-body .info-text strong {
  display: block;
  font-size: 13px;
  color: #1e293b;
}
.theme-card-body .info-text small {
  font-size: 11px;
  color: #94a3b8;
}
.theme-card-body .btn-apply {
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}
.theme-card-body .btn-apply:hover {
  transform: scale(1.05);
}
.theme-card-body .btn-apply.disabled {
  opacity: 0.6;
  cursor: default;
}

.dark .theme-card {
  background: #1e293b;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.2);
}
.dark .theme-card-body .info-text strong { color: #e2e8f0; }

/* None-card special */
.theme-card-none .theme-card-preview {
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: #94a3b8;
}
.dark .theme-card-none .theme-card-preview {
  background: #334155;
  color: #64748b;
}
