/* ==========================================
   1. CSS VARIABLES (THEME)
   ========================================== */
:root {
  --primary: #1eb6de;
  --primary-dark: #1892b2;
  --light-bg: #f8fcff;
  --border: #e1e5f1;
  --text: #1e293b;
  --text-light: #475569;
  --card-bg: #ffffff;
  --toast-bg: #2c3e50;
  --danger: #e53e3e;
  --danger-dark: #c53030;
  --success: #42b673;
  --success-dark: #23623d;
  --warning: #ed8936;
  --info: #4299e1;
}

[data-theme="dark"] {
  --primary: #1eb6de;
  --primary-dark: #1892b2;
  --light-bg: #292b32;
  --border: #4a4a5a;
  --text: #f1f5f9;
  --text-light: #cbd5e1;
  --card-bg: #1e1f28;
  --toast-bg: #111827;
  --danger: #f56565;
  --danger-dark: #e53e3e;
  --success: #48bb78;
  --success-dark: #38a169;
  --warning: #f6ad55;
  --info: #63b3ed;
}

/* ==========================================
   2. BASE & RESET
   ========================================== */
.mb10 { margin-bottom: 10px !important; }
hr.compact { margin: 8px 0 !important; }

.container-custom *,
.container-custom *::before,
.container-custom *::after { box-sizing: border-box; }

/* ==========================================
   3. CONTAINER LAYOUT
   ========================================== */
.container-custom {
  width: 100%;
  margin: 20px auto;
  background: var(--card-bg);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  position: relative;
}

/* ==========================================
   LOADING OVERLAY
   ========================================== */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 50;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
}

[data-theme="dark"] .loading-overlay {
  background: rgba(30, 31, 40, 0.85);
}

.loading-overlay i {
  font-size: 28px;
}

/* ==========================================
   4. HEADER
   ========================================== */
.tool-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 6px 6px 0 0;
}

.tool-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tool-title {
  padding-bottom: 0 !important;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
}

.tool-subtitle {
  margin: 0;
  color: var(--text-light);
  font-size: 0.75rem;
  line-height: normal;
}

.tool-actions { display: flex; gap: 6px; }

/* ==========================================
   5. BUTTONS & ACTIONS
   ========================================== */
.primary-btn,
.action-btn,
.secondary-btn,
.success-btn,
.danger-btn,
.mini-btn,
.seed-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  white-space: nowrap;
  border-radius: 4px;
  outline: none;
  text-shadow: none !important;
  box-shadow: none !important;
  transform: none !important;
  filter: none !important;
  backdrop-filter: none !important;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.primary-btn { 
    background: var(--primary); 
    color: #ffffff; 
}
.primary-btn:hover,
.primary-btn:active,
.primary-btn:focus {
    color: #ffffff;
    background: var(--primary-dark);
    border: 1px solid var(--primary-dark);
    text-shadow: none;
}
.primary-btn i,
.action-btn i,
.secondary-btn i,
.seed-btn i,
.success-btn i,
.danger-btn i { font-size: 15px; }

.primary-btn i.ci,
.action-btn i.ci,
.secondary-btn i.ci,
.seed-btn i.ci,
.success-btn i.ci,
.danger-btn i.ci { font-size: 20px; }


