:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #5d6b78;
  --line: #dde3e9;
  --accent: #0f8f86;
  --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;
}
/* Dark colors: chosen in Settings, or following the device when set to Automatic. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --panel: #182029;
    --text: #e8edf2;
    --muted: #9aa8b5;
    --line: #2b3742;
    --accent: #3cc4b8;
    --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;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --panel: #182029;
  --text: #e8edf2;
  --muted: #9aa8b5;
  --line: #2b3742;
  --accent: #3cc4b8;
  --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; flex-wrap: wrap; 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 1 0; 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; }
.card .side .app-version { font-size: 12px; opacity: .8; margin-top: 2px; }
.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; }
.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; flex-basis: 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; }

.sheet-handle { display: none; }
/* On phones the map fills the screen and the panel is a sheet you can slide down. */
@media (max-width: 760px) {
  .app { display: block; position: relative; }
  .map-wrap { position: absolute; inset: 0; }
  .panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1000; height: var(--sheet-height, 55%); max-height: calc(100% - 40px);
    border-right: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 18px rgb(0 0 0 / 0.22); transition: height 0.22s ease; overflow: hidden; }
  .panel.dragging { transition: none; }
  .sheet-handle { display: flex; justify-content: center; padding: 8px 0 2px; cursor: grab; touch-action: none; }
  .sheet-handle span { width: 42px; height: 5px; border-radius: 99px; background: var(--line); }
  .panel header { padding: 4px 16px 8px; touch-action: none; }
  .leaflet-bottom { bottom: var(--sheet-px, 0px); transition: bottom 0.22s ease; }
  .toast { left: 16px; right: 16px; max-width: none; }
}

