/* ==========================================================
   个人工作台 · 多终端适配（responsive.css）
   覆盖：超宽屏 / 笔记本 / 平板横竖屏 / 手机 / 小屏手机 / 横屏手机
   另含：触屏设备（hover:none）加大热区、安全区适配、横滑提示
   ========================================================== */

.filter-toggle { display: none; }            /* 仅手机上启用筛选折叠 */

/* ---------- 0. 全局：杜绝横向溢出 + 输入框字号防 iOS 缩放 ---------- */
html, body { max-width: 100%; overflow-x: hidden; }
* { min-width: 0; }                    /* 允许 flex/grid 子项收缩，防撑破 */
img, svg, table { max-width: 100%; }
/* iOS 在 input 字号 <16px 时聚焦会强制放大页面 */
@supports (-webkit-touch-callout: none) {
  .input, .select, .textarea, .chips input,
  .lg-field input, #loginPwd { font-size: 16px; }
}

/* ---------- 1. 超宽屏（≥1680px）：内容不再无限拉宽 ---------- */
@media (min-width: 1680px) {
  body > header, #pathBar, body > main { max-width: 1400px; }
  .summary { gap: 16px; }
  .cal-cell { min-height: 96px; }
}

/* ---------- 2. 笔记本窄屏（1024–1279px）---------- */
@media (max-width: 1279px) {
  .proj-grid { grid-template-columns: repeat(2, 1fr); }
  .kanban { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-row { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .summary { gap: 12px; }
}

/* ---------- 3. 平板（768–1023px）---------- */
@media (max-width: 1023px) {
  .wrap { padding: 0 18px; }
  .summary { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .sum-card { padding: 12px 13px; }
  .proj-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  /* 看板：横向滑动 + 吸附，掌心操作更自然 */
  .kanban {
    display: flex; gap: 12px;
    overflow-x: auto; overflow-y: hidden;
    padding-bottom: 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .kanban-col { flex: 0 0 268px; scroll-snap-align: start; }

  .cal-cell { min-height: 72px; }
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .modal { max-width: min(640px, calc(100vw - 48px)); }
}

/* ---------- 4. 手机竖屏（≤767px）---------- */
@media (max-width: 767px) {
  .wrap { padding: 0 14px; }

  /* 顶部栏：标题 + 两个按钮挤在一行，按钮收紧 */
  .topbar { height: 48px; gap: 6px; }
  .brand { gap: 6px; min-width: 0; flex: 1 1 auto; }
  .brand .logo { width: 24px; height: 24px; flex: none; }
  .brand h1 {
    font-size: 12.5px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }
  .tb-actions { gap: 5px; flex: none; }
  .tb-actions .btn { height: 32px; padding: 0 9px; font-size: 11.5px; }
  /* 手机上「一键导出全部」太占位，收成图标语义的短文案 */
  .tb-actions .btn[data-action="export-all"] { display: none; }

  /* 数据状态条：允许换行，别把按钮挤没 */
  .pathbar .pb-inner { padding: 6px 0; gap: 2px; }
  .pathbar .pb-row { row-gap: 5px; }
  .pathbar .pb-path { font-size: 10.5px; }
  .pathbar .pb-sub { font-size: 10.5px; line-height: 1.5; }
  .pathbar .pb-actions { display: flex; }        /* 手机上也要能看到「数据与备份」 */

  /* 汇总卡：2 列更省纵向空间，最后一张跨两列 */
  .summary { grid-template-columns: repeat(2, 1fr); gap: 9px; margin: 12px 0; }
  .sum-card { padding: 11px 12px; border-radius: 10px; }
  .sum-card:last-child { grid-column: 1 / -1; }
  .sum-main { font-size: 14px; }
  .sum-row { font-size: 12.5px; }

  .panel { padding: 13px 12px 16px; border-radius: 0 0 10px 10px; min-height: 0; }

  /* 分段控件铺满宽度，热区够大 */
  .tabs { display: flex; width: 100%; margin-bottom: 12px; }
  .tab { flex: 1; text-align: center; padding: 7px 6px; font-size: 13px; height: 30px; }

  /* 工具栏：筛选控件两列排布，按钮整行均分 */
  .toolbar { gap: 8px; margin-bottom: 12px; }
  .tb-group { width: 100%; }
  .tb-group.right { margin-left: 0; }
  .tb-group.right .btn { flex: 1; }
  .field-inline { flex: 1 1 calc(50% - 4px); min-width: 0; font-size: 12px; }
  .field-inline > span:first-child { flex: 0 0 auto; white-space: nowrap; }
  .field-inline .select { flex: 1; min-width: 0; width: 100%; }
  .month-nav { width: 100%; justify-content: space-between; }
  .month-label { min-width: 0; flex: 1; }

  /* 筛选区折叠：手机上默认收起，点一下展开，省出屏幕给数据 */
  .tb-group.filters {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    max-height: 0; opacity: 0; overflow: hidden;
    transition: max-height .22s ease, opacity .18s ease, margin .22s ease;
    margin: 0;
  }
  .tb-group.filters.open {
    max-height: 420px; opacity: 1;
    margin-bottom: 4px;
  }
  .tb-group.filters .field-inline { flex: none; }
  .tb-group.filters .check { grid-column: 1 / -1; }
  /* 折叠开关 */
  .filter-toggle {
    display: inline-flex; align-items: center; gap: 5px;
    height: 32px; padding: 0 11px;
    border: .5px solid rgba(0,0,0,.14); border-radius: 6px;
    background: linear-gradient(180deg,#fff,#f5f5f7);
    font-size: 12px; color: var(--text); font-family: inherit;
    cursor: pointer;
  }
  .filter-toggle .ft-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; background: var(--primary); color: #fff;
    font-size: 10px; font-weight: 600;
  }
  .filter-toggle .ft-count[hidden] { display: none; }
  .filter-toggle .ft-chev { transition: transform .2s; font-size: 9px; color: var(--text3); }
  .filter-toggle.open .ft-chev { transform: rotate(180deg); }

  /* 日历：7 列在 390px 下每格仅 ~46px，压到极简 */
  .cal-week { gap: 3px; margin-bottom: 6px; }
  .cal-week span { font-size: 10.5px; }
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 52px; padding: 4px 4px; border-radius: 6px; }
  .cal-cell .cal-d { font-size: 10.5px; }
  .cal-cell .cal-h { display: none; }            /* 工时太小看不清，统一收进弹窗 */
  .cal-cell .cal-tag {
    left: 4px; bottom: 4px; font-size: 9px;
    max-width: calc(100% - 8px);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .cal-cell::before { width: 2px; }

  /* 统计块 */
  .stat-row { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat { padding: 7px 3px; border-radius: 8px; }
  .stat em { font-size: 10.5px; }
  .stat b { font-size: 15px; }
  .rest-bar { gap: 8px 12px; font-size: 12px; padding: 10px 11px; }

  /* 表格：横向可滑 + 首列吸附，右侧操作列常驻可见 */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    position: relative;
  }
  table.grid { min-width: 620px; }
  table.grid th, table.grid td { padding: 8px 10px; font-size: 12.5px; }
  table.grid th:first-child, table.grid td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: #fff;
    box-shadow: 1px 0 0 var(--line-soft);
  }
  table.grid th:first-child { background: #fafafb; }
  table.grid tbody tr:hover td:first-child { background: #fafafb; }

  /* 项目卡单列 */
  .proj-grid { grid-template-columns: 1fr; gap: 10px; }
  .pcard { padding: 12px 13px; }

  /* 看板横向滑动，卡片宽度贴合手指 */
  .kanban { gap: 10px; }
  .kanban-col { flex: 0 0 84vw; padding: 9px; }

  /* 弹窗：底部上滑式（iOS 风格） */
  .mask { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 90vh;
    animation: sheetUp .22s cubic-bezier(.2,.85,.25,1);
  }
  .modal-head { padding: 14px 16px; position: sticky; top: 0; background: #fbfbfc; z-index: 1; }
  .modal-body { padding: 14px 16px; }
  .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    position: sticky; bottom: 0;
  }
  .mod-foot .btn, .modal-foot .btn { flex: 1; min-height: 40px; }
  .fld-row { grid-template-columns: 1fr; }
  .radios { flex-direction: column; gap: 8px; }

  /* Toast 顶部通栏 */
  .toast-root { top: auto; bottom: 18px; left: 12px; right: 12px; }
  .toast { max-width: none; width: 100%; }

  .sec-title { flex-wrap: wrap; gap: 6px; }
  .bk-row { flex-wrap: wrap; gap: 6px; }
  .bk-acts { width: 100%; justify-content: flex-end; }
  .bk-list { max-height: 46vh; }
}

/* ---------- 5. 小屏手机（≤400px）---------- */
@media (max-width: 400px) {
  .wrap { padding: 0 10px; }
  .summary { gap: 8px; }
  .sum-card { padding: 10px 11px; }
  .tb-actions .btn { padding: 0 8px; font-size: 11.5px; }
  .cal-cell { min-height: 46px; }
  .cal-cell .cal-tag { font-size: 8.5px; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
  .stat b { font-size: 14px; }
  .field-inline { flex: 1 1 100%; }
  .kanban-col { flex: 0 0 90vw; }
}

/* ---------- 6. 手机横屏 / 矮视口 ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .mask { align-items: center; padding: 10px; }
  .modal { max-height: 94vh; border-radius: 12px; }
  .cal-cell { min-height: 44px; }
  .login-gate { padding: 0; }
  .lg-split { min-height: 100vh; }
  .lg-brand { padding: 20px 24px; }
  .lg-feat { display: none; }
}

/* ---------- 7. 触屏设备：热区放大到 40px+ ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn { height: 36px; padding: 0 13px; font-size: 13px; }
  .btn-sm { height: 32px; padding: 0 10px; font-size: 12.5px; }
  .input, .select { height: 38px; font-size: 14px; }
  .tab { height: 34px; }
  .pb-btn { padding: 7px 11px; font-size: 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .seg button { height: 32px; padding: 5px 16px; }
  /* 触屏没有 hover，去掉依赖 hover 的视觉反馈，改为 :active */
  .btn:hover { background: linear-gradient(180deg,#ffffff,#f5f5f7); }
  .cal-cell:hover { border-color: var(--line); box-shadow: 0 .5px 1px rgba(0,0,0,.03); }
  .cal-cell:active { background: rgba(0,122,255,.08); border-color: rgba(0,122,255,.5); }
  .bk-row:hover, table.grid tbody tr:hover { background: transparent; }
  /* 拖拽看板在触屏改为长按，禁用误触 */
  .kcard { cursor: pointer; }
}

/* ---------- 8. 横滑提示：手机上表格/看板第一次进入给个渐隐遮罩 ---------- */
@media (max-width: 767px) {
  .table-wrap::after,
  .kanban::after { display: none; }   /* 占位，保持结构简单 */
  .scroll-hint {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--text3);
    padding: 2px 2px 6px;
  }
  .scroll-hint svg { flex: none; }
}
@media (min-width: 768px) {
  .scroll-hint { display: none; }
}

/* ---------- 9. 安全区（刘海屏 / 底部手势条）---------- */
@supports (padding: env(safe-area-inset-bottom)) {
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast-root { bottom: calc(18px + env(safe-area-inset-bottom)); }
  .login-gate { padding-top: env(safe-area-inset-top); }
}

/* ---------- 10. 打印：去掉外壳，只留内容 ---------- */
@media print {
  body { background: #fff; }
  .topbar-shell, #pathBar, .tabs, .toolbar, .toast-root, .login-gate { display: none !important; }
  body > main, body > header { max-width: 100%; }
  .panel { box-shadow: none; border: none; padding: 0; }
  .sum-card, .pcard, .kcard { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  table.grid { min-width: 0; }
}
