:root {
  --bg: #f2f2f6;
  --surface: #ffffff;
  --surface-2: #eeeef2;
  --text: #1c1c1e;
  --muted: #6c6c74;
  --line: #e2e2e8;
  --red: #d92d20;
  --red-2: #b42318;
  --red-soft: #fdeceb;
  --green: #138a45;
  --green-soft: #e3f5ea;
  --blue: #1f6fe5;
  --amber: #e8950b;
  --warn-bg: #fff6e0;
  --warn-text: #7a4a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f2f2f7;
    --muted: #9b9ba3;
    --line: #38383c;
    --red: #ff453a;
    --red-2: #d70015;
    --red-soft: #3b1714;
    --green: #30d158;
    --green-soft: #10301a;
    --blue: #4a90ff;
    --warn-bg: #3a2c0c;
    --warn-text: #ffd27a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Noto Sans CJK SC", "Microsoft YaHei", "Hiragino Sans", sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }

a { color: var(--blue); }
button { cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; }

/* ---------- 顶栏 / 底部导航 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.topbar h1 { margin: 0 auto; max-width: 640px; font-size: 26px; font-weight: 800; letter-spacing: .5px; }

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 28px; }
.view { display: none; }
.view.active { display: block; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  max-width: 160px;
  border: 0;
  background: none;
  padding: 7px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
  font-size: 11px;
  color: var(--muted);
}
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--red); font-weight: 600; }

/* ---------- 通用 ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card.note p { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.card.note p:last-child { margin-bottom: 0; }
.card.note b { color: var(--text); }
.sec-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 22px 4px 8px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.hint.pad { padding: 0 4px; }
.intro { font-size: 14px; color: var(--muted); margin: 4px 2px 14px; }
.intro b { color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--red); color: #fff; }
.btn.block { display: flex; width: 100%; margin-top: 14px; }
.btn.danger-outline { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.danger-text { background: transparent; color: var(--red); padding-left: 4px; padding-right: 4px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.btn-row + .btn.block { margin-top: 10px; }

.btn-sm {
  flex: none;
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); background-color: var(--surface); }
textarea { resize: vertical; min-height: 64px; }
::placeholder { color: var(--muted); opacity: .7; }

/* ---------- 首页 ---------- */
.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 12px 12px 12px 14px;
  margin-bottom: 12px;
  font-size: 13.5px;
}
.banner-text { flex: 1; }
.banner-text b { display: block; font-size: 14.5px; margin-bottom: 2px; }
.banner-close { border: 0; background: none; color: inherit; font-size: 15px; padding: 2px 4px; opacity: .7; }

.todo-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.todo-list:empty { display: none; }
.todo {
  border: 1px dashed var(--red);
  background: var(--red-soft);
  color: var(--red);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 600;
  text-align: left;
}

.loc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px 10px 14px;
  box-shadow: var(--shadow);
  min-height: 52px;
}
.loc-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.loc-dot.ok { background: var(--green); }
.loc-dot.stale { background: var(--amber); }
.loc-dot.err { background: var(--red); }
.loc-dot.loading { background: var(--blue); animation: blink 1s ease-in-out infinite; }
.loc-text { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); }
.loc-text b { color: var(--text); font-weight: 600; }
@keyframes blink { 50% { opacity: .25; } }

