/* Companion web. Mobile first; calm teal, red only for SOS (same palette as the Android theme). */
:root {
  --bg: #F7FAF9; --card: #EBF0EF; --text: #171D1C; --muted: #3F4948; --line: #DAE5E3;
  --brand: #0F6E6E; --on-brand: #fff; --brand-soft: #CDEEEC; --on-brand-soft: #002020;
  --sos: #D32F2F; --ok: #2E7D32; --warn: #B26A00; --warn-soft: #FFF1D6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1514; --card: #1A2120; --text: #DDE4E2; --muted: #BEC9C7; --line: #3F4948;
    --brand: #7DD3D0; --on-brand: #003736; --brand-soft: #00504F; --on-brand-soft: #CDEEEC;
    --sos: #E5534B; --ok: #81C784; --warn: #FFB74D; --warn-soft: #3A2C10;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
h1 { font-size: 22px; margin: 0; line-height: 1.25; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 4px 0 0; }
p { margin: 0; }
small { display: block; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--sos); min-height: 1.4em; text-align: center; font-size: 14px; }
.center { text-align: center; align-items: center; }

/* Buttons */
button, .button {
  font: inherit; font-weight: 600; border: 0; border-radius: 14px; padding: 13px 18px; cursor: pointer;
  text-align: center; text-decoration: none; display: inline-block; color: var(--brand); background: transparent;
  touch-action: manipulation;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: var(--on-brand); }
