/* Vaultlink -- design system + layout.
   Dark, security-dashboard aesthetic. No external fonts/icons -- system font
   stack + an inline SVG sprite (index.html) so nothing depends on a CDN. */

:root {
  --bg: #0b0d12;
  --bg-elev: #0f1117;
  --panel: #161923;
  --panel-2: #1c202c;
  --border: #272c3a;
  --border-soft: #1e222d;
  --text: #eceef4;
  --text-dim: #aeb4c4;
  --muted: #757d92;
  --accent: #4f8cff;
  --accent-dim: rgba(79, 140, 255, 0.15);
  --ok: #3ecf8e;
  --ok-dim: rgba(62, 207, 142, 0.15);
  --warn: #e0a94f;
  --warn-dim: rgba(224, 169, 79, 0.15);
  --danger: #e0555f;
  --danger-dim: rgba(224, 85, 95, 0.15);
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
/* Any element using the native `hidden` attribute must actually hide, even
   when a class on the same element also sets `display` (equal specificity,
   later-wins cascade would otherwise silently defeat `hidden`). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
.icon { display: block; flex-shrink: 0; }

/* ---------- shell / topbar ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
/* Nothing may be wider than the phone: no sideways scrolling, and no pinch-zoom of the page (the
   map handles its own pinch -- Leaflet sets touch-action: none on it). */
html, body { overflow-x: hidden; max-width: 100%; }
html { touch-action: pan-x pan-y; }
.account-line { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 10px; overflow-wrap: anywhere; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  /* Installed on an iPhone the page runs under the status bar (black-translucent): clear the clock. */
  padding: calc(12px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 1.05rem; color: var(--accent); }
.brand span { color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.pill-btn {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 7px 14px 7px 10px; font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.pill-btn:hover { border-color: var(--accent); color: var(--text); }
.pill-btn.live { color: var(--ok); border-color: rgba(62, 207, 142, 0.35); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.pill-btn.live .live-dot { background: var(--ok); box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.6); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(62, 207, 142, 0); }
  100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0); }
}

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; background: var(--panel); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: var(--radius-sm); cursor: pointer; padding: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- notice ---------- */
.notice {
  font-size: 0.82rem; line-height: 1.5; color: var(--text-dim);
  background: rgba(224, 169, 79, 0.08); border: 1px solid rgba(224, 169, 79, 0.25);
  border-radius: var(--radius); padding: 10px 16px; margin: 14px 18px 0;
}
.notice code { font-family: var(--font-mono); font-size: 0.78rem; background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 4px; }

/* ---------- main layout ---------- */
.layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 16px;
  padding: 16px 18px 32px; flex: 1; align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- sidebar / tracker list ---------- */
.sidebar {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; max-height: calc(100vh - 130px); overflow: hidden;
}
@media (max-width: 860px) { .sidebar { max-height: none; } }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.sidebar-head h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sidebar-head .count { background: var(--panel-2); color: var(--text-dim); border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; }

.tracker-list { overflow-y: auto; padding: 0 10px; flex: 1; }
.sidebar-foot { padding: 10px 14px 14px; border-top: 1px solid var(--border-soft); margin-top: 6px; }
.live-status { font-size: 0.74rem; color: var(--muted); margin-top: 8px; line-height: 1.4; }

.tracker-card {
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden;
  background: var(--panel-2);
}
.tracker-row {
  display: flex; align-items: center; gap: 9px; padding: 10px 10px;
}
.tracker-row:hover { background: rgba(255,255,255,0.02); }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--swatch, var(--accent)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--swatch, var(--accent)) 25%, transparent); }
.tracker-main { flex: 1; min-width: 0; }
.tracker-name-input {
  background: transparent; border: 1px solid transparent; padding: 3px 6px; margin: -3px -6px -3px -7px;
  font-size: 0.9rem; font-weight: 600; width: calc(100% + 7px); border-radius: 5px; color: var(--text);
  font-family: inherit;
}
.tracker-name-input:hover { background: rgba(255,255,255,0.04); }
.tracker-name-input:focus { background: var(--bg-elev); border-color: var(--accent); }
.tracker-meta { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.status-pill { font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 999px; }
.status-pill.live { background: var(--ok-dim); color: var(--ok); }
.status-pill.stale { background: var(--warn-dim); color: var(--warn); }
.status-pill.none { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.status-pill.home-ok { background: var(--ok-dim); color: var(--ok); }
.status-pill.home-away { background: var(--danger-dim); color: var(--danger); }
.charge-pill { font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 999px; background: var(--accent-dim); color: var(--accent); }
.est-pill { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 999px; background: var(--panel); color: var(--muted); border: 1px solid var(--border); }

.geo-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.geo-inputs > div { flex: 1 1 90px; min-width: 90px; }
.geo-inputs label { display: block; font-size: 0.68rem; color: var(--muted); margin-bottom: 3px; }
.battery-pill { font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 999px; }
.battery-pill.full { background: var(--ok-dim); color: var(--ok); }
.battery-pill.medium { background: var(--accent-dim); color: var(--accent); }
.battery-pill.low { background: var(--warn-dim); color: var(--warn); }
.battery-pill.critical { background: var(--danger-dim); color: var(--danger); }
.tracker-row .chev { transition: transform 0.15s; color: var(--muted); }
.tracker-card.open .chev { transform: rotate(180deg); }
.tracker-row-actions { display: flex; align-items: center; gap: 4px; }

.tracker-body { padding: 2px 12px 12px; border-top: 1px solid var(--border-soft); display: none; }
.tracker-card.open .tracker-body { display: block; }

.field-label { display: block; font-size: 0.76rem; color: var(--muted); margin: 10px 0 5px; }
.key-input-row { position: relative; }
.key-input-row input { padding-right: 38px; font-family: var(--font-mono); }
.reveal-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; background: transparent; border: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.reveal-btn:hover { color: var(--text); }

textarea, input[type=text], input[type=password], input[type=number], input[type=email] {
  width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 10px; font-size: 0.83rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 72px; font-family: var(--font-mono); resize: vertical; }
textarea.payload-input { font-size: 0.76rem; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem; color: var(--text-dim); margin: 12px 0 4px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; width: 36px; height: 20px; background: var(--border); border-radius: 999px; flex-shrink: 0; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--text-dim); border-radius: 50%; transition: transform 0.15s, background 0.15s; }
.switch-row input:checked + .switch { background: var(--accent-dim); }
.switch-row input:checked + .switch::after { transform: translateX(16px); background: var(--accent); }

.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

.btn, button {
  background: var(--accent); color: white; border: none; border-radius: var(--radius-sm);
  padding: 8px 13px; font-size: 0.83rem; font-weight: 500; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover, button:hover { filter: brightness(1.12); }
.btn.secondary, button.secondary { background: var(--panel); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover, button.secondary:hover { filter: none; border-color: var(--accent); }
.btn.danger, button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn.danger:hover, button.danger:hover { filter: none; background: var(--danger-dim); }
.btn.small, button.small { padding: 5px 10px; font-size: 0.76rem; }
.btn.full { width: 100%; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.status-line { font-size: 0.78rem; margin-top: 8px; min-height: 1.1em; }
.status-line.err { color: var(--danger); }
.status-line.ok { color: var(--ok); }

/* ---------- main / map / locations ---------- */
.main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.map-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 8px; box-shadow: var(--shadow);
  isolation: isolate; /* keeps Leaflet's z-indexes (400-1000) inside the card, under the sticky top bar */ }
#map { height: 460px; border-radius: var(--radius); overflow: hidden; }
@media (max-width: 860px) { #map { height: 340px; } }

.locations-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.locations-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: transparent; border: none; padding: 14px 16px; cursor: pointer; color: var(--text);
}
.locations-head h2 { font-size: 0.85rem; display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-weight: 600; }
.locations-head .chev { transition: transform 0.15s; }
.locations-card.collapsed .chev { transform: rotate(-90deg); }
.locations-card.collapsed #locationsBody { display: none; }
#locationsBody { padding: 0 16px 16px; }

table.overview { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
#overviewTable { display: none; }   /* until there's history; app.js shows it (an inline style, so not in the HTML: CSP style-src 'self') */
table.overview th, table.overview td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border-soft); }
table.overview th { color: var(--muted); font-weight: 500; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.overview tr.history-row td { font-size: 0.76rem; color: var(--muted); border-bottom: none; padding-top: 2px; padding-bottom: 2px; }

.empty { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 30px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty .icon { color: var(--border); }

/* ---------- security slide-over ---------- */
/* Leaflet's own panes/controls use z-index up to 1000 (confirmed in
   vendor/leaflet/leaflet.css) -- comfortably clear that here so the map can
   never bleed through the security panel or, especially, the lock overlay. */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 2000; }
.security-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border); z-index: 2001;
  display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,0.45);
}
.security-panel[hidden] { display: none; }
.security-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.security-panel-head h2 { font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.security-panel-body { padding: 6px 18px 24px; overflow-y: auto; flex: 1; }
.security-panel-body section { padding: 16px 0; border-bottom: 1px solid var(--border-soft); }
.security-panel-body section:last-child { border-bottom: none; }
.security-panel-body h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 10px; }
.hint { font-size: 0.78rem; color: var(--muted); line-height: 1.5; margin-top: 10px; }
.control-row { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-zone .hint { margin-top: 8px; }
.select { width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 0.83rem; margin-bottom: 4px; }

/* ---------- lock overlay ---------- */
#lockOverlay, #pinSetupOverlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 2500; padding: 20px; }
#lockOverlay[hidden], #pinSetupOverlay[hidden] { display: none !important; }
.trail-arrow { background: none; border: none; }
.trail-arrow svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35)); }
.leaflet-bar a.map-fit-btn { font-size: 17px; line-height: 30px; font-weight: 600; }
#authOverlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 2600; padding: 20px; }
#authOverlay[hidden] { display: none !important; }
.lock-box.auth-box input { letter-spacing: normal; text-align: left; font-size: 1rem; margin: 10px 0 0; }
.lock-box.auth-box button[type=submit] { width: 100%; padding: 11px; margin-top: 14px; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 0.85rem; margin-top: 12px; cursor: pointer; padding: 4px; }
.link-btn[hidden] { display: none; }
.account-email { font-size: 0.78rem; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-line { font-size: 0.8rem; margin: 4px 0 10px; }
.sub-line.ok { color: var(--ok); }
.sub-line.warn { color: var(--warn); }
.sub-line.bad { color: var(--danger); }
.claim-row { display: flex; gap: 6px; margin-top: 6px; }
.claim-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.08em; }
.lock-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px 28px; max-width: 340px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.lock-icon { color: var(--accent); margin-bottom: 10px; }
.lock-box h2 { margin-bottom: 6px; font-size: 1.1rem; }
.lock-box .sub { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.lock-box input { width: 100%; margin: 16px 0 4px; text-align: center; letter-spacing: 0.3em; font-size: 1.15rem; padding: 12px; }
.lock-box input + input { margin-top: 0; }
.lock-box #lockUnlockBtn, .lock-box #pinSetupBtn { width: 100%; padding: 11px; margin-top: 10px; }
.lock-box .status-line { min-height: 1.2em; margin-top: 8px; }

/* The sign-in, PIN and set-PIN screens: a live dot backdrop (backdrop.js) with the card beside it --
   left of the globe on a wide screen, below it on a phone. Each screen keeps its solid background
   underneath, so nothing behind it shows if the backdrop doesn't run. */
.login-backdrop { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.login-backdrop canvas { display: block; }
#authOverlay .lock-box, #lockOverlay .lock-box, #pinSetupOverlay .lock-box {
  position: relative; z-index: 1; text-align: left;
  background: rgba(22, 25, 35, 0.78); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  animation: card-in 0.5s ease-out both;
}
#authOverlay .lock-box h2, #lockOverlay .lock-box h2, #pinSetupOverlay .lock-box h2 { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; margin-bottom: 8px; }
#authOverlay .link-btn, #lockOverlay .link-btn, #pinSetupOverlay .link-btn { margin-left: -4px; }
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } }
@media (min-width: 760px) {
  #authOverlay, #lockOverlay, #pinSetupOverlay { justify-content: flex-start; padding-left: max(32px, 8vw); }
}
@media (max-width: 759px) and (min-height: 560px) {
  #authOverlay, #lockOverlay, #pinSetupOverlay { align-items: flex-end; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  #authOverlay .lock-box, #lockOverlay .lock-box, #pinSetupOverlay .lock-box { animation: none; }
}

