/* ==========================================================================
   全站响应式与排版兜底层（responsive.css）
   加载位置：每个页面 </head> 之前的最后一个样式表，用于兜住三类问题：
     1) 移动端自适应：统一断点 640 / 860 / 1100，收紧边距、控件触控尺寸、输入框防缩放
     2) 出框与错位：长文本、图片、表格、页头操作区在窄屏不再顶出视口
     3) 视觉不一致：字号阶梯与浅底色块统一走主题变量
   只在必要处使用 !important，避免与页面既有样式无谓对抗。
   ========================================================================== */

/* ---------- 0. 兼容两套变量：全站 --c-* 与独立页面的 --* ---------- */
:root{
  --rs-warn-soft:#fff7e8;
  --rs-info-soft:#f0f7ff;
  --rs-danger-soft:#fdecea;
  --rs-success-soft:#e6f7ee;
  --rs-gap-page:18px;
  --rs-gap-page-sm:12px;
}

/* ---------- 1. 防出框基线 ---------- */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
img,video,canvas,svg,iframe{max-width:100%;height:auto}
table{max-width:100%}
/* 长 URL、长英文串、连续数字在窄屏强制换行，避免撑破卡片 */
code,pre,.formula,.mini,.notice-line{overflow-wrap:anywhere;word-break:break-word}
pre{overflow-x:auto;white-space:pre-wrap}
/* flex / grid 子项默认允许收缩，避免固定内容把容器顶宽 */
:where(.container,.wrap,.card,.item-card,.form-item,.row,.top,.topbar,.site-nav,.chat-shell,
       .portal-header-inner,.portal-header-actions,.portal-brand,.portal-container,
       .portal-news,.portal-news-item,.portal-modules,.portal-module,.portal-split){min-width:0}

