/**
 * Standalone online storyboard HTML — desk shell overrides.
 * Loaded after storyboard-desk.css when embedding export HTML.
 *
 * Target: align with workspace 分镜台 —
 * monitor | current-shot fields, tab-exclusive board/script, cards with description.
 */
html[data-cutgo-storyboard-html] #storyboardDeskShell,
html[data-cutgo-storyboard-html] .storyboard-desk-shell {
  display: flex !important;
  min-height: 100vh;
  flex-direction: column;
}

html[data-cutgo-storyboard-html] body {
  margin: 0;
  padding: 0;
  background: #101012;
}

html[data-cutgo-storyboard-html] .storyboard-desk-shell {
  --sb-desk-top-h: min(42vh, 520px);
  --cg-media-ar: 1.7777778;
  padding: 0 12px 12px;
  box-sizing: border-box;
}

/* Tab mutual exclusion */
html[data-cutgo-storyboard-html] .hidden,
html[data-cutgo-storyboard-html] #storyboardDeskShell .hidden,
html[data-cutgo-storyboard-html] .storyboard-desk-shell .hidden,
html[data-cutgo-storyboard-html] #sbDeskBoard[hidden],
html[data-cutgo-storyboard-html] #sbDeskScript[hidden] {
  display: none !important;
}

/* Never show draft chrome in portable HTML */
html[data-cutgo-storyboard-html] #draftStatus,
html[data-cutgo-storyboard-html] .sb-desk-draft-status {
  display: none !important;
}

/* Dual column: monitor | current-shot fields */
html[data-cutgo-storyboard-html] .sb-desk-top {
  flex: 0 0 auto;
  width: 100%;
  height: var(--sb-desk-top-h);
  max-height: var(--sb-desk-top-h);
  display: grid !important;
  grid-template-columns: minmax(0, 1.25fr) minmax(240px, 0.75fr);
  gap: 10px;
  align-items: stretch;
  padding: 10px 0 0;
  box-sizing: border-box;
}

html[data-cutgo-storyboard-html] .sb-desk-top:not(:has(#sbDeskAiRail)),
html[data-cutgo-storyboard-html] .sb-desk-top:has(#sbDeskAiRail[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

html[data-cutgo-storyboard-html] .sb-desk-player-col {
  flex: 1 1 auto !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0b;
  border-radius: 10px;
  overflow: hidden;
}

/* Slot follows media aspect so contain fills without stretch or crop.
   Never use object-fit:fill — eliminating black bars must not distort. */
html[data-cutgo-storyboard-html] .sb-desk-player-slot,
html[data-cutgo-storyboard-html] #storyboardDeskPlayerSlot {
  position: relative;
  flex: 0 1 auto !important;
  width: 100% !important;
  max-width: 100%;
  height: auto !important;
  max-height: 100% !important;
  aspect-ratio: var(--cg-media-ar, 16 / 9);
  background: #000;
  overflow: hidden;
  border-radius: 10px;
}

html[data-cutgo-storyboard-html] .sb-desk-ai-rail {
  min-width: 0;
  height: 100%;
  overflow: auto;
}

html[data-cutgo-storyboard-html] .sb-desk-body {
  flex: 1 1 auto;
  min-height: 160px;
}

/* Visible drag handle between monitor and board/table */
html[data-cutgo-storyboard-html] .sb-desk-row-resizer {
  flex: 0 0 10px !important;
  height: 10px !important;
  cursor: row-resize;
  touch-action: none;
  position: relative;
  z-index: 40;
  background: transparent;
}

html[data-cutgo-storyboard-html] .sb-desk-row-resizer::before {
  content: '' !important;
  display: block !important;
  position: absolute;
  left: 18%;
  right: 18%;
  top: 4px;
  height: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.18);
}

html[data-cutgo-storyboard-html] .sb-desk-row-resizer:hover::before,
html[data-cutgo-storyboard-html] .sb-desk-row-resizer.is-active::before,
html[data-cutgo-storyboard-html] .sb-desk-row-resizer.is-portable:hover::before {
  background: rgba(163, 230, 53, 0.75) !important;
}

#storyboardDeskPlayerSlot video,
#storyboardDeskPlayerSlot iframe {
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: contain;
  object-position: center;
  display: block;
}

