/* ============================================================
 * layout.css —— 顶栏 / 三栏骨架 / 面板 / 响应式
 * ============================================================ */

/* ---------- 顶栏 ---------- */
.topbar {
  height: var(--tb-h, 58px); flex: none;
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: var(--card); /* 老浏览器回退（下一行 color-mix 不支持时生效） */
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 1100;
}

.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand .seal-logo {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, var(--seal), var(--seal-deep));
  color: #f7efe9; display: grid; place-items: center;
  font-family: var(--serif); font-size: var(--fs-19); font-weight: 700;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .22), 0 2px 6px rgba(142, 43, 33, .3);
  user-select: none;
}
.brand .t { font-family: var(--serif); font-size: var(--fs-17); font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.brand .t em { font-style: normal; color: var(--seal); }

/* 主导航 */
.nav { display: flex; gap: 2px; height: 100%; }
.nav button {
  position: relative; padding: 0 16px; height: 100%;
  font-size: var(--fs-14); font-weight: 600; color: var(--ink-2);
  transition: color var(--t-fast) var(--ease-out);
}
.nav button::after {
  content: ""; position: absolute; left: 16px; right: 16px; bottom: 0;
  height: 2px; border-radius: 2px; background: var(--seal);
  transform: scaleX(0); transition: transform var(--t-med) var(--ease-out);
}
.nav button:hover { color: var(--ink); }
.nav button.on { color: var(--seal); }
.nav button.on::after { transform: scaleX(1); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 全局搜索框 */
.g-search {
  display: flex; align-items: center; gap: 8px;
  width: 250px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); color: var(--ink-3);
  font-size: var(--fs-13); cursor: text;
  transition: all var(--t-fast) var(--ease-out);
}
.g-search:hover, .g-search.on { border-color: var(--line-strong); background: var(--card); box-shadow: var(--shadow-1); }
.g-search .kbd {
  margin-left: auto; font-size: var(--fs-11); padding: 1px 6px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: var(--card); color: var(--ink-3);
}

/* ---------- 应用骨架 ---------- */
.shell { display: flex; flex-direction: column; height: 100%; }
.workspace { flex: 1; min-height: 0; display: flex; }

/* 左侧筛选栏 */
.sidebar {
  width: 252px; flex: none;
  background: var(--card); /* 老浏览器回退（下一行 color-mix 不支持时生效） */
  background: color-mix(in srgb, var(--card) 75%, transparent);
  border-right: 1px solid var(--line);
  overflow-y: auto; padding: 16px 16px 24px;
  display: flex; flex-direction: column; gap: 4px;
  transition: margin-left var(--t-med) var(--ease-out);
}
.sidebar.collapsed { margin-left: -252px; }

/* 中央地图区 */
.map-stage { flex: 1; min-width: 0; position: relative; background: #eee9dd; }
#map { position: absolute; inset: 0; background: #eee9dd; }

/* 右侧结果+详情栏 */
.rightbar {
  width: 388px; flex: none;
  border-left: 1px solid var(--line);
  background: var(--card); /* 老浏览器回退（下一行 color-mix 不支持时生效） */
  background: color-mix(in srgb, var(--card) 82%, transparent);
  display: flex; flex-direction: column; min-height: 0;
}

/* 结果列表区（上半） */
.results {
  flex: 0 1 46%;
  min-height: 112px;
  display: flex; flex-direction: column;
}
.results.collapsed { flex: 0 0 auto; }
.results.collapsed .results-list { display: none; }
.results-head {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 8px; cursor: pointer; user-select: none;
}
.results-head b { font-size: var(--fs-14); }
.results-head .cnt { color: var(--ink-3); font-size: var(--fs-12); }
.results-head .sort { margin-left: auto; font-size: var(--fs-12); color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; }
.results-head .caret { transition: transform var(--t-med) var(--ease-out); color: var(--ink-3); font-size: var(--fs-11); }
.results.collapsed .results-head .caret { transform: rotate(-90deg); }
.results-list { overflow-y: auto; min-height: 0; padding: 2px 8px 12px; }

/* 结果与详情分割线 */
.detail-sep { flex: none; border-top: 1px solid var(--line); }

/* 详情区（下半） */
.detail { flex: 1 1 0; min-height: 200px; overflow-y: auto; display: flex; flex-direction: column; }

/* 关闭详情按钮：仅移动端堆叠布局下显示 */
.d-close { display: none; }
@media (max-width: 960px) { .d-close { display: grid; color: var(--ink-2); } }

/* ---------- 通用面板卡片 ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}

/* ---------- 浮动控件（地图上） ---------- */
.map-ctrl { position: absolute; z-index: 900; }
.map-ctrl.tl { top: 16px; left: 16px; }
.map-ctrl.tr { top: 16px; right: 16px; }
.map-ctrl.bl { bottom: 24px; left: 14px; }
.map-ctrl.br { bottom: 24px; right: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }

/* ---------- 页面视图（非地图页） ---------- */
.page {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 24px clamp(16px, 4vw, 48px) 56px;
  scroll-behavior: smooth;
}
.page-inner { max-width: 1060px; margin: 0 auto; }
.page-head { margin-bottom: 24px; }
.page-head h2 { font-family: var(--serif); font-size: var(--fs-26); letter-spacing: .03em; }
.page-head p { color: var(--ink-2); margin-top: 6px; max-width: 760px; }

/* ---------- 抽屉遮罩（移动端筛选抽屉专用） ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 1150;
  background: rgba(40, 32, 20, .42);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease-out);
}
.scrim.on { opacity: 1; pointer-events: auto; }

/* ---------- 响应式 ---------- */
@media (max-width: 1280px) {
  .rightbar { width: 344px; }
  .sidebar { width: 232px; }
  .sidebar.collapsed { margin-left: -232px; }
}
@media (max-width: 1060px) {
  .g-search { width: 170px; }
  .g-search .hint { display: none; }
}
@media (max-width: 960px) {
  body { overflow: auto; }
  /* 整页文档流：shell 不再锁视口高，顶栏 sticky 才能在全文档范围生效 */
  .shell { height: auto; min-height: 100%; }
  .workspace { flex: none; }
  .page { overflow-y: visible; }
  .workspace { flex-direction: column; }

  /* —— 顶栏：logo + 可横滑导航 + 紧凑图标，杜绝溢出 —— */
  .topbar {
    gap: 10px; padding: 0 10px;
    position: sticky; top: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .brand { gap: 8px; }
  .brand .t { display: none; }
  .nav {
    flex: 1 1 0; min-width: 0;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  /* 溢出暗示：还有更多页签时对应边缘渐隐（class 由 app.js 按滚动位置维护） */
  .nav.can-right { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
  .nav.can-left { -webkit-mask-image: linear-gradient(90deg, transparent, #000 28px); mask-image: linear-gradient(90deg, transparent, #000 28px); }
  .nav.can-left.can-right { -webkit-mask-image: linear-gradient(90deg, transparent, #000 28px, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, transparent, #000 28px, #000 calc(100% - 28px), transparent); }
  .nav button { flex: none; padding: 0 11px; font-size: var(--fs-13); }
  .top-right { gap: 8px; }
  .top-right .ibtn { width: 38px; height: 38px; }
  /* 搜索框收成图标按钮（点击仍打开全局搜索） */
  .g-search {
    width: 38px; height: 38px; padding: 0; justify-content: center;
    flex: none; cursor: pointer;
  }
  .g-search span:not(:first-child) { display: none; }

  /* —— 抽屉 —— */
  .sidebar {
    position: fixed; z-index: 1200;
    top: calc(var(--tb-h, 58px) + env(safe-area-inset-top, 0px)); bottom: 0; left: 0;
    margin-left: 0; transform: translateX(-105%);
    transition: transform var(--t-med) var(--ease-out);
    box-shadow: var(--shadow-pop);
    width: min(300px, 86vw);
  }
  .sidebar.collapsed { margin-left: 0; transform: translateX(-105%); }
  .sidebar.open { transform: none; }

  /* —— 上下堆叠：地图定高，结果/详情自然流，整页滚动 —— */
  .map-stage { flex: none; min-height: 62vh; min-height: 62svh; }
  #stage-map, #detail { scroll-margin-top: var(--tb-h, 58px); }
  .rightbar {
    flex: none; width: 100%; border-left: none; border-top: 1px solid var(--line); max-height: none;
    /* 底部留出顶栏高度：详情 scrollIntoView 能完整滚出 sticky 顶栏 */
    padding-bottom: var(--tb-h, 58px);
  }
  .results { flex: none; min-height: 0; }
  /* 首访引导：未选中任何口岸时，空态详情（含新鲜度/图例）排到结果列表之前 */
  .rightbar:has(.detail.is-empty) { flex-direction: column-reverse; }
  .rightbar:has(.detail.is-empty) .detail-sep { display: none; }
  .rightbar:has(.detail.is-empty) .detail { padding-top: 4px; }
  .results-list { max-height: 32vh; max-height: 32svh; }
  .detail { flex: none; min-height: 0; }
  .d-tabs { position: static; }
  .results-head { padding: 12px 16px 8px; }
  .results-head .sort { padding: 8px 0 8px 8px; }

  /* —— 触摸目标 —— */
  .sidebar-toggle { width: 44px; height: 44px; top: 12px; left: 12px; }
  .zoom-ctrl button { width: 40px; height: 40px; }
  .layers-btn { width: 42px; height: 42px; }
  .compass { width: 44px; height: 44px; }
  .side-search .clr { width: 28px; height: 28px; }
  .region-pill { padding: 8px 16px; }
  .legend-card .lg-row { padding: 8px 6px; }

  /* —— 键盘专属 UI 隐藏与输入字号已在 components.css 的移动端块中处理 —— */
}
