/* ===== CSS GRADIENT GENERATOR STYLES ===== */

/* CSS Variables for consistent theming */
:root {
  /* Light Theme Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #868e96;
  
  /* Accent Colors */
  --accent-primary: #007bff;
  --accent-secondary: #6c5ce7;
  --accent-success: #28a745;
  --accent-warning: #ffc107;
  --accent-danger: #dc3545;
  
  /* Border and Shadow */
  --border-color: #dee2e6;
  --border-radius: 8px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-xxl: 3rem;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-xxl: 1.5rem;
  --font-size-xxxl: 2rem;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.35s ease;
}

/* Dark Theme Variables */
[data-theme='dark'] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --border-color: #30363d;
  --accent-primary: #58a6ff;
  --accent-secondary: #a5a5ff;
}

/* ===== BASE STYLES ===== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: var(--spacing-md);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color var(--transition-base), color var(--transition-base);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Focus styles for accessibility */
:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--accent-primary);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: var(--border-radius);
  z-index: 1000;
  transition: top var(--transition-fast);
}

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

/* Visually hidden utility */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===== TYPOGRAPHY ===== */

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--spacing-md) 0;
  font-weight: 600;
  line-height: 1.3;
}

.title {
  text-align: center;
  font-size: var(--font-size-xxxl);
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--spacing-sm);
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-lg);
  margin-bottom: var(--spacing-xl);
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== LAYOUT ===== */

.site-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--spacing-xl);
}

main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

footer {
  margin-top: var(--spacing-xxl);
  padding-top: var(--spacing-xl);
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

footer a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

footer a:hover {
  text-decoration: underline;
}

/* ===== SECTIONS ===== */

section {
  margin-bottom: var(--spacing-xl);
}

.theme-section {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.preview-section h2,
.controls-section h2 {
  text-align: center;
  margin-bottom: var(--spacing-lg);
  color: var(--text-primary);
}

/* ===== THEME TOGGLE ===== */

#theme-toggle {
  display: flex;
  justify-content: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

#theme-toggle .btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
  text-decoration: none;
}

#theme-toggle .btn:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

#theme-toggle .btn[aria-pressed="true"] {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

/* Material Icons Support */
.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 1.1em;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

/* Fallback for Material Icons */
.material-icons::before {
  content: attr(data-icon);
}

/* ===== GRADIENT PREVIEW ===== */

#gradient-preview {
  width: 100%;
  max-width: 600px;
  height: 300px;
  margin: 0 auto var(--spacing-xl);
  border-radius: var(--border-radius);
  border: 2px solid var(--border-color);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-md);
  background: linear-gradient(45deg, #ff0080, #ff8c00);
}

#gradient-preview:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

#gradient-preview:focus {
  border-color: var(--accent-primary);
}

.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: none;
}

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

/* ===== CONTROLS ===== */

.controls-section {
  max-width: 800px;
  margin: 0 auto;
}

.action-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-xl);
}

#controls {
  background: var(--bg-secondary);
  padding: var(--spacing-xl);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

/* ===== FORM STYLES ===== */

.form-group {
  margin-bottom: var(--spacing-lg);
}

label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: 500;
  color: var(--text-primary);
  font-size: var(--font-size-sm);
}

input,
select,
textarea {
  width: 100%;
  padding: var(--spacing-sm);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: inherit;
  transition: all var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

input:invalid {
  border-color: var(--accent-danger);
}

small {
  display: block;
  margin-top: var(--spacing-xs);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

/* Input with slider */
.input-with-slider {
  display: grid;
  grid-template-columns: 1fr 80px;
  gap: var(--spacing-sm);
  align-items: center;
}

input[type="range"] {
  -webkit-appearance: none;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ===== FIELDSETS ===== */

fieldset {
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  background: var(--bg-primary);
}

legend {
  padding: 0 var(--spacing-sm);
  font-weight: 600;
  color: var(--text-primary);
  font-size: var(--font-size-lg);
}

.gradient-controls {
  display: none;
  padding: var(--spacing-md);
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-lg);
}

.gradient-controls.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== COLOR STOPS ===== */

.color-stops-fieldset {
  position: relative;
}

#colorStops {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: var(--spacing-md);
}

.color-stop {
  display: grid;
  grid-template-columns: 60px 1fr 40px;
  gap: var(--spacing-sm);
  align-items: center;
  padding: var(--spacing-sm);
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-sm);
  transition: all var(--transition-fast);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

.color-stop:hover {
  background: var(--bg-secondary);
  transform: translateX(4px);
}

.color-stop input[type="color"] {
  width: 50px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  cursor: pointer;
  background: none;
}

.color-stop input[type="number"] {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent-danger);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-lg);
  font-weight: bold;
  transition: all var(--transition-fast);
}