/* ---------- 2. 字号阶梯：收敛散乱取值 ---------- */
/* 桌面端统一标题与说明文字，页面内联样式不再各自为政 */
h1{font-size:clamp(22px,2.2vw + 12px,28px);line-height:1.25}
h2{font-size:20px;line-height:1.3}
h3{font-size:16px;line-height:1.4}
.mini,.notice-line,small{font-size:12px}
/* 主色系统中的浅底色块统一语义变量 */
.area-yellow,.tip-warn{background:var(--rs-warn-soft)}
.card-score,.stat-item{background:color-mix(in srgb,var(--c-primary,#2f6f8f) 5%,#fff)}

/* ---------- 3. 平板与窄桌面（<=860）：表格不再撑开页面 ---------- */
@media(max-width:860px){
  .wrap,.portal-container{width:100%}
  /* 已包在 .table-scroll 里的表格维持横滚；未包的宽表就地变成横滚容器 */
  .table-scroll{overflow-x:auto;-webkit-overflow-scrolling:touch}
  .table-scroll table{min-width:0!important}
  table{display:block;overflow-x:auto;white-space:nowrap;-webkit-overflow-scrolling:touch}
  table caption{white-space:normal}
  /* 恢复 table 内部语义，仅外层滚动 */
  table>thead{display:table-header-group}
  table>tbody,table>tfoot{display:table-row-group}
  table>tr{display:table-row}

  /* 触摸设备（平板含 iPad）的触控高度：32px 为下限 */
  /* 导航与文本按钮型链接 */
  .site-userbar a,.origin,a.back,a.brand,
  .hm-head a,.hub-summary-head a,.portal-section-head a,.portal-legal-links a,
  .portal-news-item a,#artLink{min-height:32px;display:inline-flex;align-items:center}
  /* 标题型链接只抬高高度，不改布局方向 */
  a.title,.news-card .title{min-height:32px;display:flex;align-items:center}
  /* 密集操作按钮 */
  .chipbtn,.ht-notify,.ht-actions button,.ai-mini-btn,.ai-q,.ho-btn,.sim-btn,.sim-tpl,
  .emg-toggle,.pr-copy,.tool-share-btn,.ai-share,.ai-copy,.ai-retry,.ai-hist-actions button,
  .sim-clear-search,.emg-chip,.side-newgroup,.btn-small,.nav-btn,.tab{
    min-height:32px;display:inline-flex;align-items:center;justify-content:center}
  /* 常规按钮在触摸屏给到 36px */
  .btn,.btn-red,.btn-soft,.btn-primary,.btn-green,.chipbtn,.submit-btn{min-height:36px}
}

/* ---------- 4. 手机端（<=640）：边距、字号、触控、输入框 ---------- */
@media(max-width:640px){
  body{padding:var(--rs-gap-page-sm)}
  .container,.login-box,.modal-box,.page{padding:14px}
  .container{border-radius:12px}
  h1{font-size:22px}
  h2{font-size:18px}
  h3{font-size:15px}
  /* 说明类文字不低于 12px，避免手机上难读（含各页两级选择器，优先级覆盖页面内联样式） */
  .mini,.notice-line,small,.score-formula,.tool-tag,.tool-tag-text,.g-count,
  .hm-kicker,.hm-cases-label,.brand-sub,.site-userbar,.who,.date-sub,
  .no,.emg-no,.emg-badge,.ai-foot,.nm,.portal-news-item .nm,.tool-share-btn,
  .hm-stat span,.hm-cases-row,.t-badge,.hub-live,.hub-date-note,
  .hub-summary-head span,.hub-summary-head a,.hub-action small,
  .hub-mypos span,.hub-stats span,.hub-names .t-name,.hub-names .t-empty,
  .portal-module-tags span,.emg-chip .no,.ai-msg .who,.ai-share,.ai-src,
  .ai-hist-row .who,.ai-hist-actions button,.ai-hist-actions .sel-count,
  .sim-group-hd .g-count,.side-newgroup{font-size:12px;line-height:1.55}
  /* 输入控件 16px：iOS 聚焦时不会自动放大页面 */
  input,select,textarea{font-size:16px}
  /* 主要可点区域做到 40px 左右，仍保留紧凑排版 */
  :where(.btn,.tab,.submit-btn,.portal-hbtn,.sn-btn,.chipbtn,.nav-btn,.share-btn,
         .btn-soft,.btn-primary,.btn-green,.add-case-btn,.side-newgroup){min-height:38px}
  .site-nav a{min-height:34px}
  /* 工具页密集小按钮：抬高触控高度但不改变卡片密度 */
  .sim-btn,.sim-tpl,.emg-toggle,.pr-copy,.tool-share-btn,.ai-share,.ai-copy,.ai-retry,
  .ai-hist-actions button,.sim-clear-search,.emg-chip{min-height:32px}
  /* 头部/待办/排班/助手面板的紧凑按钮：统一到 32px 触控高 */
  .ht-notify,.ht-actions button,.ai-mini-btn,.ai-q,.ho-btn,
  .hub-todos-head button,.todo-form button{min-height:32px;padding-top:4px;padding-bottom:4px;
    display:inline-flex;align-items:center;justify-content:center}
  /* 独立链接按钮（稿件来源、返回、品牌）保持可点 */
  .news-card .origin,.origin,a.back,a.brand{min-height:32px;display:inline-flex;align-items:center}
  /* 门户页的箭头链接与法务链接：窄屏按按钮高度处理 */
  .hm-head a,.hub-summary-head a,.portal-section-head a,.portal-legal-links a,
  .portal-news-item a,.hm-head a:only-child{min-height:32px;display:inline-flex;align-items:center}
  /* 站点右上角用户区（登录/资料/退出）与文献链接 */
  .site-userbar a,#artLink,.article-link{min-height:32px;display:inline-flex;align-items:center}
  /* 页头操作区在手机上换行，不顶出视口 */
  .portal-header-inner{flex-wrap:wrap;gap:6px 10px;padding:6px 0}
  .portal-header-actions{margin-left:0;width:100%;flex-wrap:wrap;justify-content:flex-end;gap:5px}
  .portal-hbtn{padding:6px 9px;font-size:12px}
  .top-bar,.header-bar,.datebar,.quick{flex-wrap:wrap}
  /* 导航在手机上换行显示，避免末位条目被横向裁掉 */
  .site-nav{flex-wrap:wrap!important;overflow-x:visible;row-gap:6px}
  /* 门户 /首页 hero：标题与引文上下堆叠，不再左右抢宽度 */
  .portal-hero-title-row{grid-template-columns:1fr;gap:6px;margin:12px 0 10px}
  .portal-hero h1{white-space:normal;letter-spacing:-.4px}
  .portal-hero .lead{font-size:12px}
  /* 文献阅读工具条：状态提示独占一行，不与按钮挤在一起 */
  .bar2{flex-wrap:wrap;gap:6px}
  .bar2 .spacer{display:none}
  .bar2 .status{flex:1 1 100%;order:10;margin-top:2px;text-align:left}
  /* 全宽提交按钮，避免 min-width 在窄屏溢出 */
  .submit-btn{width:100%;min-width:0}
  /* 安全区：刘海屏与手势条不遮挡内容 */
  body{padding-left:max(var(--rs-gap-page-sm),env(safe-area-inset-left));
       padding-right:max(var(--rs-gap-page-sm),env(safe-area-inset-right))}
}

/* ---------- 5. 超窄屏（<=380）：进一步压缩，禁止横向滚动 ---------- */
@media(max-width:380px){
  body{padding:10px}
  .container,.login-box{padding:12px}
  h1{font-size:20px}
  h2{font-size:17px}
  .portal-hbtn{padding:5px 7px;font-size:11px}
  :where(.btn,.btn-soft,.chipbtn,.nav-btn,.share-btn){padding-left:8px;padding-right:8px}
}

/* ---------- 6. 横屏矮屏（手机横过来）：避免表格与弹层压到顶部 ---------- */
@media(max-height:480px) and (orientation:landscape){
  body{padding-top:8px}
  .site-nav{margin-bottom:6px}
}

/* ---------- 7. 打印：补一条兜底（原有规则在 theme.css） ---------- */
@media print{
  .site-nav,.site-userbar,.va-dock,.no-print{display:none!important}
  table{display:table;white-space:normal}
}
