/* ============================================================
   家里人导航 · 适老化样式
   设计基准：正文 24px / 关键信息 40px / 按钮文字 30px
   触控区 ≥ 88px，对比度尽量 ≥ 7:1
   ============================================================ */

:root {
  --c-bg:        #eef2f7;
  --c-card:      #ffffff;
  --c-line:      #d5dde8;
  --c-text:      #10151c;
  --c-text-2:    #4a5462;
  --c-text-3:    #79828f;
  --c-primary:   #1257b0;
  --c-primary-d: #0d4185;
  --c-primary-l: #e7effb;
  --c-danger:    #c62828;
  --c-success:   #1b7a3d;
  --c-warn:      #b26a00;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;

  --shadow: 0 2px 10px rgba(16, 33, 60, 0.08);
  --shadow-up: 0 -4px 18px rgba(16, 33, 60, 0.12);

  --h-tap: 88px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { display: flex; justify-content: center; }

/* 电脑浏览器调试时，收成手机宽度居中 */
#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
}
@media (min-width: 600px) {
  body { background: #c9d3e0; }
  #app { box-shadow: 0 0 0 1px #b6c2d2, 0 12px 48px rgba(0,0,0,.25); }
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }

/* ---------------- 通用视图骨架 ---------------- */
.view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--c-primary);
  color: #fff;
}
.topbar .tb-title { font-size: 30px; font-weight: 700; flex: 1; }
.topbar .tb-sub { font-size: 20px; opacity: .85; }

.page-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- 首页 ---------------- */
.home-head {
  flex: 0 0 auto;
  padding: 26px 20px 18px;
  background: var(--c-primary);
  color: #fff;
}
.home-head .greet { font-size: 26px; opacity: .9; }
.home-head .who { font-size: 40px; font-weight: 800; margin-top: 4px; letter-spacing: 1px; }

.home-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: auto;
  align-content: center;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
}

.place-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 132px;
  aspect-ratio: 1 / 1;
  background: var(--c-card);
  border: 2px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  transition: transform .08s, background .12s;
  padding: 10px;
}
.place-btn:active { transform: scale(.97); background: var(--c-primary-l); }
.place-btn .p-ico { font-size: 76px; line-height: 1; }
.place-btn .p-name {
  font-size: 36px;
  font-weight: 800;
  color: var(--c-text);
  text-align: center;
  word-break: break-all;
  line-height: 1.2;
}
.place-btn .p-del {
  position: absolute; top: 6px; right: 6px;
  width: 34px; height: 34px; border-radius: 50%;
  background: #fdecec; color: var(--c-danger);
  font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* 空状态 */
.empty {
  grid-column: 1 / -1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 40px 20px; text-align: center;
  color: var(--c-text-2);
}
.empty .e-ico { font-size: 72px; }
.empty .e-tip { font-size: 26px; line-height: 1.6; }

/* 底部主按钮区 */
.home-foot {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--c-card);
  border-top: 1px solid var(--c-line);
  box-shadow: var(--shadow-up);
}
.big-action {
  min-height: var(--h-tap);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 27px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}
.big-action .a-ico { font-size: 30px; }
.big-action.go-home { background: var(--c-primary); }
.big-action.go-sos  { background: var(--c-danger); }
.big-action:active  { filter: brightness(.9); transform: scale(.98); }