.action-btn { background: var(--primary); color: #ffffff; }
.action-btn:hover,
.action-btn:active,
.action-btn:focus {
  color: #ffffff;
  background: var(--primary-dark);
  border: 1px solid var(--primary-dark);
  text-shadow: none;
}

.secondary-btn {
  background: var(--light-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.secondary-btn:hover,
.secondary-btn:active,
.secondary-btn:focus {
  background: var(--card-bg);
  color: var(--primary);
  border: 1px solid var(--primary);
  text-shadow: none;
}

.success-btn { 
  color: #ffffff; 
  background: var(--success); 
  border: 1px solid var(--success);
  }
.success-btn:hover,
.success-btn:active,
.success-btn:focus {
  color: #ffffff;
  background: var(--success-dark);
  border: 1px solid var(--success-dark);
  text-shadow: none;
}

.danger-btn { background: var(--danger); color: #ffffff; }
.danger-btn:hover,
.danger-btn:active,
.danger-btn:focus {
  color: #ffffff;
  background: var(--danger-dark);
  border: 1px solid var(--danger-dark);
  text-shadow: none;
}

.seed-button-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.seed-btn {
  flex: 1;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--light-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.seed-btn:hover {
  background: var(--card-bg);
  color: var(--primary);
  border-color: var(--primary);
  text-shadow: none;
}

#UploadImageBtn i {
  color: var(--primary);
}
[data-theme="dark"] #UploadImageBtn i {
  color: var(--primary);
}

/* ==========================================
   6. WORKSPACE GRID
   ========================================== */
.tool-workspace {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  gap: 0;
  flex: 1;
  overflow: hidden;
}

/* ==========================================
   7. PANELS
   ========================================== */
.left-panel,
.right-panel {
  background: var(--light-bg);
  padding: 5px;
  overflow-y: auto;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.left-panel::-webkit-scrollbar,
.right-panel::-webkit-scrollbar { width: 5px; }

.left-panel::-webkit-scrollbar-track,
.right-panel::-webkit-scrollbar-track { background: transparent; }

.left-panel::-webkit-scrollbar-thumb,
.right-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.left-panel::-webkit-scrollbar-thumb:hover,
.right-panel::-webkit-scrollbar-thumb:hover { background: var(--primary); }

.right-panel {
  position: relative;
  z-index: 1;
}

.middle-panel {
  padding: 10px;
  background: var(--light-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ==========================================
   8. PANEL SECTIONS
   ========================================== */
.panel-section {
  margin-bottom: 10px;
  background: var(--card-bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.panel-section:last-child { margin-bottom: 0; }

.panel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--light-bg);
  border-radius: 4px 4px 0 0;
  transition: background 0.15s;
}

.panel-section-header:hover { background: var(--border); }

.panel-section-header i {
  font-size: 9px;
  color: var(--text-light);
}

.panel-section-header i.fa-chevron-down { transition: transform 0.2s; }

.panel-section.collapsed .panel-section-header i.fa-chevron-down { transform: rotate(-90deg); }

.panel-section.collapsed .panel-section-header { border-radius: 4px; }

.panel-section-content {
  padding: 5px;
  max-height: 800px;
  overflow: hidden;
  transition: max-height 0.2s ease-in-out, padding 0.2s ease-in-out, opacity 0.15s ease;
  opacity: 1;
}

.panel-section.collapsed .panel-section-content {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
}

/* ==========================================
   9. FORM CONTROLS & WRAPS
   ========================================== */
.control-group { margin-bottom: 5px; }
.control-group:last-child { margin-bottom: 0; }

.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}

.slider-row:last-child {
  margin-bottom: 0;
}

.slider-label {
  font-size: 11px;
  color: var(--text);
  font-weight: 500;
  width: 65px;
  flex-shrink: 0;
}

.slider-value {
  font-size: 10px;
  color: var(--text);
  font-family: monospace;
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* ==========================================
   10. RANGE INPUTS (SLIDERS)
   ========================================== */
.slider-row input[type="range"],
input[type="range"] {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 0;
  height: 10px;
  cursor: pointer;
  display: block;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  margin-top: -8px;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-track {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.15);
}

/* ==========================================
   11. DROPDOWNS (EXACT ORIGINAL STYLES)
   ========================================== */
.custom-dropdown { position: relative; width: 100%; }

.custom-dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s;
  text-shadow: none !important;
  box-shadow: none !important;
  transform: none !important;
}

.custom-dropdown-trigger:hover { border-color: var(--primary); }

.custom-dropdown-trigger.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 182, 222, 0.15);
}

.custom-dropdown-trigger i {
  font-size: 9px;
  color: var(--primary);
  transition: transform 0.15s;
}

.custom-dropdown-trigger.active i { transform: rotate(180deg); }

.custom-dropdown-menu {
  position: fixed;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: none;
  max-height: 182px;
  overflow-y: auto;
  min-width: 200px;
}

.custom-dropdown-menu.open { display: block; }

.custom-dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  outline: none;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  text-shadow: none !important;
  box-shadow: none !important;
  transform: none !important;
  text-transform: none !important;
}

.custom-dropdown-item:last-child { border-bottom: none; }

.custom-dropdown-item:hover {
  background: var(--light-bg);
  color: var(--primary);
  border: none;
  border-bottom: 1px solid var(--border);
}

.custom-dropdown-item.selected {
  background: rgba(30, 182, 222, 0.1);
  color: var(--primary);
  font-weight: 600;
}

/* ==========================================
   12. PREVIEW & DROP ZONE
   ========================================== */
.preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  object-fit: contain;
  background: transparent;
}

.modified-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: transparent;
}

