/* ==========================================================================
   1. COLOR SWATCHES & BUTTON TRIGGERS
   ========================================================================== */

/* Custom Swatch Button */
.custom-color-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: left;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 3px;
  cursor: pointer;
  height: 28px;
  width: 60px;
  box-sizing: border-box;
  transition: background 0.2s, border-color 0.2s;
}

.custom-color-swatch:hover {
  background: #333;
  border-color: #666;
}

/* Inner Swatch Color Box */
.swatch-preview {
  width: 60px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid lightblue;
  display: block;
}

/* System Picker Button & Overlay (Dynamically Injected for Mac/Non-Chromium) */
.system-picker-btn-wrapper {
  position: relative;
  display: inline-block;
  height: 28px;
}

.system-picker-btn {
  background: #2b2b36;
  border: 1px solid #444;
  color: #ccc;
  padding: 0 8px;
  height: 28px;
  line-height: 26px;
  border-radius: 6px;
  font-size: 10.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  box-sizing: border-box;
  transition: background 0.15s, color 0.15s;
}

.system-picker-btn-wrapper:hover .system-picker-btn {
  background: #3a3a48;
  color: #fff;
}

/* Transparent Overlay Input to Capture Native Clicks */
.native-color-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 0;
}


/* ==========================================================================
   2. CUSTOM MODAL PICKER (POP-UP)
   ========================================================================== */

/* Backdrop Overlay */
.cp-modal-overlay,
#colorPickerModal {
  position: fixed;
  inset: 0;
  z-index: 10000 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8) !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Active State Trigger */
.cp-modal-overlay.active,
#colorPickerModal.active {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Modal Content Container */
.cp-modal-content {
  position: relative;
  background: #2F3845 !important;
  border-radius: 10px;
  border: 2px solid #728094;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  padding: 25px 20px;
  width: 310px;
  max-width: 90vw;
  text-align: center;
  color: #eee;
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.cp-modal-overlay.active .cp-modal-content,
#colorPickerModal.active .cp-modal-content {
  transform: scale(1);
}

/* Header */
.cp-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.cp-modal-title {
  color: #F7DA6D;
  font-size: 1.45em;
  font-weight: bold;
  letter-spacing: 0.02em;
}

.cp-modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 30px;
  color: #ddd;
  cursor: pointer;
  line-height: 1;
  transition: color 0.3s;
}

.cp-modal-close:hover {
  color: #ff0000;
}

/* Slider Group Layout for HSL */
.cp-sliders-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0;
}

.cp-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cp-slider-row label {
  font-size: 11px;
  color: #aaa;
  width: 70px;
  text-align: left;
  text-transform: uppercase;
}

/* Base styling for all range inputs */
.cp-hue-slider,
.cp-sat-slider,
.cp-light-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 12px;
  border-radius: 6px;
  outline: none;
}

/* Slider Background Gradients */
.cp-hue-slider {
  background: linear-gradient(
    to right,
    #ff0000 0%, #ffff00 17%, #00ff00 33%,
    #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%
  );
}

.cp-sat-slider {
  background: linear-gradient(to right, #7f7f7f, #ff0000);
}

.cp-light-slider {
  background: linear-gradient(to right, #000000, #ff0000, #ffffff);
}

/* Slider Thumb Styling */
.cp-hue-slider::-webkit-slider-thumb,
.cp-sat-slider::-webkit-slider-thumb,
.cp-light-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #1e1e24;
  box-shadow: 0 0 3px rgba(0,0,0,0.5);
  cursor: pointer;
}

.cp-hue-slider::-moz-range-thumb,
.cp-sat-slider::-moz-range-thumb,
.cp-light-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #1e1e24;
  box-shadow: 0 0 3px rgba(0,0,0,0.5);
  cursor: pointer;
}

/* EyeDropper & Active Preview Row */
.cp-tools-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cp-eyedropper-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  font-size: 13px !important;
  background: #3b82f6;
  border-color: #2563eb;
  border-radius: 6px;
  color: white;
}

