/* Design.dev — Accessibility & Enhanced UX */

/* Focus Management */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove default focus styling when not using keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* Enhanced focus states for interactive elements */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 6px;
  background: var(--accent);
  color: #05202a;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
  z-index: 1000;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 6px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #ffffff;
    --border-hover: #ffffff;
    --text: #ffffff;
    --muted: #cccccc;
    --accent: #00ffff;
  }
  
  .panel,
  .card {
    border-width: 2px;
  }
  
  button,
  input,
  select {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .card:hover {
    transform: none;
  }
}

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

/* Enhanced touch targets for mobile */
@media (pointer: coarse) {
  button,
  .tag,
  .cta,
  .card {
    min-height: 44px;
    min-width: 44px;
  }
  
  .tag,
  .pill {
    padding: 8px 12px;
  }
}

/* Dark mode preference handling */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --panel: #f8f9fa;
    --text: #1a1b1e;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    --button-bg: #f3f4f6;
    --button-border: #d1d5db;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --accent: #0ea5e9;
    --accent-2: #10b981;
    --ring: color-mix(in hsl, var(--accent), black 20%);
  }
  
  body {
    background: radial-gradient(1200px 800px at 20% -10%, #f0f9ff 0%, transparent 60%), 
                radial-gradient(1000px 700px at 120% 0%, #f0fdf4 0%, transparent 60%), 
                var(--bg);
  }
  
  .card,
  .panel {
    background: linear-gradient(180deg, #ffffff, #f8f9fa);
  }
  
  .code {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
  }
  
  .preview {
    background: #f8fafc;
    border-color: #cbd5e1;
  }
  
  .toast {
    background: #1e293b;
    border-color: #475569;
    color: #f1f5f9;
  }
  
  #palette .box {
    background: #ffffff;
    border-color: #d1d5db;
  }
  
  #palette input {
    background: #f9fafb;
    border-color: #d1d5db;
  }
  
  #palette li:hover,
  #palette li:focus {
    background: #f3f4f6;
  }
}

/* Print styles */
@media print {
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
  
  header,
  footer,
  .cta,
  .actions,
  #palette {
    display: none !important;
  }
  
  .wrap {
    max-width: none;
    padding: 0;
  }
  
  .panel {
    border: 1px solid #ccc;
    margin-bottom: 1rem;
    page-break-inside: avoid;
  }
  
  .code {
    border: 1px solid #ccc;
    padding: 0.5rem;
    font-size: 12px;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 11px;
    color: #666;
  }
  
  a[href^="#"]:after,
  a[href^="/"]:after {
    content: "";
  }
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Enhanced error states */
.error {
  border-color: #ef4444 !important;
  background-color: color-mix(in hsl, #ef4444, transparent 95%);
}

.error-message {
  color: #ef4444;
  font-size: 14px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.error-message::before {
  content: "⚠";
  font-size: 16px;
}

/* Success states */
.success {
  border-color: #10b981 !important;
  background-color: color-mix(in hsl, #10b981, transparent 95%);
}

.success-message {
  color: #10b981;
  font-size: 14px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.success-message::before {
  content: "✓";
  font-size: 16px;
}
