/* style.css · 场地测量助手 M1 */
:root {
  --blue: #1a3c6e;
  --blue-light: #2b5a9e;
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #d8dee8;
  --text: #1c2430;
  --muted: #6b7686;
  --ok: #0f7b46;
  --warn: #b8791b;
  --danger: #c0392b;
  --panel-h: 210px;
  --tool-h: 150px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body { display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
#topbar {
  flex: 0 0 auto; height: 50px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 10px; gap: 8px;
  background: var(--blue); color: #fff; padding-top: env(safe-area-inset-top);
  height: calc(50px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }
.logo {
  width: 20px; height: 20px; flex: 0 0 20px; border-radius: 4px;
  background: linear-gradient(135deg, #6ea8ff, #2b5a9e);
  position: relative;
}
.logo::after {
  content: ""; position: absolute; left: 4px; top: 4px; width: 0; height: 0;
  border-left: 6px solid #fff; border-bottom: 5px solid transparent; border-top: 5px solid transparent;
}
.brand .title { font-size: 15px; font-weight: 600; white-space: nowrap; }
.top-actions { display: flex; gap: 6px; }
.chip {
  background: rgba(255, 255, 255, 0.16); color: #fff; border: 0;
  border-radius: 14px; padding: 6px 10px; font-size: 12px; cursor: pointer;
  white-space: nowrap;
}
.chip:active { background: rgba(255, 255, 255, 0.3); }
.chip.on { background: #fff; color: var(--blue); font-weight: 600; }
.chip.bad { background: #c0392b; }

/* ---------- 舞台 ---------- */
#stage { flex: 1 1 auto; position: relative; display: flex; flex-direction: column; min-height: 0; }
#map { flex: 1 1 auto; min-height: 120px; background: #dfe4ea; z-index: 1; }
.leaflet-container { font: inherit; background: #dfe4ea; }
.leaflet-control-attribution { font-size: 9px; }

/* 采集点 */
.pt-marker { width: 14px; height: 14px; border-radius: 50%; background: #2b5a9e; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.pt-marker.start {
  width: 0; height: 0; border-radius: 0; background: transparent; border: 0;
  border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-bottom: 16px solid #e8452c; box-shadow: none; transform: translateY(-2px);
}
.pt-marker.start::after {
  content: ""; position: absolute; left: -1px; top: 14px; width: 2px; height: 12px; background: #444;
}
.seg-label {
  background: rgba(255, 255, 255, .92); color: #1c2430; border: 1px solid #b9c3d2;
  border-radius: 9px; padding: 1px 5px; font-size: 11px; font-weight: 600;
  white-space: nowrap; transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

/* 精度提示（地图右上角，避开缩放按钮与版权栏） */
#accuracyChip {
  position: absolute; right: 10px; top: 10px;
  background: rgba(26, 60, 110, .88); color: #fff; font-size: 11px;
  padding: 4px 9px; border-radius: 11px; z-index: 500; pointer-events: none;
  max-width: 62%; text-align: right; line-height: 1.4;
}
#accuracyChip.warn { background: rgba(184, 121, 27, .95); }
#accuracyChip.bad { background: rgba(192, 57, 43, .95); }

/* ---------- 数据面板 ---------- */
#panel {
  flex: 0 0 auto; background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 10px; max-height: 44vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.metric {
  background: #f7f9fc; border: 1px solid #e5eaf1; border-radius: 8px;
  padding: 5px 7px; display: flex; flex-direction: column; min-width: 0;
}
.m-label { font-size: 11px; color: var(--muted); }
.m-value {
  font-size: 15px; font-weight: 700; color: var(--blue);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m-value small { font-size: 10px; font-weight: 500; color: var(--muted); }

/* 段长表 */
#segWrap { margin-top: 8px; display: flex; flex-direction: column; min-height: 0; }
.seg-head {
  display: flex; justify-content: space-between; font-size: 12px;
  color: var(--muted); padding-bottom: 4px; border-bottom: 1px solid var(--line);
}
.seg-table { overflow-y: auto; max-height: 116px; font-size: 12px; }
.seg-row {
  display: grid; grid-template-columns: 62px 1fr 1fr; gap: 4px;
  padding: 4px 2px; border-bottom: 1px dashed #e8ecf2;
}
.seg-row b { font-weight: 600; color: var(--blue); }
.seg-row span { text-align: right; font-variant-numeric: tabular-nums; }
.seg-row.start { background: #fff6f2; }
.seg-row.start b::before { content: "🚩 "; }

/* ---------- 工具栏 ---------- */
#toolbar {
  flex: 0 0 auto; background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.mode-switch { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-btn {
  flex: 1; padding: 8px; font-size: 13px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #f7f9fc; color: var(--muted);
}
.mode-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 600; }
.tool-row { display: grid; grid-template-columns: 1.4fr 1.2fr 1fr 1.3fr; gap: 6px; }
.btn {
  padding: 12px 4px; font-size: 14px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: #f7f9fc; color: var(--text);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn-primary { background: var(--blue-light); color: #fff; border-color: var(--blue-light); font-weight: 600; }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 600; }
.btn-danger { color: var(--danger); border-color: #eccac5; }

/* ---------- 抽屉 ---------- */
#drawer {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1200;
  display: flex; align-items: flex-end;
}
.drawer-panel {
  width: 100%; max-height: 86vh; background: var(--card);
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 16px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.record-list { flex: 1 1 auto; overflow-y: auto; padding: 8px 12px; }
.record-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  margin-bottom: 8px; display: flex; align-items: center; gap: 10px;
}
.record-item .r-main { flex: 1 1 auto; min-width: 0; }
.record-item .r-name { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.record-item .r-meta { font-size: 11px; color: var(--muted); }
.record-item .r-ops { display: flex; gap: 6px; }
.mini-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  padding: 6px 9px; font-size: 12px; cursor: pointer;
}
.mini-btn.danger { color: var(--danger); }
.empty-tip { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 0; }
.drawer-foot {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--line);
}

/* ---------- 模态 ---------- */
#saveModal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1300;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-box {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.modal-box h2 { margin: 0 0 2px; font-size: 16px; }
.modal-box label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-box input {
  padding: 10px; font-size: 15px; border: 1px solid var(--line);
  border-radius: 8px; font-family: inherit;
}
.save-summary {
  background: #f7f9fc; border: 1px solid #e5eaf1; border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--text); line-height: 1.7;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }

/* ---------- 提示 ---------- */
#toast {
  position: fixed; left: 50%; top: 96px; transform: translateX(-50%);
  background: rgba(28, 36, 48, .93); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 20px; z-index: 2000; max-width: 84vw;
  text-align: center; line-height: 1.5;
}
.hidden { display: none !important; }

/* 横屏与大屏 */
@media (min-width: 720px) {
  #stage { flex-direction: row; }
  #map { flex: 1 1 60%; }
  #panel { flex: 0 0 320px; border-top: 0; border-left: 1px solid var(--line); max-height: none; }
  #toolbar {
    position: absolute; left: 0; bottom: 0; width: 380px; z-index: 600;
    border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
  }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}