.outline { border: 1.5px solid var(--brand); padding: 11.5px 16.5px; }
.danger { background: var(--sos); color: #fff; }
.light { background: #fff; color: #8f1d1d; }
.text { padding: 10px 12px; }
.text.light { background: transparent; color: #fff; text-decoration: underline; }
.big { min-height: 54px; font-size: 17px; }
.icon { font-size: 28px; line-height: 1; padding: 4px 12px; color: var(--text); }
.setup button, .setup .button, .content > button, .content > .button, .card > button, .card > .button,
.dialog > button, form > button, .overlay > div > button, .overlay > div > .button, .content > div > button, .content > div > .button { width: 100%; }

/* Setup screens */
.setup { padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; flex: 1; }
.logo { border-radius: 14px; }
form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; min-width: 0; -webkit-appearance: none; appearance: none;
}
input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.phone-row { display: flex; gap: 10px; }
.phone-row .field:first-child { width: 84px; flex: none; }
.phone-row .field:last-child { flex: 1; }
.or { text-align: center; color: var(--muted); font-size: 14px; }

/* Home layout */
.bar {
  display: flex; align-items: center; gap: 4px; justify-content: space-between; position: sticky; top: 0; z-index: 5;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px; background: var(--bg);
}
.bar a.icon { margin-left: -12px; }
.bar h1 { flex: 1; }
.content { flex: 1; padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.tabs {
  position: sticky; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; border-radius: 0; padding: 16px 4px; color: var(--muted); position: relative; }
.tabs button.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }
.badge { background: var(--sos); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 7px; margin-left: 6px; }
.card { background: var(--card); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card.primary { background: var(--brand-soft); color: var(--on-brand-soft); }
.card.primary .muted { color: inherit; opacity: .85; }
.card.primary .button.primary { background: #0F6E6E; color: #fff; }
.card.warn { background: var(--warn-soft); }
.card.soft { background: var(--warn-soft); border: 2px solid var(--warn); }
.card.sos, .card.status-sos { background: var(--sos); color: #fff; }
.card.sos .muted, .card.status-sos .muted { color: #fff; }
.card.link { text-align: left; color: var(--text); width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .button, .row > button.primary, .row > button.outline { flex: 1; }
.row > input { flex: 2; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; }
.person { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.person b { display: block; }
.person-actions { display: flex; flex: none; }
.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--line); white-space: nowrap; }
.pill.trip { background: var(--ok); color: #fff; }
.pill.soft, .pill.lost { background: var(--warn); color: #fff; }
.pill.sos { background: #fff; color: var(--sos); }
.option { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0; }
.option input { width: 22px; height: 22px; flex: none; margin: 2px 0 0; accent-color: var(--brand); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.kv:first-child { border-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); border-radius: 20px; padding: 8px 14px; color: var(--text); font-weight: 500; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.results { display: flex; flex-direction: column; }
.result { text-align: left; color: var(--text); border-radius: 12px; padding: 10px 12px; font-weight: 400; width: 100%; }
.result.on { background: var(--brand-soft); color: var(--on-brand-soft); }
.result.on .muted { color: inherit; }
.results .result { border-top: 1px solid var(--line); border-radius: 0; }

/* Map + status line */
.map { height: 44dvh; min-height: 260px; background: var(--card); }
.map.small { height: 240px; min-height: 0; border-radius: 18px; overflow: hidden; }
.status { padding: 10px 16px; font-weight: 600; font-size: 14px; }
.status:empty { display: none; }
.status.ok { background: var(--ok); color: #fff; }
.status.warn { background: var(--warn); color: #fff; }
.status.bad { background: var(--sos); color: #fff; }

/* SOS hold button */
button.sos-hold {
  width: 148px; flex: none; height: 148px; border-radius: 50%; background: var(--sos); color: #fff; padding: 0; margin: 6px auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
  box-shadow: 0 0 0 0 rgba(211, 47, 47, .35); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.sos-hold b { font-size: 34px; letter-spacing: 1px; }
.sos-hold small { font-weight: 500; }
.sos-hold.holding { animation: hold 2s linear forwards; }
@keyframes hold { to { box-shadow: 0 0 0 22px rgba(211, 47, 47, .35); transform: scale(.94); } }

/* PIN pad */
.pin-pad { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pin-dots { display: flex; gap: 14px; padding: 6px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; opacity: .6; }
.pin-dots span.on { background: currentColor; opacity: 1; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px 20px; }
.pin-key { width: 72px; height: 72px; border-radius: 50%; padding: 0; font-size: 26px; font-weight: 500; background: var(--brand-soft); color: var(--on-brand-soft); }
.pin-key.plain { background: transparent; color: inherit; font-size: 18px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5); display: flex; align-items: flex-end; justify-content: center;
}
.dialog {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; gap: 12px;
  padding: 22px 20px max(20px, env(safe-area-inset-bottom)); max-height: 92dvh; overflow: auto;
}
.overlay.countdown, .overlay.alarm { background: var(--sos); color: #fff; align-items: center; z-index: 60; overflow: auto; }
.overlay.alarm { z-index: 70; animation: flash 1s steps(2) infinite; }
@keyframes flash { 50% { background: #8f1d1d; } }
.overlay.countdown > div, .overlay.alarm > div {
  width: 100%; max-width: 420px; padding: 24px; display: flex; flex-direction: column; gap: 14px; text-align: center; align-items: center;
}
.overlay.countdown .error { color: #fff; font-weight: 600; }
.overlay.countdown .pin-key { background: rgba(255, 255, 255, .2); color: #fff; }
.count { font-size: 88px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #23302f; color: #fff; padding: 12px 18px; border-radius: 14px; max-width: min(92vw, 480px); z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.spinner { width: 36px; height: 36px; margin: 32px auto; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.maplibregl-ctrl-attrib { font-size: 11px; }
@media (prefers-reduced-motion: reduce) { .overlay.alarm, .sos-hold.holding { animation: none; } }

/* Trip photos */
.photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.photos .thumb { display: flex; flex-direction: column; align-items: center; }
.photos img { width: 88px; height: 88px; object-fit: cover; border-radius: 12px; background: var(--line); }
.photos img.photo { cursor: pointer; }
.photos .row { display: flex; gap: 8px; width: 100%; }

/* Donation page (support.html) */
body.wide #app { max-width: 760px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 22px; }
.stat.big { grid-column: 1 / -1; background: var(--brand-soft); color: var(--on-brand-soft); }
.stat.big b { font-size: 34px; }
.stat.big small { color: inherit; opacity: .85; }
.bars { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; min-height: 140px; }
.barcol { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; text-align: center; }
.bar-fill { width: 100%; max-width: 44px; background: var(--brand); border-radius: 6px 6px 0 0; }
.cats { display: flex; flex-direction: column; gap: 10px; }
.meter { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--brand); }
.ledger { margin-top: 6px; }
input[type=range] { width: 100%; accent-color: var(--brand); }

/* Legal pages and the admin page */
.legal p, .legal li { margin: 0 0 8px; }
.legal ul { margin: 0 0 8px; padding-left: 22px; }
.legal h3 { margin: 14px 0 4px; font-size: 17px; }
textarea { font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; min-height: 320px; resize: vertical; }
select, input[type=date], input[type=number] { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--brand); }
