/* =========================================================================
   FinStack 移动端/多端适配层 (v2 · Midnight Finance · 2026-08-24)
   三断点：平板 ≤1024px · 手机 ≤768px · 小屏 ≤480px
   全局基础 + 通用组件（表格/模态/网格/按钮/图表）响应式覆盖。
   各页面 <head> 引入：<link rel="stylesheet" href="/static/mobile.css?v=f45ea11c">
   ========================================================================= */

/* ---------- 全局修复：details 折叠（UA 样式被作者 display 覆盖导致失效） ---------- */
details:not([open]) > *:not(summary) { display: none !important; }

/* ---------- 地图操作提示（默认隐藏，移动端 768 块内显示） ---------- */
.map-hint { display: none; }

/* ---------- 全局基础 ---------- */
@media (max-width: 1024px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  img, svg, canvas, video { max-width: 100%; height: auto; }
  .wrap { padding-left: 18px; padding-right: 18px; }
}

/* ---------- 平板 769–1024：双列为主 ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
  /* 12 列栅格收为 6 列，避免密集区块在平板过窄 */
  .grid { grid-template-columns: repeat(6, 1fr) !important; }
  .sensor-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .cols-3 { grid-template-columns: repeat(3, 1fr) !important; }
  .metrics { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important; }
}

