/* Phase 152: final mobile workflow and layout stabilization. */

/* Hub folders keep one stable footprint at every content length. */
#hub-folder-grid .folder {
  min-width: 0;
  height: 100%;
}
#hub-folder-grid .folder-body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
#hub-folder-grid .folder-label {
  min-height: 2.55em;
  max-height: 2.55em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
#hub-folder-grid .folder-actions { margin-top: auto; }
#hub-folder-grid .folder.cbs-project-opening {
  pointer-events: none;
  opacity: .68;
}

/* The Cutting Room is part of the hub flow, including on phones. */
#cbs-cutting-room-section { flex: 0 0 auto; }

/* Mobile Writer: center the paper, retain screenplay element alignment. */
@media (max-width: 760px) {
  #project-hub {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  }
  #hub-folder-grid {
    grid-auto-rows: 188px !important;
    align-items: stretch !important;
  }
  #hub-folder-grid .folder { min-height: 188px !important; height: 188px !important; }
  #hub-folder-grid .folder-body { min-height: 168px !important; max-height: 168px !important; }
  #cbs-cutting-room-section {
    display: block !important;
    width: 100% !important;
    margin: 18px 0 0 !important;
    overflow: hidden;
  }
  #cbs-cutting-room-section > div:nth-child(2) { padding: 14px 12px 16px !important; }
  #cbs-cr-grid { width: 100% !important; scroll-snap-type: x proximity; }
  #cbs-cr-grid > div { scroll-snap-align: start; }

  body[data-active-view="writer-app"] #pages-container {
    display: flex !important;
    flex-direction: column;
    align-items: center !important;
  }
  body[data-active-view="writer-app"] #pages-container .script-page-sheet {
    width: min(100%, 612px) !important;
    max-width: 612px !important;
    margin-inline: auto !important;
  }
  body[data-active-view="writer-app"] .script-page-sheet .page-content {
    width: 100% !important;
    max-width: none !important;
    margin-inline: auto !important;
    padding-inline: clamp(16px, 5.5vw, 32px) !important;
    box-sizing: border-box !important;
    text-align: left !important;
  }
  body[data-active-view="writer-app"] .page-content .line.scene,
  body[data-active-view="writer-app"] .page-content .line.scene-heading,
  body[data-active-view="writer-app"] .page-content .line.action {
    margin-left: 0 !important;
    margin-right: 0 !important;
    text-align: left !important;
  }
  body[data-active-view="writer-app"] .page-content .line.character {
    margin-left: 28% !important;
    margin-right: 4% !important;
    text-align: left !important;
  }
  body[data-active-view="writer-app"] .page-content .line.dialogue {
    margin-left: 12% !important;
    margin-right: 8% !important;
    text-align: left !important;
  }
  body[data-active-view="writer-app"] .page-content .line.parenthetical {
    margin-left: 20% !important;
    margin-right: 12% !important;
    text-align: left !important;
  }
  body[data-active-view="writer-app"] .page-content .line.transition {
    margin-left: 35% !important;
    margin-right: 0 !important;
    text-align: right !important;
  }
  #writer-mobile-hub .wmh-dock {
    max-width: calc(100vw - 16px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  #writer-mobile-hub .wmh-dock::-webkit-scrollbar { display: none; }
  #writer-mobile-hub .wmh-quick-format {
    width: auto !important;
    min-width: 104px !important;
    padding-inline: 12px !important;
    gap: 6px;
    white-space: nowrap;
    font-size: .72rem !important;
    font-weight: 800;
  }
  body[data-keyboard-open="true"] #writer-mobile-hub,
  html[data-keyboard-open="true"] body[data-active-view="writer-app"] #writer-mobile-hub {
    display: block !important;
    visibility: visible !important;
  }

  /* Beats: remove the redundant cork-colored tail below the last beat. */
  #corkboard-app { padding-bottom: 0 !important; min-height: 0 !important; }
  #corkboard-app .cork-scroll {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0 !important;
  }

  /* Moodboard commands wrap instead of spilling out of their buttons. */
  #artdept-moodboard > div:first-child,
  [id*="moodboard"] .toolbar,
  [id*="mood-board"] .toolbar {
    flex-wrap: wrap !important;
    align-items: stretch !important;
    overflow: visible !important;
  }
  #artdept-moodboard .btn,
  [id*="moodboard"] button,
  [id*="mood-board"] button {
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 40px !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.15 !important;
    text-align: center;
  }
  #artdept-moodboard #artdept-mb-set { flex: 1 1 100%; max-width: none !important; }

  /* LightForge: compact scene rail, sticky mode switcher, scrollable work area. */
  #cine-app {
    height: calc(100dvh - var(--cbs-header-height, 58px) - var(--cbs-bottom-nav-height, 70px)) !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }
  #cine-app > div:first-child {
    padding: 8px 10px !important;
    gap: 6px !important;
    align-items: stretch !important;
  }
  #cine-subtabs {
    order: 3;
    flex: 1 1 100% !important;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    position: sticky;
    top: 0;
    z-index: 20;
    scrollbar-width: none;
  }
  #cine-subtabs::-webkit-scrollbar { display: none; }
  #cine-subtabs .cine-stab { flex: 0 0 auto; min-height: 40px; white-space: nowrap; }
  #cine-body { flex-direction: column !important; overflow: hidden !important; }
  #cine-scene-list {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 104px !important;
    min-height: 52px !important;
    max-height: 104px !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--line) !important;
    overflow: hidden !important;
  }
  #cine-scene-list.cbs152-collapsed { height: 38px !important; min-height: 38px !important; }
  #cine-scene-list > div:first-child { display: flex; align-items: center; min-height: 38px; }
  #cine-scene-items { display: flex; overflow-x: auto !important; overflow-y: hidden !important; }
  #cine-scene-items > * { flex: 0 0 min(72vw, 270px); }
  .cbs152-cine-scenes-toggle {
    margin-left: auto;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--ink);
    border-radius: 6px;
    min-width: 34px;
    min-height: 30px;
  }
  #cine-body > div:last-child { min-height: 0 !important; overflow: hidden !important; }
  #cine-panel-blueprint,
  #cine-panel-analytics { padding: 12px !important; overflow-y: auto !important; }
  #cine-panel-shots { overflow: hidden !important; }
  #cine-panel-shots > div:first-child { flex-wrap: wrap !important; padding: 8px 10px !important; }
  #cine-panel-gaffer { overflow-y: auto !important; }
  #cine-gaffer-toolbar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    position: sticky;
    top: 0;
    z-index: 12;
    scrollbar-width: none;
  }
  #cine-gaffer-toolbar::-webkit-scrollbar { display: none; }
  #cine-gaffer-toolbar > * { flex: 0 0 auto; }
  #cine-gaffer-body { flex-direction: column !important; overflow: visible !important; }
  #cine-diagram-wrap {
    flex: 0 0 auto !important;
    width: 100% !important;
    min-height: 360px !important;
    height: 48dvh !important;
  }
  #cine-gaffer-right {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    border-left: 0 !important;
    border-top: 1px solid var(--line) !important;
    overflow: visible !important;
  }

  /* Scene Outfits: a guided three-step flow without removing any controls. */
  #wardrobe-app { height: auto !important; min-height: 100%; overflow-y: auto !important; }
  .wdb-toolbar { align-items: stretch !important; }
  .wdb-toolbar-left,
  .wdb-toolbar-right { width: 100% !important; flex-wrap: wrap !important; }
  .wdb-search-wrap { order: 3; flex: 1 1 100% !important; width: 100% !important; }
  .wdb-toolbar-right .wdb-btn,
  .wdb-toolbar-right .wdb-sel { flex: 1 1 calc(50% - 6px); min-width: 0 !important; }
  .wdb-stats-strip { overflow-x: auto; flex-wrap: nowrap !important; }
  .wdb-stat { flex: 0 0 auto; }
  .wde-header { position: sticky; top: 0; z-index: 25; flex-wrap: wrap !important; }
  .wde-header-actions { width: 100%; overflow-x: auto; flex-wrap: nowrap !important; }
  .wde-header-actions > * { flex: 0 0 auto; }
  .cbs152-outfit-steps {
    position: sticky;
    top: var(--cbs-header-height, 58px);
    z-index: 24;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    padding: 6px;
    background: var(--paper, #fff);
    border-bottom: 1px solid var(--wdb-line, #ddd);
  }
  .cbs152-outfit-steps button {
    min-width: 0;
    min-height: 40px;
    border: 1px solid var(--wdb-line, #d8d0c6);
    border-radius: 6px;
    background: var(--paper, #fff);
    color: var(--wdb-ink, #24180d);
    font-size: .68rem;
    font-weight: 850;
    line-height: 1.15;
  }
  .cbs152-outfit-steps button.active { background: #4338ca; border-color: #4338ca; color: #fff; }
  .wde-body { display: flex !important; flex-direction: column !important; overflow: visible !important; }
  .wde-col { width: 100% !important; min-width: 0 !important; scroll-margin-top: 118px; }
  .wde-col-figure { order: 1; }
  .wde-col-looks { order: 2; }
  .wde-col-cont { order: 3; padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important; }
  .wde-cat-chips,
  .wde-look-tabs { position: sticky; top: 46px; z-index: 8; overflow-x: auto; flex-wrap: nowrap !important; }
  .wde-cat-chip { flex: 0 0 auto; }
  .wde-rail { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .wde-scene-list { max-height: 46dvh !important; overflow-y: auto !important; }
}

@media (min-width: 761px) {
  .cbs152-outfit-steps,
  .cbs152-cine-scenes-toggle { display: none !important; }
}
