* { margin: 0; padding: 0; box-sizing: border-box; }

/* CSS Variables for Dark/Light Theme Support */
:root {
  --bg: #0f172a; 
  --bg-card: #1e293b; 
  --bg-hover: #334155;
  --text: #f1f5f9; 
  --text-muted: #94a3b8; 
  --text-dim: #64748b;
  --primary: #6366f1; 
  --primary-hover: #818cf8;
  --secondary: #8b5cf6;
  --success: #22c55e; 
  --danger: #ef4444; 
  --warning: #f59e0b;
  --info: #3b82f6;
  --border: #334155; 
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-card: #f8fafc;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #475569;
  --text-dim: #64748b;
  --border: #e2e8f0;
}

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  line-height: 1.6; 
  transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-hover); }

/* Enhanced Mobile-First Layout */
.app { 
  display: flex; 
  min-height: 100vh; 
  position: relative;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1001;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: white;
  width: 44px;
  height: 44px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.mobile-menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  margin: 3px auto;
  transition: 0.3s;
}

/* Mobile Menu Animation */
.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* Enhanced Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 1000;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}

.sidebar-logo {
  padding: 1.5rem;
  font-size: 1.5rem;
  font-weight: bold;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 0;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
  border-right: 3px solid var(--primary);
}

.nav-item .icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

/* Main Content Area */
.main {
  flex: 1;
  margin-left: 280px;
  padding: 2rem;
  min-height: 100vh;
  background: var(--bg);
  transition: margin-left 0.3s ease;
}

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1001;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

/* Enhanced Form Controls */
input, select, textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

input::placeholder { color: var(--text-dim); }

/* Enhanced Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary), #a78bfa);
  color: white;
}

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1rem; }
.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Enhanced Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

/* Enhanced Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-hover));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-change {
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 0.5rem;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Enhanced Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-hover);
  font-weight: 600;
  color: var(--text);
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  color: var(--text-muted);
}

tr:hover td {
  background: var(--bg-hover);
  color: var(--text);
}

tr:last-child td {
  border-bottom: none;
}

/* Enhanced Toolbar */
.toolbar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  min-width: 300px;
  flex: 1;
}

/* QR Code Enhancements */
.qr-container {
  text-align: center;
  padding: 2rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.qr-container img {
  border-radius: 8px;
  background: white;
  padding: 1rem;
  box-shadow: var(--shadow);
  max-width: 100%;
  height: auto;
}

.qr-customization {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Analytics Dashboard */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
  min-height: 300px;
  position: relative;
}

.chart-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Link-in-Bio Page Builder */
.linkinbio-builder {
  max-width: 800px;
  margin: 0 auto;
}

.linkinbio-preview {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  border: 1px solid var(--border);
  margin-bottom: 2rem;
}

.linkinbio-controls {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.link-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-hover);
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.link-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.link-item-drag {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.2rem;
}

.link-item-content {
  flex: 1;
}

.link-item-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.link-item-url {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.link-item-actions {
  display: flex;
  gap: 0.5rem;
}

/* UTM Builder */
.utm-builder {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.utm-preview {
  background: var(--bg);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 1rem;
  font-family: monospace;
  font-size: 0.9rem;
  word-break: break-all;
}

/* Health Check Status */
.health-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.health-status.healthy {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.health-status.unhealthy {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.health-status.checking {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

/* Enhanced Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-primary { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.badge-secondary { background: rgba(139, 92, 246, 0.15); color: var(--secondary); }
.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-info { background: rgba(59, 130, 246, 0.15); color: var(--info); }

/* Form Groups */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* Copy Button */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.copy-btn:hover {
  color: var(--text);
  background: var(--bg);
  transform: translateY(-1px);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.toast {
  padding: 1rem 1.5rem;
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.toast::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: currentColor;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--info); }

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

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem 0;
}

.pagination .btn {
  min-width: 40px;
  padding: 0.5rem;
}

.pagination .btn.active {
  background: var(--primary);
  color: white;
}

/* Loading States */
.loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Enhanced Responsive Design */
@media (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }
  
  .main {
    margin-left: 240px;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }
  
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main {
    margin-left: 0;
    padding: 1rem;
    padding-top: 4rem;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-input {
    min-width: auto;
  }
  
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .table-wrap {
    overflow-x: auto;
  }
  
  th, td {
    padding: 0.75rem 0.5rem;
    white-space: nowrap;
  }
  
  .theme-toggle {
    top: 1rem;
    right: 4rem;
  }
  
  .toast-container {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
  
  .btn {
    padding: 0.875rem 1rem;
  }
  
  .btn-sm {
    padding: 0.625rem 0.875rem;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 0.75rem;
    padding-top: 4rem;
  }
  
  .card {
    padding: 1rem;
  }
  
  .toolbar {
    padding: 0.75rem;
  }
  
  .stat-card {
    padding: 1rem;
  }
  
  .stat-value {
    font-size: 1.5rem;
  }
  
  .chart-container {
    padding: 1rem;
    min-height: 250px;
  }
  
  .qr-container {
    padding: 1rem;
  }
  
  .sidebar {
    width: 260px;
  }
  
  th, td {
    padding: 0.5rem 0.25rem;
    font-size: 0.875rem;
  }
}

/* High DPI / Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .qr-container img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Print Styles */
@media print {
  .sidebar,
  .mobile-menu-toggle,
  .theme-toggle,
  .toast-container,
  .toolbar {
    display: none !important;
  }
  
  .main {
    margin-left: 0;
    padding: 0;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #000;
  }
  
  .btn {
    border: 1px solid #000;
    box-shadow: none;
  }
}

/* Accessibility Enhancements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus Styles for Accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --border: #000000;
  }
  
  [data-theme="light"] {
    --border: #000000;
  }
  
  .card {
    border-width: 2px;
  }
  
  .btn {
    border-width: 2px;
    border-style: solid;
  }
}

/* Dark Mode Preference Detection */
@media (prefers-color-scheme: dark) {
  :root {
    /* Already using dark theme by default */
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-card: #f8fafc;
    --bg-hover: #f1f5f9;
    --text: #1e293b;
    --text-muted: #475569;
    --text-dim: #64748b;
    --border: #e2e8f0;
  }
}