/* ---------- 平板/手机 ≤1024：表单控件统一全宽 + 左对齐 ---------- */
/* 消除 flex 系数（flex: 2 1 240px / flex: 0 0 auto 等）导致的宽度参差 */
@media (max-width: 1024px) {
  /* 平板全单列：col-* span 规则在窄容器会挤爆/裁剪，统一堆叠 */
  .grid { grid-template-columns: 1fr !important; }
  /* grid 子项默认 min-width:auto 会被内容（地图/图表等）撑宽导致横向溢出 */
  .grid > * { min-width: 0; }
  .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-12 { grid-column: span 1 !important; }
  .sensor-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .form-row { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
  .field {
    flex: none !important;
    width: 100% !important;
    min-width: 0 !important;
    text-align: left !important;
  }
  .field input, .field select, .field textarea, .field .dd {
    width: 100% !important;
    box-sizing: border-box !important;
  }
  .dd { width: 100% !important; }
  .dd-trigger {
    width: 100% !important;
    text-align: left !important;
    box-sizing: border-box !important;
  }
  .modal-box label, .card label, .field label { text-align: left !important; }
  /* .row 内的 field 同样全宽（intel/admin 表单行）；按钮保持行内 */
  .row > .field { flex: none !important; width: 100% !important; min-width: 0 !important; }
  .row > .field input, .row > .field select, .row > .field .dd { width: 100% !important; }
  /* commodities 控制条竖排 + 全宽下拉 */
  .controls { flex-direction: column !important; align-items: stretch !important; }
  .controls label.ctl, .controls .ctl { width: 100% !important; }
  /* 顶部时间范围按钮（.topbar .controls）保持横排，不落入上面的竖排规则 */
  .topbar .controls { flex-direction: row !important; align-items: center !important; flex-wrap: wrap !important; gap: 8px; }
  .topbar .controls .pill { flex: 0 0 auto !important; white-space: nowrap !important; }
  .ctl { flex-direction: column !important; align-items: stretch !important; }
  .ctl select, .ctl .dd, .ctl input { width: 100% !important; }
  .ctl .dd { max-width: 100% !important; }
  /* admin/setting：密钥输入行——输入框独占整行，操作按钮换行靠右 */
  .cfg-input-row { flex-wrap: wrap !important; justify-content: flex-end; }
  .cfg-input-row input, .cfg-input-row select { flex: 1 1 100% !important; }
  input[type="text"], input[type="password"], input[type="email"],
  input[type="number"], input[type="search"], select, textarea {
    width: 100% !important;
    box-sizing: border-box !important;
    font-size: 16px !important; /* 防 iOS 聚焦放大 */
    min-height: 44px;
  }
}

/* ---------- 手机 ≤768：单列 + 大触摸目标 ---------- */
@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; font-size: 15px; }

  /* 通用栅格 → 单列 */
  .grid { grid-template-columns: 1fr !important; }
  /* 关键修复：col-* 的 span N 在单列 grid 里会创建隐式轨道撑爆布局（sensor 巨大/sweep 被裁/地图压缩） */
  .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-12 { grid-column: span 1 !important; }
  .sensor-grid { grid-template-columns: 1fr 1fr !important; }
  /* 传感器网络缩小：卡内边距 + 字号收紧 */
  .sensor { padding: 9px !important; }
  .sensor .sv-num { font-size: 20px !important; }
  .sensor .sv-lab { font-size: 11px !important; }
  .sensor .sv-sub { font-size: 10px !important; }
  /* 全球威胁地图：移动端 2:1 与地图投影一致（x/y 缩放一致不变形）。
     min-height 必须为 0——人为 340px 会把 2:1 撑成 1.15:1，地图被纵向拉伸变形。
     地图随屏宽自适应（不再 640px 横向滚动）：zoom=1 时完整世界地图恰好
     铺满 2:1 画布，手机上直接看到全球全貌，无需左右滑动。 */
  .map-card .map-wrap { aspect-ratio: 2 / 1 !important; min-height: 0 !important; width: 100%; }
  .map-hint { display: inline; font-size: 11px; font-weight: 500; color: var(--text-3); margin-left: 8px; white-space: nowrap; }
  .crucix-section { padding-left: 6px !important; padding-right: 6px !important; }
  .crucix-root .wrap { padding-left: 6px !important; padding-right: 6px !important; }
  /* 关注列表（intel）保持单行横排（与网页端一致），容器横向滚动 */
  #intelWatches { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #intelWatches table.bt { min-width: 560px; }
  .cols-2, .cols-3 { grid-template-columns: 1fr !important; }
  .metrics { grid-template-columns: repeat(2, 1fr) !important; }
  .mkt-list { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; }

  /* 容器内边距收紧 */
  .wrap { padding-left: 12px; padding-right: 12px; }
  .card, .glass-card { padding: 14px; }

  /* ---------- 表格：保持单行横排（与网页端一致），宽表容器横向滚动 ---------- */
  table.bt, table.tbl, table.impact,
  #reportBody table {
    display: table;
    width: 100%;
  }
  table.bt thead, table.tbl thead, table.impact thead,
  #reportBody table thead { display: table-header-group; }
  table.bt tbody, table.tbl tbody, table.impact tbody,
  #reportBody table tbody { display: table-row-group; }
  table.bt tr, table.tbl tr, table.impact tr,
  #reportBody table tr { display: table-row; }
  table.bt td, table.tbl td, table.impact td,
  table.bt th, table.tbl th, table.impact th,
  #reportBody table td, #reportBody table th {
    display: table-cell;
    white-space: nowrap;
    padding: 8px 10px;
  }
  /* 表格外层横向滚动容器（保留表头） */
  .table-scroll, .table-wrap, .tbl-wrap, .bt-wrap,
  #overviewBody, #sweepBody, #impactBody, #reportBody,
  #historyList {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll table, .table-wrap table, .tbl-wrap table, .bt-wrap table,
  #overviewBody table, #sweepBody table, #impactBody table,
  #historyList table {
    min-width: 560px;
  }
  /* 核风险小表（3 列）自适应即可，不强制超宽；单元格可换行防撑破卡片 */
  .card table.tbl { min-width: 0; }
  .card table.tbl td, .card table.tbl th { white-space: normal; }
  #reportBody table { min-width: 420px; }

  /* ---------- 模态：全屏化，底部留白 ---------- */
  .modal-mask {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh;
    border-radius: 20px 20px 0 0 !important;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---------- 按钮：≥44px 触摸目标（表单统一在 ≤1024 块） ---------- */
  button, .btn, .primary, .ghost, .sidebtn, .icon-btn, .dropdown-item,
  .nav-item, a.btn {
    min-height: 44px;
    min-width: 44px;
  }
  .row { flex-wrap: wrap; }

  /* ---------- 顶部/导航 ---------- */
  .hero { padding: 16px 14px; }
  .hero-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
  .hero-mark h1 { font-size: 23px; font-weight: 700; }
  .sub { font-size: 13px; line-height: 1.5; }
  .auth-actions { top: 10px; right: 10px; }
  .sidebar { max-width: calc(100% - 24px); }

  /* ---------- 图表 ---------- */
  .svg-box, .chart-box, .plot-box { min-height: 220px; }
  .svg-box svg, .chart-box svg, .plot-box svg { width: 100% !important; height: auto; }

  /* ---------- 杂项 ---------- */
  .footer { padding: 16px 12px; font-size: 12px; }
  .hud { font-size: 12px; }
  .hint { font-size: 12px; line-height: 1.5; }
  .tag, .pill { font-size: 11px; }
  .loading-line, .bar { min-height: 14px; }
}

