:root {
  --bg: #0f0e12;
  --panel: #1a1820;
  --sidebar: #141218;
  --border: #2e2a38;
  --text: #f3eef8;
  --muted: #9a90a8;
  --accent: #c77dff;
  --accent2: #ff6bcb;
  --danger: #ff5c7a;
  --ok: #6bcB8a;
  --radius: 12px;
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 64px;
  --sidebar-ease: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body, .app-body {
  margin: 0;
  background: radial-gradient(1200px 600px at 30% -10%, #2a1638 0%, var(--bg) 50%);
  color: var(--text);
  min-height: 100vh;
}

/* —— App shell (admin-style) —— */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.65rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  overflow: hidden;
  transition: width var(--sidebar-ease), padding var(--sidebar-ease);
  will-change: width;
}
.sidebar-top {
  display: flex;
  align-items: center;
  margin-bottom: 0.65rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
  min-height: 2.75rem;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.35rem;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  color: #1a0f20;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  /* optical: cap-height sits slightly high in the box */
  padding-top: 1px;
  box-sizing: border-box;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
  overflow: hidden;
  opacity: 1;
  max-width: 140px;
  transition: opacity 0.18s ease, max-width var(--sidebar-ease), margin var(--sidebar-ease);
}
.brand-atelier {
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand-ai {
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-collapse {
  flex-shrink: 0;
  width: 100%;
  height: 1.85rem;
  margin: 0 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, width var(--sidebar-ease);
}
.sidebar-collapse:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(199, 125, 255, 0.35);
}
.collapse-ico {
  font-size: 0.95rem;
  line-height: 1;
  transition: transform var(--sidebar-ease);
  display: inline-block;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}
.side-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, padding var(--sidebar-ease);
}
.side-nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.side-nav-item.active {
  color: var(--text);
  border-color: rgba(199, 125, 255, 0.35);
  background: rgba(199, 125, 255, 0.12);
}
.nav-ico {
  flex-shrink: 0;
  opacity: 0.85;
  width: 1.25rem;
  text-align: center;
  font-size: 0.95rem;
}
.nav-label {
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  max-width: 120px;
  transition: opacity 0.16s ease, max-width var(--sidebar-ease);
}
.sidebar-foot {
  padding: 0.65rem 0.25rem 0.35rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.user-block {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.15rem 0.2rem;
}
.user-avatar {
  flex-shrink: 0;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 999px;
  background: linear-gradient(145deg, #3a2a48, #1e1828);
  border: 1px solid rgba(199, 125, 255, 0.4);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(15, 14, 18, 0.6);
  box-sizing: border-box;
}
.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-avatar-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0;
  user-select: none;
  /* optical vertical balance for single capital */
  padding-top: 1px;
  box-sizing: border-box;
}
.user-meta {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  opacity: 1;
  max-width: 160px;
  transition: opacity 0.16s ease, max-width var(--sidebar-ease);
}
.sidebar-foot .user {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
.user a { color: var(--accent); }

/* Collapsed: icons only (desktop) */
.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .side-nav-section-label {
  display: none;
}
.sidebar.collapsed .user-meta {
  display: none;
}
.sidebar.collapsed .side-nav-item {
  justify-content: center;
  padding: 0.65rem 0;
  gap: 0;
}
.sidebar.collapsed .sidebar-top {
  justify-content: center;
  width: 100%;
  min-height: 2.5rem;
  padding-bottom: 0.55rem;
  margin-bottom: 0.55rem;
}
.sidebar.collapsed .brand {
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 0 0 auto;
  gap: 0;
  padding: 0;
  margin: 0 auto;
}
.sidebar.collapsed .brand-mark {
  margin: 0 auto;
}
.sidebar.collapsed .collapse-ico {
  transform: rotate(180deg);
}
.sidebar.collapsed .sidebar-collapse {
  width: 2.15rem;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 0.55rem;
}
.sidebar.collapsed .user-block {
  justify-content: center;
  align-items: center;
  width: 100%;
  gap: 0;
  padding: 0;
  margin: 0;
}
.sidebar.collapsed .user-avatar {
  margin: 0 auto;
}
.sidebar.collapsed .sidebar-foot {
  align-items: center;
  width: 100%;
  padding-left: 0;
  padding-right: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view-top {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 14, 18, 0.75);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  z-index: 10;
}
.view-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}
.view-sub { margin: 0; font-size: 0.82rem; }
.sidebar-toggle { display: none; }

.view { display: none; flex: 1; min-height: 0; overflow: hidden; }
.view.active { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#view-history.active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
#view-studio.active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.studio-layout {
  display: grid;
  /* Fill full main width (match History / Monitor full-bleed) */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 1rem 1.25rem;
  padding: 1rem 1.5rem 1.5rem;
  max-width: none;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  align-items: stretch;
  overflow: hidden;
  box-sizing: border-box;
}
.studio-layout .panel.source {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.studio-layout .panel.studio {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (max-width: 1000px) {
  .studio-layout {
    grid-template-columns: 1fr;
    overflow: auto;
    height: auto;
    max-height: none;
  }
  .studio-layout .panel.source,
  .studio-layout .panel.studio {
    max-height: none;
    overflow: visible;
  }
}
@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    left: 0;
    width: var(--sidebar-w) !important;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  /* On mobile, use drawer open state — not icon-rail collapse */
  .sidebar.collapsed {
    width: var(--sidebar-w) !important;
  }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .user-meta {
    opacity: 1;
    max-width: 160px;
    pointer-events: auto;
  }
  .sidebar.collapsed .side-nav-item {
    justify-content: flex-start;
    padding: 0.6rem 0.7rem;
    gap: 0.65rem;
  }
  .sidebar.collapsed .collapse-ico { transform: none; }
  .sidebar.collapsed .sidebar-collapse {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
  .sidebar.collapsed .user-block { justify-content: flex-start; }
  .sidebar-collapse { display: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.5); }
  .sidebar-toggle { display: inline-flex; }
  body.nav-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 15;
  }
}

.page-panel {
  padding: 1rem 1.25rem 1.75rem;
  max-width: 1200px;
}
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-h {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}
.page-desc { margin: 0; font-size: 0.85rem; }
.history-page { max-height: none; }
.monitor-page { max-height: none; }
/* Full-bleed monitor (same idea as history-page-panel) */
.monitor-page-panel {
  max-width: none;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  padding: 1rem 1.5rem 1.5rem;
}
#view-monitor.active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
#view-monitor .monitor-tabs {
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
#view-monitor #monitorStatus {
  flex-shrink: 0;
}
.results-heading {
  margin-top: 1.25rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.25rem;
}
.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tabs { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}
.tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(199, 125, 255, 0.12);
}
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Studio mode: Edit polish | Generate photoshoot */
.studio-mode-tabs {
  margin-bottom: 0.5rem;
}
.studio-mode-tabs .tab {
  font-weight: 600;
}
.studio-mode-hint {
  margin: 0 0 0.85rem;
  line-height: 1.4;
  font-size: 0.9rem;
}
.studio-mode-pane.hidden {
  display: none !important;
}
.studio-mode-pane.active {
  display: block;
}
.photoshoot-intro {
  margin: 0 0 0.75rem;
  line-height: 1.45;
  font-size: 0.9rem;
}
.scenes-block {
  margin-bottom: 0.85rem;
  min-width: 0;
  max-width: 100%;
}
.scenes-block .preset-cat {
  margin-bottom: 0.55rem;
  min-width: 0;
}
#photoshootPrompt {
  min-height: 10rem;
  font-size: 0.92rem;
  line-height: 1.45;
  resize: vertical;
  width: 100%;
  max-width: 100%;
}

.drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  padding: 1rem;
  text-align: center;
}
.drop:hover { border-color: var(--accent); color: var(--text); }
.preview-wrap {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #000;
  cursor: zoom-in;
  position: relative;
  overflow: hidden;
}
.preview-wrap:hover .preview-hint { opacity: 1; }
.preview {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
  vertical-align: middle;
}
.preview-hint {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  font-size: 0.7rem;
  color: #fff;
  background: rgba(0,0,0,0.55);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  opacity: 0.75;
  pointer-events: none;
}
.source-meta {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-all;
}
.source-meta strong { color: var(--text); font-weight: 600; }

.immich-filters { align-items: end; margin-bottom: 0.5rem; }
.field.compact { margin: 0; min-width: 8rem; }
.people-filter { margin-bottom: 0.65rem; }
.people-label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.35rem; }
.people-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 7.5rem;
  overflow: auto;
}
.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: #121018;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.65rem 0.25rem 0.25rem;
  cursor: pointer;
  font-size: 0.82rem;
}
.person-chip img {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  object-fit: cover;
  background: #000;
}
.person-chip.on {
  color: #1a0f20;
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  font-weight: 600;
}
.person-chip.on img { box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.immich-groups { max-height: 380px; overflow: auto; display: flex; flex-direction: column; gap: 0.85rem; }
.immich-date {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.35rem;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--panel), rgba(26,24,32,0.92));
  padding: 0.25rem 0;
  z-index: 1;
}
.results figure { position: relative; }
.results img { cursor: zoom-in; }
.results .zoom-hint {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  font-size: 0.65rem;
  color: #fff;
  background: rgba(0,0,0,0.5);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  pointer-events: none;
}
.hidden { display: none !important; }