.cp-preview-circle {
  height: 26px;
  width: 140px;
  border-radius: 20px;
  border: 2px solid #444;
 overflow: hidden;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.2);

  /* White base behind the grey squares */
  background-color: #ffffff;

  /* Subtle white/light-grey checkerboard pattern */
  background-image: 
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%), 
    linear-gradient(-45deg, #e0e0e0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%), 
    linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

/* Browsers without EyeDropper support: preview bar fills the whole row */
.cp-tools-row.no-eyedropper .cp-preview-circle {
  width: 100%;
}

/* Preset Palette Boxes */
.cp-presets-grid {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.cp-preset-box {
  flex: 1;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.cp-preset-box:hover {
  transform: scale(1.1);
  border-color: #ffffff;
}

.cp-preset-box:active {
  transform: scale(0.95);
}

/* Input Values Grid */
.cp-inputs-grid {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.cp-input-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

/* Custom Flex Ratios for Input Fields */
.cp-input-field:nth-child(1) {
  flex: 0.8; /* HEX - slightly narrower */
}

.cp-input-field:nth-child(2) {
  flex: 1; /* RGB/RGBA - wider to comfortably fit 4 values */
}

.cp-input-field:nth-child(3) {
  flex: 1.2; /* NAME - slightly narrower */
}

.cp-input-field label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
}

/* Custom Color Picker Input Base & States */
.cp-input-field input,
.cp-inputs-grid input {
  background-color: #121215 !important;
  border: 1px solid #333 !important;
  color: #ffffff !important;
  padding: 6px 2px !important;
  border-radius: 4px !important;
  font-size: 11px !important;
  text-align: center !important;
  width: 100% !important;
  box-sizing: border-box !important;
  transition: background-color 0.15s ease, border-color 0.15s ease !important;
}

/* Hover state */
.cp-input-field input:hover,
.cp-inputs-grid input:hover {
  background-color: #1e1e24 !important;
  border-color: #555 !important;
}

/* Focus state */
.cp-input-field input:focus,
.cp-inputs-grid input:focus {
  background-color: #24242c !important;
  border-color: #3b82f6 !important;
  outline: none !important;
}

/* Blue highlight for selected text in input fields */
.cp-input-field input::selection {
  background: #3b82f6;
  color: #ffffff;
}

/* Prevent Chrome/Safari autofill background override */
.cp-input-field input:-webkit-autofill,
.cp-input-field input:-webkit-autofill:hover, 
.cp-input-field input:-webkit-autofill:focus {
  -webkit-text-fill-color: #ffffff !important;
  -webkit-box-shadow: 0 0 0px 1000px #121215 inset !important;
  transition: background-color 5000s ease-in-out 0s !important;
}

/* Custom Saved Colors Section */
.cp-custom-section {
  margin: 12px 0;
}

.cp-custom-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 11px;
  color: #aaa;
}

.cp-save-btn {
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444444;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.2;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cp-save-btn:hover {
  background: #383838;
  border-color: #555555;
  text-decoration: none;
}

.cp-save-btn:active {
  background: #222222;
}

.cp-custom-grid {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Empty Custom Slot Styling */
.cp-custom-slot {
  flex: 1 1 0%;
  height: 22px;
  min-width: 20px;
  border-radius: 4px;
  border: 1px dashed #ccc;
  background-color: #ffffff;
  cursor: pointer;
  box-sizing: border-box;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

/* Filled Slot Styling */
.cp-custom-slot.filled {
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.cp-custom-slot.filled:hover {
  transform: scale(1.1);
  border-color: #ffffff;
}

/* Modal Actions Footer */
.cp-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #2a2a32;
}

.cp-footer-right {
  display: flex;
  gap: 8px;
}

.cp-btn {
  height: 30px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 3px 18px !important;
  line-height: normal !important;
  box-sizing: border-box !important;
  border: 1px solid #728094;
  border-radius: 4px;
  background: #555F6D;
  color: #ffffff;
  font-family: 'Roboto', sans-serif;
  font-size: 15px !important;
  cursor: pointer;
  transition: background-color 0.3s ease;
  user-select: none;
}

.cp-btn:hover {
  background: #3399ff;
}

.cp-btn-primary {
  background: #3b82f6;
  border-color: #2563eb;
}

/* Advanced Colors link button styling */
.cp-advanced-link {
  color: #9ca3af;
  font-size: 11px;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid #33333f;
  background-color: #1a1a22;
  transition: all 0.15s ease;
  display: inline-block;
}

.cp-advanced-link:hover {
  color: #ffffff;
  background-color: #242430;
  border-color: #4b5563;
}

/* ==========================================================================
   3. CONFIRM DIALOG
   ========================================================================== */

.cp-confirm-overlay {
  z-index: 10001 !important;
}

.cp-confirm-content {
  min-width: 280px;
  max-width: 340px;
}

.cp-confirm-message {
  margin: 14px 0 0;
  font-size: 15px;
  line-height: 1.4;
  color: #eee;
}

.cp-confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.cp-btn.cp-btn-danger {
  background: #a63d3d;
  border-color: #c25b5b;
}

.cp-btn.cp-btn-danger:hover {
  background: #d14d4d;
}

/* Color Box Container */
.cp-box-container {
  position: relative;
  width: 100%;
  height: 150px;
  border-radius: 8px;
  margin-bottom: 14px;
  cursor: crosshair;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  /* Default background (pure hue, dynamic via JS) */
  background-color: hsl(0, 100%, 50%);
}

/* White gradient left-to-right (Saturation) */
.cp-box-saturation {
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

/* Black gradient bottom-to-top (Lightness/Value) */
.cp-box-value {
  width: 100%;
  height: 100%;
  background: linear-gradient(to top, #000, rgba(0, 0, 0, 0));
}

/* Draggable Target Handle Circle */
.cp-box-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
  transform: translate(-50%, -50%);
  pointer-events: none;
  top: 50%;
  left: 100%;
}

/* Standard Flex row for top HSL sliders - spans all the way across */
.cp-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cp-slider-row label {
  font-size: 11px;
  color: #aaa;
  text-align: left;
  text-transform: uppercase;
  width: 70px; /* Fixed width for labels across all rows */
  flex-shrink: 0;
}

/* Base slider inputs (Hue, Sat, Light) */
.cp-hue-slider,
.cp-sat-slider,
.cp-light-slider {
  flex: 1;
}

/* Specialized 3-column Grid specifically for the Opacity row */
.cp-slider-row:has(#cpAlphaSlider) {
  display: grid;
  grid-template-columns: 70px 1fr 45px;
  gap: 10px;
}

/* Opacity slider input */
.cp-alpha-slider {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: #3b82f6 !important;
  border-radius: 4px;
  outline: none;
  border: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Percentage text container */
.cp-slider-value {
  width: 45px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Chrome / Safari Thumb for Opacity */
.cp-alpha-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #3b82f6;
  cursor: pointer;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.4);
}

/* Firefox Thumb for Opacity */
.cp-alpha-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #3b82f6;
  cursor: pointer;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}

/* Firefox Track for Opacity */
.cp-alpha-slider::-moz-range-track {
  height: 8px;
  background: #3b82f6 !important;
  border-radius: 4px;
  border: none;
}