.btn-icon:hover:not(:disabled) {
  background: #c82333;
  transform: scale(1.1);
}

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

/* ===== PRESET GRADIENTS ===== */

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.preset-item {
  aspect-ratio: 16/9;
  border-radius: var(--border-radius);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.preset-item:hover {
  border-color: var(--accent-primary);
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.preset-item:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}

.preset-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.preset-item:hover::after {
  opacity: 1;
}

/* ===== BUTTONS ===== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  font-size: var(--font-size-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
  color: inherit;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: -1;
}

.btn:hover::before {
  opacity: 0.1;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-primary:hover {
  background: #0056b3;
  border-color: #0056b3;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--text-secondary);
  color: white;
  border-color: var(--text-secondary);
}

.btn-secondary:hover {
  background: #495057;
  border-color: #495057;
  transform: translateY(-2px);
}

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

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

/* ===== CODE OUTPUT ===== */

.code-output {
  background: var(--bg-tertiary);
  padding: var(--spacing-lg);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.code-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
}

#css-code {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  resize: vertical;
  min-height: 120px;
  width: 100%;
}

.code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-md);
}

/* ===== TOAST NOTIFICATIONS ===== */

#toast-container {
  position: fixed;
  top: var(--spacing-md);
  right: var(--spacing-md);
  z-index: 1050;
  max-width: 350px;
}

.toast {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
}

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

.toast.success {
  border-left: 4px solid var(--accent-success);
}

.toast.error {
  border-left: 4px solid var(--accent-danger);
}

.toast.warning {
  border-left: 4px solid var(--accent-warning);
}

.toast-icon {
  font-size: var(--font-size-lg);
  margin-top: 2px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.toast-message {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  font-size: var(--font-size-lg);
  line-height: 1;
}

.toast-close:hover {
  color: var(--text-primary);
}

/* ===== LOADING OVERLAY ===== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1060;
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loading-content {
  background: var(--bg-primary);
  padding: var(--spacing-xxl);
  border-radius: var(--border-radius);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.loading-content .loading-spinner {
  position: relative;
  transform: none;
  display: block;
  margin: 0 auto var(--spacing-lg);
}

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

@media (max-width: 768px) {
  .skip-link {
    display: none;
  }

  body {
    padding: var(--spacing-sm);
  }
  
  .site-header {
    margin-bottom: var(--spacing-lg);
  }
  
  .title {
    font-size: var(--font-size-xxl);
  }
  
  .subtitle {
    font-size: var(--font-size-base);
  }
  
  #gradient-preview {
    height: 200px;
  }
  
  #controls {
    padding: var(--spacing-lg);
  }
  
  .input-with-slider {
    grid-template-columns: 1fr;
    gap: var(--spacing-xs);
  }
  
  .color-stop {
    grid-template-columns: 50px 1fr 36px;
    gap: var(--spacing-xs);
  }
  
  .action-buttons {
    justify-content: stretch;
  }
  
  .action-buttons .btn {
    flex: 1;
    justify-content: center;
    min-width: 0;
  }
  
  .code-actions {
    flex-direction: column;
  }
  
  .code-actions .btn {
    justify-content: center;
  }
  
  .preset-grid {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  }
  
  #toast-container {
    left: var(--spacing-sm);
    right: var(--spacing-sm);
    max-width: none;
  }
  
  #theme-toggle {
    flex-direction: column;
    gap: var(--spacing-xs);
  }
}

@media (max-width: 480px) {
  .title {
    font-size: var(--font-size-xl);
  }
  
  #theme-toggle .btn {
    width: 120px;
    justify-content: center;
  }
  
  .action-buttons {
    grid-template-columns: 1fr 1fr;
    display: grid;
  }
}

/* ===== PRINT STYLES ===== */

@media print {
  .skip-link,
  #theme-toggle,
  .action-buttons,
  .code-actions,
  #toast-container,
  .loading-overlay {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  #gradient-preview {
    border: 2px solid #000;
    box-shadow: none;
  }
  
  #controls {
    border: 1px solid #000;
    box-shadow: none;
  }
}

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

@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;
  }
  
  .loading-spinner {
    animation: none;
  }
}

@media (prefers-contrast: high) {
  :root {
    --border-color: #000;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  }
  
  [data-theme='dark'] {
    --border-color: #fff;
  }
}

/* ===== UTILITY CLASSES ===== */

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

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--spacing-xs); }
.mb-2 { margin-bottom: var(--spacing-sm); }
.mb-3 { margin-bottom: var(--spacing-md); }
.mb-4 { margin-bottom: var(--spacing-lg); }

.fade-in {
  animation: fadeIn 0.5s ease;
}

.slide-up {
  animation: slideUp 0.3s ease;
}

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