/* ==========================================================================
   移动端响应式样式（≤768px 断点）
   暗色工作台风格：#0d0d0f 底色 / #3dd9d6 冰蓝强调色 / #ff8c42 暖橙警告色
   ========================================================================== */

/* 桌面端隐藏移动端专用元素 */
.btn-drawer-toggle,
.drawer-overlay,
.bottom-nav,
.mobile-quick-gen,
.step-toggle-hint {
  display: none;
}

/* ==========================================================================
   移动端断点
   ========================================================================== */
@media (max-width: 768px) {

  /* ---------- 设计变量调整 ---------- */
  :root {
    --sidebar-w: 280px;
    --log-w: 100%;
  }

  html { font-size: 14px; }

  body {
    overflow: auto;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0)); /* 底部导航栏高度 + 安全区 */
    padding-top: env(safe-area-inset-top, 0);
  }

  /* ---------- 布局：侧栏改抽屉，主区域全宽 ---------- */
  #app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  /* 侧栏：固定定位抽屉，默认隐藏在左侧 */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    max-width: 85vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    padding-top: env(safe-area-inset-top, 0);
  }

  /* 抽屉打开 */
  #sidebar.drawer-open {
    transform: translateX(0);
  }

  /* 抽屉遮罩层（纯半透明，不用 blur 避免整个视口模糊） */
  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 7, 0.65);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }

  .drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* 主区域全宽，移除左侧 padding */
  #main {
    width: 100%;
    flex: 1;
    overflow: visible;
  }

  /* ---------- 抽屉触发按钮（仅移动端显示） ---------- */
  .btn-drawer-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    flex-shrink: 0;
  }

  .btn-drawer-toggle:active {
    background: var(--accent-dim);
    color: var(--accent);
  }

  /* ---------- 顶部栏 ---------- */
  #header-bar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .header-title {
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  #current-project-name {
    font-size: 1rem;
  }

  .title-meta {
    font-size: 0.68rem;
  }

  /* 隐藏标题栏的设置按钮（移到底部导航"我的"） */
  #btn-settings {
    display: none;
  }

  /* 移动端隐藏桌面端链接输入栏（快捷生成区已含链接输入） */
  .link-bar {
    display: none;
  }

  /* 移动端隐藏顶部栏一键生成按钮（快捷生成区已有） */
  #btn-generate-all {
    display: none;
  }

  /* 隐藏次要按钮，精简顶部栏 */
  #btn-transactions,
  #btn-admin {
    display: none;
  }

  .header-actions {
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }

  /* 用户区域：紧凑布局 */
  .user-area {
    gap: 5px;
    margin-right: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }

  .user-name {
    max-width: 70px;
    font-size: 0.75rem;
  }

  .credit-pill {
    font-size: 0.72rem;
    padding: 2px 8px;
  }

  /* ---------- 快捷生成区（粘贴链接 + 一键生成） ---------- */
  .mobile-quick-gen {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    margin: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
  }

  .mobile-quick-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 0 12px;
    min-height: 48px;
  }

  .mobile-quick-input-row:focus-within {
    border-color: var(--border-accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
  }

  .mobile-quick-icon {
    color: var(--text-tertiary);
    flex-shrink: 0;
  }

  .mobile-quick-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.88rem;
    line-height: 1.5;
    outline: none;
    -webkit-appearance: none;
  }

  .mobile-quick-input::placeholder {
    color: var(--text-tertiary);
  }

  .mobile-quick-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 12px 20px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--accent), #2bb8b5);
    color: #0d0d0f;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    box-shadow: 0 4px 16px rgba(61, 217, 214, 0.3);
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s, transform 0.1s;
  }

  .mobile-quick-btn:active:not(:disabled) {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .mobile-quick-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .mobile-quick-btn.loading {
    opacity: 0.7;
  }

  /* ---------- 流水线：步骤卡片纵向堆叠 ---------- */
  .pipeline {
    padding: 12px 14px;
    gap: 10px;
  }

  .step-card {
    min-height: 44px;
    max-width: 100%;
    overflow: hidden;
  }

  .step-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    max-width: 100%;
    overflow: hidden;
  }

  .step-info {
    flex: 1 1 60%;
    min-width: 0;
    overflow: hidden;
  }

  .step-name {
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .step-desc {
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .step-status {
    flex-shrink: 1;
    min-width: 0;
  }

  .step-run-btn {
    flex-shrink: 0;
  }

  .step-body {
    padding: 12px;
    overflow-x: hidden;
    max-width: 100%;
    word-break: break-word;
  }

  /* 连接线在移动端隐藏，卡片自然堆叠 */
  .connector {
    display: none;
  }

  /* ---------- 步骤折叠：移动端默认折叠 step-body ---------- */
  .step-card .step-body {
    display: none;
  }
  /* 运行中自动展开（看日志） */
  .step-card.running .step-body,
  /* 手动展开 */
  .step-card.mobile-expanded .step-body {
    display: block;
  }
  /* step-header 可点击展开/收起 */
  .step-card .step-header {
    cursor: pointer;
  }
  .step-card .step-toggle-hint {
    display: none;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-left: auto;
    padding-right: 4px;
    white-space: nowrap;
    align-self: center;
  }
  /* 有产物的步骤（done/error）显示"点击查看" */
  .step-card.done .step-toggle-hint,
  .step-card.error .step-toggle-hint {
    display: inline;
  }
  /* 展开后提示变为"收起" */
  .step-card.mobile-expanded .step-toggle-hint::before {
    content: '点击收起';
  }
  .step-card.mobile-expanded .step-toggle-hint {
    display: inline;
  }
  .step-card.mobile-expanded .step-toggle-hint {
    color: var(--accent);
  }

  /* ---------- 触控优化：所有可交互元素命中区 ≥44px ---------- */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

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

  .icon-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .step-run-btn {
    min-height: 44px;
    padding: 10px 18px;
  }

  .modal-close {
    min-width: 44px;
    min-height: 44px;
  }

  /* 移除 hover 效果依赖，改用 :active 触控反馈 */
  .btn-primary:hover:not(:disabled),
  .btn-accent:hover:not(:disabled),
  .btn-danger:hover:not(:disabled),
  .btn-ghost:hover:not(:disabled),
  .step-card:hover,
  .image-card:hover,
  .project-card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border);
  }

  .btn:active:not(:disabled) {
    transform: scale(0.97);
    opacity: 0.85;
  }

  .btn-primary:active:not(:disabled) {
    background: #2bb8b5;
  }

  .btn-ghost:active:not(:disabled) {
    background: var(--accent-dim);
    color: var(--accent);
  }

  .project-card:active {
    background: var(--bg-hover);
    border-color: var(--border-accent);
  }

  .step-card:active {
    border-color: var(--border-strong);
  }

  /* ---------- 认证卡片全宽适配 ---------- */
  .auth-view {
    padding: 20px 16px;
    padding-bottom: 64px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .auth-card {
    width: 100%;
    max-width: none;
    padding: 28px 20px;
    margin-top: 20px;
  }

  .auth-brand h1 {
    font-size: 1.5rem;
  }

  /* ---------- 表单输入框全宽 ---------- */
  .form-input,
  .form-select {
    width: 100%;
    min-height: 44px;
    font-size: 0.88rem;
    padding: 10px 12px;
  }

  .form-group {
    margin-bottom: 14px;
  }

  /* 验证码行布局 */
  .auth-code-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
  }

  .auth-code-row .form-input {
    flex: 1;
    min-width: 0;
  }

  .btn-send-code {
    flex-shrink: 0;
    min-width: 110px;
    white-space: nowrap;
    font-size: 0.78rem;
  }

  /* ---------- 日志面板：底部可展开面板 ---------- */
  .log-panel {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: calc(56px + env(safe-area-inset-bottom, 0)); /* 底部导航栏上方 */
    top: auto !important;
    width: 100% !important;
    height: 44px;
    max-height: 45vh;
    transform: none !important;
    z-index: 200;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-top: 1px solid var(--border-accent);
    border-right: none;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
  }

  .log-panel.mobile-expanded {
    height: 45vh;
  }

  .log-panel.hidden {
    display: flex !important;
    height: 44px;
  }

  .log-panel .log-content {
    display: none;
  }

  .log-panel.mobile-expanded .log-content {
    display: block;
  }

  .log-header {
    cursor: pointer;
    padding: 12px 16px;
  }

  .log-title h3 {
    font-size: 0.85rem;
  }

  .log-controls {
    gap: 8px;
  }

  .log-autoscroll {
    font-size: 0.72rem;
  }

  /* ---------- 项目列表 ---------- */
  .project-list {
    max-height: none;
    flex: 1;
  }

  .project-card {
    min-height: 44px;
    padding: 12px;
  }

  .project-name {
    font-size: 0.88rem;
  }

  .project-meta {
    font-size: 0.72rem;
  }

  /* ---------- 图片画廊：单列 ---------- */
  .image-gallery {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
  }

  .image-card {
    min-height: 44px;
  }

  /* ---------- 视频片段 ---------- */
  .clip-list {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  .clip-card {
    min-height: 44px;
  }

  /* ---------- 成片区域：单列 ---------- */
  .final-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* ---------- 设置网格：单列 ---------- */
  .settings-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .toggle-row {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  /* ---------- 模态框全宽适配 ---------- */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100% !important;
    max-width: none !important;
    max-height: 85vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    margin: 0;
  }

  .modal-wide {
    width: 100% !important;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-head {
    padding: 14px 16px;
  }

  .modal-head h3 {
    font-size: 1rem;
  }

  .modal-foot {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-foot .btn {
    flex: 1;
    min-width: 120px;
  }

  /* ---------- 提示词编辑 ---------- */
  .prompt-card {
    min-height: 44px;
  }

  .prompt-field textarea {
    min-height: 44px;
    font-size: 0.82rem;
    width: 100%;
  }

  /* ---------- 管理员设置面板 ---------- */
  .admin-settings-section {
    margin-top: 16px;
  }

  .admin-section-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
  }

  .admin-section-title {
    font-size: 0.92rem;
    margin-bottom: 12px;
    color: var(--accent);
  }

  .admin-model-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
  }

  .admin-model-label {
    flex: 1;
    font-size: 0.84rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-model-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }

  .admin-model-cost {
    width: 70px !important;
    min-height: 36px;
    text-align: center;
  }

  .admin-checkin-group {
    margin-top: 12px;
  }

  .admin-checkin-group .form-input {
    width: 100%;
  }

  /* ---------- 底部导航栏 ---------- */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(21, 21, 25, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 500;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .bottom-nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-tertiary);
    font-size: 0.68rem;
    min-height: 56px;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-tab svg {
    width: 22px;
    height: 22px;
  }

  .bottom-nav-tab.active {
    color: var(--accent);
  }

  .bottom-nav-tab:active {
    background: var(--accent-dim);
  }

  /* ---------- Toast 容器：避开底部导航 ---------- */
  .toast-container {
    bottom: 66px !important;
    top: auto !important;
    left: 12px !important;
    right: 12px !important;
  }

  /* ---------- Lightbox 移动端优化 ---------- */
  .lightbox {
    padding: 0;
  }

  .lightbox-stage {
    padding: 10px;
  }

  .lightbox-media img,
  .lightbox-media video {
    max-height: 70vh;
    max-width: 100vw;
  }

  .lightbox-prev,
  .lightbox-next {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }

  /* ---------- 签到按钮 ---------- */
  .btn-checkin {
    min-height: 36px;
    font-size: 0.74rem;
    padding: 6px 12px;
  }

  .btn-checkin.checked-in {
    color: var(--ok);
    border-color: rgba(74, 222, 128, 0.3);
    background: var(--ok-soft);
  }

  /* ---------- 下拉刷新指示器 ---------- */
  .pull-refresh-indicator {
    display: none;
    text-align: center;
    padding: 12px;
    color: var(--text-tertiary);
    font-size: 0.78rem;
  }

  .pull-refresh-indicator.show {
    display: block;
  }

  /* ---------- 表格横向滚动 ---------- */
  .tx-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* ---------- 音乐选择器 ---------- */
  .music-source-selector {
    flex-direction: column;
  }

  .music-picker {
    flex-direction: column;
    gap: 8px;
  }

  .music-picker .form-select {
    width: 100%;
  }

  /* ---------- 步骤空状态 ---------- */
  .step-empty {
    padding: 16px 8px;
  }

  .empty-title {
    font-size: 0.85rem;
  }

  .empty-hint {
    font-size: 0.72rem;
  }

  /* ---------- 内容分析高亮 ---------- */
  .analysis-highlights {
    grid-template-columns: 1fr !important;
  }

  /* ---------- 防止文字选中 ---------- */
  .btn,
  .bottom-nav-tab,
  .btn-drawer-toggle,
  .step-run-btn,
  .project-card {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* ---------- 移动端禁用 scroll-snap（避免干扰长内容阅读） ---------- */
  .step-card {
    scroll-snap-align: none;
  }

  .pipeline {
    scroll-snap-type: none;
  }
}

/* ==========================================================================
   超小屏（≤375px）进一步压缩
   ========================================================================== */
@media (max-width: 375px) {
  .auth-card {
    padding: 20px 14px;
  }

  .btn-send-code {
    min-width: 90px;
    font-size: 0.72rem;
  }

  #header-bar {
    padding: 8px 10px;
  }

  .pipeline {
    padding: 10px;
  }

  .image-gallery {
    grid-template-columns: 1fr;
  }
}
