/**
 * UI Improvements CSS
 * Dark mode, responsive design, error states, tooltips
 */

/* ============================================
   DARK MODE REFINEMENT
   ============================================ */

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --text-primary: #ffffff;
  --text-secondary: #a0aec0;
  --border-color: #2d3748;
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --success-color: #48bb78;
  --error-color: #f56565;
  --warning-color: #ed8936;
  --shadow-color: rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f7fafc;
  --bg-card: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --border-color: #e2e8f0;
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --success-color: #38a169;
  --error-color: #e53e3e;
  --warning-color: #dd6b20;
  --shadow-color: rgba(0,0,0,0.1);
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 6px var(--shadow-color);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px var(--shadow-color);
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 24px;
}

.theme-toggle:hover {
  transform: rotate(180deg);
  box-shadow: 0 0 20px var(--accent-primary);
}

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

/* Mobile First Approach */
.container {
  width: 100%;
  padding: 0 15px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .container {
    max-width: 640px;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 768px;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1024px;
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1280px;
  }
}

/* Grid System */
.grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .grid-md-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-md-4 { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
  .grid-lg-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-lg-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-lg-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Responsive Typography */
.text-responsive {
  font-size: clamp(14px, 2vw, 18px);
}

.heading-responsive {
  font-size: clamp(24px, 5vw, 48px);
}

/* Mobile Navigation */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1000;
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .mobile-menu-toggle {
    display: block;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
  }
}

@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none;
  }
}

/* ============================================
   ERROR STATES
   ============================================ */

.error-container {
  background: linear-gradient(135deg, #fc8181 0%, #f56565 100%);
  border-left: 4px solid #e53e3e;
  border-radius: 8px;
  padding: 16px 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  animation: error-shake 0.5s cubic-bezier(.36,.07,.19,.97);
}

@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.error-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.error-message {
  flex: 1;
  font-weight: 500;
}

.error-dismiss {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.error-dismiss:hover {
  background: rgba(255,255,255,0.3);
}

/* Validation Error States */
.input-error {
  border-color: var(--error-color) !important;
  box-shadow: 0 0 0 3px rgba(245, 101, 101, 0.1);
}

.input-error-message {
  color: var(--error-color);
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Loading States */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 16px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spinner-rotate 1s linear infinite;
}

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state-description {
  font-size: 14px;
  max-width: 400px;
  margin: 0 auto;
}

/* ============================================
   TOOLTIPS
   ============================================ */

[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::before,
[data-tooltip]::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10000;
}

/* Tooltip Arrow */
[data-tooltip]::before {
  content: '';
  border: 6px solid transparent;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  border-top-color: rgba(0,0,0,0.9);
}

/* Tooltip Content */
[data-tooltip]::after {
  content: attr(data-tooltip);
  background: rgba(0,0,0,0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  max-width: 200px;
  white-space: normal;
  text-align: center;
  line-height: 1.4;
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Tooltip Positions */
[data-tooltip-position="left"]::before {
  left: auto;
  right: 100%;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%) translateX(-10px);
  border-color: transparent;
  border-left-color: rgba(0,0,0,0.9);
}

[data-tooltip-position="left"]::after {
  left: auto;
  right: calc(100% + 6px);
  top: 50%;
  bottom: auto;
  transform: translateY(-50%) translateX(-10px);
}

[data-tooltip-position="left"]:hover::before,
[data-tooltip-position="left"]:hover::after {
  transform: translateY(-50%) translateX(0);
}

/* ============================================
   REAL-TIME PREVIEW
   ============================================ */

.preview-container {
  position: relative;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.preview-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--error-color);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.preview-live-dot {
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  border-radius: 8px;
  background: #000;
}

.preview-controls {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.preview-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-btn:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.preview-btn.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus Visible for Keyboard Navigation */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Skip to Main Content */
.skip-to-main {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--accent-primary);
  color: white;
  padding: 12px 24px;
  text-decoration: none;
  z-index: 100000;
  transition: top 0.3s;
}

.skip-to-main:focus {
  top: 0;
}

/* Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
  }
  
  .card {
    border-width: 2px;
  }
}

/* ============================================
   CUSTOM FONT SUPPORT
   ============================================ */

.font-custom {
  font-family: var(--custom-font-family, inherit);
}

.font-heading {
  font-family: var(--heading-font-family, var(--custom-font-family, inherit));
}

.font-body {
  font-family: var(--body-font-family, var(--custom-font-family, inherit));
}

/* Font Weight Utilities */
.font-thin { font-weight: 100; }
.font-light { font-weight: 300; }
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }
.font-black { font-weight: 900; }
