/* --- Design System & CSS Variables --- */
:root {
  /* Common System Values */
  --font-display: 'Outfit', 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-sans: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --font-mono: 'Fira Code', monospace;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
}

/* --- Dark Theme Variables --- */
body.dark-theme {
  --bg-app: #090a0f;
  --bg-panel: #11131c;
  --bg-card: rgba(23, 26, 38, 0.6);
  --bg-card-hover: rgba(30, 34, 50, 0.85);
  --bg-input: #1b1e2b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  
  --text-primary: #f1f2f6;
  --text-secondary: #9ea4b7;
  --text-muted: #646a7c;
  
  --accent-color: #6366f1;
  --accent-color-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  --accent-glow: rgba(99, 102, 241, 0.25);
  
  --toast-bg: rgba(17, 19, 28, 0.95);
  --toast-border: rgba(99, 102, 241, 0.3);
  --shadow-app: 0 0 80px rgba(0, 0, 0, 0.5);
  --color-success: #10b981;
}

/* --- Light Theme Variables --- */
body.light-theme {
  --bg-app: #f4f6fa;
  --bg-panel: #ffffff;
  --bg-card: rgba(243, 244, 246, 0.8);
  --bg-card-hover: rgba(243, 244, 246, 1);
  --bg-input: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-color: #4f46e5;
  --accent-color-hover: #3730a3;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #db2777 100%);
  --accent-glow: rgba(79, 70, 229, 0.15);
  
  --toast-bg: rgba(255, 255, 255, 0.95);
  --toast-border: rgba(79, 70, 229, 0.2);
  --shadow-app: 0 10px 40px rgba(0, 0, 0, 0.05);
  --color-success: #059669;
}

/* --- Reset & Base Styles --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* --- Layout Container --- */
.app-container {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  flex-grow: 1;
}

/* --- Header Styling --- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon-wrapper {
  background: var(--accent-gradient);
  color: white;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 20px var(--accent-glow);
  animation: logo-spin 15s linear infinite;
}

.logo-icon {
  width: 24px;
  height: 24px;
}

@keyframes logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.header-logo h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 400;
}

/* --- Theme Toggle Button --- */
.theme-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

body.dark-theme .sun-icon,
body.light-theme .moon-icon {
  display: block;
}

body.dark-theme .moon-icon,
body.light-theme .sun-icon {
  display: none;
}

.theme-toggle-btn svg {
  width: 20px;
  height: 20px;
}

/* --- Main Workspace Layout --- */
.app-main {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: 100%;
}

.panel-image {
  position: sticky;
  top: 2rem;
}

@media (max-width: 1024px) {
  .panel-image {
    position: relative;
    top: 0;
  }
}

/* --- Dropzone (Upload Container) --- */
.dropzone-area {
  background: var(--bg-card);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 4rem 2rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  min-height: 450px;
  position: relative;
  backdrop-filter: blur(10px);
}

.dropzone-area:hover,
.dropzone-area.dragover {
  border-color: var(--accent-color);
  background: var(--bg-card-hover);
  box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.05);
}

.hidden-input {
  display: none;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.upload-icon-wrapper {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  color: var(--accent-color);
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.dropzone-area:hover .upload-icon-wrapper {
  transform: scale(1.05) translateY(-5px);
  color: var(--accent-color-hover);
  border-color: var(--accent-color);
  box-shadow: 0 10px 25px var(--accent-glow);
}

.upload-icon {
  width: 32px;
  height: 32px;
}

.dropzone-content h3 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}

.dropzone-or {
  color: var(--text-muted);
  font-size: 0.875rem;
  position: relative;
  width: 100%;
}

.dropzone-or::before,
.dropzone-or::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40px;
  height: 1px;
  background: var(--border-color);
}

.dropzone-or::before { left: calc(50% - 60px); }
.dropzone-or::after { right: calc(50% - 60px); }

.dropzone-subtext {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 300px;
  line-height: 1.5;
}

/* --- Common Button Styles --- */
.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.8rem 1.75rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
  filter: brightness(1.1);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

/* --- Image Preview Section --- */
.preview-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
}

.preview-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
}

#source-canvas {
  max-width: 100%;
  max-height: 500px;
  display: block;
}

.eye-dropper-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let canvas capture events, overlay is just visual */
  z-index: 10;
}

