/* ==========================================================================
   main.css —— base(重置 + 中文排版) + layout(顶栏/三栏/底栏/响应式)
              + components(面板/表格/徽标/浮层/进度条)
   硬约束：地图容器必须有确定高度；1px 分割线；圆角 ≤2px；无阴影。
   ========================================================================== */

/* ============================ base ============================ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

h1, h2, h3, h4, p, ul, ol, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; font-size: inherit; color: inherit; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.weak { color: var(--text-3); }
.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.unit { color: var(--text-3); font-size: var(--fs-label); margin-left: 3px; }
.hidden, [hidden] { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--panel-2); }
::-webkit-scrollbar-thumb { background: #2E3841; border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: #3A4550; }

/* ============================ layout ============================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* --- 顶栏 --- */
.topbar {
  flex: 0 0 var(--h-topbar);
  height: var(--h-topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--panel);
  border-bottom: 1px solid var(--divider);
}
.topbar__title { font-size: 15px; letter-spacing: 0.04em; }
.topbar__meta { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-label); }

/* --- 导航 --- */
.nav {
  flex: 0 0 var(--h-nav);
  height: var(--h-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}
.nav__tabs { display: flex; height: 100%; }
.tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 var(--sp-4);
  height: 100%;
  color: var(--text-2);
  font-size: var(--fs-body);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.nav__sources { display: flex; align-items: center; gap: var(--sp-4); font-size: var(--fs-label); }
.src-status { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; background: none; border: 0; padding: 0; }
.src-status:hover { text-decoration: underline; }
.src-status .dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot--ok    { background: var(--st-ok); }
.dot--stale { background: var(--st-stale); }
.dot--fail  { background: var(--st-fail); }
.dot--idle  { background: var(--st-idle); }
.src-status__age { color: var(--text-3); }

/* --- 主区三栏 --- */
.main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--w-left) minmax(0, 1fr) var(--w-right);
  overflow: hidden;
}
.col { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.col--left  { border-right: 1px solid var(--divider); overflow-y: auto; }
.col--right { border-left: 1px solid var(--divider); overflow-y: auto; }
.col--map   { position: relative; padding: 0; }

/* 地图容器：位置绝对定位于父级单元格 → 高度确定，不依赖百分比继承 */
.map-wrap { position: relative; width: 100%; height: 100%; flex: 1 1 auto; min-height: 240px; background: #0B0F13; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; }

.map-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(0deg, #0E1318 0 39px, #121820 39px 40px);
}
.map-fallback__inner { max-width: 420px; padding: var(--sp-5); border: 1px solid var(--panel-border); background: var(--panel); border-radius: var(--radius); }
.map-fallback__title { font-size: 15px; margin-bottom: var(--sp-2); }
.map-fallback__text { color: var(--text-2); font-size: var(--fs-table); }
.map-fallback__hint { color: var(--text-3); font-size: var(--fs-label); margin-top: var(--sp-3); }
/* 错误码：次要位置，弱化灰字，供排查用；不做强调、不加色块 */
.map-fallback__code { color: var(--text-3); font-family: var(--font-mono); font-size: var(--fs-label); margin-top: var(--sp-2); opacity: 0.85; }

.map-legend {
  position: absolute; left: var(--sp-3); bottom: var(--sp-3);
  background: rgba(15, 20, 25, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-label);
  line-height: 1.6;
  pointer-events: none;
  max-width: 260px;
}
.map-legend__row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.map-legend__line { width: 22px; height: 0; border-top-width: 2px; border-top-style: solid; display: inline-block; }
.map-legend__swatch { width: 10px; height: 10px; display: inline-block; border-radius: 1px; }
.map-legend__gradient {
  width: 46px; height: 8px; display: inline-block; border-radius: 1px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(90deg,
    rgba(74, 90, 106, 0.05) 0%, rgba(74, 90, 106, 0.55) 18%,
    rgba(201, 154, 60, 0.85) 52%, rgba(224, 112, 60, 0.9) 74%, rgba(200, 50, 60, 0.95) 100%);
}
.map-legend__note {
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.5;
  margin-top: 3px;
  max-width: 232px;
  white-space: normal;
}
/* 移动端可收起图例的标题栏（桌面隐藏） */
.map-legend__head { display: none; }
.map-legend__toggle { display: none; }

.map-scalebar {
  position: absolute; right: var(--sp-3); bottom: var(--sp-3);
  width: 60px; height: 6px;
  border: 1px solid var(--text-3); border-top: 0;
  opacity: 0.5;
}

/* --- 页脚 --- */
.footer {
  flex: 0 0 var(--h-footer);
  height: var(--h-footer);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  background: var(--panel);
  border-top: 1px solid var(--divider);
  font-size: var(--fs-label);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
}
.footer__src { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.footer__disc { overflow: hidden; text-overflow: ellipsis; }

/* --- 移动端底部 Tab（默认隐藏，≤768px 显示） --- */
.mtabs {
  display: none;
  flex: 0 0 auto;
  border-top: 1px solid var(--divider);
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mtab {
  flex: 1 1 0;
  min-height: var(--h-mtabs);
  background: none;
  border: 0;
  border-top: 2px solid transparent;
  color: var(--text-2);
  font-size: var(--fs-body);
  cursor: pointer;
}
.mtab.is-active { color: var(--text); border-top-color: var(--accent); }

/* ============================ components ============================ */
.panel { border-bottom: 1px solid var(--divider); display: flex; flex-direction: column; }
.panel__title {
  font-size: var(--fs-label);
  font-weight: 400;
  color: var(--text-2);
  letter-spacing: 0.06em;
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--divider);
  display: flex; align-items: center; justify-content: space-between;
}
.panel__count { color: var(--text-3); }
.panel__body { padding: var(--sp-2) var(--sp-3) var(--sp-4); }

/* --- 空态 --- */
.empty { color: var(--text-3); font-size: var(--fs-table); padding: var(--sp-3) 0; line-height: 1.7; }

/* --- 活跃台风列表 --- */
.storm-item {
  display: flex; gap: var(--sp-2);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  align-items: stretch;
}
.storm-item:last-child { border-bottom: 0; }
.storm-item__bar { width: 3px; flex: 0 0 3px; background: var(--st-idle); border-radius: 0; }
.storm-item__main { flex: 1 1 auto; min-width: 0; }
.storm-item__line1 { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.storm-item__no { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--text); }
.storm-item__name { color: var(--text-2); font-size: var(--fs-table); }
.storm-item__line2 { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-label); }
.storm-item__grade { }
.storm-item__time { color: var(--text-3); font-family: var(--font-mono); }
.storm-item.is-selected { background: #1B232B; }

/* --- 键值表 --- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0; font-size: var(--fs-table); }
.kv__k { color: var(--text-2); padding: var(--sp-1) 0; }
.kv__v { text-align: right; padding: var(--sp-1) 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* --- 数据表 --- */
.dtable { width: 100%; border-collapse: collapse; font-size: var(--fs-table); line-height: var(--lh-table); }
.dtable th, .dtable td { padding: 6px var(--sp-2); text-align: left; border-bottom: 1px solid var(--divider); vertical-align: top; }
.dtable thead th { color: var(--text-3); font-weight: 400; font-size: var(--fs-label); border-bottom: 1px solid var(--panel-border); }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable .num { text-align: right; }
.dtable .r { text-align: right; }
.rowhead { cursor: pointer; }
.rowhead:hover { background: #1B232B; }

/* --- 徽标 / 等级标签 --- */
.badge {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  font-size: var(--fs-label);
  line-height: 18px;
  letter-spacing: 0.04em;
}
.badge--low  { color: var(--gen-low); }
.badge--mid  { color: var(--gen-mid); }
.badge--high { color: var(--gen-high); }
.badge--dim  { color: var(--text-3); }
.grade-chip { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.grade-chip__sw { width: 8px; height: 8px; display: inline-block; }

/* --- 因子条 --- */
.fbar { display: grid; grid-template-columns: 62px 1fr 46px; gap: var(--sp-2); align-items: center; font-size: var(--fs-label); }
.fbar__label { color: var(--text-2); }
.fbar__track { height: 4px; background: #202932; position: relative; }
.fbar__fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--text-3); }
.fbar__val { text-align: right; font-family: var(--font-mono); }

/* --- 降级横幅（固定文案，禁止改写） --- */
.alertbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 6px var(--sp-4);
  background: #1E1A14;
  border-bottom: 1px solid var(--panel-border);
  border-left: 2px solid var(--gen-mid);
  font-size: var(--fs-label);
  color: var(--text-2);
}
.alertbar__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gen-mid); flex: 0 0 6px; }
.alertbar__text { flex: 1 1 auto; }
.alertbar__text b { color: var(--text); font-weight: 400; }
.alertbar__btn { flex: 0 0 auto; padding: 2px var(--sp-2); }

/* --- 面板内降级提示块 --- */
.inline-alert {
  border: 1px solid var(--panel-border);
  border-left: 2px solid var(--gen-mid);
  background: #1E1A14;
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-label);
  line-height: 1.7;
  color: var(--text-2);
  margin-bottom: var(--sp-3);
}
.inline-alert b { color: var(--text); font-weight: 400; }