/* ---------- 小屏 ≤480：更紧凑 ---------- */
@media (max-width: 480px) {
  /* 传感器网络保持 2 列紧凑（不单列），配合缩小字号 */
  .sensor-grid { grid-template-columns: 1fr 1fr !important; }
  .metrics { grid-template-columns: 1fr 1fr !important; }
  .card h2 { font-size: 13px; }
  .hero-mark h1 { font-size: 21px; font-weight: 700; }
  .sub { font-size: 12px; }
  .modal-box { max-height: 92vh; }
}

/* ---------- iPhone 刘海/底部横条安全区 ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .auth-actions { top: calc(10px + env(safe-area-inset-top, 0px)); }
}

/* =========================================================================
   FinStack 移动端/多端适配层 · 页面特例 (v1.1)
   ========================================================================= */

/* ---------- crucix / intel：页标题 + HUD 控制条 ---------- */
@media (max-width: 768px) {
  .page-title { padding: 14px 12px 6px; }
  .page-title h1 { font-size: 20px; }
  .page-title .sub { font-size: 12px; }
  .back-home { margin-left: 12px; }

  .hud-bar { flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
  .hud-bar .hud-title { flex: 1 1 100%; }
  .hud-stat { font-size: 11px; }
  .hud-btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 12px;
    flex: 1 1 auto;
    text-align: center;
  }
  .region-tabs { gap: 6px; }
  .region-tabs button, .region-tabs .tab { min-height: 40px; padding: 8px 12px; font-size: 12px; }

  /* ticker 高度压紧 */
  .ticker { height: 34px; }

  /* 传感器网格单列时卡片内 9 源对齐 */
  .sensor-grid { gap: 8px; }
  .sensor-grid .s-item, .sensor-grid .s-cell { padding: 10px; }
}

/* ---------- commodities：控制条换行 ---------- */
@media (max-width: 768px) {
  .ctl { flex-wrap: wrap; gap: 8px; }
  .ctl label, .ctl .dd { flex: 1 1 auto; min-width: 0; }
  .dd-label { font-size: 12px; }
  .dd-list { max-height: 240px; }
  .meta-ts { font-size: 11px; }
  .err-note { font-size: 12px; }
}

/* ---------- account：卡片与按钮 ---------- */
@media (max-width: 768px) {
  .main { padding: 16px 12px 48px; }
  .card { padding: 16px; }
  .card h2 { font-size: 15px; }
  .btn-row { flex-wrap: wrap; gap: 8px; }
  .btn-row .primary-btn, .btn-row .ghost-btn { flex: 1 1 100%; min-height: 44px; }
  .dropdown-item { min-height: 44px; }
}

/* ---------- admin：标签导航 & 测试块 ---------- */
@media (max-width: 768px) {
  .tabs-nav { gap: 6px; }
  .tab { min-height: 40px; padding: 8px 12px; font-size: 12px; flex: 1 1 auto; text-align: center; }
  .ds-test-step-detail { font-size: 12px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  /* 设置表单字段堆叠 */
  .form-grid, .grid-2 { grid-template-columns: 1fr !important; }
}

/* ---------- 平板 ≤1024：触摸目标加大（iPad 触屏友好） ---------- */
@media (max-width: 1024px) {
  .icon-btn { min-width: 40px; min-height: 40px; }
  .wm-ctl-btn { min-width: 40px; min-height: 40px; font-size: 15px; }
  /* 平板传感器网络 3 列紧凑 */
  .sensor { padding: 10px !important; }
  .sensor .sv-num { font-size: 21px !important; }
  .sensor .sv-lab { font-size: 11.5px !important; }
  .sensor .sv-sub { font-size: 10.5px !important; }
}

/* ---------- index：历史报告工具条换行 ---------- */
@media (max-width: 768px) {
  .hist-toolbar { flex-wrap: wrap; gap: 8px; }
  .hist-toolbar input, .hist-toolbar select { flex: 1 1 45%; min-width: 0; }
  .hist-toolbar .ghost { flex: 1 1 auto; min-height: 42px; padding: 8px 10px; font-size: 13px; }
  .hist-head h2 { font-size: 15px; }
}

/* ---------- crucix/intel：传感器卡片内文字不挤压溢出 ---------- */
@media (max-width: 768px) {
  .sensor { min-width: 0; }
  .sensor .sv-num { font-size: 22px; }
  .sensor .sv-lab { font-size: 12px; }
  .sensor .sv-sub { font-size: 11px; word-break: break-all; }
}

/* ---------- account：去登录链接触摸目标 ---------- */
@media (max-width: 1024px) {
  .login-hint a { min-height: 44px; min-width: 88px; display: inline-flex; align-items: center; justify-content: center; }
}

/* ---------- index：历史报告 checkbox 平板/手机加大 + 行高 ---------- */
@media (max-width: 1024px) {
  .hist-check, #histCheckAll {
    appearance: none; -webkit-appearance: none;
    width: 26px; height: 26px; min-width: 26px; min-height: 26px;
    border: 2px solid var(--border-2, rgba(255,255,255,.13));
    border-radius: 7px; background: transparent; vertical-align: middle;
    cursor: pointer; position: relative; flex-shrink: 0;
  }
  .hist-check:checked, #histCheckAll:checked {
    background: var(--gold, #c8a255); border-color: var(--gold, #c8a255);
  }
  .hist-check:checked::after, #histCheckAll:checked::after {
    /* 勾选标记用内联 SVG 数据 URI，不依赖字体里的勾选字形（缺字形会渲染成方框） */
    content: ""; position: absolute; inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 15px 15px no-repeat;
  }
  table.bt td { padding: 10px 8px; }
  .hist-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
  .hist-actions .ghost { min-height: 40px; padding: 7px 10px; font-size: 12px; }
}