.sb-desk-portable-player-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
  box-sizing: border-box;
  color: rgba(245, 245, 247, 0.82);
  font-size: 13px;
}

.sb-desk-portable-link-preview {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}

.sb-desk-portable-link-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.sb-desk-portable-link-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  text-align: center;
}

body.cutgo-preview .sb-desk-export-wrap,
body.cutgo-preview .sb-desk-export-actions,
body.cutgo-preview #draftStatus {
  display: none !important;
}

body.cutgo-preview .storyboard-desk-shell {
  min-height: 480px;
}

body.cutgo-preview .sb-desk-ai-prompt,
body.cutgo-preview [data-desk-capability='cuts'] {
  display: none !important;
}

.sb-desk-empty-shots {
  margin: 24px 8px;
  padding: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  text-align: center;
  color: #8e8e93;
  font-size: 13px;
  line-height: 1.5;
}

.sb-desk-empty-shots strong {
  display: block;
  margin-bottom: 6px;
  color: #f5f5f7;
  font-size: 14px;
}

/* AI gate modal (offline HTML CTA) */
.sb-portable-ai-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.sb-portable-ai-gate[hidden] {
  display: none !important;
}

.sb-portable-ai-gate-card {
  width: min(420px, 100%);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1c1c1e;
  padding: 18px 18px 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  color: #f5f5f7;
}

.sb-portable-ai-gate-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 750;
}

.sb-portable-ai-gate-card p {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.55;
  color: #c7c7cc;
}

.sb-portable-ai-gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sb-portable-ai-gate-actions a.sb-desk-btn,
.sb-portable-ai-gate-actions .sb-desk-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sb-portable-ai-gate-actions .sb-desk-btn.is-primary,
html[data-cutgo-storyboard-html] .sb-desk-ai-actions .is-primary {
  background: #a3e635;
  color: #111;
  border-color: #a3e635;
}

.print-header {
  display: none;
}

@media (max-width: 900px) {
  html[data-cutgo-storyboard-html] .sb-desk-top {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
  html[data-cutgo-storyboard-html] .sb-desk-player-slot,
  html[data-cutgo-storyboard-html] #storyboardDeskPlayerSlot {
    max-height: min(42vh, 420px);
  }
  html[data-cutgo-storyboard-html] .sb-desk-ai-rail {
    max-height: 280px;
  }
}

@media print {
  @page :first {
    size: A4 landscape;
    margin: 12mm 12mm 10mm 12mm;
  }
  @page {
    size: A4 landscape;
    margin: 16mm 12mm 10mm 12mm;
  }
  :root {
    color-scheme: light !important;
  }
  html,
  body {
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    color: #111 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .sb-desk-tabs,
  .sb-desk-row-resizer,
  .sb-desk-ai-rail,
  .sb-desk-transport,
  .cg-st-transport,
  .sb-desk-export-wrap,
  .sb-desk-col-settings,
  .sb-portable-ai-gate,
  #draftStatus {
    display: none !important;
  }
  .print-header {
    display: block !important;
    margin: 0 0 10px;
    padding: 2mm 0 0;
    page-break-after: avoid;
  }
  .print-header h1 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 700;
    color: #111 !important;
  }
  .print-header p {
    margin: 0;
    font-size: 9px;
    color: #333 !important;
    word-break: break-all;
  }
  body.desk-print-board .sb-desk-board {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    padding: 0 !important;
  }
  body.desk-print-board .sb-desk-script-wrap {
    display: none !important;
  }
  body.desk-print-board .sb-desk-card {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1px solid #bbb !important;
    background: #fff !important;
    color: #111 !important;
  }
  body.desk-print-script .sb-desk-board {
    display: none !important;
  }
  body.desk-print-script .sb-desk-script-wrap {
    display: block !important;
  }
  body.desk-print-script .script-print-root {
    display: block !important;
  }
  body.desk-print-script .script-print-root[hidden] {
    display: block !important;
  }
  body.desk-print-script .sb-desk-script-wrap {
    display: none !important;
  }
}