/* --- 按钮 --- */
.btn {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px var(--sp-3);
  cursor: pointer;
  font-size: var(--fs-table);
}
.btn:hover { border-color: var(--accent); color: var(--text); }
.btn--primary { border-color: var(--accent); color: var(--accent); }
.btn--ghost { background: transparent; }
.btn:disabled { color: var(--text-3); border-color: var(--panel-border); cursor: default; }

/* --- 图层开关 --- */
.toggles { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); font-size: var(--fs-label); }
.toggle { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-2); }
.toggle input { accent-color: var(--accent); margin: 0; }
.toggle .swatch { width: 14px; height: 0; border-top-width: 2px; border-top-style: solid; display: inline-block; }
.toggle .swatch--field {
  width: 16px; height: 10px; border: 0;
  background: linear-gradient(90deg,
    rgba(74, 90, 106, 0) 0%, rgba(74, 90, 106, 0.55) 18%,
    rgba(201, 154, 60, 0.85) 52%, rgba(224, 112, 60, 0.9) 74%, rgba(200, 50, 60, 0.95) 100%);
}
.toggle__status { color: var(--text-3); }
.toggle__status.is-error { color: var(--danger); }

/* --- 进度条（1px 线性，禁用旋转图标） --- */
.progress { height: 2px; background: var(--panel-2); overflow: hidden; }
.progress__bar { height: 100%; width: 30%; background: var(--accent); transition: width 0.2s linear; }
.skeleton { height: 10px; background: #1D252D; margin: 6px 0; border-radius: 0; }

/* --- 提示浮层（无阴影、圆角 ≤2px） --- */
.tip {
  position: fixed;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-label);
  line-height: 1.7;
  pointer-events: none;
  max-width: 280px;
}
.tip__k { color: var(--text-3); }
.tip__v { font-family: var(--font-mono); }

