/* ==========================================================================
   Image -> Model studio (tab 2). iOS-style: frosted panels, grouped rows,
   segmented controls, switches. Uses the colour tokens from style.css, so
   light / dark themes work automatically.
   ========================================================================== */

.ai-studio {
  --ai-glass: color-mix(in srgb, var(--bg-surface) 78%, transparent);
  --ai-radius: 26px;
  --ai-gap: 12px;
  width: 100%;
  height: 100%;
  padding: var(--ai-gap);
  gap: var(--ai-gap);
  grid-template-columns: 340px minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr);
  font-family: var(--font-family);
  color: var(--text-main);
}

.ai-studio[style*="display: grid"],
.ai-studio.is-active {
  display: grid !important;
}

.ai-studio button { cursor: pointer; border: 0; background: none; }
.ai-studio button:disabled { cursor: not-allowed; }

/* ---------- Panels ---------- */
.ai-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--ai-glass);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
  border: 1px solid var(--border-color);
  border-radius: var(--ai-radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.ai-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
}

.ai-group { display: flex; flex-direction: column; gap: 10px; }

.ai-group-title {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  padding: 0 4px;
}
.ai-group-title.ai-sub { margin-top: 6px; }

/* ---------- Segmented control ---------- */
.ai-segment {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-surface-secondary);
  border-radius: 13px;
}
.ai-segment-top { margin: 14px 14px 10px; }

.ai-seg {
  flex: 1;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.ai-seg.active {
  background: var(--bg-surface);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.ai-seg:disabled { opacity: 0.5; }
[data-theme="dark"] .ai-seg.active { background: var(--bg-surface-tertiary); }

.ai-soon {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.5;
  border-radius: var(--radius-pill);
  background: var(--primary-light);
  color: var(--primary);
  vertical-align: middle;
}
.ai-soon-on-primary { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* ---------- Drop zone & view slots ---------- */
.ai-drop {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.12;
  border-radius: 20px;
  background: var(--bg-surface-secondary);
  border: 1.5px dashed var(--border-color-strong);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}
.ai-drop:hover, .ai-drop.is-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.ai-drop.is-over { transform: scale(0.99); }

.ai-drop-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
}
.ai-drop-empty strong { font-size: 0.9375rem; font-weight: 600; color: var(--text-main); }
.ai-drop-empty span { font-size: 0.75rem; color: var(--text-muted); }
.ai-drop-preview { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.ai-drop-preview[hidden], .ai-drop-empty[hidden] { display: none; }

.ai-views {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ai-view-slot {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--bg-surface-secondary);
  border: 1px dashed var(--border-color-strong);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.18s ease;
}
.ai-view-slot:hover { border-color: var(--primary); }
.ai-view-slot span {
  position: relative;
  z-index: 1;
  margin-bottom: 6px;
  padding: 1px 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--bg-surface) 80%, transparent);
}
.ai-view-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 4px 4px 22px; }
.ai-view-slot img[hidden] { display: none; }
.ai-views.is-off { opacity: 0.45; pointer-events: none; }

/* ---------- Rows ---------- */
.ai-row {
  padding: 12px 14px;
  background: var(--bg-surface-secondary);
  border-radius: 16px;
}
.ai-row-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-row-text span { font-size: 0.9375rem; font-weight: 500; }
.ai-row-text small { font-size: 0.75rem; color: var(--text-muted); line-height: 1.3; }
.ai-row-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.ai-row-head label { font-size: 0.9375rem; font-weight: 500; }
.ai-row-head output { font-size: 0.875rem; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; }
.ai-row-slider input[type="range"] { width: 100%; }

/* iOS switch */
.ai-switch { position: relative; flex-shrink: 0; width: 51px; height: 31px; }
.ai-switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.ai-switch span {
  position: absolute; inset: 0;
  border-radius: 31px;
  background: var(--bg-surface-hover);
  transition: background 0.22s ease;
}
.ai-switch span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.22s cubic-bezier(0.3, 0.9, 0.3, 1);
}
.ai-switch input:checked + span { background: var(--success); }
.ai-switch input:checked + span::after { transform: translateX(20px); }
.ai-switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Footer / primary button ---------- */
.ai-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-color);
}
.ai-eta { font-size: 0.8125rem; color: var(--text-muted); white-space: nowrap; }
.ai-primary {
  flex: 1;
  min-height: 50px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-size: 1.0625rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 40%, transparent);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}
