/* ==========================================================================
   全球船舶位置查询 — 深色海图风格
   ========================================================================== */

:root {
  --bg:            #0b1119;
  --bg-panel:      #111a25;
  --bg-panel-2:    #16212e;
  --bg-input:      #0d1620;
  --border:        #22303f;
  --border-soft:   #1a2634;
  --fg:            #e6edf5;
  --fg-dim:        #8fa3b8;
  --fg-faint:      #64748b;
  --accent:        #38bdf8;
  --accent-dim:    #0ea5e9;
  --ok:            #4ade80;
  --warn:          #fbbf24;
  --err:           #f87171;
  --sidebar-w:     372px;
  --sheet-peek:    46px;   /* 手机上抽屉收起时露出的高度（把手 + 安全区） */
  --radius:        10px;
  --shadow:        0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, "Segoe UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: calc(100% - 28px);
}

/* ------------------------------------------------------------------ 侧栏 */

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-thumb { background: #22303f; border-radius: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #14202d, #111a25);
  z-index: 5;
}

.brand-mark {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(140deg, #0ea5e9, #0369a1);
  color: #eaf6ff;
  box-shadow: 0 3px 12px rgba(14, 165, 233, .3);
}

.brand-text h1 { margin: 0; font-size: 15px; letter-spacing: .2px; }
.brand-text p  { margin: 1px 0 0; font-size: 11.5px; color: var(--fg-faint); }

.conn {
  display: flex; align-items: center; gap: 7px;
  margin: 11px 14px 3px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--fg-dim);
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}

.conn .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-faint);
  flex: 0 0 8px;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, .5);
}
.conn.on  .dot { background: var(--ok);   animation: pulse 2.4s infinite; }
.conn.off .dot { background: var(--err); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, .45); }
  70%  { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.pane {
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.pane h2 {
  margin: 0 0 9px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  gap: 7px;
}

.pane-actions { margin-left: auto; display: flex; gap: 9px; }

.count {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(56, 189, 248, .12);
  border-radius: 20px;
  padding: 0 7px;
  letter-spacing: 0;
}

.link {
  background: none; border: 0; padding: 0;
  color: var(--accent);
  font: inherit; font-size: 11.5px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--err); }
.link:disabled { color: var(--fg-faint); cursor: default; text-decoration: none; }

.search { display: flex; gap: 7px; }

input[type=text], select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
}
input[type=text]::placeholder { color: #536173; }
input[type=text]:focus, select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .16);
}

button.primary {
  padding: 8px 15px;
  font: inherit;
  font-weight: 600;
  color: #04121d;
  background: linear-gradient(180deg, #56c8f8, #0ea5e9);
  border: 1px solid #0284c7;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .55; cursor: default; filter: none; }

.check {
  display: flex; align-items: center; gap: 7px;
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--fg-dim);
  cursor: pointer;
}
.check input { accent-color: var(--accent-dim); }

.hint {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--fg-faint);
  line-height: 1.5;
}
.hint.error { color: var(--err); }
/* 提示位空了就不占地方（页面保持简洁） */
.hint:empty { display: none; }

/* 「历史档案」入口：独立页面（新标签打开），本页即时查询逻辑不受影响 */.archive-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
}
.archive-row .hint { margin-top: 0; }
.archive-link {
  flex: 0 0 auto;
  padding: 6px 11px;
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  white-space: nowrap;
}
.archive-link:hover { border-color: var(--accent-dim); }

.field { margin-top: 12px; }
.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--fg-dim);
}
.field > label b { color: var(--accent); }

input[type=range] { width: 100%; accent-color: var(--accent-dim); }

code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(56, 189, 248, .1);
  color: #7dd3fc;
}

kbd {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-panel-2);
  color: var(--fg-dim);
}

textarea {
  width: 100%;
  padding: 8px 10px;
  font: 12.5px/1.6 ui-monospace, Consolas, monospace;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  resize: vertical;
  min-height: 58px;
}
textarea::placeholder { color: #536173; }
textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .16);
}