.drop-zone {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  cursor: pointer;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(30, 182, 222, 0.05);
  transform: scale(1.01);
}

.drop-zone-icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
  opacity: 0.8;
}

.drop-zone-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.drop-zone-subtitle {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
}

.drop-zone-formats {
  font-size: 11px;
  color: var(--text-light);
  background: var(--light-bg);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.truncate-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: block;
  cursor: help;
}

/* ==========================================
   13. COMPARISON CONTAINER & ZOOM/PAN
   ========================================== */
.comparison-container {
  position: relative;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  width: 100%;
  height: 100%;
  margin: 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: var(--card-bg);
  background-image: 
    linear-gradient(45deg, rgba(0,0,0,0.06) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(0,0,0,0.06) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.06) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.06) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

[data-theme="dark"] .comparison-container {
  background-image: 
    linear-gradient(45deg, rgba(255,255,255,0.06) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(255,255,255,0.06) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.06) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.06) 75%);
}

.comparison-container.zoomed {
  cursor: grab;
}

.comparison-container.zoomed:active {
  cursor: grabbing;
}

.zoom-wrapper {
  position: relative;
  transform-origin: center center;
  transition: transform 0.1s ease-out;
  flex-shrink: 0;
}

.comparison-image {
  display: block;
  pointer-events: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.original-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  clip-path: inset(0 50% 0 0);
}

.comparison-slider-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: var(--primary);
  z-index: 30;
  pointer-events: none;
}

.comparison-slider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 31;
  cursor: ew-resize;
  transition: box-shadow 0.15s, background 0.15s;
}

.comparison-slider-handle:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  background: var(--primary-dark);
}

.comparison-label {
  position: absolute;
  top: 10px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  pointer-events: none;
  z-index: 40;
  display: none;
}

.original-label { left: 10px; }
.quantized-label { right: 10px; }

.tile-count-badge {
  position: absolute;
  background: rgba(0, 0, 0, 0.75);
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 20;
  pointer-events: none;
  display: none;
}

.zoom-indicator {
  position: absolute;
  top: 35px;
  right: 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  z-index: 35;
  pointer-events: none;
  display: none;
  transition: right 0.2s;
}

.zoom-controls-wrap {
  position: absolute;
  bottom: 15px;
  right: 15px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 35;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.75);
  padding: 4px 6px;
  border-radius: 4px;
}

.comparison-container:hover .zoom-controls-wrap {
  opacity: 1;
  pointer-events: auto;
}

.zoom-btn {
  background: transparent;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  text-shadow: none;
  width: 28px;
  height: 28px;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  text-shadow: none;
  color: #ffffff;
}

.zoom-btn i {
  font-size: 12px;
}

.zoom-slider {
  width: 80px;
  height: 4px;
  margin: 0 4px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
  align-self: center;
}

.zoom-slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  margin-top: -5px;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.zoom-slider::-moz-range-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.zoom-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ==========================================
   14. BORDER & COLOR SETTINGS WRAP
   ========================================== */
.border-settings-wrap {
  display: flex;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 6px;
  background: var(--light-bg);
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  align-items: center;
}

.border-settings-wrap input[type="color"] {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.border-settings-wrap input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 3px;
  overflow: hidden;
}

.border-settings-wrap input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.border-settings-wrap input[type="color"]::-moz-color-swatch {
  border: none;
}

.border-settings-wrap .color-hex {
  cursor: default;
  font-size: 11px;
  color: var(--text-light);
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.border-toggle-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-left: auto;
}

.border-toggle-switch .toggle-label {
  font-size: 11px;
  color: var(--text);
}

.border-toggle-switch input { display: none; }

.border-toggle-switch .toggle-slider {
  width: 32px;
  height: 18px;
  background-color: var(--border);
  border-radius: 18px;
  position: relative;
  transition: background-color 0.2s;
}

.border-toggle-switch .toggle-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.border-toggle-switch input:checked + .toggle-slider { background-color: var(--primary); }

.border-toggle-switch input:checked + .toggle-slider::before { transform: translateX(14px); }

/* ==========================================
   15. EXPORT GRID
   ========================================== */
.export-content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.export-content-grid button {
  width: 100%;
  padding: 6px 2px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================
   16. TOAST & FULLSCREEN
   ========================================== */
#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  max-width: calc(100% - 40px);
}

