:root {
  --navy: #14264a;
  --navy-deep: #0d1a35;
  --sky: #7fc7ff;
  --blue: #1d6fd1;
  --blue-dark: #174f87;
  --amber: #d18400;
  --amber-light: #f2b84b;
  --red: #a52222;
  --red-bg: #fde8e8;
  --bg: #f4f7fb;
  --card: #ffffff;
  --line: #d9e1ec;
  --text: #182236;
  --muted: #5e6b80;
  --warn-bg: #fff4d6;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--navy); color: #fff;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.04em; font-size: 18px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.who { font-size: 13px; opacity: 0.85; }

.banner { padding: 8px 16px; text-align: center; background: var(--warn-bg); color: #5a4300; font-size: 14px; }
.banner.danger { background: var(--red-bg); color: var(--red); }
.sos-banner {
  width: 100%; border: 0; padding: 12px 16px; text-align: center; background: var(--red); color: #fff;
  font-weight: 700; font-size: 15px; animation: sos-blink 1.6s ease-in-out infinite;
}
@keyframes sos-blink { 0%, 100% { background: var(--red); } 50% { background: #c62828; } }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.center { text-align: center; padding: 32px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.5em; margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.compact { margin: 12px 12px 0; padding: 12px 14px; gap: 10px; }
.card h1 { font-size: 22px; margin: 0; }
.card p { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field > span { color: var(--muted); }
textarea, input[type="text"], select {
  width: 100%; padding: 10px 12px; border: 1px solid #9aa7b8; border-radius: 8px; background: #fff; font-size: 16px;
}
textarea { resize: vertical; min-height: 72px; word-break: break-all; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.primary { background: var(--blue); color: #fff; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; }
.primary:disabled { opacity: 0.5; cursor: default; }
.primary.small { padding: 8px 14px; font-size: 14px; }
.link { background: none; border: 0; color: var(--blue-dark); padding: 6px 8px; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: #ffb3b3; }
.panel .link.danger, .card .link.danger { color: var(--red); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.form { display: flex; flex-direction: column; gap: 10px; }
.result { display: flex; flex-direction: column; gap: 8px; }

/* アプリ本体: 地図（上）+ 一覧（下）+ タブ */
.app { display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.map-wrap { position: relative; height: 44dvh; min-height: 220px; background: #dfe7f1; }
.app.no-map .map-wrap { height: 0; min-height: 0; }
.app.no-map .map-wrap .map-fallback { display: none; }
.app.map-missing .map-wrap { height: 72px; min-height: 72px; }
.app.no-map.map-missing .map-wrap { height: 0; min-height: 0; }
.map { position: absolute; inset: 0; }
.map.map-picking { cursor: crosshair; }
.map-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--warn-bg); color: #5a4300; font-size: 14px; text-align: center; padding: 8px;
}
.recenter {
  position: absolute; left: 12px; bottom: 12px; z-index: 2; /* 右下は Google のズームと重なるので左下 */
  background: var(--card); color: var(--navy); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.recenter::before { content: "◎"; margin-right: 6px; color: var(--blue); }
.map-hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(20,38,74,0.92); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 13px; pointer-events: none;
}

.panel { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.tab-page { display: flex; flex-direction: column; }

.list { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.item {
  display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; text-align: left; width: 100%;
}
.item.selectable { cursor: pointer; }
.item.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(29,111,209,0.15); }
.item.stale { border-color: var(--amber); background: #fff9ea; }
.item.danger { border-color: #e9b7b7; background: #fff6f6; }
.item.sos { border-color: var(--red); background: var(--red-bg); box-shadow: 0 0 0 2px rgba(165,34,34,0.18); }
.item.sos .title { color: var(--red); }
.item.revoked { opacity: 0.55; }
.child-card { align-items: flex-start; }
.child-card .mark { margin-top: 2px; }
.child-card .status { font-size: 15px; margin-top: 2px; }
.child-card .status-place { color: var(--amber); font-weight: 600; }
.child-card .status-place::before { content: "⌂"; margin-right: 4px; }
.child-card .status-moving { color: var(--blue); font-weight: 600; }
.child-card .status-stopped { color: var(--muted); }
.child-card .status-none { color: var(--muted); }
.child-card .sub { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.battery.low { color: var(--red); font-weight: 700; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item .sub { color: var(--muted); font-size: 13px; }
.item .time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.item .actions { display: flex; gap: 4px; }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; }

.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #e9eef6; color: var(--blue-dark); font-weight: 600; }
.tag.warn { background: var(--warn-bg); color: #7a5a00; }
.tag.danger { background: var(--red-bg); color: var(--red); }
.tag.ok { background: #e3f5e8; color: #1f6b3a; }

.mark { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-size: 13px; font-weight: 700; color: #fff; }
.mark.stay { background: var(--amber); }
.mark.move { background: var(--blue); }
.mark.unknown { background: #8a8f98; }
.mark.event { background: var(--navy); }
.mark.child { background: var(--blue); }
.mark.child.stale { background: #8a8f98; }
.mark.enter { background: #1f6b3a; }
.mark.exit { background: var(--amber); }
.mark.silent { background: var(--red); }
.mark.danger { background: var(--red); }
.mark.warn { background: var(--amber); color: #fff; }
.mark.ok { background: #1f6b3a; }
.mark.sos { background: var(--red); font-size: 10px; letter-spacing: 0.02em; animation: sos-pulse 1.6s ease-out infinite; }
@keyframes sos-pulse { 0% { box-shadow: 0 0 0 0 rgba(165,34,34,0.5); } 100% { box-shadow: 0 0 0 10px rgba(165,34,34,0); } }

.date-nav { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0; gap: 8px; }
.date-label { text-align: center; display: flex; flex-direction: column; line-height: 1.2; }
.date-label span { font-size: 12px; }
.icon-button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 22px; line-height: 1; }
.chips { display: flex; gap: 8px; padding: 10px 12px 0; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; font-size: 14px; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* 履歴: 時系列のスライダー（docs/05） */
.timeline-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 0; }
.timeline-bar .play { flex-shrink: 0; font-size: 16px; background: var(--navy); color: #fff; border-color: var(--navy); }
.timeline-bar .play.playing { background: var(--card); color: var(--navy); }
.timeline-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.timeline-moment { font-size: 13px; font-weight: 600; color: var(--navy); min-height: 1.5em; overflow-wrap: anywhere; }
.timeline-moment.idle { color: var(--muted); font-weight: 400; }
.timeline-body input[type="range"] { width: 100%; margin: 0; accent-color: var(--blue); height: 28px; }
.timeline-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); line-height: 1.2; }

/* 履歴の行: 手段の印は道と同じ色。選んだ区間は青、スライダーの時刻が入っている区間は薄く */
.mark.mode { font-size: 15px; }
.mark.mode.mode-unknown { font-size: 13px; }
.item.current { background: #f1f6fd; }
.item.selected .title { color: var(--blue-dark); }
.credits { color: var(--muted); font-size: 11px; text-align: center; margin: 0; padding: 4px 12px 8px; }

.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--card);
  padding-bottom: var(--safe-bottom);
}
.tabs button { flex: 1; background: none; border: 0; padding: 10px 4px 8px; font-size: 13px; color: var(--muted); position: relative; }
.tabs button.active { color: var(--navy); font-weight: 700; box-shadow: inset 0 3px 0 var(--navy); }
.badge { position: absolute; top: 4px; right: calc(50% - 26px); background: var(--red); color: #fff; font-size: 10px; border-radius: 999px; min-width: 16px; padding: 0 4px; line-height: 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(72px + var(--safe-bottom)); transform: translateX(-50%);
  background: rgba(20,38,74,0.95); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); z-index: 50;
}

/* 地図の上の印（AdvancedMarkerElement の中身） */
.pin { display: flex; flex-direction: column; align-items: center; gap: 2px; transform: translateY(8px); }
.pin-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); }
.pin-child .pin-dot { animation: pulse 2s ease-out infinite; }
.pin-stale .pin-dot { background: #8a8f98; animation: none; }
.pin-selected .pin-dot { width: 22px; height: 22px; }
.pin-motion { min-width: 52px; height: 22px; padding: 0 6px; border: 2px solid #fff; border-radius: 12px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); margin-top: -10px; margin-left: 16px; z-index: 1; white-space: nowrap; }
.pin-label {
  background: rgba(255,255,255,0.95); border-radius: 8px; padding: 2px 8px; font-size: 12px; line-height: 1.3; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25); display: flex; flex-direction: column; white-space: nowrap;
}
.pin-label span { color: var(--muted); font-size: 11px; }
.pin-stale .pin-label span { color: var(--red); }
.pin-label-small { font-size: 11px; }
/* 子の印は点の中心が子の位置に来るようにする。印は下端中央で地図に留まるので、点だけを流れに置き、
   時速と名前は点の上下に浮かせる（以前は名前の下端が位置になり、点が名前の高さぶん北へずれて見えた） */
.pin.pin-child { position: relative; transform: translateY(50%); }
.pin-child .pin-motion { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); margin: 0; }
.pin-child .pin-label { position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); }
.live-motion { color: var(--navy); font-size: 13px; font-weight: 600; margin-top: 2px; }
.pin-number { width: 24px; height: 24px; border-radius: 50%; background: var(--amber); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); }
.pin-stay.pin-dim { opacity: 0.45; }
.pin-stay.pin-selected .pin-number { width: 30px; height: 30px; font-size: 14px; box-shadow: 0 0 0 3px rgba(29,111,209,0.35), 0 1px 4px rgba(0,0,0,0.35); }
.pin-cursor .pin-dot { width: 20px; height: 20px; background: var(--navy); animation: pulse 2s ease-out infinite; }
.pin-house { width: 12px; height: 12px; background: var(--amber); border: 2px solid #fff; border-radius: 3px; transform: rotate(45deg); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.pin-pick .pin-house { width: 16px; height: 16px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(29,111,209,0.45); } 100% { box-shadow: 0 0 0 14px rgba(29,111,209,0); } }

@media (min-width: 720px) {
  .app { grid-template-columns: 1fr 380px; grid-template-rows: 1fr auto; }
  .map-wrap { grid-row: 1 / span 2; height: auto; min-height: 0; }
  .app.map-missing .map-wrap { height: auto; }
  .panel { grid-column: 2; }
  .tabs { grid-column: 2; }
}
