/* ============================================================
 * V4.7 双端响应式 / 移动录入适配层
 * 依赖：edc.css（在其后加载）
 * 断点：≥1025 桌面 | 768–1024 平板 | ≤767 手机 | ≤400 小屏
 * 设计原则：桌面不变形；手机单列、大触控、输入框≥16px（防 iOS 缩放）、
 *           表格横向滚动、操作条吸底、导航抽屉化。
 * ============================================================ */

/* ---------- 全局移动端基础 ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
img, svg { max-width: 100%; }

/* 抽屉导航控件（桌面隐藏） */
.nav-toggle-fab{display:none}
.nav-scrim{display:none}

/* ---------- 平板：768–1024px ---------- */
@media (max-width:1024px) and (min-width:768px){
  .sidebar{width:190px}
  .sidebar .brand{padding:15px 13px}
  .nav a{padding:9px 11px;margin:1px 8px;font-size:13px}
  .content{padding:18px 18px}
  .g4{grid-template-columns:repeat(2,1fr)}
  .g3{grid-template-columns:repeat(2,1fr)}
  .vs-grid{grid-template-columns:repeat(auto-fill,minmax(200px,1fr))}
  .board-hero,.dis-hero{padding:16px 18px}
}

/* ---------- 手机：≤767px ---------- */
@media (max-width:767px){

  /* ===== 1. 布局骨架：侧边栏抽屉化 ===== */
  .layout{display:block;min-height:100vh}
  .sidebar{
    position:fixed;top:0;left:0;bottom:0;width:min(84vw,288px);height:100dvh;
    z-index:120;transform:translateX(-102%);transition:transform .24s cubic-bezier(.4,0,.2,1);
    box-shadow:8px 0 32px rgba(8,30,52,.32);border-radius:0 16px 16px 0;overflow-y:auto;
  }
  body.nav-open .sidebar{transform:translateX(0)}
  body.nav-open{overflow:hidden}
  .sidebar .nav a{min-height:44px;font-size:14.5px;padding:12px 14px}
  .sidebar .brand{padding:16px 15px}
  .sidebar .me{padding:14px 15px}

  .main{width:100%;min-width:0}
  .topbar{
    height:52px;padding:0 12px 0 56px;gap:8px;
  }
  .topbar .crumb{font-size:13px;max-width:52vw;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .topbar > span:last-child,
  .topbar > span[style*="12px"]{display:none}          /* 副标题/环境说明在手机隐藏 */
  .topbar .sp{flex:1}
  .content{padding:12px 12px calc(22px + env(safe-area-inset-bottom));overflow-x:hidden}

  /* 汉堡按钮 / 遮罩：仅当页面存在 .layout（业务外壳）时显示 */
  body:has(.layout) .nav-toggle-fab{
    display:flex;align-items:center;justify-content:center;
    position:fixed;top:9px;left:10px;width:36px;height:36px;z-index:130;
    border-radius:9px;background:rgba(255,255,255,.94);border:1px solid var(--line);
    box-shadow:0 2px 8px rgba(13,43,69,.15);font-size:18px;line-height:1;color:var(--ink);padding:0;
  }
  body:has(.layout).nav-open .nav-scrim{
    display:block;position:fixed;inset:0;z-index:110;background:rgba(8,25,43,.5);
    backdrop-filter:blur(1px);
  }
  /* 无 :has 支持的降级：由内联脚本给 body 加 .has-shell */
  body.has-shell .nav-toggle-fab{display:flex;align-items:center;justify-content:center;
    position:fixed;top:9px;left:10px;width:36px;height:36px;z-index:130;
    border-radius:9px;background:rgba(255,255,255,.94);border:1px solid var(--line);
    box-shadow:0 2px 8px rgba(13,43,69,.15);font-size:18px;line-height:1;color:var(--ink);padding:0}
  body.has-shell.nav-open .nav-scrim{display:block;position:fixed;inset:0;z-index:110;background:rgba(8,25,43,.5)}

  /* ===== 2. 卡片 / 网格 / 统计块 ===== */
  .card{padding:14px 14px;margin-bottom:12px;border-radius:12px}
  .card h3{font-size:14.5px;margin-bottom:12px}
  .g2,.g3,.g4{grid-template-columns:1fr !important;gap:12px}
  .vs-grid{grid-template-columns:1fr;gap:10px}
  .ftile{min-height:76px}
  .stu-list{grid-template-columns:1fr;gap:12px}
  .stu-kpis{grid-template-columns:repeat(2,1fr)}
  .board-hero,.dis-hero{padding:16px 15px;gap:14px;flex-direction:column;align-items:stretch}
  .board-hero .bh-stats,.dis-hero .dh-stats{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;width:100%}
  .bh-stat,.dh-stat{min-width:0;padding:8px 4px}
  .bh-stat b,.dh-stat b{font-size:16px}
  .bh-stat span,.dh-stat span{font-size:10px}
  .board-hero .bh-t,.dis-hero .dh-t{font-size:16px}
  .board-hero .bh-s,.dis-hero .dh-s{font-size:12px;max-width:100%}
  .board-bar{gap:8px}
  .board-tabs{width:100%;overflow-x:auto}
  .board-tabs a{flex:1;justify-content:center;white-space:nowrap;padding:8px 10px}

  /* ===== 3. 访视阶段（横向滑动 + 单列） ===== */
  .vs-nav{gap:7px;overflow-x:auto;scroll-snap-type:x proximity;-webkit-overflow-scrolling:touch;padding-bottom:10px}
  .vs-chip{flex:0 0 auto;scroll-snap-align:start;min-width:96px}
  .vs-stage{padding:13px 13px}
  .vs-hd{gap:10px}
  .vs-prog{width:100%}
  .vs-sum{flex-wrap:wrap;gap:8px}
  .vs-sum .si{min-width:calc(50% - 8px)}

  /* ===== 4. 表格横向滚动（仅含表格的卡片） ===== */
  .card:has(table.tb){overflow-x:auto}
  table.tb{min-width:540px;font-size:13px}
  .tb th,.tb td{padding:9px 10px}
  .ae-table input,.ae-table select{min-width:96px}

  /* ===== 5. 表单录入：大控件 / 防缩放 / 吸底操作条 ===== */
  input,select,textarea{font-size:16px;padding:10px 11px;min-height:44px}
  .field label{font-size:13px}
  .field{gap:6px}
  fieldset.fs{padding:12px 12px 14px;margin-bottom:13px}
  fieldset.fs legend{font-size:13px}
  .radios,.cbs{gap:8px}
  .radios .ri,.cbs .ci{
    padding:10px 15px;min-height:44px;font-size:14.5px;border-radius:12px;
    display:inline-flex;align-items:center;
  }
  .radios .ri input,.cbs .ci input{width:18px;height:18px;min-height:18px;accent-color:var(--primary)}
  .perm-grid .ri{min-height:40px;padding:8px 10px;margin:0 8px 8px 0}
  .calc{min-height:44px;font-size:15px}
  .q-row{padding:12px 13px}
  .q-row .qh{font-size:13.5px}

  .form-actions{
    position:sticky;bottom:0;z-index:30;background:rgba(255,255,255,.97);
    backdrop-filter:blur(8px);margin:16px -14px -14px;padding:12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top:1px solid var(--line);border-radius:0 0 12px 12px;gap:8px;
  }
  .form-actions .sp{display:none}
  .form-actions button,.form-actions a{flex:1;min-width:calc(50% - 8px);min-height:46px;justify-content:center}
  .btnrow{gap:8px}
  .btnrow button,.btnrow a{flex:1 1 calc(50% - 8px);min-height:44px;display:inline-flex;align-items:center;justify-content:center}
  .sub-hero{flex-direction:column;align-items:stretch;gap:12px}
  .sub-hero .sh-acts{display:grid;grid-template-columns:repeat(2,1fr);gap:8px}
  .sub-hero .sh-acts button,.sub-hero .sh-acts a{min-height:44px}
  .sh-meta{flex-wrap:wrap;gap:6px}
  .searchbar{gap:8px}
  .searchbar input,.searchbar select{width:100%;min-width:0}
  .vtab{gap:6px;overflow-x:auto;flex-wrap:nowrap;-webkit-overflow-scrolling:touch;padding-bottom:6px}
  .vtab a{flex:0 0 auto;white-space:nowrap;min-height:42px;display:inline-flex;align-items:center}
  .tabs{overflow-x:auto;flex-wrap:nowrap}
  .tabs a{flex:0 0 auto;white-space:nowrap;min-height:44px;display:inline-flex;align-items:center}
  .formlist .fi{flex-wrap:wrap;gap:8px;padding:12px}
  .az-form{flex-direction:column;align-items:stretch;gap:10px}
  .az-form .field{min-width:0;width:100%}
  .az-add{flex-wrap:wrap}
  .az-add input{flex:1 1 100%}
  .btn-s{min-height:38px;padding:7px 12px}

  /* ===== 6. 登录 / 锁屏 / 弹窗 ===== */
  .login-card{width:100%;max-width:100%;padding:26px 20px;border-radius:14px}
  .login-wrap{padding:16px;align-items:flex-start}
  .login-brand{display:none}
  .login-page{flex-direction:column}
  .login-panel{padding:16px;width:100%}
  .login-panel .login-card{width:100%;padding:24px 18px}
  .login-meta{font-size:12px}
  .btn-wx{min-height:48px;font-size:15px}
  #lockOverlay .lock-card{width:100%;max-width:100%;padding:22px 18px}
  .modal{width:100%;max-width:100%;padding:18px 16px}
  .modal-mask{padding:12px;align-items:flex-end}
  .toast{left:12px;right:12px;top:12px;text-align:center;font-size:13px}

  /* ===== 7. 研究参与者端 ePRO（移动优先） ===== */
  .portal{max-width:100%;min-height:100dvh}
  .portal-head{padding:16px 15px;padding-top:calc(16px + env(safe-area-inset-top))}
  .portal-body{padding:12px 12px calc(20px + env(safe-area-inset-bottom));gap:11px}
  .portal-card{max-width:100%}
  .portal .radios .ri,.portal .cbs .ci{min-height:48px;padding:12px 16px;font-size:15px}
  .portal .q-row{padding:13px}
  .portal button{min-height:48px;font-size:15px}
  .ok-tag,.rem-item{font-size:13.5px}

  /* ===== 8. 其他 ===== */
  .env-banner{font-size:12px;padding:8px 12px}
  .banner{font-size:12.5px}
  .audit-item{font-size:12.5px}
  .empty{padding:28px 16px}
  .loading{padding:40px 16px}
}

/* ---------- 小屏：≤400px ---------- */
@media (max-width:400px){
  .board-hero .bh-stats,.dis-hero .dh-stats{grid-template-columns:repeat(2,1fr)}
  .form-actions button,.form-actions a{min-width:100%;flex:1 1 100%}
  .btnrow button,.btnrow a{flex:1 1 100%}
  .sub-hero .sh-acts{grid-template-columns:1fr}
  .stu-kpis{grid-template-columns:repeat(2,1fr)}
  .topbar .crumb{max-width:44vw}
}

/* ---------- 横屏手机 / 矮屏：抽屉高度自适应 ---------- */
@media (max-height:480px) and (max-width:900px){
  .sidebar{height:100dvh;overflow-y:auto}
}

/* ---------- 打印：撤销所有响应式干扰 ---------- */
@media print{
  .nav-toggle-fab,.nav-scrim{display:none !important}
  .sidebar,.topbar{display:none !important}
  .layout{display:block !important}
  .form-actions{position:static !important;margin:18px 0 0 !important;padding:16px 0 0 !important;background:none !important;border-top:1px solid var(--line) !important}
  .card:has(table.tb){overflow:visible}
  table.tb{min-width:0}
  .g2,.g3,.g4{grid-template-columns:repeat(2,1fr) !important}
}

/* ---------- 研究参与者端登录：通道说明卡（V4.7） ---------- */
.portal-channel{background:linear-gradient(135deg,#f0fdf4,#e8f8ee);border:1px solid #bbe9cd;border-radius:12px;padding:12px 14px;margin:14px 0 12px}
.portal-channel .pc-h{font-size:13.5px;font-weight:700;color:#137a4a;margin-bottom:6px}
.portal-channel .pc-d{font-size:12.5px;color:#33614a;line-height:1.75}
.portal-channel b{color:#0b6d40}
.wx-divider{font-size:11.5px;color:#94a3b8}
@media (max-width:767px){
  .portal-channel{padding:12px;margin:12px 0}
  .portal-channel .pc-d{font-size:13px;line-height:1.8}
  .btn-wx{min-height:50px;font-size:15.5px;font-weight:600}
  .login-card .wx-divider{margin:16px 0 12px}
}