/* —— Lightbox / fullscreen viewer —— */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.lightbox.hidden { display: none !important; }
.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 4, 10, 0.92);
  backdrop-filter: blur(6px);
}
.lb-close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  z-index: 5;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.lb-close:hover { background: rgba(255,255,255,0.22); }
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1.75rem;
  cursor: pointer;
}
.lb-nav:hover { background: rgba(255,255,255,0.2); }
.lb-nav:disabled { opacity: 0.25; cursor: default; }
.lb-prev { left: 0.75rem; }
.lb-next { right: 0.75rem; }

.lb-stage {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 3.5rem 3.5rem 5rem;
}
.lb-single, .lb-compare {
  max-width: min(96vw, 1400px);
  max-height: 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-single img {
  max-width: 100%;
  max-height: calc(100vh - 8.5rem);
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
}

/* Aspect-ratio-safe before/after: frame sized to generated image display box */
.lb-compare-frame {
  position: relative;
  display: block;
  line-height: 0;
  overflow: hidden;
  border-radius: 4px;
  touch-action: none;
  user-select: none;
  max-width: min(96vw, 1400px);
  max-height: calc(100vh - 8.5rem);
  /* width/height set in JS from natural aspect ratio */
  width: auto;
  height: auto;
  background: #000;
}
.lb-layer {
  pointer-events: none;
  display: block;
}
.lb-after {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1400px);
  max-height: calc(100vh - 8.5rem);
  width: auto;
  height: auto;
  object-fit: contain;
}
.lb-before-clip {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 2;
  width: 50%;
  overflow: hidden;
  border-right: 2px solid rgba(255,255,255,0.9);
}
.lb-before-clip .lb-before {
  position: absolute;
  top: 0;
  left: 0;
  /* JS sets exact pixel width/height to match after display size */
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left top;
}
.lb-slider-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: rgba(255,255,255,0.95);
  z-index: 3;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
}
.lb-slider-line::after {
  content: "⟷";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: #1a0f20;
  font-size: 0.85rem;
  font-weight: 700;
}
.lb-slider {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  appearance: none;
}