.toast {
  background: var(--toast-bg);
  color: white;
  padding: 8px 14px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-top: 6px;
  animation: slideUp 0.2s ease, fadeOut 0.2s ease 2.8s forwards;
  max-width: 280px;
  border-left: 3px solid var(--primary);
  text-shadow: none !important;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(10px); }
}

.container-custom.is-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0; /* Prevents 100vw scrollbar calculation bugs */
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  margin: 0;
  z-index: 9999;
  box-shadow: none;
  border-radius: 0;
}

.container-custom.is-fullscreen .tool-workspace {
  flex: 1;
  height: calc(100vh - 45px);
}

/* ==========================================
   17. CUSTOM NUMBER INPUTS FOR EXPORT
   ========================================== */
.custom-number-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.custom-number-input::-webkit-outer-spin-button,
.custom-number-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom-number-input:focus {
  border-color: var(--primary);
}

/* ==========================================
   18. SLIDER ADJUST BUTTONS (+ / -)
   ========================================== */
.slider-adjust-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-light);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s;
  text-shadow: none;
}

.slider-adjust-btn i {
  color: var(--text-light);
  font-size: 10px;
}

.slider-adjust-btn:hover {
  color: var(--primary);
  background: transparent;
}

.slider-adjust-btn:active {
  transform: scale(0.9);
}

/* ==========================================
   19. ICON SELECTORS (GRID & SHAPE)
   ========================================== */
.icon-selector-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}

.icon-selector-btn {
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  padding: 0;
  outline: none;
}

.icon-selector-btn:hover {
  border-color: var(--primary);
  background: var(--light-bg);
}

.icon-selector-btn.active {
  border-color: var(--primary);
  background: rgba(30, 182, 222, 0.1);
}

.icon-selector-btn svg {
  width: 24px;
  height: 24px;
  color: var(--text);
}

.icon-selector-btn.active svg {
  color: var(--primary);
}

/* ==========================================
   20. STITCH LEGEND TABLE STYLES (NEW)
   ========================================== */
.stitch-legend-header,
.stitch-legend-row {
  display: grid;
  grid-template-columns: 24px 45px 55px 45px 45px;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
}

.stitch-legend-header {
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 2px;
  padding-bottom: 6px;
}

.stitch-legend-row:last-child {
  border-bottom: none;
}

.stitch-legend-symbol {
  font-family: monospace;
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  text-align: center;
}

.stitch-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.stitch-legend-code {
  font-family: monospace;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
}

.stitch-legend-count,
.stitch-legend-percent {
  text-align: right;
  color: var(--text-light);
  font-family: monospace;
  white-space: nowrap;
  font-size: 10px;
}

.stitch-legend-count {
  font-weight: 500;
  color: var(--text);
}


/* ==========================================
   VIEW MODE TOGGLE (SLIDER VS TOGGLE)
   ========================================== */
.view-mode-toggle {
  position: absolute;
  bottom: 60px;
  right: 15px;
  display: flex;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 35;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.comparison-container:hover .view-mode-toggle {
  opacity: 1;
  pointer-events: auto;
}

.view-mode-btn {
  background: transparent;
  color: #ffffff;
  border: none;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s;
  text-shadow: none !important;
  box-shadow: none !important;
  transform: none !important;
  filter: none !important;
  backdrop-filter: none !important;
  font-family: inherit;
  outline: none;
}

.view-mode-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  text-shadow: none;
  color: #ffffff;
}


.view-mode-btn i {
  font-size: 12px;
}




/* ==========================================
   PATTERN INFO PANEL (PROFESSIONAL UPGRADE)
   ========================================== */
.pattern-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.info-item {
  background: var(--light-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.info-label {
  font-size: 10px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 600;
}

.info-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-family: monospace;
}

.info-note {
  font-size: 10px;
  color: var(--text-light);
  text-align: center;
  font-style: italic;
}
/* ==========================================
   PATTERN INFO STACKED VALUES
   ========================================== */
.info-value-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.info-value-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-light);
  font-family: monospace;
}



/* ==========================================
   FULLSCREEN SCROLLBAR FIX
   ========================================== */
body.tool-is-fullscreen,
html.tool-is-fullscreen {
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
}



/* ==========================================
   IMAGE PANEL ACTIONS (SAVE/LOAD)
   ========================================== */
.image-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.image-actions .action-btn {
    flex: 1;
    font-size: 11px;
    padding: 6px 4px;
}