/* Street / Satellite switch on the map */
.leaflet-control-layers { border-radius: 10px !important; border: 0 !important; box-shadow: var(--shadow) !important; background: var(--panel); color: var(--text); }
.leaflet-control-layers-expanded { padding: 6px 10px; }
.leaflet-control-layers-base label { margin: 0; font-weight: 600; font-size: 13px; }
.leaflet-control-layers-base label > span { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.grow { flex: 1; min-width: 0; }
select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.row.actions { flex-wrap: wrap; margin-top: 16px; }
.switch.small { font-size: 13px; font-weight: 500; }
/* Full-screen invitation card */
.invite-button { width: 100%; margin-top: 10px; }
.invite-sheet { width: 100%; max-width: 520px; height: 100%; max-height: 100%; margin: auto; padding: 0; border: 0; background: var(--panel); color: var(--text); }
.invite-sheet::backdrop { background: rgb(0 0 0 / 0.45); }
@media (min-width: 761px) { .invite-sheet { height: auto; max-height: 92vh; border-radius: 16px; } }
.sheet-bar { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 18px; position: sticky; top: 0; background: var(--panel); }
.icon-button { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 6px; cursor: pointer; color: var(--text); }
.sheet-body { padding: 20px 22px 28px; }
.sheet-body h1 { font-size: 28px; line-height: 1.2; margin: 6px 0 8px; }
.code-card { margin-top: 18px; padding: 24px 20px; border-radius: 22px; text-align: center; background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.code-card p { margin: 8px 0 0; }
.invite-code { font: 800 38px/1.2 ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: 3px; color: var(--accent); }
.button.pill { width: 100%; max-width: 320px; margin-top: 20px; padding: 16px; border-radius: 99px; font-size: 17px; }
.qr { width: 210px; height: 210px; margin: 0 auto; padding: 10px; background: #fff; border-radius: 14px; }
.qr svg { width: 100%; height: 100%; display: block; }
.sheet-body .link-box { margin-top: 16px; }
#codeEntry .button { width: 100%; margin-top: 14px; }

/* Profile photos, icons and colors */
.avatar { overflow: visible; }
/* Pinned to the circle's edges so a photo can never show at its full size. */
.avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%; max-width: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar-icon { font-size: 22px; line-height: 1; }
.map-marker .avatar-icon { font-size: 20px; }
.profile-row { display: flex; align-items: center; gap: 16px; }
.profile-avatar .avatar { width: 72px; height: 72px; font-size: 24px; }
.profile-avatar .avatar-icon { font-size: 38px; }
.profile-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.file-button { position: relative; overflow: hidden; display: inline-block; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.choice { height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); font-size: 22px; font-weight: 700; cursor: pointer; display: grid; place-items: center; padding: 0; }
.choice.chosen { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.choice.swatch { border-color: transparent; }
.choice.swatch.chosen { border-color: var(--text); }

/* Driving reports */
.report-controls { display: grid; gap: 8px; margin-bottom: 12px; }
.report-controls select { width: 100%; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed=true] { background: var(--accent); color: var(--accent-text); }
.date-row input { text-align: center; }
.report-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.report-heading h2 { margin: 6px 0; }
.tab-body h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.tile.warn { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); background: color-mix(in srgb, var(--danger) 7%, transparent); }
.tile-value { font-size: 20px; font-weight: 750; }
.tile-label { font-size: 12px; color: var(--muted); }
.bands { display: grid; gap: 6px; }
.band { display: grid; grid-template-columns: 78px 1fr 70px; align-items: center; gap: 8px; font-size: 13px; }
.band-bar { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.band-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.band-fill.fast { background: var(--danger); }
.band-value { text-align: right; color: var(--muted); }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th, .report-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.role-select { width: auto; padding: 6px 8px; }
.member-admin { grid-template-areas: "who remove" "limit limit" "role role"; }
.member-admin > .role-label { grid-area: role; }
@media print {
  .map-wrap, .tabs, .panel header, .report-controls, .sheet-handle, .report-heading button, .toast, .staging-banner { display: none !important; }
  .app, .panel, .tab-body { display: block !important; position: static !important; height: auto !important; overflow: visible !important; box-shadow: none !important; }
  .tab-body:not([data-panel=reports]) { display: none !important; }
}

.place-notify { display: flex; align-items: center; gap: 12px; margin: 0; font-weight: 400; cursor: pointer; flex: 1; min-width: 0; }
.place-notify input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

/* Download page */
.download-card { max-width: 460px; }
.welcome { text-align: center; margin: 14px 0 6px; }
.welcome h2 { margin: 8px 0 6px; font-size: 22px; }
.welcome p { margin: 0; }
.welcome-check { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #fff; font-size: 30px; font-weight: 800; }
.download-button { font-size: 18px; padding: 15px; }
#computerDownload p { text-align: center; }
.steps li strong { color: var(--text); }
.download-links { margin-top: 18px; }

/* Phone setup problems shown under a member's name */
.phone-issues { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge.issue { background: var(--warn-bg); color: var(--warn-text); white-space: normal; border-radius: 8px; }

/* Vehicle and shoe pickers */
.choice-grid.styles { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }
.style-choice { height: auto; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; }
.style-preview { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); }
.style-preview svg { width: 22px; height: 22px; }
.style-name { color: var(--muted); }
.small-swatches { grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); margin-top: 6px; }
.small-swatches .choice { height: 32px; border-radius: 50%; border: 1px solid var(--line); }
.small-swatches .choice.chosen { border: 3px solid var(--text); }
.choice.swatch[style*="rgb(255, 255, 255)"] { border-color: var(--line); }

/* The street map darkens with the theme; satellite photos are left alone. */
:root[data-theme="dark"] .street-tiles { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.7); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .street-tiles { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.7); }
}

/* Follow mode chip on the map */
.follow-chip { position: absolute; z-index: 1000; top: 12px; left: 50%; transform: translateX(-50%); border: 0; border-radius: 99px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-text); font-weight: 700; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; }
.follow-chip.paused { background: var(--panel); color: var(--accent); }
/* Speed above a driver's circle on the map */
.speed-label { position: absolute; left: 50%; bottom: calc(100% + 5px); transform: translateX(-50%); padding: 2px 7px; border-radius: 99px;
  background: #17202a; color: #fff; font-size: 12px; font-weight: 800; line-height: 1.3; white-space: nowrap; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); pointer-events: none; }
/* Over the speed limit: a red label with flames licking up off the top */
.speed-label.over { background: #d0180b; box-shadow: 0 0 12px rgb(255 80 0 / 0.8); isolation: isolate; }
.speed-label.over::before, .speed-label.over::after { content: ''; position: absolute; left: 2px; right: 2px; bottom: 62%; z-index: -1; transform-origin: 50% 100%; pointer-events: none; }
.speed-label.over::before { height: 26px;
  background: linear-gradient(to top, #e61e00 0%, #ff6a00 35%, #ffb300 65%, #ffe27a 92%);
  clip-path: polygon(0% 100%, 4% 62%, 10% 80%, 17% 22%, 25% 74%, 33% 40%, 41% 78%, 50% 0%, 59% 76%, 67% 34%, 75% 72%, 83% 18%, 90% 78%, 96% 58%, 100% 100%);
  animation: flames 0.38s ease-in-out infinite alternate; }
.speed-label.over::after { height: 17px; left: 14%; right: 14%;
  background: linear-gradient(to top, #ffb300 0%, #ffe27a 60%, #fff7d1 100%);
  clip-path: polygon(0% 100%, 12% 45%, 24% 82%, 38% 15%, 50% 70%, 62% 10%, 76% 80%, 88% 40%, 100% 100%);
  animation: flames 0.27s ease-in-out infinite alternate-reverse; }
@keyframes flames {
  0% { transform: scaleY(0.78) skewX(-6deg); }
  50% { transform: scaleY(1.15) skewX(4deg); }
  100% { transform: scaleY(0.92) skewX(-2deg); }
}
@media (prefers-reduced-motion: reduce) { .speed-label.over::before, .speed-label.over::after { animation: none; } }

/* Report ready pop-up */
.pdf-dialog { width: min(360px, calc(100% - 32px)); border: 0; border-radius: 18px; padding: 24px 22px 18px; background: var(--panel); color: var(--text); text-align: center; box-shadow: var(--shadow); }
.pdf-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.pdf-dialog h2 { margin: 10px 0 4px; font-size: 20px; }
.pdf-dialog p { margin: 0 0 18px; word-break: break-word; }
.pdf-icon { width: 54px; height: 64px; margin: 0 auto; border-radius: 8px; background: #c0392b; color: #fff; font-weight: 800; display: grid; place-items: center; letter-spacing: 1px; }
.pdf-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pdf-actions .hidden + .button, .pdf-actions .button:only-child { grid-column: 1 / -1; }
.pdf-actions .button { padding: 13px; font-size: 16px; }
.pdf-close { margin-top: 12px; border: 0; }
.badge.offline { background: var(--danger); color: #fff; white-space: normal; border-radius: 8px; }
.map-marker.offline .avatar { box-shadow: 0 0 0 3px var(--danger); }
.badge.stopped { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

/* Circles: the dropdown in the header picks which circle the map and lists show. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.circle-select { flex: 1; min-width: 0; margin: 0 10px; padding: 6px 28px 6px 10px; font-size: 17px; font-weight: 650; color: var(--text); background-color: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; text-overflow: ellipsis; }
.panel header .brand { flex: none; display: flex; align-items: center; }
.child-circles { margin-top: 12px; }
#newCircleForm, #joinCircleForm { margin-top: 8px; }
#newCircleForm input, #joinCircleForm input { flex: 1; min-width: 0; }
h3 { margin: 18px 0 6px; }
/* Each member: who and Remove, then the speed alert, then both role menus side by side. */
.member-admin { grid-template-areas: "who remove" "limit limit" "roles roles"; }
.member-admin > .role-label { grid-area: auto; }
.member-admin .roles { grid-area: roles; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.admin-circle { margin-bottom: 14px; }
.admin-circle .admin-member { padding: 6px 0 6px 14px; }
.settings-nav { margin: 4px 0 6px; }
