:root {
  --bg: #0b0e12;
  --grouped-bg: #12171e;
  --card: #1c222b;
  --border: #2a3340;
  --text: #f5f7fa;
  --muted: #8e99a8;
  --blue: #0a84ff;
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(20, 25, 33, 0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  flex: 1;
}

.header-side {
  min-width: 64px;
  display: flex;
  align-items: center;
}
.header-side.right { justify-content: flex-end; gap: 8px; }

.icon-btn {
  background: transparent;
  color: var(--blue);
  border: none;
  padding: 4px 6px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
}

.padded { padding: 14px 16px; }

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 14px 4px 6px;
}

.card {
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
}

.card-pad { padding: 14px; }

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row.clickable { cursor: pointer; }
.list-row.clickable:active { background: rgba(255, 255, 255, 0.05); }

input, button, select {
  font: inherit;
  border-radius: 10px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="time"], input[type="datetime-local"] {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  color-scheme: dark;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.btn {
  border: none;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.full { width: 100%; }
.btn.secondary { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.btn.danger { background: rgba(255, 69, 58, 0.16); color: var(--red); }
.btn.danger-solid { background: var(--red); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.row { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 3px; }
.grow { flex: 1; min-width: 0; }

.muted { color: var(--muted); font-size: 13px; }
.small-text { font-size: 12px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.sos-banner {
  background: var(--red);
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 12px 16px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

/* Family Overview Map */
.family-map-wrap {
  position: relative;
  border-bottom: 1px solid var(--border);
}
#familyMap {
  height: 45vh;
  min-height: 260px;
  width: 100%;
  background: #161c24;
}

/* Child Top Tabs */
.child-top-tabs {
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Map + floating pill */
.map-wrap { position: relative; }
#map {
  height: 310px;
  width: 100%;
  background: #161c24;
}
.battery-pill {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background: rgba(20, 25, 33, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Child info strip (phone number + device model) */
.info-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 0 16px 12px;
  font-size: 13px;
  color: var(--muted);
}
.phone-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.phone-link:hover { text-decoration: underline; }

/* Action bar matching iOS ChildDetailView (2 equal-width buttons) */
.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 16px 12px;
}

.quick-sound-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.action-btn {
  border: none;
  border-radius: 12px;
  padding: 11px 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.action-btn.blue-filled { background: var(--blue); color: #fff; }
.action-btn.blue-tint { background: rgba(10, 132, 255, 0.16); color: var(--blue); }
.action-btn.green-filled { background: var(--green); color: #000; }
.action-btn.green-tint { background: rgba(48, 209, 88, 0.16); color: var(--green); }
.action-btn.orange-tint { background: rgba(255, 159, 10, 0.16); color: var(--orange); }
.action-btn.red-filled { background: var(--red); color: #fff; }

/* Large 4-pill switcher for Activity & Controls */
.pill-switcher {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: #1c222b;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.pill-switcher button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.pill-switcher button.active {
  background: var(--blue);
  color: #fff;
}

/* Quiet Time presets & rows */
.preset-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.preset-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.preset-btn:active { background: rgba(255, 255, 255, 0.08); }
.qt-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(10, 132, 255, 0.16);
  color: var(--blue);
}
.qt-badge.silent { background: rgba(255, 159, 10, 0.18); color: var(--orange); }
.qt-badge.vibrate { background: rgba(10, 132, 255, 0.18); color: var(--blue); }
.qt-badge.normal { background: rgba(48, 209, 88, 0.18); color: var(--green); }

.live-badge {
  background: rgba(48, 209, 88, 0.2);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

/* Segmented control */
.segmented {
  display: flex;
  background: #232a35;
  padding: 3px;
  border-radius: 10px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 6px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button.active {
  background: #3a4454;
  color: #fff;
}

/* Call / Location circular icons */
.circle-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.circle-icon.green { background: rgba(48, 209, 88, 0.16); color: var(--green); }
.circle-icon.blue { background: rgba(10, 132, 255, 0.16); color: var(--blue); }
.circle-icon.red { background: rgba(255, 69, 58, 0.16); color: var(--red); }

/* Day pills for Safe Zone schedule */
.day-pills {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 10px 0;
}
.day-pill {
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.day-pill.selected { background: var(--blue); color: #fff; }

/* Bottom Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 950;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(20, 25, 33, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(8px + env(safe-area-inset-bottom));
}
.tab-bar button {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}
.tab-bar button.active { color: var(--blue); }

/* Modal sheet for Add/Edit Safe Zone */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--grouped-bg);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--grouped-bg);
  z-index: 10;
}
#szMap {
  height: 220px;
  width: 100%;
  border-radius: 12px;
  margin-bottom: 10px;
  background: #161c24;
}

.battery-chart-svg {
  width: 100%;
  height: 170px;
  display: block;
}

.invite-code { font-size: 24px; font-weight: 800; letter-spacing: 0.14em; }
.error { color: var(--red); font-size: 13px; margin-top: 6px; }
.hidden { display: none !important; }

/* Push-to-Talk & Remote Controls */
.ptt-btn {
  width: 100%;
  padding: 18px 16px;
  border: none;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.1s ease, background 0.15s ease;
}
.ptt-btn:active,
.ptt-btn.recording {
  background: var(--red);
  transform: scale(0.98);
}
.ptt-icon { font-size: 20px; line-height: 1; }

.slider-group {
  margin-bottom: 10px;
}
.slider-group input[type="range"] {
  margin-top: 4px;
}

/* Unified Chat Timeline & Composer */
.chat-timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  max-height: 48vh;
  overflow-y: auto;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--grouped-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  padding: 24px 12px;
}
.chat-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.chat-row.parent {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-row.child {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 6px 3px;
}
.chat-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.38;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row.parent .chat-bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.chat-row.child .chat-bubble {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.chat-voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.chat-play-btn {
  border: none;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}
.chat-row.child .chat-play-btn {
  background: rgba(10, 132, 255, 0.2);
  color: var(--blue);
}
.chat-voice-dur {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.92;
}
.broadcast-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 159, 10, 0.25);
  color: #ffd180;
}
.chat-row.child .broadcast-pill {
  background: rgba(255, 159, 10, 0.18);
  color: var(--orange);
}
.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--muted);
}
.chat-receipt.read {
  color: var(--blue);
  font-weight: 600;
}
.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.broadcast-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: #3a4454;
  border-radius: 999px;
  transition: background 0.18s ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
}
.switch input:checked + .switch-slider {
  background: var(--orange);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}
.chat-text-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-text-row input[type="text"] {
  margin-bottom: 0;
  flex: 1;
}
.chat-send-btn {
  padding: 11px 16px !important;
  font-size: 14px !important;
  border-radius: 10px !important;
  flex-shrink: 0;
}
.chat-composer .ptt-btn {
  padding: 13px 16px;
  font-size: 15px;
}
.chat-composer .ptt-btn.broadcast-mode {
  background: var(--orange);
  color: #000;
}
.chat-composer .ptt-btn.broadcast-mode.recording {
  background: var(--red);
  color: #fff;
}