.lb-toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 0.75rem 1rem 1rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
}
.lb-caption-block { flex: 1; min-width: 8rem; display: flex; flex-direction: column; gap: 0.15rem; }
.lb-caption { font-size: 0.9rem; color: #eee; }
.lb-filename { font-size: 0.78rem; color: #aaa; word-break: break-all; }
.lb-counter { font-size: 0.85rem; color: #bbb; }
.lb-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.lb-btn {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.lb-btn:hover, .lb-btn.on {
  border-color: var(--accent);
  background: rgba(199, 125, 255, 0.25);
}
.lb-btn:disabled { opacity: 0.35; cursor: default; }
.lb-actions.hidden { display: none !important; }

body.lb-open { overflow: hidden; }

.row { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.55rem 0; min-width: 0; }
.field.grow { flex: 1 1 12rem; min-width: min(100%, 12rem); }
.field span { font-size: 0.75rem; color: var(--muted); }
textarea, select, input[type="number"], input[type="search"], input[type="text"], input[type="datetime-local"] {
  background: #121018;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
/* Long model ids (seedream-…) must not collapse to one letter per line */
select {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
textarea { resize: vertical; width: 100%; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0.75rem;
  min-width: 0;
  max-width: 100%;
}
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  overflow-wrap: break-word;
  word-break: normal;
}
/* Exclusive groups (grade / exposure): subtle cue they radio-switch */
.chip.chip-mutex {
  border-style: dashed;
}
.chip.chip-mutex.on {
  border-style: solid;
}
.chip.on {
  color: #1a0f20;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  border-color: transparent;
  font-weight: 600;
}

.check.explicit {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 92, 122, 0.35);
  background: rgba(255, 92, 122, 0.08);
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
  line-height: 1.35;
}
.check.explicit input { margin-top: 0.2rem; }

.primary {
  width: 100%;
  margin-top: 0.5rem;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #1a0f20;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
}
.primary:disabled { opacity: 0.5; cursor: wait; }
.status { min-height: 1.2rem; color: var(--muted); font-size: 0.9rem; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.results figure {
  margin: 0;
  background: #0a090d;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.results img { width: 100%; display: block; }
.results figcaption {
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}
.results a { color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.4rem;
  max-height: 340px;
  overflow: auto;
}
.grid button {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: #000;
}
.grid button.selected { border-color: var(--accent); }
.grid img { width: 100%; height: 90px; object-fit: cover; display: block; }

.history { display: flex; flex-direction: column; gap: 0.4rem; }
.history.history-page {
  max-height: none;
  overflow: visible;
  gap: 0.45rem;
}
.history button {
  text-align: left;
  background: #121018;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}
.history button:hover { border-color: var(--accent); }
.muted { color: var(--muted); font-size: 0.85rem; }

/* —— Monitor tab —— */
.monitor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
}
button.secondary:hover { border-color: var(--accent); }
.monitor-root {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: none;
  max-height: none;
  overflow: auto;
  padding-right: 0.25rem;
  box-sizing: border-box;
}
.monitor-notes {
  background: rgba(255, 92, 122, 0.08);
  border: 1px solid rgba(255, 92, 122, 0.35);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}
.monitor-notes p { margin: 0.25rem 0; }
.monitor-notes code { color: var(--accent); }
.mon-section {
  margin-bottom: 1.25rem;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}
.mon-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.mon-sub {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.mon-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.55rem;
  width: 100%;
}
.mon-card {
  background: #121018;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.mon-card strong { font-size: 1.1rem; }
.mon-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.mon-hint { font-size: 0.72rem; color: var(--muted); display: block; margin-top: 0.15rem; }
.mon-table-wrap {
  overflow-x: auto;
  width: 100%;
  max-width: none;
}
.mon-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: auto;
}
.mon-table th, .mon-table td {
  text-align: left;
  padding: 0.4rem 0.45rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.mon-table th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; }
.mon-table.compact td, .mon-table.compact th { padding: 0.3rem 0.4rem; }
.mon-table tr.offline { opacity: 0.55; }
.mon-table code { font-size: 0.78rem; color: var(--accent); }
.mon-table code.sku { color: var(--text); word-break: break-all; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.lane-uncensored {
  color: #1a0f20;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  border-color: transparent;
}
.badge.lane-moderated {
  color: #ffc9d2;
  border-color: var(--danger);
  background: rgba(255, 92, 122, 0.15);
}
.badge.lane-standard { color: var(--text); background: #121018; }

/* Model picker table */
.model-field {
  margin: 0.35rem 0 0.75rem;
  min-width: 0;
  max-width: 100%;
}
.model-table-wrap {
  margin-top: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 14rem;
  background: #141218;
  /* sticky thead needs a non-collapse table + solid header bg */
  isolation: isolate;
}
.model-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  table-layout: fixed;
}
.model-table th,
.model-table td {
  text-align: left;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  line-height: 1.25;
}
.model-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  /* Opaque sticky header so rows never bleed through while scrolling */
  background: #1a1620;
  position: sticky;
  top: 0;
  z-index: 3;
  white-space: nowrap;
  box-shadow: 0 1px 0 var(--border);
}
.model-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}
.model-table thead th.sortable:hover {
  color: var(--text);
}
.model-table thead th.sortable .sort-ind {
  display: inline-block;
  margin-left: 0.25rem;
  opacity: 0.45;
  font-size: 0.65rem;
}
.model-table thead th.sortable.sort-asc .sort-ind,
.model-table thead th.sortable.sort-desc .sort-ind {
  opacity: 1;
  color: var(--accent);
}
.model-table thead th.sortable.sort-asc .sort-ind::after { content: "▲"; }
.model-table thead th.sortable.sort-desc .sort-ind::after { content: "▼"; }
.model-table thead th.sortable:not(.sort-asc):not(.sort-desc) .sort-ind::after { content: "⇅"; }
.model-table .model-prov {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}
.model-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}
.model-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}
.model-table tbody tr.selected {
  background: rgba(199, 125, 255, 0.14);
}
.model-table tbody tr.selected td:first-child {
  color: var(--text);
  font-weight: 600;
}
/* Model: compact; ellipsis instead of wrapping */
.model-table th:nth-child(1),
.model-table td.model-id {
  width: 38%;
}
.model-table td.model-id {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
}
.model-table th:nth-child(2),
.model-table td.model-lane {
  width: 7.25rem;
  white-space: nowrap;
}
/* Prompt limit: room for "32,768" on one line */
.model-table th:nth-child(3),
.model-table td.model-limit {
  width: 7.5rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.82rem;
}
.model-table th:nth-child(4),
.model-table td.model-price {
  width: 5.75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.82rem;
}
.model-table tr.selected td.model-limit,
.model-table tr.selected td.model-price {
  color: var(--text);
}
.seed-row.hidden {
  display: none !important;
}
.preset-detail-panel {
  margin: 0.5rem 0 0.85rem;
  padding: 0.65rem 0.75rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(199, 125, 255, 0.06);
}
.preset-detail-panel.hidden {
  display: none !important;
}
.preset-detail-panel .field-label {
  display: block;
  margin-bottom: 0.2rem;
}
.preset-detail-hint {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  line-height: 1.35;
}
.preset-detail-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.preset-detail-panel input[type="text"],
.preset-detail-panel textarea {
  width: 100%;
  font: inherit;
}
.preset-detail-panel textarea {
  min-height: 3.5rem;
  resize: vertical;
}
.badge.ok {
  color: #0d2a18;
  background: var(--ok);
  border-color: transparent;
}
.badge.danger {
  color: #ffc9d2;
  border-color: var(--danger);
  background: rgba(255, 92, 122, 0.2);
}

.mon-ledger .mon-time { white-space: nowrap; font-size: 0.78rem; }
.mon-ledger .mon-model { font-size: 0.85rem; }
.mon-ledger .amt-debit { color: #ff9aab; font-variant-numeric: tabular-nums; }
.mon-ledger .amt-credit { color: var(--ok); font-variant-numeric: tabular-nums; }
.badge.kind-image { color: var(--accent); border-color: rgba(199,125,255,0.45); }
.badge.kind-llm { color: #9ecbff; border-color: rgba(120,170,255,0.4); }
.badge.kind-credit { color: var(--ok); border-color: rgba(107,203,138,0.45); }
.badge.kind-inference, .badge.kind-other { color: var(--muted); }

/* —— Metadata panel —— */
.meta-panel {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.meta-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}
.meta-head h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.meta-policy { flex: 1; font-size: 0.72rem; }
button.secondary.compact {
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
}
.meta-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  font-size: 0.82rem;
}
.meta-summary dt { color: var(--muted); }
.meta-summary dd { margin: 0; word-break: break-word; }
.meta-form { margin-top: 0.55rem; display: flex; flex-direction: column; gap: 0.45rem; }
.meta-hint { margin: 0.25rem 0 0; font-size: 0.75rem; line-height: 1.35; }
.meta-gps.disabled { opacity: 0.45; pointer-events: none; }

/* —— Presets / looks —— */
.field-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.looks-block { margin-bottom: 0.65rem; }
.presets-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.35rem 0 0.4rem;
}
.presets-toolbar .field-label { margin: 0; }
.presets-toolbar-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.presets-block,
.scenes-block {
  margin-bottom: 0.75rem;
  max-height: min(42vh, 28rem);
  overflow: auto;
  padding-right: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
  padding: 0.35rem 0.45rem 0.5rem;
}
.preset-cat { margin-bottom: 0.55rem; }
.preset-cat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
/* Collapsible library sections in Studio */
.preset-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}
.preset-section[open] {
  background: rgba(255, 255, 255, 0.03);
}
.preset-section-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  list-style: none;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}
.preset-section-summary::-webkit-details-marker { display: none; }
.preset-section-summary::before {
  content: "▸";
  display: inline-block;
  width: 0.9rem;
  color: var(--muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.preset-section[open] > .preset-section-summary::before {
  transform: rotate(90deg);
}
.preset-section-title {
  flex: 1 1 auto;
  min-width: 0;
}
.preset-section-meta {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  flex-shrink: 0;
}
.preset-section-meta.has-on {
  color: var(--accent);
}
.preset-section-body {
  padding: 0 0.55rem 0.55rem;
}
.prompt-preview-panel {
  margin: 0.35rem 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  overflow: hidden;
}
.prompt-preview-summary {
  cursor: pointer;
  list-style: none;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.prompt-preview-summary::-webkit-details-marker { display: none; }
.prompt-preview-hint {
  font-weight: 400;
  font-size: 0.75rem;
}
.prompt-preview {
  margin: 0;
  padding: 0.55rem 0.75rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  max-height: 14rem;
  overflow: auto;
  border-top: 1px solid var(--border);
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
}
.prompt-preview.has-content {
  color: var(--text);
  opacity: 0.92;
}
.chip.look-chip {
  border-color: rgba(199, 125, 255, 0.45);
}
.chip.look-chip.on {
  background: linear-gradient(120deg, rgba(199,125,255,0.35), rgba(255,107,203,0.35));
}
.recipe-hint {
  font-size: 0.75rem;
  line-height: 1.4;
  margin: 0.35rem 0 0.75rem;
}
.seed-actions .row { gap: 0.35rem; }

/* —— Batch selection —— */
.batch-panel {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.batch-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}
.batch-head h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.batch-head .muted { flex: 1; font-size: 0.78rem; }
.batch-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 7.5rem;
  overflow: auto;
}
.batch-item {
  position: relative;
  width: 4.2rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  padding: 0;
  cursor: pointer;
}
.batch-item.active { border-color: var(--accent); }
.batch-item img.batch-pending {
  background: linear-gradient(135deg, #2a2438, #1a1520);
  min-height: 64px;
}
.batch-item img {
  width: 100%;
  height: 4.2rem;
  object-fit: cover;
  display: block;
}
.batch-item .batch-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.15rem;
  height: 1.15rem;
  border: none;
  border-radius: 999px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.batch-item .batch-idx {
  position: absolute;
  left: 2px;
  bottom: 2px;
  font-size: 0.65rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}
.batch-item.done { outline: 2px solid var(--ok); }
.batch-item.fail { outline: 2px solid var(--danger); }
.batch-item.running { outline: 2px solid var(--accent2); }
.batch-progress {
  margin-top: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.batch-results {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.batch-job-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: #121018;
}
.batch-job-card .batch-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.batch-job-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.immich-select-hint { font-size: 0.75rem; margin: 0 0 0.45rem; }
.grid button.thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.grid button.thumb .sel-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #1a0f20;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
}
.grid button.thumb { position: relative; }
.generate-row { align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.batch-immich-opt { margin: 0; font-size: 0.82rem; color: var(--muted); }

.prompt-budget {
  font-size: 0.75rem;
  margin: 0 0 0.65rem;
  font-variant-numeric: tabular-nums;
}
.prompt-budget.ok { color: var(--ok); }
.prompt-budget.over { color: var(--danger); }

a.brand {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.brand:hover .brand-atelier { opacity: 0.9; }

.history-card {
  text-align: left;
  background: #121018;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  width: 100%;
  font: inherit;
}
.history-card:hover { border-color: var(--accent); }
.history-card .hist-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}
.history-card .hist-settings {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 0.25rem 0 0.45rem;
  word-break: break-word;
}
.history-card .hist-settings code {
  color: var(--accent);
  font-size: 0.72rem;
}
.history-card .hist-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.history-card .hist-actions button {
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
}
.hist-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}
.hist-chip {
  font-size: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
  color: var(--muted);
}

/* —— GPS map picker —— */
.map-picker-wrap {
  margin-top: 0.5rem;
}
.batch-meta-box {
  margin-top: 0.85rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(199, 125, 255, 0.35);
  border-radius: 8px;
  background: rgba(199, 125, 255, 0.06);
}
.batch-meta-title {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.batch-meta-desc {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  line-height: 1.35;
}
.batch-meta-offset-row {
  margin-bottom: 0.35rem;
}
#batchMetaApply {
  margin-top: 0.45rem;
  width: 100%;
}
.map-picker-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.map-picker-tools input[type="search"] {
  flex: 1;
  min-width: 8rem;
  background: #121018;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.85rem;
}
.meta-map {
  height: 220px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0a0c;
  z-index: 1;
}
.map-hint {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
}
/* Leaflet dark-ish controls */
.meta-map .leaflet-control-attribution {
  font-size: 0.65rem;
  background: rgba(20, 18, 24, 0.85) !important;
  color: var(--muted) !important;
}
.meta-map .leaflet-control-attribution a { color: var(--accent) !important; }

/* —— History two-column —— */
.history-page-panel {
  max-width: none;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem 0.75rem;
  box-sizing: border-box;
  overflow: hidden;
}
.history-page-panel .page-toolbar {
  flex-shrink: 0;
}
.history-split {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(340px, 1.2fr);
  gap: 1rem;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
@media (max-width: 900px) {
  /* Vertical / narrow: let the page scroll; don’t trap content in a 0-height flex pane */
  .app-main {
    height: auto;
    max-height: none;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }
  #view-history.active,
  #view-library.active,
  #view-monitor.active,
  #view-studio.active {
    overflow: auto;
    flex: 1 1 auto;
  }
  .history-page-panel { overflow: visible; }
  .history-split {
    grid-template-columns: 1fr;
    overflow: visible;
    flex: none;
  }
  .history-list-col {
    max-height: 50vh;
    max-height: 50dvh;
    overflow-y: auto;
  }
  .history-detail-col {
    max-height: none;
    overflow: visible;
  }
  /* Library: same vertical-screen treatment as History */
  .library-page-panel {
    overflow: visible;
    flex: none;
    height: auto;
    max-height: none;
    min-height: 0;
    padding-bottom: 2rem;
  }
  .library-list {
    flex: none;
    max-height: none;
    overflow: visible;
  }
  .monitor-page-panel {
    overflow: visible;
    flex: none;
    height: auto;
    max-height: none;
  }
}
.history-list-col {
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.35rem;
  /* only content that fits the column scrolls inside */
}
.history-detail-col {
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem 1.1rem;
}
.history-page {
  max-height: none !important;
  height: auto;
  overflow: visible;
}
.st-ok { color: var(--ok) !important; }
.st-fail { color: var(--danger) !important; }
.st-run { color: #e8b84a !important; }
.st-muted { color: var(--muted) !important; }
.hist-desc {
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.4;
  margin: 0.3rem 0 0.45rem;
  opacity: 0.92;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-card,
.history-batch {
  position: relative;
  padding-right: 2.1rem;
}
.hist-trash {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.hist-trash:hover {
  color: var(--danger);
  border-color: rgba(255, 92, 122, 0.45);
  background: rgba(255, 92, 122, 0.1);
}

/* Confirm modal */
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-modal.hidden { display: none !important; }
.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.confirm-dialog {
  position: relative;
  z-index: 1;
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.2rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}
.confirm-dialog h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}
.confirm-dialog p { margin: 0 0 0.5rem; font-size: 0.88rem; line-height: 1.4; }
.confirm-warn {
  color: var(--danger) !important;
  font-size: 0.82rem !important;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
button.danger {
  background: var(--danger);
  border: none;
  color: #1a0a10;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  font: inherit;
}
button.danger:hover { filter: brightness(1.08); }
body.modal-open { overflow: hidden; }
.history-detail-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.9rem;
}
.history-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}
.history-detail-head h3 {
  margin: 0;
  font-size: 0.95rem;
}
.history-detail-section {
  margin-bottom: 1rem;
}
.history-detail-section h4 {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.hist-dl {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.35rem 0.65rem;
  font-size: 0.82rem;
  margin: 0;
}
.hist-dl dt { color: var(--muted); }
.hist-dl dd { margin: 0; word-break: break-word; }
.hist-dl code { color: var(--accent); font-size: 0.78rem; }
.hist-prompt {
  white-space: pre-wrap;
  background: #121018;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
  max-height: 8rem;
  overflow: auto;
}
.hist-prompt-final { max-height: 12rem; color: var(--muted); }
.hist-line { font-size: 0.78rem; margin: 0.2rem 0 0.4rem; }
.hist-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.hist-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #000;
}
.hist-thumb-fail {
  font-size: 0.65rem;
  color: var(--danger);
  align-self: center;
}
.history-card.selected,
.history-batch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(199, 125, 255, 0.35);
  background: rgba(199, 125, 255, 0.08);
}
.history-batch {
  text-align: left;
  background: #121018;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  width: 100%;
  margin-bottom: 0.4rem;
}
.history-batch:hover { border-color: rgba(199, 125, 255, 0.5); }
.history-card { margin-bottom: 0.4rem; }
.hist-batch-thumbs {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.4rem;
}
.hist-batch-item .hist-thumbs { margin-top: 0; }
.hist-img-block { margin-bottom: 0.85rem; }
.hist-img-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.65rem;
  margin-bottom: 0.4rem;
}
.hist-img-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
.hist-job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 0 0 auto;
}
.hist-file-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-top: 1px solid var(--border);
}
.hist-file-row .hist-file-btn {
  font-size: 0.65rem !important;
  padding: 0.2rem 0.4rem !important;
  min-height: 0;
  line-height: 1.2;
  flex: 1 1 auto;
  justify-content: center;
}
.hist-img-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.hist-img-card {
  width: 7.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0a0a0c;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  font-size: 0.68rem;
  text-align: center;
}
.hist-img-card img {
  width: 100%;
  height: 5.5rem;
  object-fit: cover;
  display: block;
  background: #000;
}
.hist-img-card span {
  display: block;
  padding: 0.25rem;
}
.hist-img-card:hover { border-color: var(--accent); color: var(--text); }

/* Rotate controls on results */
.result-fig figcaption {
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.rot-btn {
  min-width: 1.85rem;
  padding: 0.2rem 0.4rem !important;
  font-size: 0.95rem !important;
  line-height: 1;
}
.hist-img-card-wrap {
  display: flex;
  flex-direction: column;
  width: 7.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0a0a0c;
}
.hist-img-card-wrap .hist-img-main {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  text-align: center;
  width: 100%;
}
.hist-img-card-wrap .hist-img-main img {
  width: 100%;
  height: 5.5rem;
  object-fit: cover;
  display: block;
  background: #000;
}
.hist-img-card-wrap .hist-img-main span { display: block; padding: 0.25rem; }
.hist-rot-row {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-top: 1px solid var(--border);
}

.source-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.source-panel-head h2 {
  margin: 0;
}
.source-rot-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.source-rot-hint { font-size: 0.72rem; }

/* ── Library nav + page ── */
.side-nav-section {
  margin-top: 0.85rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.side-nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0.25rem 0.7rem 0.35rem;
}
.side-nav-item.side-nav-sub {
  padding: 0.4rem 0.7rem;
  font-size: 0.88rem;
}
.side-nav-item.side-nav-sub .nav-ico {
  font-size: 0.95rem;
  opacity: 0.9;
  line-height: 1;
}
.library-page-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  padding: 1rem 1.25rem 1.5rem;
  max-width: 1100px;
  width: 100%;
  box-sizing: border-box;
}
.library-page-panel .page-toolbar {
  flex-shrink: 0;
}
.library-toolbar { gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.lib-import-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.library-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.75rem;
  padding-bottom: 0.5rem;
}
#libraryStatus {
  flex-shrink: 0;
  margin-top: 0.35rem;
}
.lib-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.65rem 0.85rem;
  align-items: start;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.02);
  min-width: 0;
}
.lib-row.disabled-row { opacity: 0.55; }
.lib-row-main { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.lib-row-title {
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.lib-row-frag {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}
.lib-row-main code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}
.lib-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lib-badge.mode-edit { border-color: rgba(120,180,255,0.5); color: #9ec5ff; }
.lib-badge.mode-photoshoot { border-color: rgba(199,125,255,0.5); color: var(--accent); }
.lib-badge.mode-both { border-color: rgba(120,220,160,0.45); color: #8fd9a8; }
.lib-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}
.lib-order-btns { display: flex; flex-direction: column; gap: 0.2rem; }
.lib-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}
.lib-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.lib-modal.hidden { display: none !important; }
.lib-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}
.lib-modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--panel, #1a1620);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem 1.25rem 1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}
.lib-modal-body { display: flex; flex-direction: column; gap: 0.65rem; margin: 0.75rem 0 1rem; }
.lib-modal-body textarea { min-height: 7rem; resize: vertical; }
.lib-modal-actions { justify-content: flex-end; gap: 0.5rem; }
.lib-look-presets {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.lib-look-presets label {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  font-size: 0.88rem;
  cursor: pointer;
}
#view-library.active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* OpenCode prompt assist */
.assist-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  margin: 0.35rem 0 0.75rem;
  min-width: 0;
  max-width: 100%;
}
.assist-model {
  flex: 1 1 10rem;
  max-width: 100%;
  min-width: 0;
  font-size: 0.82rem;
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
}
.assist-hint {
  font-size: 0.78rem;
  flex: 1 1 100%;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.assist-bar.busy { opacity: 0.7; pointer-events: none; }
.assist-bar.hidden { display: none !important; }

.prompt-budget {
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.4;
}
.seed-actions { flex: 0 0 auto; }

/* Mobile / narrow: stack recipe controls so text never collapses to 1 letter/line */
@media (max-width: 720px) {
  .studio-layout {
    padding: 0.75rem 0.85rem 1.25rem;
  }
  .studio-layout .panel.studio,
  .studio-layout .panel.source {
    min-width: 0;
    max-width: 100%;
  }
  .row {
    flex-direction: column;
    align-items: stretch;
  }
  .field,
  .field.grow {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .seed-actions .row {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .generate-row {
    flex-direction: column;
    align-items: stretch;
  }
  .generate-row .primary {
    width: 100%;
  }
  .assist-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .assist-model {
    max-width: none;
    width: 100%;
  }
  .lib-row {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "order main"
      "actions actions";
  }
  .lib-order-btns { grid-area: order; }
  .lib-row-main { grid-area: main; }
  .lib-row-actions {
    grid-area: actions;
    justify-content: flex-start;
    margin-top: 0.25rem;
  }
  .library-page-panel {
    padding: 0.75rem 0.85rem 2rem;
    max-width: none;
  }
  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .library-toolbar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .library-toolbar .secondary,
  .library-toolbar .primary,
  .library-toolbar .lib-import-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    text-align: center;
  }
  .lib-modal {
    align-items: flex-end;
    padding: 0;
  }
  .lib-modal-card {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 920px);
    border-radius: 14px 14px 0 0;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  .lib-modal-actions {
    flex-direction: row !important;
    flex-wrap: wrap;
  }
  .lib-modal-actions .secondary,
  .lib-modal-actions .primary {
    flex: 1 1 auto;
  }
  .chip {
    font-size: 0.82rem;
    padding: 0.35rem 0.65rem;
  }
  #photoshootPrompt {
    min-height: 8rem;
    font-size: 16px; /* avoid iOS zoom on focus */
  }
  textarea, select, input[type="number"], input[type="search"], input[type="text"] {
    font-size: 16px;
  }
}
