/* ============================================
   移动端优化补丁 — style.css 之后加载
   ============================================ */

/* --- 0. 禁用自定义光标（移动端 & 触屏设备） --- */
@media (hover: none) and (pointer: coarse) {
  *, *::before, *::after,
  a, button, .btn, .nav-item, .upload-zone, .knowledge-card,
  .char-avatar, .preview-item, .history-card.select-mode,
  .history-delete, .filter-btn, .modal-btn, .hamburger,
  .sidebar-close, .consent-actions .btn, .preview-remove-btn,
  .preview-remove, .history-checkbox, input[type="range"],
  select, [role="button"], [onclick],
  input[type="text"], input[type="number"], textarea,
  [contenteditable="true"], [disabled], .btn-primary:disabled {
    cursor: auto !important;
  }
}
/* 同时在小屏幕上禁用自定义光标（覆盖 style.css 底部的全局 cursor 规则） */
@media (max-width: 900px) {
  *, *::before, *::after {
    cursor: auto !important;
  }
  a, button, .btn, .nav-item, .upload-zone, .knowledge-card,
  .filter-btn, .modal-btn, .hamburger, .sidebar-close,
  .consent-actions .btn, select, [role="button"], [onclick] {
    cursor: pointer !important;
  }
}

/* --- 2. 平板断点 900px 以下 --- */
@media (max-width: 900px) {
  /* 侧边栏遮罩层提高 z-index，确保盖住 sidebar 内容 */
  .sidebar-overlay {
    z-index: 101;
    top: 0; left: 0; right: 0; bottom: 0; /* Safari 兼容：inset 需要回退 */
  }
  .sidebar {
    z-index: 102;
  }

  /* 移动端顶部栏增加安全区域（刘海屏） */
  .mobile-header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
    height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
  }

  /* 主内容区考虑顶部安全区域 */
  .main-wrapper {
    margin-top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    padding: 20px 24px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    /* 防止水平溢出 */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* 面板 & 页面标题 */
  .panel {
    padding: 18px;
  }
  .page-header {
    margin-bottom: 16px;
  }
  .page-header h1 {
    font-size: 1.25rem;
  }
  .page-desc {
    font-size: 0.85rem;
  }

  /* 上传区域适度缩小 */
  .upload-zone {
    padding: 32px 18px;
  }
  .upload-zone i {
    font-size: 2.4rem;
  }
  .upload-zone p {
    font-size: 1rem;
  }

  /* 知识库：4列 + 右侧详情（平板端） */
  .knowledge-layout {
    gap: 16px;
  }
  .knowledge-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  .knowledge-detail {
    width: 300px;
  }
  .kd-placeholder {
    height: 280px;
  }
  .kd-inner {
    padding: 18px 16px;
  }
  .kd-avatar {
    width: 56px;
    height: 56px;
  }
  .kd-name {
    font-size: 1.1rem;
  }

  /* 检测结果双栏保持，间距缩小 */
  .detect-split-equal {
    gap: 16px;
  }

  /* 聊天区域适配平板高度 */
  .chat-container {
    height: calc(100vh - var(--mobile-header-height) - 100px);
  }
  .chat-bubble {
    max-width: 85%;
  }
  .chat-input-area {
    padding: 12px 16px;
  }
  .chat-model-bar {
    padding: 8px 12px;
  }
  .chat-model-select {
    max-width: 180px;
    font-size: 0.8rem;
  }
  .chat-model-hint {
    max-width: 120px;
  }
  .history-toolbar {
    gap: 10px;
  }
  .history-filter-group {
    gap: 6px;
  }

  /* 视频帧表格 */
  .frame-table-scroll {
    max-height: 400px;
  }

  /* 管理员设置：双栏 → 单栏（平板端） */
  .admin-settings-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

/* ===== 知识库布局（基础样式，所有设备） ===== */
.knowledge-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.knowledge-grid {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}
.knowledge-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow), 0 4px 16px rgba(0,0,0,0.2);
}
.knowledge-card {
  padding: 16px 10px 14px !important;
}
.knowledge-card .kc-icon {
  width: 48px !important;
  height: 48px !important;
  margin-bottom: 8px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.knowledge-card .kc-icon img {
  width: 40px !important;
  height: 40px !important;
}
.knowledge-card .kc-name {
  font-size: 0.82rem !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
}
.knowledge-detail {
  width: 400px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  position: sticky;
  top: 24px;
  min-height: 360px;
  overflow: hidden;
  transition: background var(--transition), border var(--transition);
}
.kd-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 360px;
  color: var(--text-muted);
  gap: 12px;
}
.kd-placeholder i {
  font-size: 2.5rem;
  opacity: 0.35;
}
.kd-placeholder p {
  font-size: 0.9rem;
}
.kd-inner {
  padding: 24px 20px;
  animation: kdFadeIn 0.3s ease;
}
@keyframes kdFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kd-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.kd-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 3px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
}
.kd-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.kd-name {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
}
.kd-alias {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.kd-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kd-row {
  display: flex;
  gap: 8px;
  font-size: 0.88rem;
  line-height: 1.6;
}
.kd-label {
  flex-shrink: 0;
  width: 72px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
}
.kd-value {
  color: var(--text-primary);
  word-break: break-all;
}
.kd-desc {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.75;
}
.kd-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 20px 0;
}
.kd-loading i {
  color: var(--accent);
}

