/**
 * Copyright (c) 2026 Hexful.com
 * All rights reserved.
 * 
 * Unauthorized use, distribution, or modification of this code
 * is strictly prohibited.
 */
:root {
  --primary-color: #10a37f;
  --btn-color: #121212;
  --background: #ffffff;
  --card-bg: #ffffff;
  --contrast-bg: #f7f7f8;
  --border-color: #e5e5e5;
  --text-color: #121212;
  --text-secondary: #222222;
  --border-radius: 8px;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
}
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.image-body {
  font-family: var(--font-sans);
  background-color: var(--background);
  color: var(--text-color);
  padding: 24px;
  min-height: 100dvh;
  max-width: 1400px;
  margin: auto;
  width: 100%;
  box-sizing: border-box;
  padding: 0 1rem;
}
.img-color-picker-container {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Single page header — match Contrast "Pair" row */
.image-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 50px;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  box-sizing: border-box;
}

.image-page-title {
  margin: 0;
  padding-left: 0;
  letter-spacing: -0.5px;
  font-size: 1.5rem;
  font-weight: 600;
  color: #121212;
  font-family: var(--font-sans);
  line-height: 1.2;
}

.image-page-actions {
  display: flex;
  width: auto;
  margin-left: auto;
  flex: 0 0 auto;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.image-page-actions > .image-export-menu {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
}

@media (min-width: 768px) {
  .image-page-actions {
    gap: 12px;
  }
}

.image-upload-toolbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-top: 12px;
  margin-bottom: 0;
  height: auto;
  min-height: 0;
}

.image-upload-toolbar[hidden] {
  display: none !important;
}

/* Desktop sidebar layout: align Image tab columns with shared right-pane rails */
@media (min-width: 896px) {
  .image-body {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0 !important;
  }

  .img-color-picker-container {
    max-width: var(--content-max-width);
    margin: 0 auto 20px auto;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    padding: 0;
    box-sizing: border-box;
  }
}
@media (max-width: 1200px) {
  .img-color-picker-container {
    grid-template-columns: 1fr;
  }
}
/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  height: 50px;
}

h2 {
  font-family: var(--font-sans);
  font-size: 1.5em;
  font-weight: 500;
  letter-spacing: -0.5px;
}
/* Add media query for smaller screens */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    height: auto; /* Allow header height to adjust */
    gap: 10px; /* Add gap between title and button group */
  }

  /* Optional: If buttons are in a btn-group inside the header */
  .header .btn-group {
     margin-top: 10px; /* Add space below the title */
  }

  /* Match Saved tab mobile: full-width row, controls share space equally */
  #image-tab-container .header .btn-group {
    width: 100%;
  }

  #image-tab-container .header .btn-group > button,
  #image-tab-container .header .btn-group > select.img-select-button {
    flex: 1;
    min-width: 0;
    width: auto;
  }
}
/* Upload Section */
.upload-section {
  background: var(--card-bg);
  padding: 0;
  border: none;
  border-radius: var(--border-radius);
}
#imageUpload {
  display: none;
}
#imageContainer {
  position: relative;
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px;
  text-align: center;
  overflow: hidden;
  cursor: pointer;
}
#imageContainer img {
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
.choose-file-container {
  margin-top: 20px;
}
.custom-file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  color: #121212;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  box-sizing: border-box;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.custom-file-btn:focus-visible {
  outline: 2px solid #111827;
  outline-offset: 2px;
}
.custom-file-btn:hover {
  background: #ffffff;
  background-color: #ffffff;
  border-color: #999;
  color: #121212;
}
.upload-instructions {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 10px;
  text-align: left;
}
.btn-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

#image-tab-container .image-page-actions {
  align-items: center;
}

.image-export-menu {
  position: relative;
  display: flex;
}

.image-export-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  min-width: 160px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-sizing: border-box;
}

