/* ============================================================
   FT Compass · 全站响应式适配
   ≤860px 负责移动端；≥861px 负责把 14 个模块的顶栏高度
   钉死在同一数值，与外层侧栏 logo 区齐平（否则两边各自按内容
   算高度，会出现 66 / 67px 的发丝缝）。
   各模块在 </head> 前引入，确保覆盖模块内联样式。
   ============================================================ */
.twhint { display: none; }
.paperhint { display: none; }

/* ---- 键盘焦点环 ----
   :focus-visible 只在键盘导航时出现，鼠标点击不留框。
   浅色区用深琥珀（#a16207，白底 4.9:1）；深绿顶栏/侧栏用亮琥珀（6.3:1）。
   旧的 #ffc53d 在白底只有 1.58:1，等于没有焦点指示。 */
:focus-visible {
  outline: 3px solid #a16207;
  outline-offset: 2px;
}
/* 深色底（顶栏、侧栏）用更亮的一档，并离边框远一点 */
header :focus-visible,
nav :focus-visible,
.mbar :focus-visible {
  outline-color: #ffd76e;
  outline-offset: 3px;
}

/* ---- 独立打开模块页时的「← 工作台」（由 assets/standalone.js 注入） ---- */
.ft-back {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  font-size: 12.5px; line-height: 1;
  padding: 7px 10px;
  color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.26);
  border-radius: var(--r-sm);
  text-decoration: none; white-space: nowrap;
}
.ft-back:hover { background: rgba(255,255,255,.2); color: #fff; }

/* ---- 右下角提示条 ----
   由 assets/a11y.js 接管 window.alert 后生成；每条第 role="alert"，
   屏幕阅读器立即播报。深底白字 14.8:1，不与页面浅色卡片抢注意力。 */
.ft-toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.ft-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px 11px 14px;
  background: #1f2933;
  color: #fff;
  border-radius: var(--r-sm);
  box-shadow: 0 10px 28px rgba(15,23,32,.28);
  font-size: 13px;
  line-height: 1.55;
  animation: ft-toast-in .18s ease-out;
}
.ft-toast-text { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.ft-toast-x {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.78);
  font-size: 13px;
  line-height: 1;
  padding: 3px 5px;
  cursor: pointer;
  border-radius: 3px;
}
.ft-toast-x:hover { color: #fff; background: rgba(255,255,255,.16); }
.ft-toast-x:focus-visible { outline: 2px solid #ffd76e; outline-offset: 1px; }
.ft-toast.is-out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes ft-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@media screen and (max-width: 520px) {
  .ft-toasts { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}
@media print { .ft-toasts { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  .ft-toast { animation: none; }
  .ft-toast.is-out { transition: none; }
}

/* ---- 桌面端：顶栏统一 60px（与侧栏 logo 区同高） ---- */
@media screen and (min-width: 861px) {
  header { min-height: 60px !important; padding-top: 8px !important; padding-bottom: 8px !important; box-sizing: border-box; }
}

@media screen and (max-width: 860px) {
  html, body { max-width: 100%; overflow-x: hidden; }

  /* ---- 顶栏 ----
     外层 mbar 已显示模块名，iframe 内的模块头压缩成纯动作条：
     只保留按钮，避免手机上两条深绿顶栏叠在一起。没有按钮的模块整条隐藏。
     ft-standalone = 直接访问模块 URL，没有外层顶栏，标题必须保留。 */
  html:not(.ft-standalone) header { padding: 6px 10px !important; flex-wrap: wrap !important; gap: 8px !important; justify-content: flex-end !important; min-height: 0 !important; }
  html:not(.ft-standalone) header img,
  html:not(.ft-standalone) header .logo,
  html:not(.ft-standalone) header h1 { display: none !important; }
  html:not(.ft-standalone) header:not(:has(button)) { display: none !important; }
  html:not(.ft-standalone) header button { padding: 6px 10px !important; font-size: 12.5px !important; }

  /* ---- 独立打开：保留标题，收紧尺寸避免换行 ---- */
  html.ft-standalone header { padding: 10px 12px !important; gap: 8px !important; flex-wrap: wrap !important; }
  html.ft-standalone header img, html.ft-standalone header .logo { width: 28px !important; height: 28px !important; }
  html.ft-standalone header h1 { font-size: 15px !important; line-height: 1.35 !important; flex: 1 1 auto !important; min-width: 0; }
  html.ft-standalone header button { padding: 6px 10px !important; font-size: 12.5px !important; }
  html.ft-standalone .ft-back { padding: 6px 9px; font-size: 12px; }

  /* ---- 主区域：左右双栏 → 上下堆叠 ---- */
  main { display: block !important; max-width: none !important; width: auto !important; padding: 12px 12px 72px !important; }
  main > .left { width: auto !important; flex: none !important; }
  main > .right { width: auto !important; margin-top: 12px !important; }

  /* ---- 工具条 / 按钮 / 筛选 ---- */
  .toolbar, .btnrow, .acts, .paper-tools, .filterbar, .chain, .mrow { flex-wrap: wrap !important; gap: 8px !important; }
  .toolbar input, .toolbar select { min-width: 0 !important; font-size: 13px !important; }
  /* 搜索输入框独占一行，否则会被后面的按钮挤成省略号 */
  .toolbar input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 100% !important; }
  .chain-derive { margin-left: 0 !important; }
  .filterbar input[type=range] { width: 120px !important; }

  /* ---- 统计条 ---- */
  .stats { display: flex !important; flex-wrap: wrap !important; gap: 14px !important; }
  .kpis { grid-template-columns: repeat(2, 1fr) !important; }
  .stats-bar { flex-wrap: wrap !important; gap: 14px !important; padding: 0 12px 12px !important; }

  /* ---- 表单 / 卡片网格 ---- */
  .grid2, .f2, .fgrid, .dr2, .br-two { grid-template-columns: 1fr !important; }
  .fgrid .full, .f2 .full { grid-column: auto !important; }
  .br-shots { grid-template-columns: 1fr !important; }
  .profile-card .info { min-width: 0 !important; flex: 1 1 100%; }

  /* ---- 标签页 ---- */
  .tabs { overflow-x: auto !important; white-space: nowrap; padding: 0 8px !important; }
  .tab { padding: 9px 10px !important; font-size: 12.5px !important; flex: 0 0 auto; }

  /* ---- 弹窗 ---- */
  dialog { width: 96vw !important; max-width: 96vw !important; max-height: 92vh; }
  .dlg-b, .db { max-height: calc(92vh - 118px) !important; overflow: auto !important; }
  .mask { padding: 14px !important; }
  .modal { padding: 16px !important; max-height: 92vh; overflow: auto; }

  /* ---- 列表高度：让详情/纸面在手机上也够得着 ---- */
  .clist, .qlist { max-height: 260px !important; }
  .doclist { max-height: 220px !important; }
  .log { max-height: 170px !important; }

  /* ---- 数据表横向滚动（纸面表格除外） ---- */
  .twhint { display: block; font-size: 11px; color: var(--text-3); margin: 0 2px 6px; }
  .tw { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .tw table { min-width: 720px; }
  #rT { min-width: 760px; }
  .form-card { overflow-x: auto; }
  .items-table { min-width: 560px; }

  /* ---- 单证 / 报价：A4 纸面横向滚动，不压缩版式 ----
     提示挂在纸面自己身上：只有 #paper 真的显示时才出现。
     旧写法 body:has(.paper) main > .right::before 在报价页会落到编辑表单上方，
     而那时纸面还是 display:none，用户照着提示滑没有任何反应。 */
  main > .right { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  main > .right > .paperhint { display: none; }
  .paper { min-width: 0; padding: 28px 30px; }
  .paper table { min-width: 0; }

  /* ---- 客户 360 ---- */
  .profile-card { gap: 10px !important; }
  .linked-item { align-items: flex-start !important; }
  .comp-top { align-items: flex-start !important; }
  .comp-acts { margin-left: 0 !important; }
}

@media screen and (max-width: 520px) {
  main .grid { grid-template-columns: 1fr !important; }
  .stats { display: grid !important; grid-template-columns: 1fr 1fr; gap: 10px !important; }
  .stats.s3 { grid-template-columns: repeat(3, 1fr) !important; }
  .stat b { font-size: 20px !important; }
  header h1 span { display: none; }
  .srcnote { padding: 0 0 12px !important; }
  .fgrid, .f2 { gap: 10px !important; }
}

@media screen and (max-width: 640px) {
  /* 这一档纸面被固定为 620px，必然横向滚动，提示才有意义；
     641~860px 纸面自适应宽度、不需要滑，所以不显示。 */
  .paper { min-width: 620px; padding: 24px 26px; }
  main > .right:has(> #paper[style*="block"]) > .paperhint {
    display: block; font-size: 11px; color: var(--text-3); margin: 0 2px 6px;
  }
}

@media screen and (max-width: 390px) {
  main { padding-left: 10px !important; padding-right: 10px !important; }
  .tab { padding: 8px 8px !important; }
}
