/* ============================================================
   ImageMaker3D — Bambu Studio Slicer-Style Dark Theme
   ============================================================ */
:root {
  --bg-0: #121418;
  --bg-1: #1a1d24;
  --bg-card: #222630;
  --bg-card-header: #282d38;
  --bg-card-header-hover: #2f3542;
  --bg-input: #151820;
  --border: #2e3340;
  --border-input: #383e4e;
  --text-0: #f2f4f8;
  --text-1: #a8b0c2;
  --text-2: #6c7385;
  --accent: #00ae42;
  /* Signature Bambu Studio Green */
  --accent-hover: #00c74d;
  --accent-gradient: linear-gradient(135deg, #00ae42, #008a34);
  --accent-soft: rgba(0, 174, 66, 0.18);
  --radius: 8px;
  --header-h: 56px;
  --sidebar-w: 350px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Header ---------------- */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #181b22;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 8px rgba(0, 174, 66, 0.35));
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .3px;
  background: linear-gradient(90deg, #ffffff 40%, var(--accent) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.tagline {
  font-size: 11px;
  color: var(--text-1);
  letter-spacing: .2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------------- Workspace Split (Critical Layout) ---------------- */
.workspace {
  display: flex;
  height: calc(100vh - var(--header-h));
  max-height: calc(100vh - var(--header-h));
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* ---------------- Left Panel: Slicer Process Style ---------------- */
.panel {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow-y: scroll !important; /* Always show vertical scrollbar for all dropdowns */
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  padding: 14px 12px 140px 14px; /* Generous 140px bottom buffer so every option scrolls fully above the bottom */
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* Visible, modern desktop slicer scrollbar */
.panel::-webkit-scrollbar {
  width: 10px;
}

.panel::-webkit-scrollbar-track {
  background: #13161c;
  border-left: 1px solid var(--border);
}

.panel::-webkit-scrollbar-thumb {
  background: #475066;
  border-radius: 6px;
  border: 2px solid #13161c;
  transition: background .2s ease;
}

.panel::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.panel {
  scrollbar-width: auto;
  scrollbar-color: #475066 #13161c;
}

/* ---------------- Cards & Accordions ---------------- */
.accordion {
  flex-shrink: 0 !important; /* CRITICAL: Never shrink, squeeze, or reduce the dropdown cards! */
  height: auto !important;
  min-height: min-content !important;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  transition: border-color .15s ease, box-shadow .15s ease;
  box-sizing: border-box;
}

.accordion:hover {
  border-color: #3c4354;
}

.accordion[open] {
  height: auto !important;
  min-height: min-content !important;
}

.accordion[open] > .section-body {
  height: auto !important;
  min-height: min-content !important;
  overflow: visible !important; /* Keep all controls fully visible, never clipped */
}

.accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--text-0);
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-header);
  border-bottom: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}

.accordion summary:hover {
  background: var(--bg-card-header-hover);
}

.accordion[open] summary {
  border-bottom-color: var(--border);
}

.accordion summary::-webkit-details-marker {
  display: none;
}

.accordion-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chevron-icon {
  color: var(--accent);
  transition: transform .2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.accordion[open] .chevron-icon {
  transform: rotate(90deg);
}

.section-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------------- Controls & Typography ---------------- */
.control {
  display: flex;
  flex-direction: column;
}

.control label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  font-weight: 600;
  color: #e0e4ec;
  margin-bottom: 6px;
  letter-spacing: .1px;
}

.control label .sub {
  font-weight: 400;
  color: var(--text-2);
  font-size: 11px;
}

.hint {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.45;
  margin-top: 5px;
}

.hint.mono {
  font-family: "JetBrains Mono", Consolas, monospace;
  color: var(--text-1);
}

.control-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.control-row>div {
  flex: 1;
}

.control-row label {
  margin-bottom: 0;
}

/* ---------------- Sliders & Numbers Side-by-Side ---------------- */
.slider-num-group {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.slider-num-group input[type="range"] {
  flex: 1;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #13151c;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #181b22;
  box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0, 174, 66, 0.45);
  transition: transform .12s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.18);
  background: var(--accent-hover);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #181b22;
  cursor: pointer;
}

.control-num-input {
  width: 52px;
  height: 27px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  padding: 2px 6px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.control-num-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.num-unit-wrap {
  display: inline-flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 0 6px 0 2px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.num-unit-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.num-unit-wrap .control-num-input {
  border: none;
  background: transparent;
  width: 46px;
  padding: 2px 4px;
}

.num-unit-wrap .unit {
  font-size: 11px;
  color: var(--text-2);
  font-weight: 600;
  user-select: none;
}

/* ---------------- File Upload Pill ---------------- */
.file-upload-wrapper {
  position: relative;
  width: 100%;
}

.file-input-hidden {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.file-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px dashed var(--border-input);
  border-radius: 7px;
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-upload-btn:hover {
  background: #1b1f2a;
  border-color: var(--accent);
  color: #fff;
}

.file-upload-btn svg {
  color: var(--accent);
}

/* ---------------- Side-by-Side Source Buttons ---------------- */
.source-buttons-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.source-buttons-row .file-upload-wrapper {
  flex: 1.1;
  min-width: 0;
}

.gallery-toggle-btn {
  flex: 0.9;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 7px;
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
  user-select: none;
  white-space: nowrap;
}

.gallery-toggle-btn svg {
  color: var(--accent);
  flex-shrink: 0;
}

.gallery-toggle-btn:hover,
.gallery-toggle-btn.active {
  background: #242936;
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 174, 66, 0.2);
}

/* Dropdown Thumbnail List (Compact Slicer Style) */
.defaults-dropdown {
  margin-top: 8px;
  background: #161922;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  animation: fadeInDown 0.15s ease-out;
  max-height: 240px;
  overflow-y: auto;
}

.defaults-dropdown::-webkit-scrollbar {
  width: 5px;
}

.defaults-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.defaults-dropdown::-webkit-scrollbar-thumb {
  background: #2a3142;
  border-radius: 4px;
}

.defaults-dropdown::-webkit-scrollbar-thumb:hover {
  background: #3a4359;
}

.defaults-grid {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.default-thumb-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.default-thumb-card:hover {
  border-color: var(--border);
  background: #202533;
}

.default-thumb-card.active {
  border-color: var(--accent);
  background: rgba(0, 174, 66, 0.14);
}

.default-thumb-img {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #0d111b;
  flex-shrink: 0;
}

.default-thumb-title {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-1);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.default-thumb-card.active .default-thumb-title {
  color: #fff;
  font-weight: 600;
}

/* ---------------- Palette Rows ---------------- */
.palette {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.palette-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
}

.palette-row .swatch-label {
  flex: 1;
  font-size: 11.5px;
  color: var(--text-1);
  display: flex;
  justify-content: space-between;
}

.palette-row .swatch-label b {
  color: var(--text-0);
  font-weight: 600;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 26px;
  border: 1px solid var(--border-input);
  border-radius: 5px;
  background: none;
  cursor: pointer;
  padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* Per-color Z-step inputs */
.zstep-input-wrap {
  display: inline-flex;
  align-items: center;
  background: #1b1e27;
  border: 1px solid var(--border-input);
  border-radius: 5px;
  padding: 1px 5px;
  gap: 2px;
  flex-shrink: 0;
}

.zstep-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.zstep-input {
  width: 40px;
  background: transparent;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 11.5px;
  text-align: right;
  outline: none;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.zstep-input::-webkit-inner-spin-button,
.zstep-input::-webkit-outer-spin-button {
  opacity: 0.8;
}

.zstep-input-wrap .unit {
  font-size: 10px;
  color: var(--text-2);
  font-weight: 600;
  user-select: none;
}

/* ---------------- Toggle Switch ---------------- */
.switch {
  position: relative;
  width: 42px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 22px;
  transition: .2s;
  cursor: pointer;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: var(--text-1);
  border-radius: 50%;
  transition: .2s;
}

.switch input:checked+.slider {
  background: rgba(0, 174, 66, 0.28);
  border-color: var(--accent);
}

.switch input:checked+.slider::before {
  transform: translateX(20px);
  background: var(--accent);
}

/* ---------------- Segmented Pill Controls ---------------- */
.mode-toggle-group,
.format-select-group {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 7px;
  padding: 3px;
  gap: 3px;
}

.mode-toggle-btn,
.format-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 5px;
  color: var(--text-1);
  padding: 6px 8px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}

.mode-toggle-btn:hover,
.format-btn:hover {
  color: var(--text-0);
  background: rgba(255, 255, 255, 0.04);
}

.mode-toggle-btn.active,
.format-btn.active {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 174, 66, 0.35);
}

/* ---------------- Buttons ---------------- */
.history-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: 7px;
  padding: 8px 15px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s, background .15s, opacity .15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-icon {
  padding: 7px 11px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 3px 14px rgba(0, 174, 66, 0.35);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 5px 20px rgba(0, 174, 66, 0.55);
  filter: brightness(1.08);
}

.btn-secondary {
  background: #242934;
  color: var(--text-0);
  border: 1px solid var(--border-input);
}

.btn-secondary:hover:not(:disabled) {
  background: #2d3342;
  border-color: var(--accent);
  color: #fff;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none !important;
  transform: none !important;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: 13.5px;
}

/* ---------------- Magic Background Remover ---------------- */
.bg-remove-control {
  background: rgba(30, 36, 48, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.bg-remove-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bg-remove-header label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-0);
  letter-spacing: .2px;
}

.badge-smart {
  font-size: 9.5px;
  font-weight: 800;
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border: 1px solid rgba(129, 140, 248, 0.35);
  border-radius: 4px;
  padding: 1.5px 6px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.bg-remove-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-magic {
  flex: 1;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #db2777 100%);
  color: #fff;
  box-shadow: 0 3px 14px rgba(124, 58, 237, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.btn-magic:hover:not(:disabled) {
  box-shadow: 0 5px 22px rgba(124, 58, 237, 0.6);
  filter: brightness(1.1);
}

.btn-magic svg {
  animation: pulse-wand 3s ease-in-out infinite;
}

@keyframes pulse-wand {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.15) rotate(6deg); }
}

.bg-remove-progress {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: #a5b4fc;
  background: rgba(79, 70, 229, 0.15);
  border: 1px solid rgba(129, 140, 248, 0.3);
  border-radius: 6px;
  padding: 6px 10px;
}

.spinner-small {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(165, 180, 252, 0.25);
  border-top-color: #a5b4fc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ---------------- Right Viewport ---------------- */
.viewport {
  position: relative;
  flex: 1;
  height: calc(100vh - var(--header-h));
  background: radial-gradient(ellipse at 50% 40%, #151922 0%, var(--bg-0) 75%);
  overflow: hidden;
}

.viewport canvas {
  display: block;
}

.stats {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  background: rgba(24, 27, 34, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  pointer-events: none;
}

.stats b {
  color: var(--text-0);
}

.pip {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  background: rgba(24, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
}

.pip-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-2);
}

#pipCanvas {
  width: 208px;
  border-radius: 5px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
  background-color: #0f131a;
  background-image:
    linear-gradient(45deg, #191f2b 25%, transparent 25%),
    linear-gradient(-45deg, #191f2b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #191f2b 75%),
    linear-gradient(-45deg, transparent 75%, #191f2b 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
}

.viewport-hint {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 5;
  font-size: 11px;
  color: var(--text-2);
  background: rgba(24, 27, 34, 0.75);
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ---------------- Toast Notification ---------------- */
.toast-notification {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 100;
  background: rgba(24, 27, 34, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  color: var(--text-0);
  padding: 10px 16px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: 320px;
}

.toast-notification.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-notification.error {
  border-left-color: #ff3b69;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .workspace {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
  }

  .panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .viewport {
    min-height: 60vh;
    height: 60vh;
  }

  html,
  body {
    overflow: auto;
  }
}