/* --- 报告滑出层 --- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 70; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  z-index: 80;
  display: flex; flex-direction: column;
}
.drawer__head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--divider);
}
.drawer__title { font-size: 14px; }
.drawer__actions { display: flex; gap: var(--sp-2); }
.drawer__body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-4); font-size: var(--fs-table); line-height: 1.8; }
.drawer__body h4 { font-size: var(--fs-table); color: var(--text); margin: var(--sp-4) 0 var(--sp-2); font-weight: 400; border-bottom: 1px solid var(--divider); padding-bottom: 4px; }
.drawer__body h4:first-child { margin-top: 0; }
.drawer__body p { color: var(--text-2); margin: 0 0 var(--sp-2); }
.drawer__body .mono { color: var(--text); }

/* --- 免责声明条（潜势模块顶部常驻） --- */
.disclaimer {
  border: 1px solid var(--panel-border);
  border-left: 2px solid var(--danger);
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-label);
  line-height: 1.7;
  color: var(--text-2);
  margin-bottom: var(--sp-3);
}
.disclaimer b { color: var(--text); font-weight: 400; }

.note { color: var(--text-3); font-size: var(--fs-label); line-height: 1.7; margin-top: var(--sp-2); }
.note--warn { color: var(--gen-mid); }
.section-sep { height: 1px; background: var(--divider); margin: var(--sp-3) 0; }