/* ---------- 平板 ≤1024：通用按钮加大（iPad 触屏） ---------- */
@media (max-width: 1024px) {
  .ghost, .btn, .primary, .pill { min-height: 40px; padding: 8px 14px; }
  .hud-btn { min-height: 40px; }
  .region-tab, .region-tabs button { min-height: 40px; padding: 8px 12px; }
}

/* ---------- 用户区（登录/注册/头像）：由 auth-userbar.js 注入 .auth-actions。
   容器只做布局不绘制，所以登录、注册、头像各自只有自身一层边框 —— 不要再给
   容器加 border/background/shadow，那正是"重复边框"的来源。 ---------- */

/* =========================================================================
   移动端导航：左侧悬浮栏 → 左上角汉堡菜单
   手机 ≤768px 隐藏左侧悬浮（.sidebar 首页 / .nav-rail 子页），
   改为左上角 .menu-toggle 汉堡键 + 左侧滑出的 .mobile-menu 抽屉（9 个模块入口）。
   ========================================================================= */
.menu-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 1750;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--surface-1, rgba(255,255,255,.06));
  border: 1px solid var(--border-2, rgba(255,255,255,.13));
  color: var(--text-2);
  align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.menu-toggle .mt-bars { display: flex; flex-direction: column; gap: 4px; }
.menu-toggle .mt-bar { display: block; width: 20px; height: 2px; border-radius: 2px; background: currentColor; }
.menu-scrim {
  position: fixed; inset: 0; z-index: 1680;
  background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.menu-scrim.open { opacity: 1; pointer-events: auto; }
.mobile-menu {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 1700;
  width: min(300px, 84vw);
  background: var(--bg-2, #12131a);
  border-right: 1px solid var(--border-2, rgba(255,255,255,.13));
  box-shadow: 8px 0 28px rgba(0,0,0,.4);
  transform: translateX(-102%); opacity: 0; pointer-events: none;
  transition: transform .25s ease, opacity .2s ease;
  padding: calc(72px + env(safe-area-inset-top, 0px)) 14px 24px;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 4px;
}
.mobile-menu.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
.mobile-menu a {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; border-radius: 12px; min-height: 44px;
  color: var(--text-1, #d9d5cb); text-decoration: none;
  font-size: 15px; font-weight: 500;
}
.mobile-menu a:hover, .mobile-menu a.active {
  background: var(--surface-1, rgba(255,255,255,.07)); color: var(--text-0, #f0ede6);
}
.mobile-menu a svg { width: 22px; height: 22px; flex-shrink: 0; display: block; }
.mobile-menu .mm-close {
  margin-left: auto; border: 0; background: transparent; color: var(--text-2);
  font-size: 22px; cursor: pointer; min-height: 40px; min-width: 40px;
}
/* IA 2.0 分组：抽屉内组标题（DISCOVER 发现 / RESEARCH 研究 / DECIDE 决策 / MANAGE 管理） */
.mobile-menu .mm-group {
  margin: 12px 0 4px; padding: 0 14px;
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  color: var(--gold, #c8a255); opacity: .85;
  font-family: "Outfit", sans-serif;
}
.mobile-menu .mm-group:first-of-type { margin-top: 0; }
@media (max-width: 768px) {
  .menu-toggle { display: flex; }
  .sidebar, .nav-rail { display: none !important; }
}
