/* ui_ux_patch_j — 手机竖屏自动适配（媒体查询 + JS class 双保险） */

/* ══════════════════════════════════════════════════════════════
   JS/UA 标记手机：不依赖 viewport（小米「桌面模式」也生效）
   ══════════════════════════════════════════════════════════════ */
body.drama-premium.drama-surface-phone {
  background: #071510 !important;
  --drama-viewport-h: auto !important;
  --drama-viewport-media-h: auto !important;
  --drama-form-min-h: 0px !important;
  --drama-panel-max-h: 9999px !important;
}

body.drama-premium.drama-surface-phone .drama-shell {
  display: flex !important;
  flex-direction: column !important;
  height: auto !important;
  min-height: 100dvh !important;
  max-height: none !important;
  overflow: visible !important;
}

body.drama-premium.drama-surface-phone .drama-scroll {
  flex: 0 0 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
}

body.drama-premium.drama-surface-phone .tab-page:not(.active) {
  display: none !important;
}

body.drama-premium.drama-surface-phone .tab-page.active {
  display: flex !important;
  flex-direction: column !important;
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

body.drama-premium.drama-surface-phone .drama-card-fill,
body.drama-premium.drama-surface-phone .tab-page.active .drama-card-fill,
body.drama-premium.drama-surface-phone #page-idea .drama-card-fill,
body.drama-premium.drama-surface-phone #page-outline .drama-card-fill,
body.drama-premium.drama-surface-phone #page-detail .drama-card-fill {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

body.drama-premium.drama-surface-phone .drama-page-viewport,
body.drama-premium.drama-surface-phone .drama-text-viewport,
body.drama-premium.drama-surface-phone .tab-page.active .drama-page-viewport,
body.drama-premium.drama-surface-phone #page-idea .drama-page-viewport {
  flex: 0 0 auto !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow-y: visible !important;
}

body.drama-premium.drama-surface-phone .drama-agent-dock {
  flex: 0 0 auto !important;
  margin-top: 0 !important;
}

body.drama-premium.drama-surface-phone .drama-viewport-resize {
  display: none !important;
}

/* ══════════════════════════════════════════════════════════════
   手机 / 窄屏（≤768px）：消除中间巨大空白
   小米、微信内置浏览器等均走这里
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  html.drama-layout-compat body.drama-premium,
  body.drama-premium.drama-surface-phone {
    background: #071510 !important;
    --drama-viewport-h: auto;
    --drama-viewport-media-h: auto;
    --drama-form-min-h: 0px;
    --drama-panel-max-h: 9999px;
  }

  html.drama-layout-compat body.drama-premium .drama-shell,
  body.drama-premium.drama-surface-phone .drama-shell {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    overflow: visible !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }

  /* 关键：中间内容区不要 flex 撑满 */
  html.drama-layout-compat body.drama-premium .drama-scroll,
  body.drama-premium.drama-surface-phone .drama-scroll {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 8px 10px 4px !important;
  }

  html.drama-layout-compat body.drama-premium .tab-page:not(.active),
  body.drama-premium.drama-surface-phone .tab-page:not(.active) {
    display: none !important;
  }

  html.drama-layout-compat body.drama-premium .tab-page.active,
  body.drama-premium.drama-surface-phone .tab-page.active {
    display: flex !important;
    flex-direction: column !important;
    flex: 0 0 auto !important;
    min-height: 0 !important;
  }

  html.drama-layout-compat body.drama-premium .drama-card-fill,
  html.drama-layout-compat body.drama-premium .tab-page.active .drama-card-fill,
  body.drama-premium.drama-surface-phone .drama-card-fill,
  body.drama-premium.drama-surface-phone .tab-page.active .drama-card-fill,
  body.drama-premium #page-params .drama-card-fill,
  body.drama-premium #page-idea .drama-card-fill,
  body.drama-premium #page-outline .drama-card-fill,
  body.drama-premium #page-detail .drama-card-fill,
  body.drama-premium #page-storyboard .drama-card-fill,
  body.drama-premium #page-subtitles .drama-card-fill,
  body.drama-premium #page-edit .drama-card-fill {
    flex: 0 0 auto !important;
    min-height: 0 !important;
  }

  /* 关键：取消 app.css 里 calc(100dvh - 220px) 的固定视口高度 */
  html.drama-layout-compat body.drama-premium .drama-page-viewport,
  html.drama-layout-compat body.drama-premium .drama-text-viewport,
  html.drama-layout-compat body.drama-premium .tab-page.active .drama-page-viewport,
  body.drama-premium.drama-surface-phone .drama-page-viewport,
  body.drama-premium.drama-surface-phone .drama-text-viewport,
  body.drama-premium.drama-surface-phone .tab-page.active .drama-page-viewport,
  body.drama-premium #page-params .drama-page-viewport,
  body.drama-premium #page-params .drama-text-viewport,
  body.drama-premium #page-idea .drama-page-viewport {
    flex: 0 0 auto !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-y: visible !important;
  }

  body.drama-premium #page-params .drama-text-viewport,
  body.drama-premium #page-idea .drama-text-viewport {
    max-height: none !important;
    overflow-y: visible !important;
  }

  body.drama-premium .drama-page-viewport-media {
    max-height: min(46vh, 400px) !important;
    overflow-y: auto !important;
  }

  body.drama-premium .drama-viewport-resize {
    display: none !important;
  }

  body.drama-premium .drama-force-next-bar {
    flex-shrink: 0;
    padding: 6px 10px 4px !important;
  }

  body.drama-premium .drama-agent-dock {
    flex: 0 0 auto !important;
    max-height: min(50vh, 420px) !important;
    margin-top: 0 !important;
  }

  body.drama-premium .agent-dock-log {
    min-height: 88px !important;
    max-height: min(26vh, 200px) !important;
  }

  /* 顶栏紧凑 */
  body.drama-premium .drama-header.header-row {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px 8px !important;
  }

  body.drama-premium .drama-brand-lockup .brand-mark {
    width: 32px !important;
    height: 32px !important;
  }

  body.drama-premium .drama-brand-title {
    font-size: 1rem !important;
  }

  body.drama-premium .drama-eyebrow-inline,
  body.drama-premium .drama-surface-badge--pc,
  body.drama-premium .drama-mobile-link {
    display: none !important;
  }

  body.drama-premium .drama-header-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  body.drama-premium .drama-header-actions .btn {
    padding: 6px 10px !important;
    font-size: 0.72rem !important;
  }

  /* 步骤 Tab 横滑 */
  body.drama-premium .drama-tabs .tab-bar {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  body.drama-premium .drama-tabs .tab-bar::-webkit-scrollbar {
    display: none;
  }

  body.drama-premium .tab-item {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 10px !important;
    font-size: 0.72rem !important;
  }

  body.drama-premium .drama-scroll .card {
    padding: 12px 10px !important;
    margin-bottom: 0 !important;
  }

  body.drama-premium::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #059669, #34d399, #059669);
    z-index: 10000;
    pointer-events: none;
  }

  body.drama-premium .drama-shell,
  body.drama-premium .drama-header,
  body.drama-premium .drama-tabs {
    background: #0a1a14 !important;
  }
}

/* 电脑宽屏：保持分栏 */
@media (min-width: 769px) {
  body.drama-premium.drama-surface-desktop .drama-shell {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  body.drama-premium.drama-surface-desktop .drama-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }
}

/* JS 标记：手机 */
body.drama-premium.drama-surface-phone .agent-dock-chat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
