/* BODHI Dashboard · css/mobile.css · 移动端 / 窄屏响应式层
   ⚠ 必须在 index.html 所有 css/ 之后加载，才能盖过各域桌面默认。
   桌面优先的制片工具；本文件只保证手机可读、可导航、可搜、可看片。 */

/* 桌面：移动端专用控件默认隐藏 */
.mobile-nav-toggle,
.mobile-search-toggle,
.mobile-nav-close,
.sidebar-backdrop {
  display: none;
}

/* ── 平板收窄（≤900）：侧栏可手动收，主区多留宽 ─────────────────── */
@media (max-width: 900px) {
  #main { padding: 1.1rem; }
  .page-title { font-size: 18px; }
}

/* ── 手机 / 小屏壳层（≤768）──────────────────────────────────────
   侧栏改抽屉：默认离屏，☰ 打开 + 遮罩关闭；主区全宽。
   比旧「52px 图标条」更省宽、标签可读、触控更大。 */
@media (max-width: 768px) {
  /* safe-area：刘海 / Home 条 */
  #app {
    height: 100dvh;
    height: 100vh; /* fallback */
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }

  .mobile-nav-toggle,
  .mobile-search-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 8px;
    border: 1px solid var(--b-line, rgb(var(--ink-200)));
    background: var(--b-surface-2, rgb(var(--ink-50)));
    color: var(--b-text-2, rgb(var(--ink-600)));
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
  }
  .dark .mobile-nav-toggle,
  .dark .mobile-search-toggle {
    border-color: rgb(var(--ink-700));
    background: rgb(var(--ink-800));
    color: rgb(var(--ink-300));
  }
  .mobile-nav-toggle:active,
  .mobile-search-toggle:active { background: var(--b-surface-3, rgb(var(--ink-100))); }

  .mobile-nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: auto;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1;
    color: var(--b-text-dim, rgb(var(--ink-500)));
    cursor: pointer;
  }
  .mobile-nav-close:hover { background: var(--b-surface-3, rgb(var(--ink-100))); }

  /* 桌面收起按钮在手机抽屉里无意义 */
  #sidebar-toggle { display: none !important; }

  /* 抽屉侧栏 */
  #sidebar {
    position: fixed;
    z-index: 80;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(18rem, 86vw) !important;
    max-width: 18rem;
    transform: translateX(-105%);
    transition: transform var(--mo-base) var(--mo-out);   /* token 见 css/ui.css :root */
    box-shadow: none;
    border-right: 1px solid var(--b-line, rgb(var(--ink-200)));
    /* 覆盖 body.sidebar-collapsed 的窄栏样式 */
    flex-direction: column;
  }
  body.mobile-nav-open #sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgb(0 0 0 / .28);
  }
  /* 抽屉内永远显示完整品牌 + 文字标签（忽略 collapsed 态） */
  body.mobile-nav-open #sidebar .sidebar-brand,
  #sidebar .sidebar-brand { display: block !important; }
  body.mobile-nav-open #sidebar .nav-link .nav-label,
  #sidebar .nav-link .nav-label { display: inline !important; }
  body.mobile-nav-open #sidebar .nav-link,
  #sidebar .nav-link {
    justify-content: flex-start !important;
    padding: 10px 12px !important;
    min-height: 42px;
    gap: 10px;
  }
  body.mobile-nav-open #sidebar .nav-link .nav-icon,
  #sidebar .nav-link .nav-icon { width: 18px; height: 18px; }
  body.mobile-nav-open #sidebar .sidebar-head,
  #sidebar .sidebar-head {
    flex-direction: row !important;
    padding: .85rem 1rem !important;
    gap: .75rem !important;
  }
  body.mobile-nav-open #sidebar .sidebar-head img,
  #sidebar .sidebar-head img { width: 2.25rem !important; height: 2.25rem !important; }
  body.mobile-nav-open #sidebar .sidebar-foot,
  #sidebar .sidebar-foot { padding: .75rem 1rem !important; }
  /* 抽屉总是展开形态：收起态藏掉的账户名 / 余额在这里放回来 */
  #sidebar .side-acct { justify-content: flex-start !important; padding: 6px 8px !important; }
  #sidebar .side-acct-text { display: flex !important; }
  #sidebar .side-acct-caret { display: inline !important; }
  body.mobile-nav-open #sidebar #nav,
  #sidebar #nav { padding: .5rem .6rem !important; }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 75;
    background: rgb(var(--ink-950) / .48);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  body.mobile-nav-open .sidebar-backdrop {
    display: block;
  }
  body.mobile-nav-open { overflow: hidden; }

  /* 顶栏：两行友好；系列 + 集 + 动作 */
  #topbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem .5rem;
    padding: .5rem .65rem;
    padding-top: max(.5rem, env(safe-area-inset-top, 0px));
    row-gap: .45rem;
    z-index: 30;
  }
  #topbar #series-switch { order: 2; }
  #topbar #episode-switch {
    order: 3;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }
  #topbar #episode-switch > .text-xs { display: none; } /* 「当前集」标签省宽 */
  #topbar #episode-switch select {
    max-width: 100%;
    width: 100%;
    min-width: 0;
    font-size: 13px;
  }
  #topbar #jobs-mailbox-slot { order: 4; }
  #topbar #feedback-slot { order: 5; }
  #topbar .mobile-search-toggle { order: 6; }

  /* 桌面搜索框默认藏；展开搜索态再显示为第二行全宽 */
  #topbar #search-input {
    display: none;
    order: 10;
    flex: 1 1 100%;
    max-width: none;
    width: 100%;
    min-height: 40px;
    font-size: 16px; /* iOS 防自动放大 */
  }
  body.mobile-search-open #topbar #search-input {
    display: block;
  }
  body.mobile-search-open #topbar .mobile-search-toggle {
    background: rgb(var(--gold-500) / .18);
    border-color: rgb(var(--gold-500) / .55);
    color: rgb(var(--gold-600));
  }

  /* 搜索结果贴顶栏下方全宽（#search-results 在 #topbar 内） */
  #search-results {
    left: 8px !important;
    right: 8px !important;
    top: calc(100% + 4px) !important;
    max-width: none !important;
    width: auto;
    max-height: min(60vh, 420px);
  }

  /* 顶栏胶囊按钮：只留图标，省宽 */
  #topbar .topbar-btn {
    padding: 7px 9px;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
  }
  #topbar .topbar-btn > span:not(.topbar-btn-icon):not(.jobs-dot):not(.fb-dot) {
    display: none;
  }

  /* 系列分段：可缩文字 */
  .series-seg-btn {
    padding: 5px 8px;
    font-size: 12px;
  }
  .series-seg-btn .series-seg-icon { width: 13px; height: 13px; }

  /* 主内容 */
  #main {
    padding: .85rem .75rem 5.5rem; /* 底留 agent FAB + 安全区 */
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
  }
  .route-slow-note { top: 108px; right: 10px; }

  /* ── 内容组件 ─────────────────────────────────────────────── */
  .shot-grid {
    grid-template-columns: 1fr;
    gap: .75rem;
  }

  .page-head { gap: 8px; }
  .page-title { font-size: 17px; }
  .page-title .page-title-sub {
    display: block;
    margin-left: 0;
    margin-top: 2px;
  }

  .chip { padding: 6px 11px; min-height: 32px; } /* 触控友好 */
  .chip-row { gap: 6px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .tabbar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab-item { padding: 10px 12px; white-space: nowrap; flex-shrink: 0; }

  .btn { min-height: 36px; padding: 8px 14px; }
  .btn-sm { min-height: 32px; }

  /* 通用表格横向滑 */
  .overflow-x-auto { -webkit-overflow-scrolling: touch; }

  /* 费用条：标签别钉死 7rem */
  .page-shell .w-28 { width: 4.5rem; }
  .page-shell .w-20 { width: 3.5rem; }

  /* 资产宫格：手机单列/双列（tailwind sm: 在 CDN 下仍生效，这里钉住极窄） */
  #main .grid.grid-cols-2 { gap: .65rem; }

  /* Modal：贴边全宽，接近原生 sheet */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }
  .modal-card {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    max-height: 100vh !important;
    border-radius: 0;
    min-height: 0;
  }
  /* 100vw 含滚动条会撑出视口几像素；助手剧集 picker 用 100% 贴 overlay */
  .modal-card.agent-ep-picker {
    max-width: 100% !important;
    max-height: 100% !important;
  }
  .modal-card-shot-detail {
    max-height: 100dvh !important;
    max-height: 100vh !important;
  }
  .shot-detail-header {
    padding: .75rem .85rem .6rem;
    padding-top: max(.75rem, env(safe-area-inset-top, 0px));
    flex-wrap: wrap;
  }
  .shot-detail-col {
    padding: .75rem .85rem 1rem;
  }

  /* AI 生成 / 改图 / ref picker / 反馈：同样全宽 sheet */
  .aigen-overlay { padding: 0; align-items: stretch; }
  .aigen-panel,
  .aigen-panel-auto,
  .fb-modal,
  .picker-panel {
    width: 100% !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    height: 100vh !important;
    max-height: 100dvh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
  }
  .aigen-panel-auto { height: auto !important; max-height: 100dvh !important; }
  .aigen-panel { padding: 12px 14px; }

  /* 本场预览：侧栏改顶栏堆叠 */
  .sp-body { flex-direction: column; }
  .sp-side {
    flex: 0 0 auto;
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid rgb(var(--ink-200));
  }
  .dark .sp-side { border-bottom-color: rgb(var(--ink-700)); }

  /* lightbox 工具条触控 */
  .lightbox-bar button { min-width: 40px; min-height: 36px; }
}