.image-export-menu-panel button,
.btn-group .image-export-menu-panel button,
.header .btn-group .image-export-menu-panel button {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  justify-content: flex-start;
  gap: 0;
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.2;
  color: #121212;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.image-export-menu-panel button:hover,
.btn-group .image-export-menu-panel button:hover,
.header .btn-group .image-export-menu-panel button:hover {
  background: #F2F2F2;
  background-color: #F2F2F2;
  border-color: transparent;
  transform: none;
}

.image-export-menu-panel[hidden] {
  display: none;
}

/* Edge-aware export/format menus (set by JS, same idea as mixer tooltips) */
.image-export-menu-panel--align-start {
  left: 0;
  right: auto;
}

.image-export-menu-panel--align-end {
  left: auto;
  right: 0;
}

/* Chevron style aligned with Similar Shades export */
.image-export-menu > button .img-dropdown-chevron {
  display: inline-block;
  width: 13px;
  height: 11px;
  flex-shrink: 0;
  margin-left: 2px;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='13'%20height='11'%20viewBox='0%200%2013%2011'%3E%3Cpath%20d='M2.5%203.25l4%204%204-4'%20fill='none'%20stroke='%23000'%20stroke-width='1.75'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 13px 11px;
}

.btn-group button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  color: #121212;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  box-sizing: border-box;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* Icon styling (if icons are added to HTML) */
.btn-group button svg {
  width: 16px;
  height: 16px;
}

.btn-group button:hover {
  background: #ffffff;
  background-color: #ffffff;
  border-color: #999;
  color: #121212;
}

/* Image tab controls: match Contrast / Recent / Saved pill sizing */
#image-tab-container .upload-section .header .btn-group > button,
#image-tab-container .image-page-actions > button,
#image-tab-container .image-page-actions > .image-export-menu > button,
#image-tab-container .image-page-actions > .img-select-button,
#image-tab-container .image-page-actions > select.img-select-button,
#image-tab-container #image-save-palette.searched-color-button,
#image-tab-container .custom-file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: #ffffff;
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  color: #121212;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  box-sizing: border-box;
  flex: 0 0 auto;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#image-tab-container .upload-section .header .btn-group > button:hover,
#image-tab-container .image-page-actions > button:hover,
#image-tab-container .image-page-actions > .image-export-menu > button:hover,
#image-tab-container .image-page-actions > .img-select-button:hover,
#image-tab-container .image-page-actions > select.img-select-button:hover,
#image-tab-container #image-save-palette.searched-color-button:hover,
#image-tab-container .custom-file-btn:hover {
  background: #ffffff;
  background-color: #ffffff;
  border-color: #999;
  color: #121212;
  transform: none;
}

/* Force image dropdown panels to match Recent menu (beat .btn-group button) */
#image-tab-container .image-export-menu-panel,
.image-export-menu-panel {
  min-width: 160px;
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  padding: 6px;
  gap: 4px;
}

#image-tab-container .image-export-menu-panel button,
#image-tab-container .btn-group .image-export-menu-panel button,
#image-tab-container .header .btn-group .image-export-menu-panel button {
  width: 100% !important;
  margin: 0;
  border: 1px solid transparent;
  background: transparent !important;
  background-color: transparent !important;
  text-align: left !important;
  justify-content: flex-start !important;
  gap: 0;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  font-size: 14px !important;
  font-weight: 400 !important;
  line-height: 1.2;
  color: #121212;
  text-transform: uppercase;
  box-shadow: none;
  transform: none;
}

#image-tab-container .image-export-menu-panel button:hover,
#image-tab-container .btn-group .image-export-menu-panel button:hover,
#image-tab-container .header .btn-group .image-export-menu-panel button:hover {
  background: #F2F2F2 !important;
  background-color: #F2F2F2 !important;
  transform: none;
}

/* Stack buttons vertically on very small screens (other headers only) */
@media (max-width: 480px) {
  .header .btn-group {
    flex-direction: column;
    align-items: stretch; /* Make buttons fill width */
    width: 100%; /* Ensure button group takes full width */
  }
  .header .btn-group button {
    width: 100%; /* Explicitly set button width */
    justify-content: center; /* Center content within full-width button */
  }

  /* Make custom file button full width on small screens too */
  .custom-file-btn {
      display: flex;
      width: 100%;
      text-align: center;
      margin-top: 10px;
      box-sizing: border-box;
  }
}

/* Custom select with icon */
.btn-group select {
  padding: 8px 12px;
  padding-right: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background-color: var(--card-bg);
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='13'%20height='11'%20viewBox='0%200%2013%2011'%3E%3Cpath%20d='M2.5%203.25l4%204%204-4'%20fill='none'%20stroke='%23000'%20stroke-width='1.75'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 13px 11px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background 0.2s;
  text-align: left;
}
.btn-group select:hover {
  background-color: #ffffff;
  border-color: #999;
  color: #121212;
}

/* Style the select with img-select-button class like a Recent pill */
.btn-group select.img-select-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: left;
  gap: 6px;
  height: 34px;
  min-height: 34px;
  padding: 0 30px 0 14px;
  border-radius: 999px;
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  color: #121212;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  box-sizing: border-box;
  transition: background-color 0.15s ease, border-color 0.15s ease;

  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='13'%20height='11'%20viewBox='0%200%2013%2011'%3E%3Cpath%20d='M2.5%203.25l4%204%204-4'%20fill='none'%20stroke='%23000'%20stroke-width='1.75'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 13px 11px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Ensure hover state is consistent with Recent / Saved */
.btn-group select.img-select-button:hover {
  background: #ffffff;
  background-color: #ffffff;
  border-color: #999;
  color: #121212;
}

/* Palette header controls: keep content-sized pills like Contrast */
@media (max-width: 1024px) {
  #image-tab-container .image-page-actions {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Keep Save first, then format (HEX), then Export */
  #image-tab-container #image-save-palette { order: 1; }
  #image-tab-container #imageFormatMenu { order: 2; }
  #image-tab-container #imageExportMenu { order: 3; }

  #image-tab-container .image-page-actions > button,
  #image-tab-container .image-page-actions > select.img-select-button,
  #image-tab-container .image-page-actions > .image-export-menu {
    flex: 0 0 auto;
    min-width: fit-content;
    width: auto;
    justify-content: flex-start;
  }

  #image-tab-container .image-page-actions > .image-export-menu > button {
    width: auto;
  }

  #image-tab-container .image-page-actions .image-export-menu-panel button {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    padding: 8px 12px;
    background: transparent;
  }

  #image-tab-container .image-page-actions .image-export-menu-panel button:hover {
    background: #F2F2F2;
    background-color: #F2F2F2;
  }
}