.sos-wrap { display: flex; flex-direction: column; align-items: center; padding: 34px 0 6px; }
.sos-btn {
  position: relative;
  width: min(62vw, 236px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  color: #fff;
  background: radial-gradient(circle at 34% 28%, #ff7466, #e5372a 52%, #b42318);
  box-shadow: 0 12px 32px rgba(217, 45, 32, .38), inset 0 -8px 18px rgba(0, 0, 0, .16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform .12s;
}
.sos-btn::before {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 3px solid #e5372a;
  opacity: 0;
  animation: ring 2.6s ease-out infinite;
}
.sos-btn:active { transform: scale(.96); }
.sos-btn b { font-size: clamp(46px, 15vw, 64px); line-height: 1; letter-spacing: 3px; }
.sos-btn span { font-size: 18px; margin-top: 8px; font-weight: 600; }
@keyframes ring { 0% { transform: scale(.9); opacity: .55; } 100% { transform: scale(1.12); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sos-btn::before, .loc-dot.loading { animation: none; } }

.safe-btn {
  margin-top: 30px;
  width: 100%;
  max-width: 380px;
  padding: 15px;
  border-radius: 16px;
  border: 0;
  background: var(--green-soft);
  color: var(--green);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
}
.safe-btn:active { filter: brightness(.95); }

.home-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  padding: 13px 14px;
  text-align: left;
  font: inherit;
  color: var(--text);
  box-shadow: var(--shadow);
}
.tile b { font-size: 15px; }
.tile small { font-size: 12px; color: var(--muted); }
.summary { text-align: center; font-size: 12.5px; color: var(--muted); margin: 16px 0 0; }

/* ---------- 我的信息 ---------- */
.group {
  border: 0;
  margin: 0 0 14px;
  padding: 0 14px 4px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.group legend {
  float: left;
  width: 100%;
  padding: 13px 0 6px;
  font-weight: 700;
  font-size: 16px;
}
.group legend small { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }
.field { clear: both; padding: 10px 0 12px; }
.group-hint { clear: both; margin: 0 0 4px; }
.group .field + .field { border-top: 1px solid var(--line); }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field-head label, .field > label, .field-label { display: block; font-size: 14px; font-weight: 600; }
.field > label, .field-label { margin-bottom: 6px; }
.field-head small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 3px; }
.tag-lock {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--warn-text);
  background: var(--warn-bg);
  padding: 0 6px;
  border-radius: 6px;
  margin-left: 4px;
  vertical-align: 1px;
}

.inc { flex: none; position: relative; cursor: pointer; }
.inc input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.inc span {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.inc span::before { content: "不发送"; }
.inc input:checked + span { background: var(--red-soft); color: var(--red); font-weight: 600; }
.inc input:checked + span::before { content: "✓ 随求助发送"; }
.inc input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }
.save-note { text-align: center; font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

/* ---------- 联系人 ---------- */
.contact-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.contact-list:empty { display: none; }
.contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  width: 100%;
  background: none;
  font: inherit;
  color: var(--text);
  text-align: left;
}
.contact-list li:first-child .contact { border-top: 0; }
.c-main { flex: 1; min-width: 0; }
.c-main b { font-weight: 600; }
.c-main small { color: var(--muted); margin-left: 6px; font-size: 13px; }
.c-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 20px; line-height: 1; margin-left: auto; }

.badge {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}
.b-sms { background: #34c759; }
.b-wechat { background: #07c160; }
.b-qq { background: #12b7f5; }
.b-line { background: #06c755; }
.b-whatsapp { background: #1fa855; }
.b-email { background: #5e5ce6; }
.b-share { background: #8e8e93; }
.b-copy { background: #636366; }

/* ---------- 更多 ---------- */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
}
.list-item:first-child { border-top: 0; }
.hl-txt { flex: 1; min-width: 0; font-size: 14.5px; }
.hl-num { display: block; font-weight: 800; font-size: 19px; line-height: 1.3; color: var(--red); font-variant-numeric: tabular-nums; }
.hl-txt small { display: block; color: var(--muted); font-size: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.inline-select { width: auto !important; min-width: 130px; }
.tips ol { padding-left: 20px; margin: 0; }
.tips li { margin: 4px 0 10px; font-size: 14px; color: var(--muted); }
.tips li b { color: var(--text); }
.footer-note { text-align: center; font-size: 12px; color: var(--muted); margin-top: 24px; }

/* ---------- 发送面板 ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .42);
  opacity: 0;
  transition: opacity .2s;
}
.sheet.open { opacity: 1; }
.sheet-panel {
  width: 100%;
  max-width: 640px;
  height: calc(100% - env(safe-area-inset-top) - 18px);
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(30px);
  transition: transform .22s ease-out;
  overflow: hidden;
}
.sheet.open .sheet-panel { transform: none; }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet[data-mode="sos"] .sheet-head h2 { color: var(--red); }
.sheet[data-mode="safe"] .sheet-head h2 { color: var(--green); }
.close-btn {
  border: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}
.close-btn.light { background: #eee; color: #444; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
}
.block { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; box-shadow: var(--shadow); }
.block-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
}
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.sheet[data-mode="safe"] .chip.on { background: var(--green); border-color: var(--green); }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 8px; font: inherit; font-size: 14px; color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); font-weight: 700; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 15px; }
.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background .2s;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.preview { margin-top: 12px; background: var(--surface); border-radius: var(--radius); padding: 11px 14px; box-shadow: var(--shadow); }
.preview summary { font-weight: 600; font-size: 14px; cursor: pointer; }
.preview pre {
  white-space: pre-wrap;
  word-break: break-all;
  font: 13.5px/1.6 inherit;
  font-family: inherit;
  margin: 10px 0 2px;
  max-height: 46vh;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}
.len-warn { color: var(--amber); }

.ch-grid { display: flex; flex-direction: column; gap: 8px; }
.ch-grid + .ch-grid { margin-top: 8px; }
.ch-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.ch-btn:active { filter: brightness(.96); }
.ch-btn.primary { border: 2px solid var(--red); padding: 9px 11px; }
.sheet[data-mode="safe"] .ch-btn.primary { border-color: var(--green); }
.ch-btn.small { min-height: 48px; padding: 7px 12px; margin-left: 22px; width: calc(100% - 22px); }
.ch-btn.small .badge { width: 28px; height: 28px; font-size: 12px; border-radius: 8px; }
.ch-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-txt b { font-weight: 600; font-size: 15.5px; }
.ch-txt small { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-check {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
}
.ch-btn.done { border-color: var(--green); }
.ch-btn.done .ch-check { background: var(--green); border-color: var(--green); }
.more-ch { margin-top: 12px; }
.more-ch summary { font-size: 14px; color: var(--muted); padding: 8px 4px; cursor: pointer; }
.empty-hint { font-size: 13.5px; color: var(--muted); margin: 0 4px 10px; }

/* ---------- 救援信息卡（始终高对比度浅色） ---------- */
.card-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #fff;
  color: #000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(env(safe-area-inset-bottom) + 28px);
}
.rcard { max-width: 640px; margin: 0 auto; }
.rcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 5px solid #d92d20; padding-bottom: 10px; }
.rcard-head b { display: block; font-size: 30px; color: #d92d20; line-height: 1.2; }
.rcard-head span { font-size: 12.5px; color: #555; letter-spacing: .3px; }
.rcard-help { font-size: 18px; font-weight: 700; margin: 14px 0 6px; }
.rcard-help span { font-size: 14px; font-weight: 400; color: #444; }
#cardList { margin: 0; }
.r-row { display: grid; grid-template-columns: minmax(92px, 32%) 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid #ddd; }
.r-row dt { font-size: 14px; font-weight: 700; color: #333; }
.r-row dt small { display: block; font-weight: 400; color: #777; font-size: 12px; }
.r-row dd { margin: 0; font-size: 19px; font-weight: 600; word-break: break-word; }
.r-row.key dd { font-size: 22px; }
.r-empty { font-size: 16px; color: #555; padding: 16px 0; }

/* ---------- 联系人对话框 ---------- */
dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(calc(100vw - 32px), 440px);
  max-height: calc(100dvh - 40px);
  background: var(--bg);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .42); }
.dlg-body { padding: 18px 16px 14px; }
.dlg-body h2 { margin: 0 0 8px; font-size: 19px; }
.dlg-body .field { padding: 8px 0; }
.ch-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ch-pick label {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  background: var(--surface);
  cursor: pointer;
}
.ch-pick label.on { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); font-weight: 600; }
.ch-pick input { position: absolute; opacity: 0; pointer-events: none; }
.ch-pick .badge { width: 30px; height: 30px; font-size: 13px; border-radius: 9px; }
.form-err { color: var(--red); font-size: 13.5px; min-height: 1em; margin: 4px 0 0; }
.form-err:empty { display: none; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.dlg-actions .spacer { flex: 1; }
.confirm-dlg { width: min(calc(100vw - 48px), 340px); }
.cf-msg { margin: 4px 0 6px; font-size: 15px; color: var(--muted); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  z-index: 100;
  width: max-content;
  max-width: calc(100vw - 32px);
  background: rgba(28, 28, 30, .95);
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