.batch-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.batch-actions select { flex: 1 1 120px; width: auto; min-width: 0; font-size: 12.5px; }
.batch-actions button { padding: 7px 12px; font: inherit; font-size: 12.5px; }
.batch-actions button:not(.primary) {
  color: var(--fg);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}
.batch-actions button:not(.primary):hover { border-color: var(--accent-dim); color: var(--accent); }
.batch-actions button:disabled { opacity: .5; cursor: default; }
.batch-or { font-size: 11.5px; color: var(--fg-faint); }

/* ------------------------------------------------------------- 搜索结果 */

.results { margin-top: 10px; }

.candidate {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--bg-panel-2);
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color .14s, transform .14s;
}
.candidate:hover { border-color: var(--accent-dim); transform: translateX(2px); }
.candidate .c-main { min-width: 0; flex: 1; }
.candidate .c-name {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.candidate .c-meta {
  font-size: 11.5px;
  color: var(--fg-faint);
  font-family: ui-monospace, Consolas, monospace;
}
.candidate .c-type {
  font-size: 11px;
  color: var(--fg-dim);
  text-align: right;
  white-space: nowrap;
}
.candidate .c-add {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
}

/* ------------------------------------------------------------- 关注列表 */

.watch { list-style: none; margin: 0; padding: 0; }

.watch li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.watch li:hover { background: var(--bg-panel-2); }
.watch li.active {
  background: rgba(14, 165, 233, .12);
  border-color: rgba(14, 165, 233, .45);
}
.watch .w-icon { flex: 0 0 20px; display: grid; place-items: center; }
.watch .w-main { flex: 1; min-width: 0; }
.watch .w-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.watch .w-sub {
  font-size: 11px;
  color: var(--fg-faint);
  font-family: ui-monospace, Consolas, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.watch .w-del {
  background: none; border: 0; cursor: pointer;
  color: var(--fg-faint); font-size: 15px; line-height: 1;
  padding: 2px 3px;
}
.watch .w-del:hover { color: var(--err); }

.empty {
  padding: 10px 2px;
  font-size: 12px;
  color: var(--fg-faint);
}

.credits {
  margin-top: auto;
  padding: 13px 16px 18px;
  font-size: 11px;
  color: var(--fg-faint);
  line-height: 1.6;
}

/* ------------------------------------------------------------------ 地图 */

.map-wrap { position: relative; overflow: hidden; }

#map {
  position: absolute;
  inset: 0;
  background: #08111a;
}

.leaflet-container { background: #08111a; font: inherit; }
.leaflet-control-attribution {
  background: rgba(10, 17, 25, .78) !important;
  color: var(--fg-faint) !important;
  font-size: 10.5px !important;
}
.leaflet-control-attribution a { color: var(--fg-dim) !important; }
.leaflet-bar a {
  background: var(--bg-panel) !important;
  color: var(--fg) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--bg-panel-2) !important; }

.map-toolbar {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 500;
}
.map-toolbar > * { pointer-events: auto; }

.legend {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 6px 11px;
  font-size: 11.5px;
  color: var(--fg-dim);
  background: rgba(10, 17, 25, .82);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
/* 图例里并排的三个小圆点：紧凑一点，示意"每条船颜色不同" */
.legend-item .swatch + .swatch { margin-left: -4px; }

.toolbar-buttons { display: flex; gap: 7px; }
.toolbar-buttons button {
  padding: 6px 11px;
  font: inherit; font-size: 12px;
  color: var(--fg);
  background: rgba(10, 17, 25, .82);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.toolbar-buttons button:hover { border-color: var(--accent-dim); color: var(--accent); }

/* ------------------------------------------------------------- 船舶标记 */

.ship-icon { background: none; border: 0; }

/* 亮色闪烁：脉冲环向外扩散 + 箭头明暗脉动。
   用 CSS 动画而不是 JS 定时器——标记每 2 分钟整体重绘一次，
   CSS 动画不会因此中断，也不占主线程。

   两个几何注意点（都是踩过的坑）：
   1) 脉冲环动画的是**半径 r**，不是 transform: scale()。圆心在 SVG 里恒为
      (16,16)，改 r 只让圆均匀向外长；transform 依赖 transform-origin，
      在 Leaflet 的 transformed 容器里对 SVG 子元素解析不稳定，会偏心。
   2) 箭头的缩放用显式的 `transform-origin: var(--icon-mid) var(--icon-mid)`，
      不依赖 transform-box: fill-box 推算，缩放中心严格落在 (16,16)。 */
@keyframes ship-pulse {
  0%   { r: 5;  opacity: .95; stroke-width: 2.6; }
  70%  { r: 15; opacity: 0;   stroke-width: .9; }
  100% { r: 15; opacity: 0;   stroke-width: .9; }
}

/* 箭头闪烁：**白色泛光层叠加变亮**，不是把填充淡出。
   淡出会透出深色海面（实测淡到 35% 变成 #103d6a，看着就是发黑），
   而叠加白色只会变亮，永远不会出现黑色。 */
@keyframes ship-flash {
  0%, 100% { opacity: 0; }
  50%      { opacity: .62; }
}

/* 箭头轻微缩放 + 外发光呼吸，增强"在闪"的感觉 */
@keyframes ship-arrow-beat {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

@keyframes ship-glow {
  0%, 100% { filter: drop-shadow(0 0 3px var(--marker-color, #38bdf8)); }
  50%      { filter: drop-shadow(0 0 12px var(--marker-color, #38bdf8))
                     drop-shadow(0 0 4px #ffffff); }
}

.ship-icon svg { display: block; overflow: visible; }

.ship-icon .ship-pulse { animation: ship-pulse 1.8s ease-out infinite; }
.ship-icon .ship-pulse.is-selected { animation-duration: 1.1s; }

.ship-icon .ship-flash { animation: ship-flash 1.1s steps(1, end) infinite; }

.ship-icon .ship-arrow {
  transform-origin: var(--icon-mid, 16px) var(--icon-mid, 16px);
  animation: ship-arrow-beat 1.1s ease-in-out infinite;
}

.ship-icon .ship-hull { animation: ship-glow 1.8s ease-in-out infinite; }

/* 选中：闪得更快，并去掉缩放，让选中的船保持完整形状便于辨认 */
.ship-icon.selected .ship-flash { animation-duration: .7s; }
.ship-icon.selected .ship-arrow { animation: none; }

/* 鼠标悬停时不闪，方便看清和点击 */
.ship-icon:hover .ship-flash { animation: none; opacity: 1; }
.ship-icon:hover .ship-arrow { animation: none; }
.ship-icon:hover .ship-hull { animation: none; filter: drop-shadow(0 0 12px #ffffff); }

/* 桌面端（大屏、常见街道图）对比加强：加粗深色外描边、加大外发光。
   底图按白底算时，鲜艳填充只有 1.1~1.6 的对比度，轮廓全靠深色描边，
   所以这里把描边和发光都加一档。 */
@media (min-width: 881px) {
  .ship-icon .ship-arrow { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .55)); }
  .ship-icon .ship-hull { animation-name: ship-glow-strong; }
}

@keyframes ship-glow-strong {
  0%, 100% { filter: drop-shadow(0 0 4px var(--marker-color, #38bdf8))
                     drop-shadow(0 1px 1px rgba(0, 0, 0, .6)); }
  50%      { filter: drop-shadow(0 0 16px var(--marker-color, #38bdf8))
                     drop-shadow(0 0 5px #ffffff)
                     drop-shadow(0 1px 2px rgba(0, 0, 0, .7)); }
}

/* 尊重"减少动态效果"偏好：关掉闪烁，保留亮色描边 */
@media (prefers-reduced-motion: reduce) {
  .ship-icon .ship-pulse { animation: none; opacity: 0; }
  .ship-icon .ship-flash { animation: none; opacity: 1; }
  .ship-icon .ship-arrow { animation: none; }
  .ship-icon .ship-hull { animation: none; filter: drop-shadow(0 0 4px var(--marker-color, #38bdf8)); }
}

/* Leaflet 弹窗（深色） */
.leaflet-popup-content-wrapper {
  background: rgba(13, 21, 31, .97);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: rgba(13, 21, 31, .97); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; line-height: 1.6; }
.leaflet-popup-close-button { color: var(--fg-faint) !important; }
.leaflet-tooltip {
  background: rgba(13, 21, 31, .95);
  border: 1px solid var(--border);
  color: var(--fg);
  box-shadow: none;
  font-size: 11.5px;
}
.leaflet-tooltip-top:before { border-top-color: var(--border); }

.popup-title { font-weight: 700; margin-bottom: 4px; }
.popup-body { color: var(--fg-dim); }

.ship-icon.selected .ship-hull path { filter: drop-shadow(0 0 6px #ffffff); }

.ship-label {
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  color: #eaf6ff;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  transform: translateX(-50%);
  pointer-events: none;
}

/* ----------------------------------------------------------- 详情浮层 */
/* 窄一点、贴边一点：尽量少挡地图，尤其别压住选中船舶的航迹线 */

.detail {
  position: absolute;
  top: 50px; right: 6px;
  width: 244px;
  max-height: calc(100% - 62px);
  overflow-y: auto;
  background: rgba(13, 21, 31, .95);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
  z-index: 600;
}

.detail-close {
  position: absolute; top: 5px; right: 5px;
  width: 21px; height: 21px;
  background: none; border: 0;
  color: var(--fg-faint);
  font-size: 16px; line-height: 1;
  cursor: pointer; border-radius: 5px;
}
.detail-close:hover { color: var(--fg); background: var(--bg-panel-2); }

.detail-head {
  padding: 9px 28px 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}
/* 船舶照片（有登记才渲染，见 refreshDetail） */
.detail-photo { margin-bottom: 8px; }
.detail-photo img {
  display: block;
  width: 100%;
  max-height: 190px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  cursor: zoom-in;
}

/* 图片放大层（点任意处 / Esc 关闭）。注意 display:flex 会盖掉 [hidden]，必须显式写 */
.lightbox {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px;
  background: rgba(5, 11, 18, .88);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 94vw; max-height: 86vh;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.lightbox-cap { color: #dbe6f5; font-size: 13px; }
.detail-head h3 { margin: 0; font-size: 13.5px; }
.detail-head .sub {
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--fg-faint);
  font-family: ui-monospace, Consolas, monospace;
}

.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.badge {
  font-size: 9.5px;
  padding: 1px 6px;
  border-radius: 20px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--fg-dim);
}
.badge.ok    { background: rgba(74, 222, 128, .12); border-color: rgba(74, 222, 128, .35); color: #86efac; }
.badge.warn  { background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .35); color: #fde68a; }
.badge.err   { background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .35); color: #fca5a5; }
.badge.cache { background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .3); color: #7dd3fc; }

.kv {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 3px 8px;
  padding: 9px 10px;
  font-size: 11.5px;
}
.kv dt { color: var(--fg-faint); }
.kv dd { margin: 0; color: var(--fg); word-break: break-word; }
.kv dd.mono { font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

.detail-actions {
  display: flex; gap: 5px; flex-wrap: wrap;
  padding: 0 10px 10px;
}
.detail-actions button {
  padding: 4px 8px;
  font: inherit; font-size: 11px;
  color: var(--fg);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.detail-actions button:hover { border-color: var(--accent-dim); color: var(--accent); }
.detail-actions button.on {
  border-color: rgba(14, 165, 233, .55);
  background: rgba(14, 165, 233, .14);
  color: #7dd3fc;
}

.detail-note {
  margin: 0 10px 10px;
  padding: 6px 8px;
  font-size: 10.5px;
  color: var(--warn);
  background: rgba(251, 191, 36, .08);
  border: 1px solid rgba(251, 191, 36, .25);
  border-radius: 6px;
}

/* ------------------------------------------------------------- 状态栏 */

.statusbar {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  font-size: 11.5px;
  color: var(--fg-faint);
  background: #0a121b;
  border-top: 1px solid var(--border-soft);
  font-family: ui-monospace, Consolas, monospace;
}
.statusbar .spacer { flex: 1; }

/* --------------------------------------------------------------- toast */

.toast {
  position: absolute;
  bottom: 16px; left: 50%;
  transform: translateX(-50%);
  padding: 8px 15px;
  font-size: 12.5px;
  color: #04121d;
  background: var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 700;
  max-width: 70%;
}
.toast.err { background: var(--err); color: #2a0505; }

/* ---------------------------------------------------------- 响应式 */

/* 抽屉把手：桌面端不需要 */
.sheet-handle { display: none; }
/* 面板悬浮按钮：只有窄屏才有意义（桌面端侧栏常驻） */
#btn-sheet { display: none; }

/*
 * 手机 / 窄屏（≤880px）
 *
 * 之前的做法是「侧栏 44% + 地图 56%」：手机上控制面板只占 44vh 还要内部滚动，
 * 输入框也被挤到几十像素宽，很难用。改成地图铺满、控制面板做成**可收起的
 * 底部抽屉**：
 *   - 收起（默认）：只露一条把手 + 顶部品牌行，地图几乎全屏
 *   - 展开：抽屉上滑到 78vh，带半透明遮罩，点遮罩或把手收起
 */
@media (max-width: 880px) {
  .app {
    display: block;                 /* 不用 grid，改用绝对定位控制层叠 */
    position: relative;
    height: calc(100dvh - 28px);    /* dvh：避开移动端地址栏伸缩导致的跳动 */
  }

  .map-wrap { position: absolute; inset: 0; }

  .sidebar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    max-height: 78dvh;
    z-index: 900;
    display: flex;
    flex-direction: column;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .5);
    overflow: hidden;               /* 由内层 .sheet-body 滚动 */
    transition: transform .26s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* 收起状态：整体下移，只留把手高度 */
  .app:not(.sheet-open) .sidebar { transform: translateY(calc(100% - var(--sheet-peek))); }

  .sheet-handle {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    flex: 0 0 auto;
    padding: 9px 16px 11px;
    background: linear-gradient(180deg, #16222e, #111a25);
    border: 0;
    border-bottom: 1px solid var(--border-soft);
    color: var(--fg);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    touch-action: manipulation;
  }
  .sheet-grip {
    position: absolute;
    top: 4px; left: 50%;
    width: 38px; height: 4px;
    margin-left: -19px;
    border-radius: 3px;
    background: #33465a;
  }
  .sheet-label { font-weight: 600; }
  .sheet-chevron { margin-left: auto; color: var(--accent); font-size: 11px; }
  .app.sheet-open .sheet-chevron { transform: rotate(180deg); }

  /* 抽屉内容区自己滚动，把手固定在顶部 */
  .sidebar > .brand,
  .sidebar > .conn,
  .sidebar > .pane,
  .sidebar > .credits { flex: 0 0 auto; }
  .sidebar { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* 展开时压暗地图，点击遮罩收起 */
  .app.sheet-open::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(4, 9, 15, .5);
    z-index: 850;
  }

  /* 详情面板改为地图下缘的窄条，避免和抽屉打架 */
  .detail {
    top: auto; bottom: 8px; left: 8px; right: 8px;
    width: auto;
    max-height: 36dvh;
    z-index: 800;
  }
  .app.sheet-open .detail { display: none; }

  .toast { bottom: auto; top: 12px; max-width: 92%; z-index: 1000; }

  /* 触摸目标放大；输入框 16px 以上，否则 iOS 聚焦时会自动放大页面 */
  input[type=text], select, textarea { font-size: 16px; }
  button.primary, .toolbar-buttons button { min-height: 40px; }
  .watch li { padding: 10px 8px; }
  .watch .w-del { font-size: 19px; padding: 4px 8px; }

  /* 图例已从页面移除；工具栏按钮在窄屏缩小一点 */
  .map-toolbar { gap: 6px; }
  .toolbar-buttons button { padding: 7px 9px; font-size: 11.5px; }

  /* 给 Leaflet 缩放控件留出抽屉把手的位置 */
  .leaflet-top.leaflet-left { top: 46px; }

  #btn-sheet { display: inline-block; }
}

/* 很窄的手机：搜索框与按钮分两行，别把输入框挤没了 */
@media (max-width: 480px) {
  .search { flex-wrap: wrap; }
  .search input[type=text] { flex: 1 1 100%; }
  .search button.primary { flex: 1 1 100%; }
  .sidebar { max-height: 84dvh; }
  .detail { max-height: 48dvh; }
  .pane { padding: 12px 13px 14px; }
}


/* ==================================================================
   登录框（替换原品牌标题区）+ 注册弹窗
   ================================================================== */
.login-box { padding: 14px 16px 12px; border-bottom: 1px solid var(--border-soft); }
.login-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.login-head-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #06121d;
}
.login-head-name { font-size: 15px; font-weight: 600; letter-spacing: .2px; }

.login-row { margin-bottom: 8px; }
.login-row input {
  width: 100%; box-sizing: border-box; padding: 8px 10px;
  font-size: 13px; font-family: inherit;
  color: var(--fg); background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.login-row input::placeholder { color: var(--fg-faint); }
.login-row input:focus { border-color: var(--accent); }

.login-cap { display: flex; gap: 8px; }
/* 作者样式的 display 会盖掉浏览器默认的 [hidden]{display:none}，所以显式补回：
   验证码行只有服务端要求时才由 index.html 的 loadCaptcha() 显示出来 */
.login-cap[hidden] { display: none; }
.login-cap input { flex: 1; min-width: 0; }
.login-cap img {
  height: 35px; width: 116px; flex: none; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: #f7fafd;
}

.login-err { min-height: 17px; font-size: 12px; line-height: 1.5; color: var(--err); margin-bottom: 6px; }
.login-err.ok { color: var(--ok); }

.login-btn {
  width: 100%; padding: 9px; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; color: #06121d;
  background: var(--accent); border: none; border-radius: 8px;
}
.login-btn:hover:not(:disabled) { background: #7dd3fc; }
.login-btn:disabled { opacity: .6; cursor: default; }

.login-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-top: 9px; font-size: 11.5px; color: var(--fg-faint);
}
.login-foot a { color: var(--accent); text-decoration: none; }
.login-foot a:hover { text-decoration: underline; }

/* ---- 注册弹窗（自带样式，不依赖合同系统主题）---- */
.lg-mask {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(3, 8, 14, .72);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow: auto;
}
.lg-modal {
  width: 100%; max-width: 540px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.lg-modal h3 {
  display: flex; align-items: center; margin: 0; padding: 14px 18px;
  font-size: 15px; border-bottom: 1px solid var(--border-soft);
}
.lg-modal h3 .x {
  margin-left: auto; background: none; border: 0; cursor: pointer;
  color: var(--fg-dim); font-size: 20px; line-height: 1; padding: 0 4px;
}
.lg-body { padding: 16px 18px; }
.lg-note { font-size: 12px; color: var(--fg-dim); margin-bottom: 14px; line-height: 1.6; }
.lg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.lg-grid .full { grid-column: 1 / -1; }
.lg-f label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 4px; }
.lg-f input, .lg-f select {
  width: 100%; box-sizing: border-box; padding: 7px 10px;
  font-size: 13px; font-family: inherit; color: var(--fg);
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; outline: none;
}
.lg-f input:focus, .lg-f select:focus { border-color: var(--accent); }
.lg-body .lg-err { margin: 12px 0 0; }
.lg-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--border-soft);
}
.lg-foot button {
  padding: 7px 16px; font-size: 13px; font-family: inherit; cursor: pointer;
  color: var(--fg); background: var(--bg-panel-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.lg-foot button.primary { background: var(--accent); color: #06121d; border-color: transparent; font-weight: 600; }
.lg-foot button:disabled { opacity: .6; cursor: default; }
