/* ============================================================
   Local Live 响应式适配
   断点：桌面 >1024px | 平板 768-1024px | 手机 <768px
   ============================================================ */

/* ── 平板适配 (768px - 1024px) ── */
@media (max-width: 1024px) and (min-width: 769px) {
  /* 通用：ORB 缩小 */
  #orb { width: 280px; height: 280px; }
  .orb-container { width: 280px; height: 280px; }

  /* 深空主题：左右栏压缩 */
  [data-theme="deep-space"] .app {
    grid-template-columns: 320px 1fr;
    gap: 12px;
    padding: 12px;
  }
  [data-theme="deep-space"] .panel-left { padding: 14px; }

  /* 工作台：右栏压缩 */
  [data-theme="workbench"] .app {
    grid-template-columns: 1fr 300px;
  }

  /* 对话优先：右栏压缩 */
  [data-theme="converse"] .app {
    grid-template-columns: 1fr 240px;
  }

  /* vertex：左右侧栏自动隐藏 */
  [data-theme="vertex-space"] .vertex-left-feed,
  [data-theme="vertex-space"] .vertex-right-panel {
    display: none;
  }

  /* 设置面板宽度 */
  .settings-modal { width: 90vw; max-width: 720px; }

  /* 按钮触摸区域 */
  .orb-action-row button {
    min-height: 40px;
    min-width: 40px;
  }
}

