/* ==========================================================================
   EDITOR STUDIO MODULE STYLES - MODERN WHATSAPP-LIKE UI
   ========================================================================== */

/* --------------------------------------------------------------------------
   Root & Main Layout
   -------------------------------------------------------------------------- */
.module-root {
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: #000;
  display: flex;
  flex-direction: column;
  /* width: 100%; <-- REMOVED to allow margins to shrink it */
}

.module-root.editor-module-root {
  --editor-top-right-top: 71px;
  --editor-top-right-offset: 35px;
  --editor-close-btn-size: 36px;
  --editor-close-gap: 8px;
}

.module-surface {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* --------------------------------------------------------------------------
   Top Bar (Header)
   -------------------------------------------------------------------------- */
.editor-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3000;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0) 100%);
  pointer-events: none; /* Let clicks pass through empty areas */
}

/* Reserve space for scrollbars so right pills never get blocked */
.editor-module-root,
.editor-module-root .module-surface,
.editor-module-root .editor-container {
  scrollbar-gutter: stable both-edges;
}

/* Add right padding to keep pills clear of scrollbars */
.editor-module-root .editor-top-bar {
  padding-right: 28px;
}

.editor-top-bar {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.editor-top-bar.editor-top-bar--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.editor-top-bar > * {
  pointer-events: auto; /* Re-enable clicks on buttons */
}

.editor-action-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.editor-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.editor-action-btn img {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.editor-header-tools {
  display: flex;
  gap: 16px;
  align-items: center;
}

/* --------------------------------------------------------------------------
   Canvas & Image Area
   -------------------------------------------------------------------------- */
.editor-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  width: 100%;
  height: 100%;
}

.editor-image-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Max dimensions handled by JS logic */
}

/* --------------------------------------------------------------------------
   Floating Controls (Vertical Sliders)
   -------------------------------------------------------------------------- */
.editor-controls-layer {
  position: absolute;
  inset: 0;
  z-index: 2900;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  padding: 60px 12px 20px 12px; /* Top padding clears the header */
}

.editor-control-column {
  display: flex;
  flex-direction: column;
  justify-content: center;
  pointer-events: auto;
  gap: 20px;
}

/* Right Side: Color Slider */
.editor-color-slider-container {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.color-swatch.active {
  transform: scale(1.2);
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.5);
}

/* Left Side: Thickness Slider */
.editor-thickness-slider-container {
  height: 200px;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  position: relative;
}

.editor-thickness-slider {
  appearance: none;
  -webkit-appearance: none;
  width: 180px; /* Width becomes height when rotated */
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  outline: none;
  transform: rotate(-90deg);
  transform-origin: center;
}

.editor-thickness-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* --------------------------------------------------------------------------
   Text Input Styles
   -------------------------------------------------------------------------- */
.editor-text-pill {
  position: absolute;
  /* Removed background/border for transparent default style */
  background: transparent;
  border: 1px dashed rgba(255,255,255,0.3); /* Subtle guide border */
  border-radius: 8px;
  padding: 8px;
  min-width: 60px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  /* Ensure text doesn't overflow */
  max-width: 80vw;
}

.editor-text-pill.editing, 
.editor-text-pill:hover,
.editor-text-pill.selected {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(4px);
}