/* --- 微型 SVG 图表 --- */
.mini-chart { width: 100%; height: 96px; display: block; }
.legend-inline { display: flex; gap: var(--sp-3); font-size: var(--fs-label); color: var(--text-3); margin-top: var(--sp-1); }

/* ============================ 响应式 ============================ */
/* 768–1280：双栏（地图 + 右栏），左栏折叠 */
@media (max-width: 1280px) {
  .main { grid-template-columns: minmax(0, 1fr) var(--w-right); }
  .col--left { display: none; }
}

/* ≤768：移动端单视图布局 + 底部 Tab（地图 / 台风 / 潜势 / 报告 四视图均可达）。
   触摸目标 ≥44×44；地图容器高度确定；随系统字号增高不裁切。 */
@media (max-width: 768px) {
  /* 用 dvh 规避移动浏览器地址栏导致的底部裁切；并保留 vh 兜底 */
  .app { height: 100vh; height: 100dvh; }

  /* 顶栏 / 导航 / 页脚允许随系统字号增高（不裁切）：解除固定 flex 基高 */
  .topbar { flex: 0 0 auto; height: auto; min-height: var(--h-topbar); padding: 6px var(--sp-3); flex-wrap: wrap; gap: 4px var(--sp-3); }
  .nav { flex: 0 0 auto; height: auto; min-height: var(--h-nav); padding: 4px var(--sp-3); flex-wrap: wrap; }
  .nav__tabs { display: none; }                 /* 顶部视图 Tab 由底部 Tab 取代 */
  .nav__sources { flex-wrap: nowrap; overflow-x: auto; gap: var(--sp-3); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav__sources::-webkit-scrollbar { display: none; }
  .nav__sources .src-status { white-space: nowrap; }
  .footer { flex: 0 0 auto; height: auto; min-height: 0; white-space: normal; padding: 4px var(--sp-3); font-size: 11px; line-height: 1.45; }
  .footer__src { display: none; }               /* 来源已在顶栏状态灯体现，页脚只留免责声明 */

  /* 单栏堆叠主区 */
  .main { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr); }
  .col--left, .col--right { display: none; }
  .col--map { order: 1; display: flex; }
  .map-wrap { min-height: 0; }

  /* 视图切换（data-mview 由 60-app.js 维护） */
  .app[data-mview="storms"] .col--map,
  .app[data-mview="genesis"] .col--map { display: none; }
  .app[data-mview="storms"] .col--left,
  .app[data-mview="storms"] .col--right,
  .app[data-mview="genesis"] .col--left,
  .app[data-mview="genesis"] .col--right { display: flex; }
  .app[data-mview="storms"] .main,
  .app[data-mview="genesis"] .main { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .app[data-mview="storms"] .col--left,
  .app[data-mview="storms"] .col--right,
  .app[data-mview="genesis"] .col--left,
  .app[data-mview="genesis"] .col--right { height: auto; overflow: visible; border-right: 0; border-left: 0; }

  /* 底部 Tab */
  .mtabs { display: flex; }

  /* 触摸目标 ≥44×44 */
  .btn { min-height: 44px; padding: 0 var(--sp-3); }
  .toggle { min-height: 44px; padding: 6px 2px; }
  .toggle input { width: 20px; height: 20px; }
  .toggles { gap: 4px var(--sp-3); }
  .storm-item { min-height: 44px; align-items: center; }
  .src-status { min-height: 44px; padding: 0 var(--sp-1); }
  .dtable th, .dtable td { padding: 10px var(--sp-2); }
  a, .rowhead { touch-action: manipulation; }

  /* 图例：移动端可收起（默认由 50-ui-monitor.js 按视口初始化） */
  .map-legend { pointer-events: auto; max-width: min(260px, 78vw); }
  .map-legend__head { display: block; }
  .map-legend__toggle {
    display: block; width: 100%; min-height: 44px; box-sizing: border-box;
    text-align: left; background: none; border: 0; border-bottom: 1px solid var(--divider);
    color: var(--text-2); padding: 0 var(--sp-1); font-size: var(--fs-label);
  }
  .map-legend.is-collapsed .map-legend__body { display: none; }

  /* 报告滑出层在移动端占满整屏 */
  .drawer { width: 100%; }
}