@media (max-width: 640px) {
  #accountEmail, #signOutBtn { display: none !important; }   /* in the settings panel instead */
}
@media (max-width: 480px) {
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
  .pill-btn span:last-child { display: none; }
  .pill-btn { padding: 7px; }
  .notice, .layout { margin-left: 10px; margin-right: 10px; padding-left: 10px; padding-right: 10px; }
}

/* ---------- which trackers the map shows ---------- */
.map-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 2px 2px 8px; }
.map-chips[hidden] { display: none; }
.map-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim); min-width: 0;
  font-size: 0.8rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip-label { overflow: hidden; text-overflow: ellipsis; }
.chip-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--chip); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); }
.map-chip[aria-pressed="true"] { background: var(--chip, var(--accent)); border-color: var(--chip, var(--accent)); color: #fff; }
.map-chips.picking .map-chip[aria-pressed="false"] { opacity: 0.55; }
.chip-hint { font-size: 0.72rem; color: var(--muted); white-space: nowrap; padding-left: 4px; }
.tracker-card.off-map .tracker-row { opacity: 0.5; }
.leaflet-tooltip.map-label {
  background: #fff; color: var(--label, #111); border: 2px solid var(--label, #111); border-radius: 6px;
  font-weight: 700; font-size: 12px; padding: 1px 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.leaflet-tooltip-top.map-label::before { border-top-color: var(--label, #111); }

/* ---------- history ---------- */
.history-card.collapsed .history-body, .history-card.collapsed .history-chips { display: none; }
.history-chips { padding: 0 16px 6px; }
.history-body { padding: 0 16px 16px; }
.history-intro { margin-top: 0; }
.tl-tracker { margin-top: 14px; }
.tl-tracker-head { display: flex; align-items: center; gap: 9px; font-size: 0.9rem; margin-bottom: 6px; }
.tl-count { margin-left: auto; color: var(--muted); font-size: 0.74rem; font-weight: 400; white-space: nowrap; }
.tl-day {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 2px; background: transparent;
  border: none; border-top: 1px solid var(--border-soft); color: var(--text-dim); font-size: 0.82rem;
  font-weight: 600; cursor: pointer; text-align: left;
}
.tl-day .chev { transform: rotate(-90deg); transition: transform 0.15s; }
.tl-day.open .chev { transform: none; }
.tl-list { list-style: none; margin: 0 0 8px; padding: 0; position: relative; }
.tl-list::before { content: ""; position: absolute; left: 10px; top: 14px; bottom: 14px; width: 2px; background: var(--border); }
.tl-item { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; padding: 8px 6px 8px 0; border-radius: var(--radius-sm); cursor: pointer; }
.tl-item:hover, .tl-item:focus-visible { background: rgba(255, 255, 255, 0.04); outline: none; }
.tl-gap { cursor: default; }
.tl-gap:hover { background: none; }
.tl-time { position: relative; padding-left: 24px; font-size: 0.78rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.tl-time::before {
  content: ""; position: absolute; left: 6px; top: 3px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--swatch); box-shadow: 0 0 0 3px var(--panel);
}
.tl-stop .tl-time::before { left: 5px; width: 12px; height: 12px; border-radius: 3px; top: 2px; }
.tl-turn .tl-time::before { border-radius: 2px; transform: rotate(45deg); }
.tl-gap .tl-time::before { background: var(--panel); border: 2px dashed var(--muted); width: 6px; height: 6px; }
.tl-title { font-size: 0.86rem; font-weight: 600; color: var(--text); }
.tl-place { font-size: 0.8rem; color: var(--text-dim); margin-top: 1px; overflow-wrap: anywhere; }
.tl-line { font-size: 0.76rem; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.tl-foot a { color: var(--text-dim); }
@media (max-width: 480px) {
  .tl-item { grid-template-columns: 84px minmax(0, 1fr); }
  .history-body { padding: 0 12px 14px; }
  .history-chips { padding: 0 12px 6px; }
}

/* ---------- safe places (home, work) ---------- */
.places { margin-top: 12px; }
.place-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border-soft); }
.place-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 0.82rem; }
.place-text span { color: var(--muted); font-size: 0.76rem; overflow-wrap: anywhere; }
.place-editor { padding: 10px 0; border-top: 1px solid var(--border-soft); font-size: 0.82rem; }
.address-row { display: flex; gap: 6px; margin-top: 8px; }
.address-row input { flex: 1; min-width: 0; }
.place-msg { margin-top: 6px; }
.place-matches { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.place-match {
  display: block; width: 100%; text-align: left; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 7px 9px; font-size: 0.78rem; cursor: pointer; line-height: 1.35;
}
.place-match[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-dim); color: var(--text); }
.place-coords { margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.place-coords summary { cursor: pointer; }
.place-coords .geo-inputs { margin-top: 6px; align-items: center; }
.place-chosen { margin-top: 10px; color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.radius-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; color: var(--text-dim); font-size: 0.8rem; }
.radius-control { display: inline-flex; align-items: center; gap: 5px; }
.radius-control .select { width: auto; margin: 0; padding: 4px 8px; font-size: 0.78rem; }
.radius-control .radius-km { width: 72px; padding: 4px 6px; font-size: 0.8rem; margin: 0; }
.radius-control [hidden] { display: none; }
.place-radius { flex-basis: 100%; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.78rem; }
.radius-control span { white-space: nowrap; }
/* A tag standing just above the place, pointing down at it, drawn over the trail's arrows. */
.leaflet-marker-icon.place-tag {
  width: 44px !important; height: auto !important; margin-left: -22px !important; margin-top: -30px !important;
  padding: 1px 0; border-radius: 5px; text-align: center; white-space: nowrap;
  background: #fff; color: var(--tag, #111); border: 2px solid var(--tag, #111); font: 700 11px/1.4 system-ui, sans-serif;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.leaflet-marker-icon.place-tag::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -5px;
  border: 5px solid transparent; border-top-color: var(--tag, #111); border-bottom: 0;
}

/* ---------- sign-in unlock: change password ---------- */
.change-pw { margin: 4px 0 12px; font-size: 0.82rem; color: var(--text-dim); }
.change-pw summary { cursor: pointer; padding: 4px 0; }
.change-pw form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.change-pw input { width: 100%; }

/* ---------- claim card scanner ---------- */
.scan-btn { margin-top: 8px; }
.scan-overlay { position: fixed; inset: 0; z-index: 2700; background: rgba(0, 0, 0, 0.85); display: flex; align-items: center; justify-content: center; padding: 16px; }
.scan-box { width: 100%; max-width: 420px; position: relative; display: flex; flex-direction: column; gap: 12px; }
.scan-box video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); background: #000; }
.scan-frame { position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 1; margin: 14%; border: 3px solid rgba(255, 255, 255, 0.85); border-radius: 14px; pointer-events: none; }
.scan-msg { color: #fff; text-align: center; font-size: 0.9rem; }
.scan-msg.err { color: var(--danger); }
.enable-unlock { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.enable-unlock[hidden] { display: none; }
.enable-unlock input { width: 100%; }

/* ---------- the app's own confirmation dialog (above the lock and sign-in screens) ---------- */
.confirm-overlay { position: fixed; inset: 0; z-index: 2800; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.confirm-box { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.confirm-box p { font-size: 0.92rem; line-height: 1.5; color: var(--text); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.mfa-box input { width: 100%; margin-top: 12px; letter-spacing: 0.3em; text-align: center; font-size: 1.15rem; }
.mfa-box .status-line { min-height: 1.2em; margin-top: 6px; }

/* ---------- map: order of reports, best estimate, key ---------- */
.leaflet-tooltip.map-label.start-label { border-style: dashed; font-weight: 600; opacity: 0.92; }
.leaflet-tooltip-bottom.map-label::before { border-bottom-color: var(--label, #111); }
.estimate-target { background: none; border: none; }
.estimate-target svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35)); }
.map-key { font: 12.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; text-align: right; }
.map-key-btn {
  background: #fff; color: #1f2937; border: 2px solid rgba(0, 0, 0, 0.2); border-radius: 6px; padding: 4px 10px;
  font-weight: 700; font-size: 12.5px; cursor: pointer; background-clip: padding-box;
}
.map-key-btn:hover { background: #f3f4f6; filter: none; }
.map-key-panel {
  margin-top: 6px; width: 290px; max-width: calc(100vw - 80px); max-height: 60vh; overflow-y: auto; text-align: left;
  background: #fff; color: #1f2937; border-radius: 8px; padding: 10px 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.map-key-panel[hidden] { display: none; }
.map-key-panel h4 { margin: 0 0 6px; font-size: 13px; }
.map-key-panel ul { list-style: none; margin: 0; padding: 0; }
.map-key-panel li { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: center; padding: 5px 0; border-top: 1px solid #eef0f3; }
.map-key-panel li:first-child { border-top: none; }
.map-key-panel svg { justify-self: center; }
.key-tag { justify-self: center; font-size: 10.5px; font-weight: 700; color: #2563eb; border: 1.5px dashed #2563eb; border-radius: 5px; padding: 0 4px; background: #fff; }
.key-tag.place { border-style: solid; color: #ea580c; border-color: #ea580c; }

/* ---------- Map / Satellite switch ---------- */
.basemap-switch { display: flex; background: #fff; border: 2px solid rgba(0, 0, 0, 0.2); border-radius: 7px; background-clip: padding-box; overflow: hidden; }
.basemap-switch button {
  border: none; border-radius: 0; background: #fff; color: #1f2937; font: 700 12.5px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 7px 11px; cursor: pointer;
}
.basemap-switch button + button { border-left: 1px solid #e5e7eb; }
.basemap-switch button[aria-pressed="true"] { background: #2563eb; color: #fff; }
.basemap-switch button:hover { filter: none; }

/* Setup, history tools and local report preview */
.service-health { margin: 12px 20px; padding: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.service-health { display:flex; flex-wrap:wrap; gap:8px 24px; font-size:.8rem; color:var(--text-dim); }
.history-tools { padding:14px 18px; display:flex; gap:12px; align-items:end; flex-wrap:wrap; }
.history-tools label { display:flex; flex-direction:column; gap:6px; font-size:.85rem; }
.history-tools label[hidden] { display:none; }
.history-tools input, .history-tools select { min-height:44px; background:var(--panel); color:var(--text); border:1px solid var(--border); border-radius:6px; padding:8px; }
.history-tools p { flex-basis:100%; margin:0; }
#incidentDialog { width:min(920px, 94vw); max-height:90dvh; overflow:auto; background:var(--panel); color:var(--text); border:1px solid var(--border); border-radius:14px; padding:24px; }
#incidentDialog::backdrop { background:#000b; }
#incidentDialog h1 { font-size:1.5rem; }
#incidentDialog p { line-height:1.6; }
#incidentDialog table { width:100%; border-collapse:collapse; font-size:.8rem; }
#incidentDialog td, #incidentDialog th { padding:8px; border:1px solid var(--border); text-align:left; overflow-wrap:anywhere; }
/* Times and coordinates stay on one line (a number broken over two lines misreads); only the address
   wraps. On a phone the table is then wider than the screen and the report scrolls sideways. */
#incidentDialog td:not(:last-child) { white-space:nowrap; overflow-wrap:normal; }
#incidentDialog th { overflow-wrap:normal; }   /* headers wrap between words, so the table still fits an A4 page */
#incidentDialog td:last-child { min-width:12em; }
.report-actions { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:10px; }
:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
@media(max-width:600px) {
  input, select, textarea { font-size:16px !important; }
  button, .icon-btn, .pill-btn, .tl-day { min-height:44px; }
  .icon-btn { min-width:44px; }
  .topbar { flex-wrap:wrap; gap:8px; }
  .topbar-actions { flex-wrap:wrap; }
  .account-email { max-width:140px; overflow:hidden; text-overflow:ellipsis; }
  .service-health { margin:10px; }
  #incidentDialog { padding:14px; }
  .history-tools { align-items:stretch; }
  .history-tools > button { width:100%; }
  .locations-card { min-width:0; overflow-x:auto; }
  .security-panel { padding-bottom:env(safe-area-inset-bottom); }
}
@media print {
  body:has(#incidentDialog[open]) > * { display:none !important; }
  body:has(#incidentDialog[open]) > #incidentDialog { display:block !important; position:static; width:100%; max-height:none; overflow:visible; margin:0; padding:0; border:0; background:white; color:black; }
  #incidentDialog .report-actions { display:none; }
  #incidentDialog td, #incidentDialog th { border-color:#aaa; }
  #incidentDialog tr { break-inside:avoid; }
  #incidentDialog thead { display:table-header-group; }
}

/* Atella's eight-ray mark, shared with the product website. */
.brand > .icon, .auth-box > .lock-icon { color: #f1efd9; }