/* ── 更窄手机（≤420）─────────────────────────────────────────── */
@media (max-width: 420px) {
  .series-seg-btn {
    padding-inline: 6px;
    font-size: 11px;
  }
  /* 系列名过长时只留图标 */
  .series-seg-btn > :not(.series-seg-icon) {
    /* 文本节点无法选；用 max-width 截断按钮内文字 */
  }
  #topbar #series-switch .series-seg-btn {
    max-width: 5.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #main { padding-inline: .6rem; }
}

@media (max-width: 768px) {
  .dashboard-page { gap: 14px; }
  .dashboard-titlebar { align-items: flex-start; }
  .dashboard-series-title { font-size: 22px; }
  .dashboard-sync { margin-top: 4px; }
  .dashboard-focus { padding: 20px; border-radius: 14px; }
  .dashboard-focus.has-preview .dashboard-focus__stage { grid-template-columns: 1fr; gap: 18px; }
  .dashboard-preview-stack { min-height: 178px; width: min(100%, 360px); margin: 0 auto; }
  .dashboard-focus__top { flex-direction: column; gap: 16px; }
  .dashboard-focus__title h2 { font-size: 29px; }
  .dashboard-focus__actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-focus__actions .btn { width: auto; min-width: 0; justify-content: center; }
  .dashboard-metrics { grid-template-columns: 1fr 1fr; gap: 12px; }
  .dashboard-metrics > :first-child { grid-column: 1 / -1; }
  .dashboard-section { padding: 16px; }
  .production-rail { grid-template-columns: repeat(5, minmax(56px, 1fr)); overflow-x: auto; padding-bottom: 4px; }
  .production-step { padding-inline: 4px; }
  .production-step__label { font-size: 10px; }
  .dashboard-personal { grid-template-columns: 1fr; }
  .dashboard-lower-grid { grid-template-columns: 1fr; }
}

/* ── 横屏矮屏：抽屉别占满 ─────────────────────────────────────── */
@media (max-width: 900px) and (max-height: 480px) {
  #sidebar { width: min(16rem, 70vw) !important; }
  #main { padding-bottom: 3.5rem; }
}

/* ── 触控：减少 hover 依赖、加大可点区 ───────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .strip-frame .strip-play { opacity: .55; } /* 无 hover 时也露出播放提示 */
  .lift:hover { transform: none; box-shadow: none; }
  .lift:active {
    transform: scale(.985);
    opacity: .96;
  }
  .nav-link { min-height: 44px; }
  .icon-btn { width: 32px; height: 32px; }
}

/* 减少动画（系统偏好）已收口到 css/motion.css 顶部的全局兜底（覆盖全站所有
   animation/transition，不再逐处点名）。别在这里重开局部 reduce 块。 */