/* ==========================================
   GRID TOGGLE ROW (SYMBOL OVERLAY)
   ========================================== */
.grid-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    background: var(--light-bg);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.grid-toggle-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
}

.grid-toggle-row .border-toggle-switch {
    margin-left: 0;
}







/* ==========================================
   CANVAS EDITING TOOLBAR
   ========================================== */
.canvas-toolbar {
  position: absolute;
  bottom: 15px;
  left: 15px;
  display: flex;
  align-items: center;
  gap: 0px; /* Removed gap to prevent clicks falling through to canvas */
  z-index: 100; /* Increased z-index to ensure it sits above zoom controls */
  background: rgba(0, 0, 0, 0.85);
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.comparison-container:hover .canvas-toolbar {
  opacity: 1;
  pointer-events: auto;
}

.canvas-tool-btn {
  background: transparent;
  color: #ffffff;
  font-size: 14px;
  padding: 6px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  width: 32px;
  height: 32px;
  text-shadow: none !important;
  box-shadow: none !important;
  pointer-events: auto; /* Force buttons to always catch clicks */
  margin: 0 2px; /* Replaced gap with margin for better click targeting */
}
.canvas-tool-btn i.ci {
 font-size: 18px;
}
.canvas-tool-btn svg {
  width: 16px;
  height: 16px;
  display: block; /* Removes inline baseline spacing issues */
  flex-shrink: 0;
}
.canvas-tool-btn:first-child {
  margin-left: 0;
}

.canvas-tool-btn:last-child {
  margin-right: 0;
}

.canvas-tool-btn:hover {
  color: #ffffff;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.15);
  text-shadow: none;
}

.canvas-tool-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.canvas-tool-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.canvas-tool-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 4px;
}

/* Cursors for tools - Added !important to override .zoomed grab cursor */
.comparison-container.tool-paint,
.comparison-container.tool-paint.zoomed { 
  cursor: crosshair !important; 
}

.comparison-container.tool-eraser,
.comparison-container.tool-eraser.zoomed { 
  cursor: crosshair !important; 
}

.comparison-container.tool-eyedropper,
.comparison-container.tool-eyedropper.zoomed { 
  cursor: crosshair !important; 
}

.comparison-container.tool-pan { 
  cursor: grab; 
}

.comparison-container.tool-pan:active { 
  cursor: grabbing; 
}

/* Legend row clickable */
.stitch-legend-row {
  cursor: pointer;
  transition: background 0.15s;
}

.stitch-legend-row:hover {
  background: var(--light-bg);
}

.stitch-legend-row.selected-color {
  background: rgba(30, 182, 222, 0.15);
  outline: 1px solid var(--primary);
}



/* ==========================================
   CUSTOM SVG CURSORS FOR PAINT TOOLS
   ========================================== */
#QuantizedCanvas {
    pointer-events: auto !important;
}

.comparison-container.tool-paint #QuantizedCanvas,
.comparison-container.tool-paint.zoomed #QuantizedCanvas {
    /* Hotspot 12 25 places the clicking point exactly at the tip of the brush */
    cursor: url("data:image/svg+xml;utf8,<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill='currentColor' d='M21.7,3.1c-1-1.1-3.1-1.1-4.1,0l-8,8.3C8.9,11.3,8,11.3,7,11.6c-1.5,0.5-2.8,1.8-3.2,3.3c-0.1,0.4-0.4,1.5,0,2.7C3.9,18,4,18.2,4.1,18.4c0.1,0.2,0.2,0.3,0.2,0.5c0.1,0.4-0.1,0.6-0.5,1.2H2.3c-0.4,0-0.8,0.5-0.8,1s0.3,0.8,0.8,0.8h1.8h3.6h1.7c0.7,0,1.4-0.2,2-0.7c1.8-1.4,2.7-3.4,2.4-5.4l8-8.3C22.8,6.1,22.7,4.3,21.7,3.1zM10.5,19.7c-0.3,0.2-0.7,0.4-1.1,0.4H7.6H5.5c0.2-0.5,0.3-0.9,0.3-1.4c-0.1-0.4-0.2-0.7-0.3-1c-0.1-0.1-0.1-0.3-0.2-0.5c-0.3-0.7-0.1-1.4,0-1.8c0.3-1.1,1.2-2,2.2-2.3s1.9-0.3,2.8,0.1c1.3,0.5,1.8,1.7,2,2.6C12.5,17.2,11.8,18.6,10.5,19.7zM20.6,6.3L13.2,14c-0.5-0.9-1.2-1.6-2-2.1l7.5-7.8c0.5-0.5,1.5-0.5,2,0C21.1,4.7,21.1,5.7,20.6,6.3z'/></svg>") 12 25, auto !important;
}

