/* ============================================
   PALETA DE CORES - COREL INSPIRED
   ============================================ */

:root {
  /* Tokens específicos da paleta */
  --palette-min-height: 100px;
  --palette-header-h: 32px;
  --palette-footer-h: 28px;
  --palette-swatch-size: 32px;
  --palette-gap: 4px;
  --palette-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.color-palette-corel {
  position: fixed;
  inset: auto 0 0 72px;
  height: var(--palette-min-height);
  
  /* Glassmorphism sutil */
  background: color-mix(in srgb, var(--surface-0) 95%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  
  /* Borda superior elegante */
  border-top: 1px solid var(--surface-200);
  box-shadow: 
    0 -1px 3px rgba(0, 0, 0, 0.02),
    0 -4px 12px rgba(0, 0, 0, 0.04),
    0 -8px 24px rgba(0, 0, 0, 0.06);
  
  display: flex;
  flex-direction: column;
  z-index: 40;
  
  /* Transição suave para todas as propriedades animáveis */
  transition: height var(--palette-transition);
  will-change: height;
  
  /* Previne seleção de texto durante drag */
  user-select: none;
}

/* Modo editor - ajuste de layout */
.editor-workspace-corel .color-palette-corel {
  left: 52px;
  right: 280px;
}

/* ============================================
   HEADER
   ============================================ */

.palette-header {
  height: var(--palette-header-h);
  background: linear-gradient(
    180deg,
    var(--surface-50) 0%,
    var(--surface-100) 100%
  );
  border-bottom: 1px solid var(--surface-200);
  
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  
  cursor: grab;
}

.palette-header:active {
  cursor: grabbing;
}

.palette-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.palette-title i {
  color: var(--primary);
  font-size: 0.875rem;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

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

.palette-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.palette-btn {
  --btn-size: 24px;
  
  width: var(--btn-size);
  height: var(--btn-size);
  padding: 0;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  
  font-size: 0.75rem;
  cursor: pointer;
  
  transition: all var(--palette-transition);
  will-change: transform, background-color;
}

.palette-btn:hover {
  background: var(--surface-200);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.palette-btn:active {
  transform: translateY(0);
  background: var(--surface-300);
}

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

/* ============================================
   SCROLL AREA
   ============================================ */

.palette-scroll {
  flex: 1;
  min-height: 0; /* Fix para flexbox */
  
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  
  padding: 0.5rem 0;
  background: var(--surface-0);
  
  /* Scrollbar estilizada cross-browser */
  scrollbar-width: thin;
  scrollbar-color: var(--surface-300) var(--surface-100);
}

.palette-scroll::-webkit-scrollbar {
  height: 8px;
}

.palette-scroll::-webkit-scrollbar-track {
  background: var(--surface-100);
  border-radius: var(--radius-full);
  margin: 0 0.5rem;
}

.palette-scroll::-webkit-scrollbar-thumb {
  background: var(--surface-300);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-100);
}

.palette-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--surface-400);
}

/* ============================================
   COLOR SWATCHES
   ============================================ */

.palette-colors {
  display: flex;
  gap: var(--palette-gap);
  align-items: center;
  
  height: 100%;
  padding: 0 0.75rem;
  min-width: min-content; /* Garante scroll quando necessário */
}

.palette-swatch {
  width: var(--palette-swatch-size);
  height: var(--palette-swatch-size);
  
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  
  /* Sombra interna para profundidade */
  box-shadow: 
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    inset 0 -1px 2px rgba(0, 0, 0, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.05);
  
  transition: all var(--palette-transition);
  will-change: transform, box-shadow;
}

/* Indicador de cor ativa */
.palette-swatch::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-lg);
  border: 2px solid transparent;
  transition: border-color var(--palette-transition);
}

.palette-swatch:hover {
  transform: scale(1.12) translateY(-2px);
  box-shadow: 
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10;
}

.palette-swatch:focus-visible {
  outline: none;
}

.palette-swatch:focus-visible::after {
  border-color: var(--primary);
}

.palette-swatch.active {
  border-color: var(--primary);
  transform: scale(1.08);
}

.palette-swatch.active::after {
  border-color: var(--primary);
  opacity: 0.3;
}

/* ============================================
   FOOTER
   ============================================ */

.palette-footer {
  height: var(--palette-footer-h);
  background: linear-gradient(
    0deg,
    var(--surface-50) 0%,
    var(--surface-100) 100%
  );
  border-top: 1px solid var(--surface-200);
  
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
}

.current-colors {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-indicator {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.color-indicator-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.current-fill,
.current-stroke {
  width: 22px;
  height: 22px;
  
  border-radius: var(--radius-md);
  border: 2px solid var(--surface-300);
  
  cursor: pointer;
  position: relative;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  
  box-shadow: 
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.1);
  
  transition: all var(--palette-transition);
}

.current-fill:hover,
.current-stroke:hover {
  transform: scale(1.15);
  border-color: var(--primary);
  box-shadow: 
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Icon overlay para indicar tipo */
.current-fill::before {
  content: 'F';
  opacity: 0.9;
}

.current-stroke::before {
  content: 'S';
  opacity: 0.9;
}

/* ============================================
   RESIZE HANDLE
   ============================================ */

.palette-resize {
  cursor: ns-resize;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0 0.5rem;
  
  display: flex;
  align-items: center;
  gap: 0.25rem;
  
  opacity: 0.6;
  transition: opacity var(--palette-transition);
}

.palette-resize:hover {
  opacity: 1;
  color: var(--text-secondary);
}

/* Indicador visual de resize */
.palette-resize::before {
  content: '';
  width: 24px;
  height: 3px;
  background: currentColor;
  border-radius: var(--radius-full);
  opacity: 0.3;
}

/* ============================================
   MINIMIZED STATE
   ============================================ */

.color-palette-corel.minimized {
  height: var(--palette-header-h);
}

.color-palette-corel.minimized .palette-scroll,
.color-palette-corel.minimized .palette-footer {
  display: none;
}

/* Animação suave ao minimizar */
.color-palette-corel.minimizing {
  overflow: hidden;
}

/* ============================================
   RESPONSIVE & ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .color-palette-corel,
  .palette-btn,
  .palette-swatch,
  .current-fill,
  .current-stroke,
  .palette-resize {
    transition: none;
  }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
  .palette-swatch {
    box-shadow: 
      inset 0 1px 2px rgba(255, 255, 255, 0.1),
      inset 0 -1px 2px rgba(0, 0, 0, 0.3),
      0 1px 2px rgba(0, 0, 0, 0.2);
  }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Estado de drag em andamento */
.color-palette-corel.is-dragging {
  opacity: 0.9;
  transition: none;
  pointer-events: none;
}

/* Tooltip simples para swatches */
.palette-swatch[data-color]:hover::before {
  content: attr(data-color);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  
  padding: 0.25rem 0.5rem;
  background: var(--surface-900);
  color: var(--surface-0);
  font-size: 0.6875rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  
  animation: tooltip-in 150ms ease;
}

@keyframes tooltip-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}