/* Studio (v2) page-specific styles.
   Lightweight and focused on layout + key UI affordances. */

:root {
  --pe-primary: #2563eb; /* fallback; overridden by theme.css */
  --pe-bg: #f8f9fa;
  --pe-panel-bg: #ffffff;
  --pe-border: rgba(15, 23, 42, 0.12);
  --pe-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

/* Studio navbar: match homepage styling */
[data-page="studio"] .navbar {
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

[data-page="studio"] .navbar .navbar-brand .navbar-logo-wrapper {
  color: var(--pe-primary);
}

[data-page="studio"] .navbar .nav-link {
  font-weight: 600;
}

[data-page="studio"] .navbar .btn.btn-primary {
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18);
}

.studio-container {
  width: 100%;
  padding: 0;
  --studioSidebarWidth: 420px;
  height: 100%;
}

.studio-container .main-content {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

[data-page="studio"] main.flex-grow-1 {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.config-sidebar {
  width: var(--studioSidebarWidth);
  flex: 0 0 var(--studioSidebarWidth);
  max-width: 100%;
  background: var(--pe-panel-bg);
  border-right: 1px solid var(--pe-border);
  padding: 1.25rem 1.25rem 2rem;
  overflow-y: auto;
  position: relative;
}

.pane-divider {
  flex: 0 0 10px;
  width: 10px;
  cursor: col-resize;
  position: relative;
  background: linear-gradient(
    to right,
    rgba(15, 23, 42, 0.02),
    rgba(15, 23, 42, 0.06),
    rgba(15, 23, 42, 0.02)
  );
  border-left: 1px solid rgba(15, 23, 42, 0.08);
  border-right: 1px solid rgba(15, 23, 42, 0.08);
}

.pane-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.18);
}

.pane-divider:focus-visible {
  outline: 3px solid rgba(40, 167, 69, 0.35);
  outline-offset: -2px;
}

@media (max-width: 991.98px) {
  .studio-container .main-content {
    flex-direction: column;
    height: 100%;
    overflow: auto;
  }
  .config-sidebar {
    width: 100%;
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--pe-border);
    max-height: none;
    overflow: visible;
  }
}

.config-section {
  padding-top: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.config-section:last-child {
  border-bottom: 0;
}

.project-name-header .project-reset-btn {
  white-space: nowrap;
}

/* Upload zones */
.upload-zone {
  border: 2px dashed rgba(15, 23, 42, 0.18);
  border-radius: 14px;
  background: rgba(248, 249, 250, 0.7);
  padding: 1.25rem;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    transform 150ms ease;
  user-select: none;
}

.upload-zone:hover,
.upload-zone:focus-within {
  border-color: rgba(40, 167, 69, 0.55);
  background: rgba(212, 237, 218, 0.45);
  transform: translateY(-1px);
}

.upload-zone.dragover {
  border-color: rgba(40, 167, 69, 0.75);
  background: rgba(212, 237, 218, 0.7);
}

.upload-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Expandable sections */
.expandable-section .section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}

.expandable-section .section-content {
  margin-top: 0.75rem;
}

.expandable-section.collapsed .section-content {
  display: none;
}

/* Feature option blocks */
.feature-item {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  padding: 0.9rem;
  background: #fff;
}

.feature-options {
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.feature-image-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .feature-image-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.feature-image-control {
  padding: 0.75rem;
  border-radius: 12px;
  background: rgba(248, 249, 250, 0.7);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

/* Preview panel host */
.preview-panel {
  background: var(--pe-bg);
  padding: 1rem;
  overflow: hidden;
  height: 100%;
  flex: 1 1 auto;
  min-width: 0;
}

/* Make only the right tool rail scroll (icons list) */
[data-page="studio"] .threejs-preview__right-rail,
[data-page="studio"] [data-threejs="right-rail"] {
  /* Hide tool rail icons on Studio */
  display: none !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-gutter: stable;
}

/* Match reference site's visible rail scrollbar */
[data-page="studio"] .threejs-preview__right-rail,
[data-page="studio"] [data-threejs="right-rail"] {
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--pe-primary) var(--pe-bg); /* Firefox */
}

[data-page="studio"] .threejs-preview__right-rail::-webkit-scrollbar,
[data-page="studio"] [data-threejs="right-rail"]::-webkit-scrollbar {
  width: 8px;
}

[data-page="studio"]
  .threejs-preview__right-rail::-webkit-scrollbar-thumb,
[data-page="studio"]
  [data-threejs="right-rail"]::-webkit-scrollbar-thumb {
  background: var(--pe-primary);
  border-radius: 4px;
  transition: 0.2s;
}

[data-page="studio"]
  .threejs-preview__right-rail::-webkit-scrollbar-track,
[data-page="studio"]
  [data-threejs="right-rail"]::-webkit-scrollbar-track {
  background: var(--pe-bg);
  border-radius: 4px;
}

/* Ensure the tool rail reliably captures wheel/pointer events (above canvas). */
[data-page="studio"] .threejs-preview canvas[data-threejs="canvas"] {
  z-index: 1;
}

[data-page="studio"] .threejs-preview__right-rail,
[data-page="studio"] [data-threejs="right-rail"] {
  z-index: 10;
  pointer-events: auto;
}

[data-page="studio"] .threejs-preview__actions {
  pointer-events: auto;
}

/* Prevent the preview pane from becoming the scroll container */
[data-page="studio"] .threejs-preview,
[data-page="studio"] .viewer-stage,
[data-page="studio"] .book-3d-viewer {
  overflow: hidden;
}

@media (max-width: 991.98px) {
  .preview-panel {
    min-height: 520px;
    height: auto;
  }

  .pane-divider {
    display: none !important;
  }
}

/* Purchase modal overlay (custom, not Bootstrap modal) */
.purchase-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1060;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.purchase-modal-overlay[hidden] {
  display: none !important;
}

.purchase-modal {
  width: min(980px, 100%);
  max-height: min(88vh, 860px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--pe-shadow);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.purchase-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.purchase-modal-header,
.purchase-modal-body,
.purchase-modal-footer {
  padding: 1.25rem 1.25rem;
}

.purchase-modal-header {
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.purchase-modal-footer {
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.purchase-summary-card {
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(248, 249, 250, 0.7);
  border-radius: 14px;
  padding: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.purchase-summary-card-low {
  border-color: rgba(220, 53, 69, 0.35);
  background: rgba(220, 53, 69, 0.06);
}

.purchase-price-items {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
}

.purchase-price-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px dashed rgba(15, 23, 42, 0.12);
}

.purchase-price-item:last-child {
  border-bottom: 0;
}

/* Background blur when overlay open */
body.modal-blur-active > *:not(.purchase-modal-overlay) {
  filter: blur(2px);
}
