/**
 * Advanced Theme System for Loovree Admin
 * Enhanced dark mode and responsive improvements
 */

/* ===== ADVANCED DARK THEME REFINEMENTS ===== */
[data-theme="dark"] {
  /* Enhanced dark colors */
  --color-neutral-0: #0a0e1a;
  --color-neutral-50: #0f172a;
  --color-neutral-100: #1e293b;
  --color-neutral-200: #334155;
  --color-neutral-300: #475569;
  --color-neutral-400: #64748b;
  --color-neutral-500: #94a3b8;
  --color-neutral-600: #cbd5e1;
  --color-neutral-700: #e2e8f0;
  --color-neutral-800: #f1f5f9;
  --color-neutral-900: #f8fafc;
  --color-neutral-950: #ffffff;

  /* Dark specific adjustments */
  --bg-app: #0a0e1a;
  --bg-surface: #0f172a;
  --bg-surface-raised: #1e293b;
  --bg-surface-overlay: #1e293b;
  --bg-muted: #1e293b;
  --bg-subtle: #334155;

  --text-primary: #f8fafc;
  --text-secondary: #e2e8f0;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --text-brand: #60a5fa;

  --border-default: #334155;
  --border-muted: #475569;
  --border-subtle: #1e293b;

  --state-hover: #1e293b;
  --state-active: #334155;

  --sidebar-bg: #0a0e1a;
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #f8fafc;
  --sidebar-item-hover: rgba(255, 255, 255, 0.05);
  --sidebar-item-active: rgba(96, 165, 250, 0.15);
  --sidebar-border: rgba(51, 65, 85, 0.5);

  /* Dark theme shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-base: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.7);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
}

/* Dark theme specific component overrides */
[data-theme="dark"] .iframe-wrapper {
  background-color: var(--bg-surface-raised);
  border-color: var(--border-muted);
}

[data-theme="dark"] .toast {
  background-color: var(--bg-surface-raised);
  border-color: var(--border-muted);
  color: var(--text-primary);
}

[data-theme="dark"] .notification-menu {
  background-color: var(--bg-surface-raised);
  border-color: var(--border-muted);
}

[data-theme="dark"] .spinner {
  border-color: var(--border-muted);
  border-top-color: var(--color-primary-400);
}

/* ===== ENHANCED RESPONSIVE DESIGN ===== */

/* Tablet specific adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
  .admin-sidebar {
    width: 240px;
    min-width: 240px;
  }

  .admin-topbar {
    padding: var(--space-4) var(--space-5);
  }

  .page-title {
    font-size: var(--font-size-xl);
  }

  .user-details {
    display: flex;
  }

  .iframe-container {
    padding: var(--space-5);
  }
}

/* Enhanced mobile design */
@media (max-width: 767px) {
  .admin-sidebar {
    width: 100vw;
    max-width: 320px;
  }

  .admin-topbar {
    padding: var(--space-3) var(--space-4);
  }

  .topbar-left {
    flex: 1;
    min-width: 0;
  }

  .page-title {
    font-size: var(--font-size-lg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-subtitle {
    display: none;
  }

  .topbar-right {
    gap: var(--space-2);
  }

  .notification-menu {
    right: 0;
    left: var(--space-4);
    width: auto;
  }

  .iframe-container {
    padding: var(--space-3);
  }

  .iframe-wrapper {
    min-height: calc(100vh - 180px);
  }

  /* Mobile-specific nav adjustments */
  .nav-section-title {
    padding: 0 var(--space-4) var(--space-2);
  }

  .nav-item {
    padding: var(--space-4) var(--space-4);
  }

  .nav-text {
    font-size: var(--font-size-base);
  }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
  .admin-topbar {
    padding: var(--space-2) var(--space-3);
  }

  .iframe-container {
    padding: var(--space-2);
  }

  .toast-container {
    top: var(--space-2);
    right: var(--space-2);
    left: var(--space-2);
  }

  .modal-content {
    max-width: 95vw;
    max-height: 95vh;
    width: 95vw;
    height: 95vh;
  }
}

/* ===== ADVANCED ANIMATIONS & MICRO-INTERACTIONS ===== */

/* Smooth theme transition */
* {
  transition: background-color var(--duration-200) var(--ease-out),
              border-color var(--duration-200) var(--ease-out),
              color var(--duration-200) var(--ease-out),
              box-shadow var(--duration-200) var(--ease-out);
}

/* Enhanced navigation animations */
.nav-item {
  position: relative;
  overflow: hidden;
}

.nav-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transition: left var(--duration-500) var(--ease-out);
}

.nav-item:hover::before {
  left: 100%;
}

/* Sidebar collapse animation improvements */
.admin-sidebar {
  transition: width var(--duration-300) var(--ease-out),
              min-width var(--duration-300) var(--ease-out);
}

.sidebar-text {
  transition: opacity var(--duration-200) var(--ease-out),
              visibility var(--duration-200) var(--ease-out);
}

/* Enhanced button hover effects */
.btn {
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  transition: width var(--duration-300) var(--ease-out),
              height var(--duration-300) var(--ease-out);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.btn:hover::before {
  width: 200%;
  height: 200%;
}

/* Toast entrance animations */
@keyframes toastSlideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toastSlideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.toast {
  animation: toastSlideIn var(--duration-300) var(--ease-out);
}

.toast.removing {
  animation: toastSlideOut var(--duration-200) var(--ease-in);
}

/* Modal entrance improvements */
@keyframes modalFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(4px);
  }
}

@keyframes modalScaleIn {
  from {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.modal-overlay.open {
  animation: modalFadeIn var(--duration-300) var(--ease-out);
}

.modal-overlay.open .modal-content {
  animation: modalScaleIn var(--duration-300) var(--ease-out);
}

/* Loading spinner improvements */
@keyframes pulseGlow {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.spinner {
  position: relative;
}

.spinner::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 1px solid var(--color-primary-500);
  border-radius: 50%;
  animation: pulseGlow 2s ease-in-out infinite;
  opacity: 0.3;
}

/* Enhanced focus indicators for better accessibility */
.focus-ring:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* Notification badge animation */
@keyframes badgePopIn {
  0% {
    transform: scale(0) rotate(180deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(360deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(360deg);
    opacity: 1;
  }
}

.notification-badge.show {
  animation: badgePopIn var(--duration-300) var(--ease-bounce);
}

/* ===== ADVANCED SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-muted);
  border-radius: var(--radius-md);
}

::-webkit-scrollbar-thumb {
  background: var(--border-muted);
  border-radius: var(--radius-md);
  transition: background-color var(--duration-200) var(--ease-out);
}

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

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--bg-surface);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--border-default);
}

/* ===== PRINT OPTIMIZATIONS ===== */
@media print {
  /* Reset theme colors for print */
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
  
  .admin-sidebar,
  .admin-topbar,
  .mobile-menu-toggle,
  .toast-container,
  .notification-menu {
    display: none !important;
  }
  
  .admin-content {
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .iframe-container {
    padding: 0 !important;
  }
  
  .iframe-wrapper {
    border: 1px solid #ccc !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}

/* ===== HIGH CONTRAST MODE ENHANCEMENTS ===== */
@media (prefers-contrast: high) {
  :root {
    --border-default: #000000;
    --border-muted: #333333;
    --text-muted: #000000;
    --bg-muted: #f0f0f0;
  }

  [data-theme="dark"] {
    --border-default: #ffffff;
    --border-muted: #cccccc;
    --text-muted: #ffffff;
    --bg-muted: #333333;
  }

  .btn {
    border: 2px solid currentColor;
  }

  .nav-item:hover,
  .nav-item:focus {
    outline: 2px solid currentColor;
    outline-offset: -2px;
  }
}

/* ===== MOTION SENSITIVITY SUPPORT ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }

  .nav-item::before {
    display: none;
  }

  .btn::before {
    display: none;
  }

  .spinner::after {
    display: none;
  }
}

/* ===== ENHANCED TOOLTIP SYSTEM ===== */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-overlay);
  color: var(--text-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-index-tooltip);
  opacity: 0;
  animation: tooltipFadeIn var(--duration-200) var(--ease-out) forwards;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ===== ENHANCED ERROR STATES ===== */
.error-boundary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  padding: var(--space-8);
  text-align: center;
  color: var(--text-muted);
}

.error-boundary .error-icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  color: var(--color-error-500);
}

.error-boundary .error-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.error-boundary .error-message {
  margin-bottom: var(--space-6);
  max-width: 400px;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.admin-app {
  contain: layout style;
}

.admin-sidebar {
  contain: layout style;
  will-change: transform;
}

.iframe-wrapper {
  contain: strict;
}

.toast {
  contain: layout;
  will-change: transform;
}

/* GPU acceleration for smooth animations */
.nav-item,
.btn,
.toast,
.modal-content {
  transform: translateZ(0);
  backface-visibility: hidden;
}