/* ── 手机适配 (<768px) ── */
@media (max-width: 768px) {
  /* 全局：禁止横向滚动 */
  html, body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  /* 通用：单列布局 */
  .app {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr auto !important;
    padding: 8px !important;
    gap: 8px !important;
    height: 100vh;
    height: 100dvh; /* 动态视口高度，适配移动端地址栏 */
  }

  .panel {
    height: auto !important;
    padding: 12px !important;
    max-height: none !important;
  }

  /* ORB 缩小 */
  #orb { width: 160px !important; height: 160px !important; }
  .orb-container { width: 160px !important; height: 160px !important; }

  /* 按钮：触摸友好尺寸 */
  .orb-action-row {
    --orb-btn-h: 44px;
    --orb-btn-px: 14px;
    gap: 8px;
  }
  .orb-action-row button {
    min-height: 44px;
    min-width: 44px;
    font-size: 13px;
  }
  .orb-controls button,
  .bottom-bar button {
    min-height: 44px;
    min-width: 44px;
  }

  /* 底部栏：固定底部，安全区域 */
  .bottom-bar {
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 100;
    background: var(--bg);
    border-top: 1px solid var(--border);
  }

  /* 聊天区：底部留出空间给控制栏 */
  .transcript {
    padding-bottom: 80px !important;
  }

  /* 输入框 */
  .input-row {
    padding: 8px;
    gap: 6px;
  }
  .input-row input {
    font-size: 16px; /* 防止 iOS 缩放 */
    padding: 10px 12px;
  }

  /* 设置面板：全屏模态 */
  .settings-modal {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
  }
  .settings-tabs {
    flex-wrap: wrap;
    gap: 4px;
  }
  .settings-tab {
    padding: 8px 10px;
    font-size: 12px;
    min-height: 44px;
  }

  /* 深空主题：ORB 在上，聊天在下 */
  [data-theme="deep-space"] .panel-left {
    order: 1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
    gap: 8px;
    height: auto;
  }
  [data-theme="deep-space"] .panel-right {
    order: 2;
    min-height: 40vh;
  }
  [data-theme="deep-space"] .job-section { display: none; }
  [data-theme="deep-space"] .orb-info { font-size: 10px; }

  /* 工作台：聊天在上，ORB+指标在下 */
  [data-theme="workbench"] .panel-left { order: 2; }
  [data-theme="workbench"] .panel-right { order: 1; }
  [data-theme="workbench"] .metrics-panel {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  [data-theme="workbench"] .metric-card {
    flex: 1 1 45%;
    padding: 6px;
  }

  /* 对话优先：聊天在上，ORB在下 */
  [data-theme="converse"] .panel-left { order: 2; }
  [data-theme="converse"] .panel-right { order: 1; }
  [data-theme="converse"] .job-section { display: none; }

  /* 调音台：隐藏 VU 表，单列 */
  [data-theme="console"] .vu-panel { display: none !important; }
  [data-theme="console"] .app {
    grid-template-columns: 1fr !important;
  }

  /* 声场：ORB 居中，dock 底部 */
  [data-theme="stage"] .stage-dock {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  /* vertex：隐藏左右侧栏，ORB 居中 */
  [data-theme="vertex-space"] .vertex-left-feed,
  [data-theme="vertex-space"] .vertex-right-panel {
    display: none !important;
  }
  [data-theme="vertex-space"] .vertex-orb-stage {
    transform: scale(0.7);
  }
  [data-theme="vertex-space"] .vertex-bottom-dock {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  /* glass：ORB 缩小，卡片紧凑 */
  [data-theme="glass"] .glass-orb-card {
    padding: 12px;
  }
  [data-theme="glass"] .orb-action-row {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* 思考流：高度减小 */
  .thinking-stream {
    max-height: 40px;
    font-size: 11px;
  }

  /* 对话气泡：减小边距 */
  .transcript-item {
    margin: 4px 0;
  }
  .transcript-bubble {
    padding: 8px 12px;
    font-size: 14px;
    max-width: 90%;
  }

  /* 任务卡片：紧凑 */
  .job-card {
    padding: 6px 8px;
  }
  .job-task { font-size: 10px; }

  /* 报告卡片：紧凑 */
  .search-result-card {
    padding: 10px;
  }
  .search-result-body {
    font-size: 12px;
  }

  /* 引导弹窗：全屏 */
  #onboardingModal .modal-content {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
  }

  /* 权限确认卡片：底部弹出 */
  .permission-card {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-width: 100%;
  }

  /* 文本输入弹窗：全屏 */
  .text-modal {
    width: 95vw !important;
    max-width: 95vw !important;
  }
  .text-modal textarea {
    font-size: 16px; /* 防止 iOS 缩放 */
  }

  /* 健康状态面板：紧凑 */
  .health-panel {
    padding: 8px;
  }
  .health-item {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* 字体整体微调 */
  body {
    font-size: 14px;
  }
  h1 { font-size: 20px; }
  h2 { font-size: 17px; }
  h3 { font-size: 15px; }
}

/* ── 超小屏 (<480px) ── */
@media (max-width: 480px) {
  #orb { width: 120px !important; height: 120px !important; }
  .orb-container { width: 120px !important; height: 120px !important; }

  .orb-action-row {
    --orb-btn-h: 40px;
    --orb-btn-px: 10px;
  }
  .orb-action-row button {
    font-size: 12px;
    min-width: 40px;
  }

  .transcript-bubble {
    font-size: 13px;
    padding: 6px 10px;
  }

  .settings-tab {
    padding: 6px 8px;
    font-size: 11px;
  }
}

/* ── 触摸优化（所有触屏设备）── */
@media (hover: none) and (pointer: coarse) {
  /* 移除 hover 效果，改用 active */
  button:hover, .settings-tab:hover, .job-card:hover {
    transform: none !important;
    box-shadow: none !important;
  }
  button:active {
    opacity: 0.7;
    transform: scale(0.97);
  }

  /* 所有可点击元素最小触摸区域 */
  button,
  .settings-tab,
  .job-cancel,
  .theme-card,
  .memory-card button,
  .provider-card button {
    min-height: 44px;
    min-width: 44px;
  }

  /* 禁止双击缩放 */
  * {
    touch-action: manipulation;
  }

  /* 输入框聚焦时不放大（iOS） */
  input, textarea, select {
    font-size: 16px;
  }
}

/* ── 横屏手机优化 ── */
@media (max-height: 500px) and (orientation: landscape) {
  #orb { width: 100px !important; height: 100px !important; }
  .orb-container { width: 100px !important; height: 100px !important; }
  .app { padding: 4px !important; gap: 4px !important; }
  .panel { padding: 8px !important; }
  .transcript { max-height: 40vh; }
}
