:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #5d6b78;
  --line: #dde3e9;
  --accent: #2563c9;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff2d6;
  --warn-text: #6b4600;
  --ok: #1e8a52;
  --shadow: 0 2px 10px rgb(0 0 0 / 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --panel: #182029;
    --text: #e8edf2;
    --muted: #9aa8b5;
    --line: #2b3742;
    --accent: #5b9bff;
    --accent-text: #0b1420;
    --danger: #ff7b6b;
    --warn-bg: #3d2e0c;
    --warn-text: #ffd98a;
    --ok: #4fd18b;
    --shadow: 0 2px 12px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.button { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }
.button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.button.small { padding: 6px 10px; font-size: 13px; }
.button:disabled { opacity: 0.6; cursor: default; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=number] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
input:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.error { color: var(--danger); min-height: 1.4em; margin: 10px 0 0; }

/* Sign-in and join pages */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 750; margin: 0 0 4px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.auth-card .button { width: 100%; margin-top: 20px; }
.download-button { display: block; text-align: center; text-decoration: none; margin-top: 18px; }
.center { text-align: center; }
.steps-title { font-size: 16px; margin: 20px 0 6px; }
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }
.consent { display: flex; gap: 10px; align-items: flex-start; margin-top: 18px; padding: 12px; border-radius: 10px; background: var(--bg); font-weight: 400; }
.consent input { margin-top: 4px; width: 18px; height: 18px; flex: none; }

/* Family map */
.app { display: grid; grid-template-columns: 380px 1fr; height: 100%; }
.panel { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel header .brand { font-size: 20px; }
.panel header .brand svg { width: 28px; height: 28px; }
.tabs { display: flex; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected=true] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 12px 16px 24px; }
.tab-body h2 { font-size: 16px; margin: 18px 0 8px; }
.tab-body h2:first-child { margin-top: 4px; }
#map { height: 100%; min-height: 0; }

.card { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--panel); width: 100%; text-align: left; cursor: pointer; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 650; }
.card .detail { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.card .side { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; border: 3px solid var(--panel); box-shadow: 0 1px 4px rgb(0 0 0 / 0.35); }
.avatar { position: relative; }
.motion { position: absolute; right: -7px; bottom: -6px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 2px solid var(--panel); box-shadow: 0 1px 3px rgb(0 0 0 / 0.35); }
.motion svg { width: 14px; height: 14px; fill: #1f2933; }
.motion.car { background: #2f6fdb; }
.motion.car svg { fill: #fff; }
.motion.walk { background: #2fa36b; }
.motion.walk svg { fill: #fff; }
.map-marker .motion { width: 22px; height: 22px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 12px; font-weight: 650; background: var(--bg); color: var(--muted); }
.badge.driving { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.paused, .badge.speeding { background: var(--warn-bg); color: var(--warn-text); }
.score { display: inline-grid; place-items: center; min-width: 34px; height: 26px; padding: 0 6px; border-radius: 8px; font-weight: 750; font-size: 14px; color: #fff; }
.score.good { background: var(--ok); }
.score.fair { background: #d08a12; }
.score.poor { background: var(--danger); }
.safety { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; margin-top: 6px; }
#drives .card { flex-wrap: wrap; }
.member-admin { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "who remove" "limit limit"; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member-admin > .row { grid-area: who; }
.member-admin > label { grid-area: limit; }
.member-admin > button { grid-area: remove; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; font-size: 13px; color: var(--muted); }
label.inline input { width: 110px; padding: 6px 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.invite-email { margin-top: 8px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); margin-bottom: 12px; }
.link-box { word-break: break-all; padding: 10px; border-radius: 10px; background: var(--bg); font-size: 13px; margin: 8px 0; }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 600; margin: 8px 0; }
.switch input { width: 22px; height: 22px; }

.map-marker { background: transparent; border: 0; }
.map-marker .avatar { width: 38px; height: 38px; font-size: 14px; }
.map-marker.stale .avatar { filter: grayscale(0.7); opacity: 0.75; }
.map-hint { position: absolute; z-index: 1000; top: 12px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 8px 14px; border-radius: 99px; box-shadow: var(--shadow); font-weight: 600; }
.map-wrap { position: relative; min-height: 0; }
.toast { position: fixed; z-index: 2000; right: 16px; bottom: 16px; max-width: 340px; background: var(--panel); border-left: 4px solid var(--accent); padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow); }
.staging-banner { position: fixed; z-index: 3000; left: 0; right: 0; bottom: 0; padding: 5px; text-align: center; background: #ffe3a1; color: #332200; font-weight: 600; font-size: 13px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 42% 58%; }
  .map-wrap { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); }
  .panel header { padding: 8px 16px; }
  .toast { left: 16px; right: 16px; max-width: none; }
}