/* Magnifier (Color Eyedropper) */
.magnifier {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: var(--radius-full);
  border: 4px solid #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5), inset 0 0 8px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  background-repeat: no-repeat;
  display: block;
  z-index: 20;
  transform: translate(-50%, -50%);
}

/* Reticle crosshair inside magnifier */
.magnifier::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  border: 2px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 2px rgba(0,0,0,0.8);
  background: transparent;
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.instruction-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-left: auto;
}

@media (max-width: 640px) {
  .instruction-text {
    margin-left: 0;
    width: 100%;
  }
}

/* --- Card Styles --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.card-header svg {
  color: var(--accent-color);
  width: 22px;
  height: 22px;
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.card-header-actions {
  margin-left: auto;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-input);
}

/* --- Controls Card Styling --- */
.controls-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.badge {
  background: var(--accent-color);
  color: white;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Range Slider Custom Styling */
.slider-wrapper {
  padding: 0.5rem 0;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--bg-input);
  outline: none;
  transition: background var(--transition-fast);
  border: 1px solid var(--border-color);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--accent-color);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-fast), background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: var(--accent-color-hover);
}

/* Custom Select Dropdown Styling */
.custom-select {
  font-family: var(--font-sans);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.custom-select:hover {
  border-color: var(--border-hover);
}

.custom-select:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* --- Palette swatches grid --- */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1rem;
  min-height: 240px;
  align-items: stretch;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-muted);
  text-align: center;
  padding: 3rem 0;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

/* Color Swatch Card */
.swatch-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
  aspect-ratio: 1 / 2;
  min-height: 220px;
}

@media (max-width: 640px) {
  .swatch-card {
    aspect-ratio: 1.5 / 1;
    min-height: 140px;
    flex-direction: row;
  }
}

.swatch-color-fill {
  flex-grow: 1;
  width: 100%;
  cursor: pointer;
  position: relative;
  transition: flex-grow var(--transition-normal);
}

@media (max-width: 640px) {
  .swatch-color-fill {
    width: 40%;
    height: 100%;
  }
}

/* Hover effect for color fill */
.swatch-color-fill::after {
  content: 'Copy HEX';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  pointer-events: none;
  white-space: nowrap;
}

.swatch-card:hover .swatch-color-fill::after {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

/* Swatch info section */
.swatch-info {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--bg-card-hover);
}

@media (max-width: 640px) {
  .swatch-info {
    width: 60%;
    justify-content: center;
  }
}

.swatch-hex {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.swatch-formats {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.swatch-format-row {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-xs);
  transition: background var(--transition-fast);
}

.swatch-format-row:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

/* Custom interactive controls for lock and manual picker */
.swatch-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  border-top: 1px solid var(--border-color);
  padding-top: 6px;
}

.swatch-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.swatch-btn:hover {
  color: var(--text-primary);
  background: var(--bg-input);
}

.swatch-btn.active {
  color: var(--accent-color);
}

.swatch-color-picker-wrapper {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-xs);
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.swatch-color-input {
  position: absolute;
  top: -5px;
  left: -5px;
  width: 28px;
  height: 28px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: none;
}

/* Accessible Contrast Check Indicator */
.contrast-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.contrast-badge.pass {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
}

.contrast-badge.fail {
  background-color: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* --- Export Card Styling --- */
.export-tabs-header {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  gap: 1.5rem;
}

.export-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  padding-bottom: 0.75rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.export-tab-btn:hover {
  color: var(--text-primary);
}

.export-tab-btn.active {
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.code-block-wrapper {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  max-height: 250px;
  overflow-y: auto;
}

.code-block-wrapper pre {
  margin: 0;
}

.code-block-wrapper code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.btn-copy-code {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-copy-code:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-copy-code svg {
  width: 16px;
  height: 16px;
}

.download-action-wrapper {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 9999;
}

.toast {
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transform: translateY(20px);
  opacity: 0;
  animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  backdrop-filter: blur(10px);
}

.toast svg {
  color: var(--color-success);
  width: 18px;
  height: 18px;
}

.toast-message {
  font-size: 0.9rem;
  font-weight: 500;
}

@keyframes toast-in {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast.fade-out {
  animation: toast-out 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toast-out {
  to {
    transform: translateY(10px);
    opacity: 0;
  }
}

/* Utility Hidden */
.hidden {
  display: none !important;
}