/* --- 3. 手机断点 600px 以下 --- */

/* 手机端底部弹出框（仅手机） */
@media (max-width: 600px) {
  .knowledge-mobile-sheet {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    inset: 0;
    z-index: 3000;
    pointer-events: none;
  }
  .knowledge-mobile-sheet.open {
    display: block;
    pointer-events: auto;
  }
  .kms-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    inset: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s;
  }
  .knowledge-mobile-sheet.open .kms-overlay {
    opacity: 1;
  }
  .kms-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 75vh;
    overflow-y: auto;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.3);
  }
  .knowledge-mobile-sheet.open .kms-content {
    transform: translateY(0);
  }
  .kms-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 16px;
  }
}

@media (max-width: 600px) {
  /* ---- 全局触摸目标最小 44px ---- */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }
  .btn-sm {
    min-height: 36px;
    padding: 8px 14px;
    font-size: 0.82rem;
  }
  .filter-btn {
    min-height: 36px;
    padding: 6px 14px;
  }
  .history-delete {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .preview-remove-btn,
  .preview-remove {
    width: 36px;
    height: 36px;
  }
  .modal-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  /* ---- 主内容区底部安全区域 ---- */
  .main-wrapper {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  }

  /* ---- 管理员设置：双栏 → 单栏 ---- */
  .admin-settings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .admin-add-fields {
    gap: 8px;
  }
  .admin-add-actions {
    flex-direction: column;
  }
  .admin-add-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ---- Chat 容器：动态高度，适配虚拟键盘 ---- */
  .chat-container {
    height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 52px);
    height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 52px);
  }
  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    /* 防止输入框被虚拟键盘遮挡 */
    position: sticky;
    bottom: 0;
    background: var(--bg-panel);
    z-index: 2;
  }
  .chat-model-bar {
    padding: 6px 10px;
    gap: 6px;
  }
  .chat-model-select {
    max-width: none;
    flex: 1;
    font-size: 16px; /* 防 iOS 缩放 */
    min-height: 36px;
  }
  .chat-model-hint {
    display: none;
  }
  .chat-input {
    font-size: 16px; /* 防止 iOS 自动缩放 */
    min-height: 44px;
  }
  .chat-bubble {
    max-width: 88%;
  }
  /* 发送按钮：移动端加大触摸区 */
  #chatSendBtn {
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #chatSendBtn:active {
    transform: scale(0.92);
  }
  #chatSendBtn:disabled {
    opacity: 0.4;
  }
  /* 聊天气泡内文字换行优化 */
  .chat-text {
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
  }

  /* ---- 检测表格：横向滚动 ---- */
  .detection-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .detection-table {
    min-width: 320px;
    white-space: nowrap;
  }
  .detection-table th,
  .detection-table td {
    padding: 8px 8px;
    font-size: 0.78rem;
  }
  .det-bbox {
    font-size: 0.72rem;
  }

  /* ---- 帧检测表格：横向滚动 ---- */
  .frame-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .frame-detection-table {
    min-width: 500px;
  }
  .frame-detection-table th,
  .frame-detection-table td {
    padding: 6px 6px;
    font-size: 0.7rem;
  }

  /* ---- 上传区域：更大触摸区 ---- */
  .upload-zone {
    padding: 28px 16px;
    border-style: solid;
    border-color: var(--border);
    background: var(--bg-card);
  }
  .upload-zone:active {
    border-color: var(--accent);
    background: rgba(124, 92, 252, 0.08);
  }
  /* 移动端隐藏"拖拽"提示，只显示"点击选择" */
  .upload-zone .upload-hint-drag {
    display: none !important;
  }
  .upload-zone .upload-hint-tap {
    display: inline !important;
  }

  /* ---- 上传操作按钮：纵向堆叠，全宽 ---- */
  .upload-actions {
    flex-direction: column;
    gap: 8px;
  }
  .upload-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ---- 单图检测结果区域 ---- */
  .single-result-img-wrap img {
    max-height: 220px;
  }
  .annotated-img-wrap img {
    max-height: 200px;
  }

  /* ---- 多图结果卡片 ---- */
  .multi-card-images {
    grid-template-columns: 1fr;
  }
  .multi-img-section img {
    max-height: 200px;
  }

  /* ---- 视频检测 ---- */
  .video-stream-img {
    min-height: 180px;
    border-radius: 8px;
  }
  .video-result-layout .detect-split-equal > .panel {
    min-height: auto;
  }
  /* 视频操作按钮加大间距 */
  .video-result-layout .upload-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .video-result-layout .upload-actions .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
    min-height: 44px;
  }

  /* ---- 历史记录 ---- */
  .history-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .history-filter-group {
    width: 100%;
    justify-content: center;
  }
  .history-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  .history-actions .btn-sm {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }
  .history-stats {
    width: 100%;
    text-align: center;
  }
  .history-card-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }
  .history-card-actions {
    width: 100%;
    justify-content: space-between;
  }
  .history-card-body {
    grid-template-columns: 1fr;
  }
  .history-img-wrap img {
    max-height: 200px;
  }
  .history-card-dets {
    padding: 10px 14px;
  }
  .det-tag {
    font-size: 0.76rem;
    padding: 4px 8px;
  }
  .history-det-list {
    padding: 10px 12px;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .hist-avatar-ring {
    width: 40px;
    height: 40px;
  }
  .hist-avatar-inner img {
    width: 30px;
    height: 30px;
  }
  .hist-det-row {
    padding: 8px 10px;
    gap: 6px;
  }
  .hist-det-name {
    font-size: 0.78rem;
  }
  .hist-det-meta {
    font-size: 0.68rem;
  }
  .hist-det-bbox {
    font-size: 0.64rem;
  }

  /* ---- 知识库 ---- */
  .knowledge-layout {
    flex-direction: column;
  }
  .knowledge-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px;
  }
  .knowledge-detail {
    display: none !important; /* 手机端隐藏右侧面板 */
  }
  .knowledge-card {
    padding: 14px 8px 12px !important;
  }
  .knowledge-card .kc-icon {
    width: 52px !important;
    height: 52px !important;
    margin-bottom: 8px !important;
  }
  .knowledge-card .kc-icon img {
    width: 44px !important;
    height: 44px !important;
  }
  .knowledge-card .kc-name {
    font-size: 0.78rem !important;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* 知识库详情面板（PC/Pad） */
  .knowledge-detail {
    display: none;
  }
  /* 手机端底部弹出框 */
  .knowledge-mobile-sheet {
    display: none;
  }

  /* ---- 设置页面 ---- */
  .settings-content {
    max-width: 100%;
  }
  .setting-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .setting-row label {
    min-width: auto;
    width: 100%;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
  }
  .setting-row input[type="range"] {
    width: 100%;
    flex: none;
  }
  .setting-row select {
    width: 100%;
    flex: none;
    min-height: 44px;
    font-size: 16px; /* 防止 iOS 缩放 */
  }
  .setting-row span {
    width: 100%;
    text-align: right;
  }

  /* ---- 模态框（大图预览） ---- */
  .modal-content {
    max-width: 98vw;
    max-height: 90vh;
    padding: 0 4px;
  }
  .modal-content img {
    max-height: 80vh;
    border-radius: var(--radius);
  }
  .modal-actions {
    top: -44px;
    right: 4px;
  }
  .modal-btn {
    width: 44px;
    height: 44px;
  }

  /* ---- Toast 适配安全区域 ---- */
  .toast-container {
    top: calc(var(--mobile-header-height) + 8px + env(safe-area-inset-top));
    right: 10px;
    left: 10px;
  }
  .toast {
    max-width: 100%;
    font-size: 0.84rem;
    padding: 12px 14px;
  }

  /* ---- 同意弹窗 ---- */
  .consent-overlay {
    padding: 16px;
    padding-top: max(15vh, calc(16px + env(safe-area-inset-top)));
    align-items: flex-start;
  }
  .consent-modal {
    padding: 24px 18px;
  }
  .consent-modal h2 {
    font-size: 1.1rem;
  }
  .consent-icon {
    font-size: 2.2rem;
  }
  .consent-actions {
    flex-direction: column;
    gap: 8px;
  }
  .consent-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 48px;
    font-size: 0.95rem;
  }

  /* ---- 检测结果中的角色头像区域 ---- */
  .detected-chars {
    gap: 10px;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .char-avatar {
    flex-shrink: 0;
  }
  .char-avatar .avatar-ring {
    width: 52px;
    height: 52px;
  }
  .char-avatar .char-name {
    max-width: 56px;
    font-size: 0.68rem;
  }
  .char-avatar .char-conf {
    font-size: 0.64rem;
  }

  /* ---- 进度条更明显 ---- */
  .progress-bar {
    height: 6px;
    margin-top: 10px;
  }

  /* ---- 分页按钮加大 ---- */
  .pagination {
    gap: 8px;
  }
  .pagination .btn {
    min-height: 40px;
    padding: 8px 14px;
  }

  /* ---- 页面标题优化 ---- */
  .page-header h1 {
    font-size: 1.1rem;
  }
  .page-desc {
    font-size: 0.78rem;
    line-height: 1.4;
  }

  /* ---- 侧边栏导航项加大触摸区 ---- */
  .nav-item {
    padding: 14px 16px;
    min-height: 48px;
  }

  /* ---- 视频实时信息栏 ---- */
  .video-live-bar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    font-size: 0.78rem;
  }
  .live-sep {
    display: none;
  }
}

