/* 0.8.6+ 手机适配（老猫 11-03 01:17，iPhone Safari 390 宽首页右侧露白边）。每个页面最后加载，只放窄屏规则 + 少量全局兜底。
   根因（生产 0.8.5）：首页「两种方式接入你的 Agent」.two 用 1fr 轨道、.ac 没有 min-width:0，MCP 配置 <pre> 的最长行把卡片撑到 414px，
   整页 scrollWidth 432 > 390。0.8.6 已改 minmax(0,1fr) + min-width:0；这里再把所有网格 / 弹性子项的同类陷阱一并收住。
   后台登录页同理（.lg 1fr 轨道 + 380 盒子 + 32 内边距 = 444px）。 */

/* 兜底（元素已逐个修好，这只防以后新内容再撑破；clip 不产生滚动容器，不影响 sticky） */
html,body{max-width:100%}
@supports (overflow:clip){html,body{overflow-x:clip}}
pre,code,.mono{overflow-wrap:anywhere}
pre{max-width:100%;overflow-x:auto}
img,svg,video{max-width:100%}

/* iOS：弹窗高度按可见区域（dvh）算，底部工具栏不再盖住「确定」按钮；toast 避开 Home 指示条 */
.dialog{max-height:calc(100vh - 40px)}
@supports (height:100dvh){.dialog{max-height:calc(100dvh - 40px)}}
#toast{bottom:calc(32px + env(safe-area-inset-bottom,0px))}
.mask{padding:20px 12px calc(20px + env(safe-area-inset-bottom,0px))}
.foot{padding-bottom:calc(22px + env(safe-area-inset-bottom,0px))}

/* 头部导航：900 以下原来整排隐藏，只剩「控制台」；改成第二行横滑，引擎与价格 / 文档 / Playground 都能点到 */
@media (max-width:900px){
  .nav-in{flex-wrap:wrap;height:auto;min-height:56px;padding-top:8px;gap:4px 12px}
  .nav-in>.brand{flex:1;min-height:44px}
  .nav-links{display:flex;order:3;flex:1 0 100%;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch;
    margin:0 -18px;padding:0 10px 6px;gap:2px}
  .nav-links::-webkit-scrollbar{display:none}
  .nav-links a{flex:0 0 auto;display:inline-flex;align-items:center;min-height:40px;padding:0 12px;white-space:nowrap}
}

@media (max-width:760px){
  /* 触控 ≥ 40px：官网 / 文档 / 控制台的小号按钮与分段按钮；后台按钮与输入框也拉到 40 */
  :root{--ctl-h-sm:40px}
  body.adm{--ctl-h:40px;--ctl-h-sm:40px;--ctl-h-lg:44px}
  button.link{min-height:40px;display:inline-flex;align-items:center}
  .tabs button{min-height:40px;padding:0 14px}
  .foot-cols a{padding:9px 0}
  /* iOS 输入框字号 < 16px 会在聚焦时自动放大 */
  input:not([type=checkbox]):not([type=radio]),select,textarea{font-size:16px!important}
  /* 卡片头：标题 + 右侧按钮 / tab 换行，不再把标题挤成一列 */
  .panel-hd{flex-wrap:wrap}
  .panel-hd>div:first-child{flex:1 1 220px;min-width:0}
  /* 一行输入 + 按钮：输入框独占一行 */
  .field-row{flex-wrap:wrap}
  .field-row>input:not([type=checkbox]),.field-row>textarea{flex:1 1 100%;min-width:0}
  .field-row>select{flex:1 1 0;min-width:0;max-width:none!important}
}

/* 价目表（首页 #engines、控制台价目）：窄屏改成卡片行——接口一整行，档位 / 条件在左，积分在右 */
@media (max-width:560px){
  .tbl.ptbl-m thead{display:none}
  .tbl.ptbl-m,.tbl.ptbl-m tbody{display:block}
  .tbl.ptbl-m tr{display:grid;grid-template-columns:minmax(0,1fr) auto;column-gap:12px;row-gap:4px;padding:12px 16px;border-bottom:1px solid var(--ln-2)}
  .tbl.ptbl-m tr:last-child{border-bottom:0}
  .tbl.ptbl-m tr>td,.panel .tbl.ptbl-m tr>td:first-child,.panel .tbl.ptbl-m tr>td:last-child,.card .tbl.ptbl-m tr>td:first-child,.card .tbl.ptbl-m tr>td:last-child{display:block;padding:0;border:0;white-space:normal}
  .tbl.ptbl-m tr>td:nth-child(1){grid-column:1 / -1}
  .tbl.ptbl-m tr>td:nth-child(2){grid-column:1;display:flex;flex-wrap:wrap;gap:6px;align-items:baseline}
  .tbl.ptbl-m tr>td:nth-child(2) small{display:inline;margin:0}
  .tbl.ptbl-m tr>td:nth-child(3){grid-column:1}
  .tbl.ptbl-m tr>td:nth-child(4){grid-column:2;grid-row:2 / span 2;align-self:center;text-align:right}
  .tbl.ptbl-m tr>td:nth-child(4)::after{content:" 积分";font-size:12px;font-weight:500;color:var(--tx-3)}
  .tbl.ptbl-m code{word-break:normal;overflow-wrap:anywhere}
  .et small{white-space:normal}
}

/* 控制台 */
@media (max-width:560px){
  .kpi{padding:16px}
  .kpi .v{font-size:22px;white-space:nowrap}
  #ents td{white-space:nowrap}
  #spend .panel-hd .tabs{width:100%}
  #spend .panel-hd .tabs button{flex:1}
}

/* 后台：登录页与主框架的单列轨道用 minmax(0,1fr)；总览双栏改单栏；弹窗表单单列 */
@media (max-width:1000px){
  #app,.lg{grid-template-columns:minmax(0,1fr)}
  .lg-main{padding:20px}
}
@media (max-width:700px){
  .grid2{grid-template-columns:minmax(0,1fr)}
  .form-grid{grid-template-columns:minmax(0,1fr)}
  .dialog{padding:18px}
  .dialog .acts{flex-wrap:wrap}
  .dialog .acts .btn{flex:1 1 auto}
  .pool-tw{max-height:none}
  .ph{flex-wrap:wrap;gap:10px}
}
@media (max-width:400px){.pill{max-width:100%}.pill span{white-space:normal;text-overflow:clip}}