.editor-text-area {
  background: transparent;
  border: none;
  color: #fff;
  text-align: center;
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  outline: none;
  resize: none;
  overflow: hidden;
  width: 100%;
  height: 100%;
  padding: 4px;
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   Quality Pill & Dropdown
   -------------------------------------------------------------------------- */
.editor-quality-pill {
  display: flex;
  overflow: hidden;
  max-width: 220px;
  background: rgba(5,5,5,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 16px;
  color: white;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease, right 0.3s ease;
  border: 1px solid rgba(255,255,255,0.2);
  /* Default glowing animation state */
  box-shadow: 0 0 8px rgba(100, 100, 255, 0.3), 0 0 16px rgba(100, 100, 255, 0.15), 0 6px 20px rgba(0,0,0,0.4);
  animation: glowPulse 3s ease-in-out infinite;
  letter-spacing: 0.3px;
  white-space: nowrap;
  
  position: absolute;
  top: calc(var(--editor-top-right-top, 71px) + env(safe-area-inset-top, 0px));
  right: calc(var(--editor-top-right-offset, 35px) + var(--editor-close-btn-size, 36px) + var(--editor-close-gap, 8px));
  z-index: 3001;
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-quality-pill:hover {
  background: rgba(30,30,30,0.95);
  border-color: rgba(255,255,255,0.4);
}

@keyframes glowPulse {
  0% { box-shadow: 0 0 8px rgba(100, 100, 255, 0.3), 0 0 16px rgba(100, 100, 255, 0.15); border-color: rgba(255,255,255,0.2); }
  50% { box-shadow: 0 0 12px rgba(100, 100, 255, 0.5), 0 0 24px rgba(100, 100, 255, 0.3); border-color: rgba(255,255,255,0.5); }
  100% { box-shadow: 0 0 8px rgba(100, 100, 255, 0.3), 0 0 16px rgba(100, 100, 255, 0.15); border-color: rgba(255,255,255,0.2); }
}

.editor-quality-dropdown {
  display: none;
  position: absolute;
  top: calc(var(--editor-top-right-top, 71px) + env(safe-area-inset-top, 0px) + 40px);
  right: calc(var(--editor-top-right-offset, 35px) + var(--editor-close-btn-size, 36px) + var(--editor-close-gap, 8px));
  background: rgba(15,15,15,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  min-width: 240px;
  z-index: 3002;
  flex-direction: column;
  gap: 4px;
}

.editor-quality-option {
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #ccc;
  font-family: system-ui, -apple-system, sans-serif;
}

.editor-quality-option .header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.editor-quality-option .sub-pill {
  display: inline-block;
  font-size: 10px;
  background: rgba(255,255,255,0.1);
  padding: 2px 8px;
  border-radius: 4px;
  align-self: flex-start;
  opacity: 0.9;
  color: #7fd4ff; /* light blue for resolution numbers */
  font-weight: 500;
}

.editor-quality-option.selected .sub-pill {
  background: rgba(255,255,255,0.2);
  opacity: 1;
}

/* Special shine effect for HIGH resolution */
.editor-quality-option[data-mode="DEEP_THINKING_4K"] .sub-pill {
  background: linear-gradient(135deg, rgba(255,215,0,0.2), rgba(255,165,0,0.3));
  border: 1px solid rgba(255,215,0,0.3);
  color: #ffd700;
  box-shadow: 0 0 8px rgba(255,215,0,0.2);
}

.editor-quality-option:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.editor-quality-option.selected {
  background: #444;
  color: #fff;
  font-weight: 500;
}

.editor-quality-option .cost {
  font-size: 11px;
  opacity: 0.7;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   Quality Pill - Push when capsule panel is open
   -------------------------------------------------------------------------- */
.main-content.generations-open .editor-quality-pill {
  right: calc(var(--capsule-panel-width, 242px) + 35px);
}

.main-content.generations-open .editor-quality-dropdown {
  right: calc(var(--capsule-panel-width, 242px) + 35px);
}

/* --------------------------------------------------------------------------
   Sidebar Integration (desktop)
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  /* Match Viewpoint Studio logic: Target class inside .main-content directly */
  .sidebar.open ~ .main-content .editor-module-root {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Capsule panel logic */
  .main-content.generations-open .editor-module-root {
    margin-right: var(--capsule-panel-width);
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Combined panels logic */
  .sidebar.open ~ .main-content.generations-open .editor-module-root {
    margin-left: var(--sidebar-width);
    margin-right: var(--capsule-panel-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Adjust floating controls to respect right panel */
  .main-content.generations-open .editor-module-root .editor-controls-layer,
  body.workspace-mode .main-content.generations-open .editor-module-root .editor-controls-layer {
    padding-right: 12px !important; /* Reset to default since container shrinks */
  }

  /* CRITICAL FIX: Reset inner surface margins to prevent double-indentation from combined.css */
  .sidebar.open ~ .main-content .editor-module-root .module-surface,
  .main-content.generations-open .editor-module-root .module-surface,
  .sidebar.open ~ .main-content.generations-open .editor-module-root .module-surface,
  body.workspace-mode .editor-module-root .module-surface {
    margin: 0 !important;
    width: 100% !important;
  }
}

/* --------------------------------------------------------------------------
   Mobile Responsive Overrides
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .editor-top-bar {
    padding: 16px;
  }
  
  .editor-action-btn img {
    width: 28px; /* Larger targets */
    height: 28px;
  }
  
  .editor-controls-layer {
    padding-top: 70px; /* More clearance */
  }
  
  .color-swatch {
    width: 32px; /* Larger touch targets */
    height: 32px;
  }
  
  .editor-text-pill {
    padding: 12px; /* Easier to tap */
  }
}

/* --------------------------------------------------------------------------
   Loading Spinner
   -------------------------------------------------------------------------- */
.image-loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #fff;
  font-family: system-ui, -apple-system, sans-serif;
  z-index: 100;
  pointer-events: none;
}

.spinner-wheel {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
}

.loading-text {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.8;
  letter-spacing: 0.5px;
}

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

.fade-in-image {
  opacity: 0;
  transition: opacity 0.5s ease-out;
}

.fade-in-image.visible {
  opacity: 1 !important;
}