/* ---------------- 导航页 ---------------- */
.nav-view { background: #dde6f2; }

.nav-head {
  flex: 0 0 auto;
  background: var(--c-primary);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.nav-head .nh-main { flex: 1; min-width: 0; }
.nav-head .nh-dist {
  font-size: 52px; font-weight: 800; line-height: 1.1; letter-spacing: 1px;
}
.nav-head .nh-dist small { font-size: 26px; font-weight: 600; margin-left: 6px; }
.nav-head .nh-time { font-size: 24px; opacity: .9; margin-top: 2px; }
/* 圆形图标按钮：导航页与各顶栏通用 */
.nh-back {
  flex: 0 0 auto;
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  color: #fff; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  padding: 0;
}
.nh-back:active { background: rgba(255,255,255,.32); }

.nav-map {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: #cfd9e6;
}
.nav-map #mapCanvas { position: absolute; inset: 0; }

/* 地图占位（无 Key 时） */
.map-fallback {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  color: var(--c-text-2);
  background:
    repeating-linear-gradient(0deg, #dbe4ef 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, #dbe4ef 0 1px, transparent 1px 40px),
    #e9eff7;
}
.map-fallback .mf-ico { font-size: 64px; }
.map-fallback .mf-msg { font-size: 24px; line-height: 1.6; max-width: 320px; }
.map-fallback .mf-hint { font-size: 19px; color: var(--c-text-3); }

.nav-foot {
  flex: 0 0 auto;
  background: var(--c-card);
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-up);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.nav-foot .nf-turn {
  flex: 0 0 auto;
  width: 74px; height: 74px; border-radius: 18px;
  background: var(--c-primary-l);
  display: flex; align-items: center; justify-content: center;
  font-size: 42px;
}
.nav-foot .nf-text { flex: 1; min-width: 0; }
.nav-foot .nf-now {
  font-size: 34px; font-weight: 800; line-height: 1.22;
  color: var(--c-text);
}
.nav-foot .nf-next {
  font-size: 22px; color: var(--c-text-2); margin-top: 6px;
  line-height: 1.35;
}

/* 到达态 */
.arrived {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  padding: 30px; text-align: center;
}
.arrived .ar-ico { font-size: 96px; }
.arrived .ar-t { font-size: 40px; font-weight: 800; color: var(--c-success); }
.arrived .ar-s { font-size: 26px; color: var(--c-text-2); }

/* ---------------- 帮助 / 迷路页 ---------------- */
.sos-card {
  background: var(--c-card);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  text-align: center;
}
.sos-card .s-ico { font-size: 60px; }
.sos-card .s-t { font-size: 30px; font-weight: 700; margin-top: 8px; }
.sos-card .s-d { font-size: 22px; color: var(--c-text-2); margin-top: 6px; }

.sos-btn {
  width: 100%;
  min-height: 110px;
  border-radius: var(--r-md);
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 14px;
}
.sos-btn.call { background: var(--c-danger); }
.sos-btn.loc  { background: var(--c-primary); }
.sos-btn.plain {
  background: var(--c-card); color: var(--c-text);
  border: 2px solid var(--c-line);
  font-size: 28px; min-height: var(--h-tap);
}
.sos-btn:active { filter: brightness(.92); }

/* ---------------- 家人端 ---------------- */
.fam-head {
  flex: 0 0 auto;
  padding: 18px 20px;
  background: var(--c-primary);
  color: #fff;
  display: flex; align-items: center; gap: 12px;
}
.fam-head .fh-t {
  flex: 1; min-width: 0;
  font-size: 26px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fam-head .fh-x {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
}

.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.list-item .li-ico { font-size: 36px; flex: 0 0 auto; line-height: 1; }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-name {
  font-size: 24px; font-weight: 700; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .li-addr {
  font-size: 17px; color: var(--c-text-3); margin-top: 3px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-item .li-ops { display: flex; gap: 6px; flex: 0 0 auto; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--c-primary-l); color: var(--c-primary);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.icon-btn.danger { background: #fdecec; color: var(--c-danger); }
.icon-btn:active { filter: brightness(.92); }

.fab {
  position: absolute;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  height: 76px;
  padding: 0 26px;
  border-radius: 38px;
  background: var(--c-primary);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 20px rgba(18,87,176,.4);
  z-index: 10;
}
.fab:active { transform: scale(.97); }

/* 表单 */
.field { margin-bottom: 22px; }
.field label {
  display: block; font-size: 21px; font-weight: 600;
  color: var(--c-text-2); margin-bottom: 8px;
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 68px;
  padding: 14px 16px;
  font-size: 24px;
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-card);
  border: 2px solid var(--c-line);
  border-radius: var(--r-sm);
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--c-primary); }
.field .hint { font-size: 18px; color: var(--c-text-3); margin-top: 6px; line-height: 1.5; }

.btn-primary, .btn-secondary {
  width: 100%;
  min-height: 84px;
  border-radius: var(--r-md);
  font-size: 28px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 12px;
}
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:active { background: var(--c-primary-d); }
.btn-secondary {
  background: var(--c-card); color: var(--c-text);
  border: 2px solid var(--c-line);
}
.btn-primary:disabled { background: #b8c4d3; color: #fff; }

/* PIN 门禁 */
.pin-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 26px; padding: 30px;
}
.pin-dots { display: flex; gap: 20px; }
.pin-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--c-line); background: transparent;
  transition: background .12s;
}
.pin-dot.on { background: var(--c-primary); border-color: var(--c-primary); }
.pin-tip { font-size: 24px; color: var(--c-text-2); }
.pin-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 14px; width: 100%; max-width: 320px;
}
.pin-key {
  height: 82px; border-radius: var(--r-md);
  background: var(--c-card); border: 1px solid var(--c-line);
  font-size: 34px; font-weight: 600; color: var(--c-text);
  box-shadow: var(--shadow);
}
.pin-key:active { background: var(--c-primary-l); }
.pin-key.ghost { background: transparent; border: none; box-shadow: none; font-size: 22px; }

/* ---------------- 候选地址 ---------------- */
.cand {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--c-card); border: 2px solid var(--c-line);
  border-radius: var(--r-md); padding: 16px; margin-bottom: 12px;
}
.cand .cd-idx {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: var(--c-primary-l); color: var(--c-primary);
  font-size: 22px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.cand .cd-body { flex: 1; min-width: 0; }
.cand .cd-name { font-size: 24px; font-weight: 700; }
.cand .cd-addr { font-size: 19px; color: var(--c-text-3); margin-top: 4px; }
.cand .cd-src {
  font-size: 16px; color: var(--c-text-3);
  background: #f0f3f8; border-radius: 6px; padding: 1px 8px;
  display: inline-block; margin-top: 8px;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%) translateY(20px);
  max-width: 420px;
  padding: 16px 26px;
  background: rgba(16, 30, 50, .92);
  color: #fff;
  font-size: 23px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 999;
  text-align: center;
  line-height: 1.4;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- 调试面板 ---------------- */
.debug-panel {
  position: fixed;
  left: 8px; bottom: 8px;
  width: 300px;
  max-height: 70vh;
  overflow-y: auto;
  background: rgba(12, 20, 32, .95);
  color: #d7e3f5;
  font-size: 15px;
  font-family: Consolas, "Courier New", monospace;
  border-radius: 10px;
  padding: 10px 12px;
  z-index: 998;
  line-height: 1.5;
  border: 1px solid #2a3d58;
}
.debug-panel .dp-t {
  font-weight: 700; color: #7ab6ff; margin-bottom: 6px;
  font-size: 14px; letter-spacing: .5px;
}
.debug-panel .dp-row { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.debug-panel button {
  background: #1e3350; color: #cfe2ff; border: 1px solid #33507a;
  border-radius: 6px; padding: 5px 9px; font-size: 13px;
  font-family: inherit;
}
.debug-panel button:active { background: #2b4a72; }
.debug-panel .dp-log { color: #8fa6c4; font-size: 13px; white-space: pre-wrap; word-break: break-all; }

/* 底部进入家人端的入口（长按 3 秒） */
.family-entry {
  position: absolute;
  right: 10px; bottom: 4px;
  font-size: 12px; color: rgba(0,0,0,.18);
  padding: 8px 10px;
  user-select: none;
  z-index: 5;
}

/* 滚动条美化（桌面调试用） */
.page-body::-webkit-scrollbar, .home-grid::-webkit-scrollbar { width: 6px; }
.page-body::-webkit-scrollbar-thumb, .home-grid::-webkit-scrollbar-thumb {
  background: #c3cede; border-radius: 3px;
}