.ai-primary:hover:not(:disabled) { filter: brightness(1.08); }
.ai-primary:active:not(:disabled) { transform: scale(0.98); }
.ai-primary:disabled { opacity: 0.55; box-shadow: none; }

/* ---------- Centre stage ---------- */
.ai-center {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: var(--ai-radius);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background:
    radial-gradient(120% 90% at 50% 40%, color-mix(in srgb, var(--bg-surface) 96%, #fff) 0%, var(--bg-surface) 55%, var(--bg-surface-secondary) 100%);
  box-shadow: var(--shadow-md);
}
.ai-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.ai-stage-empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 280px; text-align: center; color: var(--text-muted);
}
.ai-stage-empty strong { font-size: 1.0625rem; font-weight: 600; color: var(--text-secondary); }
.ai-stage-empty span { font-size: 0.875rem; }
.ai-stage canvas { width: 100%; height: 100%; display: block; }

.ai-stats {
  position: absolute;
  top: 14px; left: 14px;
  z-index: 2;
  min-width: 190px;
  padding: 10px 14px;
  display: grid;
  gap: 6px;
  background: var(--ai-glass);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  font-size: 0.8125rem;
}
.ai-stats > div { display: flex; justify-content: space-between; gap: 16px; }
.ai-stats span { color: var(--text-muted); }
.ai-stats strong { font-weight: 600; font-variant-numeric: tabular-nums; }

.ai-dock {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  z-index: 2;
  display: flex; gap: 6px;
  padding: 6px;
  background: var(--ai-glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
}
.ai-dock-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border-radius: var(--radius-pill);
  font-size: 0.9375rem; font-weight: 600;
  color: var(--text-main);
  transition: background 0.15s ease, opacity 0.15s ease;
}
.ai-dock-btn:hover:not(:disabled) { background: var(--bg-surface-secondary); }
.ai-dock-btn:disabled { opacity: 0.4; }
.ai-dock-primary { background: var(--primary); color: #fff; }
.ai-dock-primary:hover:not(:disabled) { background: var(--primary-hover); }

/* ---------- Right panel ---------- */
.ai-right .ai-scroll { padding-top: 14px; }
.ai-engines { display: flex; flex-direction: column; gap: 8px; }
.ai-engine {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 16px;
  background: var(--bg-surface-secondary);
  border: 1.5px solid transparent;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.ai-engine.active { border-color: var(--primary); background: var(--primary-light); }
.ai-engine:disabled { opacity: 0.55; }
.ai-engine-name { font-size: 0.9375rem; font-weight: 600; }
.ai-engine-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.3; }

.ai-library { display: flex; flex-direction: column; gap: 8px; }
.ai-library-empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 120px; padding: 16px;
  text-align: center;
  font-size: 0.8125rem; color: var(--text-muted);
  border: 1.5px dashed var(--border-color-strong);
  border-radius: 16px;
}

/* ---------- Narrow screens ---------- */
@media (max-width: 1100px) {
  .ai-studio {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    overflow-y: auto;
  }
  .ai-center { min-height: 420px; }
  .ai-panel { max-height: none; }
}

/* ---------- Forma Lite: viewport, library, status ---------- */
.ai-viewport { position: absolute; inset: 0; }
.ai-viewport canvas { width: 100%; height: 100%; display: block; }
.ai-stage-empty { position: relative; z-index: 1; pointer-events: none; }
.ai-stage.has-model .ai-stage-empty { display: none; }

.ai-eta { white-space: normal; line-height: 1.3; max-width: 130px; font-size: 0.75rem; }
.ai-eta[data-kind="ok"] { color: var(--success); }
.ai-eta[data-kind="error"] { color: var(--danger); }

.ai-dock-btn.is-on { background: var(--primary-light); color: var(--primary); }

.ai-lib-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px;
  text-align: left;
  border-radius: 16px;
  background: var(--bg-surface-secondary);
  border: 1.5px solid transparent;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.ai-lib-item:hover { background: var(--bg-surface-tertiary); }
.ai-lib-item.active { border-color: var(--primary); background: var(--primary-light); }
.ai-lib-item img {
  width: 48px; height: 48px; flex-shrink: 0;
  object-fit: contain;
  border-radius: 12px;
  background: var(--bg-surface);
}
.ai-lib-item span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-lib-item strong { font-size: 0.875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-lib-item small { font-size: 0.75rem; color: var(--text-muted); }
