/* ════════════════════════════════════════════════════════════════
   responsive.css — Phone-class breakpoints (375 / 393 / 430) + tablet
   ────────────────────────────────────────────────────────────────
   Owner: VIS-P1-01 / VIS-P2-12 — mobile responsive + drawer
   Loaded AFTER style.css so it can layer on top without modification.
   All selectors are scoped inside media queries (≥ desktop is unaffected).
   New class names use `.ds-*` / `.responsive-*` prefixes only.
   ════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════
   1) iPhone SE / 14 Pro class — phones (≤ 393px)
   ─── sidebar = drawer, smaller headings, denser layout
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 393px) {
  /* —— Sidebar 完全转为 drawer，避免 228px (60% 屏宽) 长期占据视野 —— */
  .sidebar,
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  body.sidebar-open .sidebar,
  body.sidebar-open .app-sidebar,
  .sidebar.mobile-open,
  .app-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* —— 汉堡按钮：< 393px 强制显示（兜底）—— */
  .hamburger-btn,
  #sidebar-toggle {
    display: inline-flex !important;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  /* —— Backdrop: drawer 打开时显示半透明遮罩 —— */
  body.sidebar-open::after,
  body .ds-drawer-backdrop {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    animation: ds-fade-in 0.18s ease both;
  }
  body.sidebar-open::after {
    pointer-events: none; /* :after 不能交互；真正交互的是 .ds-drawer-backdrop */
  }
  .ds-drawer-backdrop {
    display: none;
  }
  body.sidebar-open .ds-drawer-backdrop {
    display: block;
  }

  /* —— main-content 不左缩，因为 sidebar 是浮层 —— */
  .main-content,
  #main-content {
    margin-left: 0 !important;
    padding: 0.5rem !important;
  }

  /* —— 标题字号缩 2px（正文不动以保可读性）—— */
  h1, .h1 { font-size: 1.35rem !important; }
  h2, .h2 { font-size: 1.2rem !important; }
  h3, .h3 { font-size: 1.05rem !important; }
  h4, .h4 { font-size: 0.95rem !important; }
  h5, .h5 { font-size: 0.85rem !important; }
  .page-header h4 { font-size: 0.95rem !important; }

  /* —— 表格的 stacked card helper（业务可在 < 768px 给 table 加 .responsive-stack）—— */
  table.responsive-stack thead {
    display: none;
  }
  table.responsive-stack,
  table.responsive-stack tbody,
  table.responsive-stack tr,
  table.responsive-stack td {
    display: block;
    width: 100%;
  }
  table.responsive-stack tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    background: var(--card, #fff);
  }
  table.responsive-stack td {
    border: none !important;
    padding: 0.25rem 0 !important;
    text-align: left !important;
    position: relative;
  }
  table.responsive-stack td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    margin-right: 0.25rem;
  }

  /* —— Cmdk-palette 在窄屏全屏铺开 —— */
  #cmdk-palette {
    padding-top: 4vh !important;
  }
  #cmdk-palette > * {
    max-width: 95vw !important;
    width: 95vw !important;
  }

  /* —— Modal 全屏化以避免边距挤压 —— */
  .modal-dialog {
    margin: 0 !important;
    max-width: 100vw !important;
    min-height: 100vh;
  }
  .modal-content {
    border-radius: 0;
    min-height: 100vh;
  }
}

/* ═══════════════════════════════════════════════════════════════
   2) Tablet — 393 < w ≤ 768
   ─── 标准平板优化：sidebar 仍可 toggle，但内容区间更宽松
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 394px) and (max-width: 768px) {
  /* sidebar 沿用 style.css 已有 max-width:768px 的 mobile-open 行为，
     此处仅修补 backdrop 与字号 */
  .ds-drawer-backdrop {
    display: none;
  }
  body.sidebar-open .ds-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
    animation: ds-fade-in 0.18s ease both;
  }

  /* 平板字号稍小但不极端 */
  .page-header h4 { font-size: 1.05rem; }

  /* 卡片间距 */
  .card-body { padding: 0.85rem; }
}

/* ═══════════════════════════════════════════════════════════════
   3) Touch target 兜底（< 768px 全段）
   ───  WCAG 2.5.5: 所有可交互元素至少 44×44 (style.css 中 spotty)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .btn:not(.btn-link):not(.btn-sm):not(.btn-xs),
  .nav-link,
  .form-control,
  .form-select,
  .dropdown-item,
  a.list-group-item-action,
  [role="button"]:not(.btn-sm):not(.btn-xs) {
    min-height: 44px;
  }
  /* 输入框 padding 兼容 44px */
  .form-control,
  .form-select {
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }
  /* 但 icon-only 按钮（badge 区域）保留紧凑 */
  .action-icon-btn,
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   4) Cmd+K 帮助 modal — 按键 chip 样式
   ═══════════════════════════════════════════════════════════════ */
.kbd,
kbd.kbd {
  display: inline-block;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: #334155;
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  border: 1px solid #cbd5e1;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 3px 6px;
  min-width: 18px;
  text-align: center;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  white-space: nowrap;
  vertical-align: middle;
}
.kbd + .kbd {
  margin-left: 2px;
}

/* 快捷键帮助 modal 容器 */
#ds-kb-help-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  animation: ds-fade-in 0.16s ease both;
}
#ds-kb-help-modal.show {
  display: flex;
}
#ds-kb-help-modal .ds-kb-help-card {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 20px 24px;
}
#ds-kb-help-modal h5 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#ds-kb-help-modal .ds-kb-help-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#ds-kb-help-modal .ds-kb-help-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
  color: #334155;
}
#ds-kb-help-modal .ds-kb-help-list li:last-child {
  border-bottom: none;
}
#ds-kb-help-modal .ds-kb-help-list .ds-kb-desc {
  flex: 1;
  margin-right: 12px;
}
#ds-kb-help-modal .ds-kb-help-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0 4px;
}

@keyframes ds-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* —— 窄屏 modal 自适应 —— */
@media (max-width: 393px) {
  #ds-kb-help-modal {
    padding-top: 4vh;
  }
  #ds-kb-help-modal .ds-kb-help-card {
    max-width: 95vw;
    margin: 0 8px;
  }
}