/* Small/mobile: stack page header like Contrast */
@media (max-width: 768px) {
  #image-tab-container .image-page-header {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 1.75rem;
  }

  #image-tab-container .image-page-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
    gap: 8px;
  }

  #image-tab-container .image-page-actions > button,
  #image-tab-container .image-page-actions > select.img-select-button,
  #image-tab-container .image-page-actions > .image-export-menu {
    flex: 1 1 auto;
    min-width: fit-content;
    width: auto;
    height: 34px;
    min-height: 34px;
  }

  #image-tab-container .image-page-actions > .image-export-menu {
    padding: 0;
    height: auto;
    min-height: 0;
  }

  #image-tab-container .image-page-actions > .image-export-menu > button {
    width: 100%;
    height: 34px;
    min-height: 34px;
  }
}

/* Narrow mobile: full-width controls, one per row — match Contrast */
@media (max-width: 480px) {
  #image-tab-container .image-page-actions {
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }

  #image-tab-container .image-page-actions > button,
  #image-tab-container .image-page-actions > select.img-select-button,
  #image-tab-container .image-page-actions > .image-export-menu {
    flex: 1 1 auto;
    width: 100%;
    height: 34px;
    min-height: 34px;
  }

  #image-tab-container .image-page-actions > .image-export-menu {
    padding: 0;
    height: auto;
    min-height: 0;
  }

  #image-tab-container .image-page-actions > .image-export-menu > button {
    width: 100%;
  }
}

/* Draggable Swatches */
.draggable-swatch {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  cursor: grab;
  z-index: 10;
}
.draggable-swatch:active {
  cursor: grabbing;
}
.draggable-swatch:hover {
  border-color: var(--primary-color);
}
/* Magnifier */
#magnifierCanvas {
  display: none;
  position: absolute;
  pointer-events: none;
  z-index: 9999;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
  border: 2px solid #fff;
}
/* Palette Display */
.palette-display {
  background: var(--card-bg);
  padding: 0;
  border: none;
  border-radius: var(--border-radius);
}
.palette-row {
  position: relative;
  height: 120px;
  border-radius: var(--border-radius);
  margin-bottom: 8px;
  padding: 10px;
  display: block;
}
.palette-info {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  font-size: 0.87rem;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
}
.palette-info .hex-value {
  font-size: 1.1rem;
  text-transform: uppercase;
}
.img-color-picker-icons {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 1rem;
}

/* Match Mixer desktop behavior: reveal row actions on hover/focus */
@media (hover: hover) and (pointer: fine) {
  .palette-row .img-color-picker-icons {
    opacity: 0;
    transform: translateY(-2px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
  }

  .palette-row:hover .img-color-picker-icons,
  .palette-row:focus-within .img-color-picker-icons {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
}
.img-color-picker-icons svg {
  width: 24px;
  height: 24px;
  cursor: pointer;
  transition: background 0.2s;
  border-radius: 4px;
  padding: 2px;
}
.img-color-picker-icons svg:hover {
  background-color: rgb(255 255 255 / 20%);
}
/* Color Picker Panel */
.img-color-picker-color-picker {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 20px;
  width: 420px;
  max-width: 500px;
  text-align: center;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: none;
}
.img-color-picker-color-picker h3 {
  font-size: 1.25rem;
  margin-bottom: 16px;
}
.img-color-picker-sv-picker {
  position: relative;
  width: 100%;
  height: 160px;
  margin-bottom: 16px;
  border-radius: var(--border-radius);
  overflow: hidden;
  cursor: crosshair;
  background: linear-gradient(to top, rgba(0,0,0,1), rgba(0,0,0,0)),
              linear-gradient(to right, #fff, red);
}
.img-color-picker-sv-indicator {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 3px rgba(0,0,0,0.4);
  pointer-events: none;
  transform: translate(-7px, -7px);
}
.img-color-picker-hue-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 25px;
  border-radius: var(--border-radius);
  background: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red);
  outline: none;
  margin-bottom: 16px;
}
.img-color-picker-hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border-color);
  transition: background 0.3s;
}
.img-color-picker-hue-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border-color);
  transition: background 0.3s;
}
.color-input-container {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  justify-content: center;
}
#hexInput {
  flex: 1;
  padding: 10px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
}
#hexInput:focus {
  outline: none;
  border-color: var(--primary-color);
}
#colorPreview {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
}
#pickerButtons {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
#pickerButtons button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  cursor: pointer;
  background: var(--btn-color);
  color: #fff;
  transition: background 0.3s;
}
#pickerButtons button:hover {
  background: #000000;
}