/* ============================================================
   Paint Color Visualizer — visualizer.css
   ============================================================ */

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

:root {
  --bg:          #1a1c1e;
  --surface:     #25282c;
  --surface2:    #2e3237;
  --border:      #3a3f45;
  --accent:      #e8a045;
  --accent-dim:  #b87d30;
  --text:        #e8eaed;
  --text-muted:  #8a9099;
  --danger:      #e05050;
  --success:     #4caf72;
  --radius:      8px;
  --radius-sm:   4px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Host div ─────────────────────────────────────────────── */
#paint-visualizer {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 0;
}

/* ── Header ───────────────────────────────────────────────── */
.pv-header {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.pv-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.pv-header h1 span {
  color: var(--accent);
}

.pv-mode-badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 100px;
  padding: 3px 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pv-mode-badge.ai { border-color: var(--accent); color: var(--accent); }
.pv-mode-badge.manual { border-color: #6c9ef8; color: #6c9ef8; }

/* ── Main layout ──────────────────────────────────────────── */
.pv-main {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: start;
}

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

/* ── Canvas area ──────────────────────────────────────────── */
.pv-canvas-area {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pv-upload-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
}

.pv-upload-prompt svg {
  opacity: 0.35;
}

.pv-upload-prompt p {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.pv-upload-prompt p strong {
  color: var(--text);
  display: block;
  font-size: 1rem;
  margin-bottom: 4px;
}

/* ── Upload button ────────────────────────────────────────── */
.pv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}

.pv-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pv-btn-primary {
  background: var(--accent);
  color: #1a1200;
}
.pv-btn-primary:hover:not(:disabled) { background: #f0aa50; }

.pv-btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.pv-btn-ghost:hover:not(:disabled) { background: var(--border); }

.pv-btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.pv-btn-danger:hover:not(:disabled) { background: rgba(224,80,80,0.1); }

/* ── Canvas element ───────────────────────────────────────── */
#pv-canvas {
  display: block;
  max-width: 100%;
  cursor: crosshair;
}

/* ── Canvas overlays ──────────────────────────────────────── */
.pv-canvas-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
}

.pv-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pv-spin 0.7s linear infinite;
}

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

.pv-overlay-msg {
  font-size: 0.8rem;
  color: var(--text);
  background: rgba(26,28,30,0.85);
  padding: 4px 12px;
  border-radius: 100px;
  backdrop-filter: blur(4px);
}

/* ── Canvas toolbar ───────────────────────────────────────── */
.pv-canvas-toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pv-toolbar-group {
  display: flex;
  gap: 4px;
  background: rgba(26,28,30,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  backdrop-filter: blur(4px);
}

.pv-icon-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}

.pv-icon-btn:hover { background: var(--surface2); color: var(--text); }
.pv-icon-btn.active { background: var(--accent); color: #1a1200; }
.pv-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Progress bar ─────────────────────────────────────────── */
.pv-progress-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 14px;
  background: linear-gradient(transparent, rgba(26,28,30,0.95));
}

.pv-progress-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

.pv-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.pv-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s;
  width: 0%;
}

/* ── Side panel ───────────────────────────────────────────── */
.pv-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.pv-card-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
}

/* ── Surface selector ─────────────────────────────────────── */
.pv-surface-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pv-surface-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.pv-surface-item:hover { background: var(--surface2); }

.pv-surface-item.active {
  background: rgba(232,160,69,0.1);
  border-color: rgba(232,160,69,0.4);
}

.pv-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}

.pv-swatch::after {
  content: '';
  position: absolute;
  inset: -4px;
}

.pv-surface-name {
  font-size: 0.825rem;
  flex: 1;
}

.pv-surface-color-label {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.pv-surface-mask-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.pv-surface-mask-dot.has-mask { background: var(--success); }

/* ── Color palette ────────────────────────────────────────── */
.pv-palette-search {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  margin-bottom: 8px;
  outline: none;
}
.pv-palette-search:focus { border-color: var(--accent); }
.pv-palette-search::placeholder { color: var(--text-muted); }

.pv-palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  max-height: 168px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.pv-color-chip {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
  position: relative;
}

.pv-color-chip:hover { transform: scale(1.15); z-index: 1; }
.pv-color-chip.selected { border-color: white; transform: scale(1.1); z-index: 1; }

.pv-color-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.pv-color-custom label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.pv-color-picker {
  width: 32px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
  padding: 1px;
}

.pv-color-hex-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  outline: none;
}
.pv-color-hex-input:focus { border-color: var(--accent); }

/* ── Strength slider ──────────────────────────────────────── */
.pv-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pv-slider-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 80px;
}

.pv-slider {
  -webkit-appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.pv-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
}

.pv-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
}

.pv-slider-val {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* ── Action bar ───────────────────────────────────────────── */
.pv-action-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pv-action-row .pv-btn { flex: 1; justify-content: center; min-width: 60px; }

/* ── Status / notice bar ──────────────────────────────────── */
.pv-notice {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.pv-notice.info { background: rgba(108,158,248,0.12); color: #8ab4f8; border: 1px solid rgba(108,158,248,0.25); }
.pv-notice.warn { background: rgba(232,160,69,0.12); color: var(--accent); border: 1px solid rgba(232,160,69,0.25); }
.pv-notice.error { background: rgba(224,80,80,0.12); color: #f28b82; border: 1px solid rgba(224,80,80,0.25); }
.pv-notice.success { background: rgba(76,175,114,0.12); color: #81c995; border: 1px solid rgba(76,175,114,0.25); }

/* ── Upload bar at bottom of canvas ──────────────────────── */
.pv-canvas-bottom {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

/* ── Tolerance slider (magic wand) ───────────────────────── */
.pv-tol-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Hidden input ─────────────────────────────────────────── */
.pv-hidden { display: none !important; }

/* ── Before/after toggle label ───────────────────────────── */
.pv-compare-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 2px;
}

/* ── Responsive tweaks ────────────────────────────────────── */
@media (max-width: 480px) {
  .pv-palette-grid { grid-template-columns: repeat(5, 1fr); }
  .pv-header h1 { font-size: 1rem; }
}