.comparison-container.tool-eraser #QuantizedCanvas,
.comparison-container.tool-eraser.zoomed #QuantizedCanvas {
    /* Hotspot 5 22 places the clicking point exactly at the bottom-left corner of the eraser */
    cursor: url("data:image/svg+xml;utf8,<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill='currentColor' d='M21.6,8.6l-6.4-6.4c-0.7-0.7-2-0.7-2.7,0L2.4,12.4c-0.7,0.7-0.7,2,0,2.7l6.4,6.4c0.7,0.7,2,0.7,2.7,0l10.1-10.2C22.3,10.6,22.3,9.3,21.6,8.6zM15,14.9l-4.2,4.2c-0.4,0.4-1,0.4-1.4,0l-4.6-4.6c-0.4-0.4-0.4-1,0-1.4L9,8.9c0.2-0.2,0.5-0.2,0.7,0l5.3,5.3C15.2,14.4,15.2,14.7,15,14.9z'/></svg>") 5 22, auto !important;
}

.comparison-container.tool-eyedropper #QuantizedCanvas,
.comparison-container.tool-eyedropper.zoomed #QuantizedCanvas {
    /* Hotspot 3 29 places the clicking point exactly at the very tip of the dropper */
    cursor: url("data:image/svg+xml;utf8,<svg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path fill='currentColor' d='M12.5,13.4l1.4,1.3l-5,4.9l-3.2,0.5l-1,1c-0.8,0.8-1.7,1-2.2,0.6l-0.2-0.2c-0.5-0.4-0.2-1.4,0.6-2.2l1-1l0.5-3.2l4.9-4.9l1.5,1.5l-4.5,4.4c-0.4,0.3-0.4,0.9,0,1.2l0.4,0.4c0.3,0.3,0.9,0.3,1.2,0L12.5,13.4zM16.8,11.3c-0.1,0.1-0.2,0.2-0.3,0.2l0.7,0.7c0.4,0.4,0.4,1,0,1.4l-0.6,0.6l-7-6.9l0.6-0.6c0.4-0.4,1-0.4,1.4,0l0.8,0.8c0.1-0.1,0.1-0.2,0.2-0.3l4.4-4.5c0.8-0.8,2.2-0.8,3,0l1.1,1.1c0.4,0.4,0.6,1,0.6,1.5c0,0.6-0.4,1.2-0.8,1.6L16.8,11.3zM20.3,6.1c0.2-0.2,0.3-0.4,0.3-0.7s-0.1-0.5-0.3-0.7l-1.1-1.1c-0.4-0.4-1-0.4-1.3,0L13.5,8c-0.1,0.1-0.2,0.2-0.2,0.3l2.3,2.3c0.1,0,0.2-0.1,0.3-0.2L20.3,6.1z'/></svg>") 3 29, auto !important;
}

.comparison-container.tool-pan #QuantizedCanvas {
    cursor: grab !important;
}

.comparison-container.tool-pan:active #QuantizedCanvas {
    cursor: grabbing !important;
}





/* ==========================================
   21. RESPONSIVE
   ========================================== */
@media (max-height: 800px) {
  .container-custom {
    margin: 10px auto;
    max-height: calc(100vh - 20px);
    border-radius: 6px;
  }
  .tool-header { padding: 6px 12px; }
  .panel-section-content { padding: 4px; }
}

@media (max-width: 900px) {
  .container-custom {
    max-height: none;
    height: auto;
    overflow: visible;
  }
  
  .tool-workspace {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }
  
  .left-panel,
  .right-panel {
    border: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
    height: auto;
  }
  
  .middle-panel {
    padding: 10px;
    overflow: visible;
    align-items: center;
  }
  
  .drop-zone {
    min-height: 300px;
  }
  
  .comparison-container {
    max-height: 60vh;
    height: 60vh;
    min-height: 300px;
    margin: 0;
  }

  .container-custom.is-fullscreen .comparison-container {
    max-height: calc(100vh - 80px);
    height: calc(100vh - 80px);
  }
}