/* ===== 人物简介模态弹窗（基础样式） ===== */
.char-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  inset: 0;
  z-index: 5000;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: charModalFadeIn 0.2s ease;
}
@keyframes charModalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.char-modal {
  width: 380px;
  max-width: 100%;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  animation: charModalSlideUp 0.25s ease;
}
@keyframes charModalSlideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 工具栏 */
.char-modal-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.char-modal-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border: none;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.char-modal-copy {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.char-modal-copy:hover {
  background: rgba(255, 255, 255, 0.3);
}
.char-modal-close {
  background: rgba(255, 80, 80, 0.2);
  color: #ffaaaa;
  border: 1px solid rgba(255, 80, 80, 0.3);
}
.char-modal-close:hover {
  background: rgba(255, 80, 80, 0.4);
  color: #fff;
}

/* 卡片主体 */
.char-modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.char-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
}
.char-modal-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
}
.char-modal-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.char-modal-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 检测信息条 */
.char-modal-detect {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.char-modal-detect i {
  margin-right: 3px;
  font-size: 0.75rem;
}
.char-modal-conf strong {
  color: var(--accent);
  font-weight: 700;
}
.char-modal-bbox {
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* 简介内容 */
.char-modal-body {
  padding: 16px 18px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.75;
  max-height: 280px;
  overflow-y: auto;
  word-break: break-word;
}
.char-modal-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 10px 0;
}
.char-modal-loading i {
  color: var(--accent);
}

/* ===== 人物简介弹窗（移动端覆盖） ===== */
@media (max-width: 600px) {
  .char-modal-overlay {
    align-items: flex-end;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .char-modal {
    width: 100%;
    animation-name: charModalMobileUp;
  }
  @keyframes charModalMobileUp {
    from { opacity: 0; transform: translateY(60px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .char-modal-toolbar {
    gap: 6px;
  }
  .char-modal-tool-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    min-height: 40px;
  }
  .char-modal-header {
    padding: 14px 16px;
  }
  .char-modal-avatar {
    width: 44px;
    height: 44px;
  }
  .char-modal-title {
    font-size: 1rem;
  }
  .char-modal-detect {
    gap: 12px;
    padding: 10px 16px;
    flex-wrap: wrap;
  }
  .char-modal-body {
    padding: 14px 16px;
    max-height: 50vh;
  }
}

/* --- 4. 超小屏幕 360px 以下 --- */
@media (max-width: 360px) {
  .knowledge-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .knowledge-card {
    padding: 10px 4px 8px !important;
  }
  .knowledge-card .kc-icon {
    width: 40px !important;
    height: 40px !important;
    margin-bottom: 6px !important;
  }
  .knowledge-card .kc-icon img {
    width: 34px !important;
    height: 34px !important;
  }
  .knowledge-card .kc-name {
    font-size: 0.72rem !important;
  }
  .page-header h1 {
    font-size: 1rem;
  }
  .chat-bubble {
    max-width: 92%;
  }
}

/* --- 5. 横屏手机优化 --- */
@media (max-height: 500px) and (orientation: landscape) {
  .chat-container {
    height: calc(100vh - 40px);
  }
  .consent-overlay {
    padding-top: 10px;
  }
  .consent-modal {
    padding: 16px;
  }
  .consent-icon {
    font-size: 1.8rem;
    margin-bottom: 8px;
  }
}

/* --- 6. 暗色主题下移动端优化 --- */
@media (max-width: 600px) {
  /* 上传区域在暗色主题下更明显 */
  .upload-zone {
    background: var(--bg-card);
  }
  /* 表格行点击区域加大 */
  .detection-table tr {
    min-height: 44px;
  }
}

/* --- 7. iPad/平板横屏布局（参考PC端） --- */
@media (min-width: 601px) and (max-width: 1100px) and (orientation: landscape) {
  /* 侧边栏保持PC端可见 */
  .sidebar {
    transform: none !important;
    width: var(--sidebar-width) !important;
  }
  .sidebar-close {
    display: none !important;
  }
  .sidebar-overlay {
    display: none !important;
    pointer-events: none !important;
  }
  /* 隐藏移动端顶部栏 */
  .mobile-header {
    display: none !important;
  }
  /* 主内容区参考PC端布局 */
  .main-wrapper {
    margin-left: var(--sidebar-width) !important;
    margin-top: 0 !important;
    padding: 20px 24px !important;
  }
  /* 面板使用PC端尺寸 */
  .panel {
    padding: 18px;
  }
  .page-header h1 {
    font-size: 1.3rem;
  }
  /* 检测结果保持双栏 */
  .detect-split-equal {
    grid-template-columns: 1fr 1fr;
  }
  /* 管理员设置双栏 */
  .admin-settings-grid {
    grid-template-columns: 1fr 1fr;
  }
  .admin-add-actions {
    flex-direction: row;
  }
  .admin-add-actions .btn {
    width: auto;
  }
  /* 上传区域紧凑 */
  .upload-zone {
    padding: 28px 16px;
  }
  .upload-zone i {
    font-size: 2.2rem;
  }
  /* 知识库多列 */
  .knowledge-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  /* 历史记录保持双图 */
  .history-card-body {
    grid-template-columns: 1fr 1fr;
  }
  .history-toolbar {
    flex-direction: row;
    align-items: center;
  }
  .history-filter-group {
    width: auto;
    justify-content: flex-start;
  }
  .history-actions {
    width: auto;
    flex-wrap: nowrap;
  }
  .history-stats {
    width: auto;
  }
  /* 聊天容器 */
  .chat-container {
    height: calc(100vh - 120px);
  }
  .chat-model-select {
    max-width: 220px;
  }
  .chat-model-hint {
    display: block;
    max-width: 160px;
  }
  /* 视频帧表格 */
  .frame-table-scroll {
    max-height: 400px;
  }
}

/* --- 8. iPad/平板竖屏布局（参考手机端） --- */
@media (max-width: 900px) and (orientation: portrait) {
  /* 确保移动端布局生效：侧边栏隐藏、显示汉堡菜单 */
  .sidebar {
    transform: translateX(-100%) !important;
  }
  .sidebar.open {
    transform: translateX(0) !important;
    visibility: visible;
    pointer-events: auto;
  }
  .mobile-header {
    display: flex !important;
  }
  .sidebar-overlay {
    display: block !important;
  }
  .main-wrapper {
    margin-left: 0 !important;
    margin-top: calc(var(--mobile-header-height) + env(safe-area-inset-top)) !important;
  }
  /* 单栏布局 */
  .detect-split-equal {
    grid-template-columns: 1fr;
  }
  .admin-settings-grid {
    grid-template-columns: 1fr;
  }
  .history-card-body {
    grid-template-columns: 1fr;
  }
  .knowledge-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  /* 上传区域适中 */
  .upload-zone {
    padding: 30px 16px;
  }
  /* 知识库详情隐藏（使用底部弹出） */
  .knowledge-detail {
    display: none !important;
  }
}

/* --- 9. iOS Safari 弹性滚动修复 --- */
@supports (-webkit-touch-callout: none) {
  .chat-messages {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  .frame-table-scroll {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  .detection-table-wrap {
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  /* iOS Safari: inset 回退（旧版本不支持 inset 简写） */
  .consent-overlay,
  .sidebar-overlay,
  .modal-overlay,
  .char-modal-overlay,
  .knowledge-mobile-sheet {
    top: 0; left: 0; right: 0; bottom: 0;
  }
  /* iOS Safari: 防止输入框聚焦时页面跳动 */
  .chat-input,
  .chat-model-select,
  input[type="text"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important; /* 防止 iOS 自动缩放 */
  }
  /* iOS Safari: fixed 定位在虚拟键盘弹出时的修复 */
  .chat-input-area {
    position: sticky;
    bottom: 0;
  }
}

/* =============================================
   10. 全面自适应修复（跨设备 / 屏占比）
   ============================================= */

/* ---- 10a. 动态视口高度（仅移动端） ---- */
@media (max-width: 900px) {
  .chat-container {
    height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 80px);
    height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 80px);
  }
  .main-wrapper {
    min-height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
    min-height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
    overflow-x: hidden;
  }
  .page {
    min-width: 0;
  }
  .panel {
    min-width: 0;
    overflow: hidden;
  }
}
@media (max-width: 600px) {
  .chat-container {
    height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 52px);
    height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px) - 52px);
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .chat-container {
    height: calc(100dvh - 40px);
    height: calc(100vh - 40px);
  }
}

/* ---- 10b. 检测结果双栏自适应（仅平板及以下） ---- */
@media (max-width: 900px) {
  .detect-split-equal {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}
@media (max-width: 768px) {
  .detect-split-equal {
    grid-template-columns: 1fr;
  }
}

/* ---- 10c. 图片 / 视频防溢出（仅移动端） ---- */
@media (max-width: 900px) {
  .single-result-img-wrap,
  .annotated-img-wrap,
  .multi-img-section,
  .history-img-wrap {
    overflow: hidden;
    max-width: 100%;
  }
  .single-result-img-wrap img,
  .annotated-img-wrap img,
  .multi-img-section img,
  .history-img-wrap img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
  }
}
@media (max-width: 900px) {
  .video-stream-img {
    width: 100%;
    height: auto;
    max-height: 60vh;
    object-fit: contain;
  }
}
@media (max-width: 600px) {
  .video-stream-img {
    max-height: 45vh;
    min-height: 160px;
  }
  .single-result-img-wrap img {
    max-height: 40vh;
  }
  .annotated-img-wrap img {
    max-height: 35vh;
  }
}

/* ---- 10d. 弹窗自适应（仅移动端） ---- */
@media (max-width: 600px) {
  .modal-content {
    max-width: 100vw;
    max-height: 92vh;
    max-height: 92dvh;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .modal-content img {
    max-width: 100%;
    max-height: 80vh;
    max-height: 80dvh;
    object-fit: contain;
    border-radius: var(--radius);
  }
  .modal-content-video {
    max-width: 100vw;
    max-height: 90vh;
    max-height: 90dvh;
  }
  .modal-content-video video {
    max-width: 100%;
    max-height: 75vh;
    max-height: 75dvh;
    border-radius: var(--radius);
  }
  .modal-actions {
    top: -40px;
    right: 4px;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .modal-content {
    max-width: 85vw;
    max-height: 95vh;
    max-height: 95dvh;
  }
  .modal-content img {
    max-height: 90vh;
    max-height: 90dvh;
  }
  .modal-content-video video {
    max-height: 88vh;
    max-height: 88dvh;
  }
}

/* ---- 10e. 横屏手机全面优化 ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .main-wrapper {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .page-header {
    margin-bottom: 8px;
    gap: 4px;
  }
  .page-header h1 {
    font-size: 1rem;
  }
  .page-desc {
    display: none;
  }
  .panel {
    padding: 10px 14px;
  }
  .upload-zone {
    padding: 14px 12px;
  }
  .upload-zone i {
    font-size: 1.5rem;
    margin-bottom: 6px;
  }
  .upload-zone p {
    font-size: 0.88rem;
  }
  .upload-zone span {
    font-size: 0.72rem;
  }
  .result-stats {
    margin-bottom: 10px;
  }
  .stat-chip {
    padding: 5px 10px;
    font-size: 0.78rem;
  }
  .detect-split-equal {
    gap: 10px;
  }
  .knowledge-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .knowledge-card {
    padding: 8px 6px !important;
  }
  .knowledge-card .kc-icon {
    width: 36px !important;
    height: 36px !important;
  }
  .knowledge-card .kc-name {
    font-size: 0.68rem !important;
  }
  .frame-table-scroll {
    max-height: 200px;
  }
}

/* ---- 10f. 超宽屏 / 折叠屏适配 ---- */
@media (min-width: 1400px) {
  .main-wrapper {
    max-width: 1200px;
    margin-left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - 1200px) / 2);
    margin-right: auto;
  }
}
@media (min-width: 1800px) {
  .main-wrapper {
    max-width: 1400px;
    margin-left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - 1400px) / 2);
  }
  .knowledge-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* ---- 10g. 流体网格（仅移动端） ---- */
@media (max-width: 900px) {
  .history-det-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
  }
  .multi-card-images {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
  }
  .history-card-body {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
  .history-card-body-video {
    grid-column: 1 / -1;
  }
}
@media (max-width: 600px) {
  .history-det-list {
    grid-template-columns: 1fr;
  }
  .multi-card-images {
    grid-template-columns: 1fr;
  }
  .history-card-body {
    grid-template-columns: 1fr;
  }
}

/* ---- 10h. 表格横向滚动（仅移动端） ---- */
@media (max-width: 900px) {
  .detection-table-wrap,
  .frame-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .detection-table {
    min-width: 280px;
  }
  .frame-detection-table {
    min-width: 480px;
  }
}

/* ---- 10i. 视频操作按钮自适应（仅移动端） ---- */
@media (max-width: 900px) {
  .video-result-layout .upload-actions {
    flex-wrap: wrap;
  }
  .video-result-layout .upload-actions .btn {
    flex: 1 1 auto;
    min-width: 100px;
    justify-content: center;
  }
}
@media (max-width: 400px) {
  .video-result-layout .upload-actions {
    flex-direction: column;
  }
  .video-result-layout .upload-actions .btn {
    width: 100%;
  }
}

/* ---- 10j. 安全区域统一处理（仅移动端） ---- */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    .chat-input-area {
      padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .kms-content {
      padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
    .consent-overlay {
      padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    .toast-container {
      top: calc(var(--mobile-header-height) + 8px + env(safe-area-inset-top));
    }
  }
}

/* ---- 10k. 移动端主内容安全间距 ---- */
@media (max-width: 900px) {
  .main-wrapper {
    margin-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---- 10l. 角色详情弹窗自适应（仅移动端） ---- */
@media (max-width: 900px) {
  .char-modal {
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 40px);
    max-height: calc(100vh - 40px);
  }
  .char-modal-body {
    max-height: calc(100dvh - 260px);
    max-height: calc(100vh - 260px);
    overflow-y: auto;
  }
}
@media (max-width: 600px) {
  .char-modal {
    max-width: 100%;
    max-height: calc(100dvh - 20px);
    max-height: calc(100vh - 20px);
  }
  .char-modal-body {
    max-height: 50vh;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .char-modal-overlay {
    align-items: center;
    padding: 8px;
  }
  .char-modal {
    max-height: calc(100dvh - 16px);
    max-height: calc(100vh - 16px);
  }
  .char-modal-body {
    max-height: calc(100dvh - 200px);
    max-height: calc(100vh - 200px);
  }
}

/* ---- 10m. 同意弹窗自适应（仅移动端） ---- */
@media (max-width: 600px) {
  .consent-modal {
    max-width: min(480px, calc(100vw - 32px));
    max-height: calc(100dvh - 40px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
}
@media (max-height: 600px) {
  .consent-overlay {
    padding-top: 8px;
    align-items: flex-start;
  }
  .consent-modal {
    padding: 16px;
  }
  .consent-icon {
    font-size: 2rem;
    margin-bottom: 10px;
  }
  .consent-modal h2 {
    font-size: 1rem;
  }
}

/* ---- 10n. 知识库弹出框自适应 ---- */
@media (max-width: 900px) {
  .kms-content {
    max-height: 75vh;
    max-height: 75dvh;
    overscroll-behavior: contain;
  }
}
@media (max-width: 900px) and (max-height: 600px) {
  .kms-content {
    max-height: 85vh;
    max-height: 85dvh;
  }
}

/* ---- 10o. 文本溢出保护（仅移动端） ---- */
@media (max-width: 900px) {
  .hist-det-name,
  .kc-name,
  .char-name,
  .history-video-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-text,
  .kd-desc,
  .char-modal-body,
  .kms-content {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}
