:root {
  /* SBG palette: deep botanic green accent on neutral white (matches dashboard).
     Names kept (--purple*) to minimise churn; values are green. */
  --purple: #2D6A4F;
  --purple-deep: #1B4332;
  --ink: #1A1F1C;
  --ink-70: rgba(26,31,28,0.66);
  --line: #E7EAE8;
  --bg: #FAFBFA;
  --red: #D7263D;
  --green: #1B4332;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --display: "Chillax", "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --bar-h: 52px;
  --act-h: 76px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
body { display: flex; flex-direction: column; }

/* Top bar */
.bar {
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 9px; padding-left: 16px; padding-right: 12px;
  background: var(--purple-deep); color: #fff; flex: 0 0 auto; z-index: 10;
}
.title { font-weight: 700; font-size: 16px; font-family: var(--display); letter-spacing: -0.01em; }
.sheet h2 { font-family: var(--display); letter-spacing: -0.01em; }
.projsel {
  max-width: 40vw; font-family: inherit; font-size: 13px; color: #fff;
  background-color: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 6px 26px 6px 8px; -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='%23ffffff'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 10px 6px;
}
.projsel option { color: #000; }
.gps { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-family: var(--mono); opacity: .95; }
.gps .dot { width: 9px; height: 9px; border-radius: 50%; background: #c0392b; box-shadow: 0 0 0 0 rgba(255,255,255,.4); }
.gps .dot.ok { background: #2ecc71; }
.gps .dot.mid { background: #f1c40f; }
.iconbtn {
  flex: 0 0 auto; background: none; border: 0; color: #fff; padding: 4px;
  font-size: 30px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

/* Profile balloon popover (anchored under the profile button) */
.popover {
  position: absolute; right: 8px; z-index: 50;
  top: calc(var(--bar-h) + env(safe-area-inset-top) + 6px);
  width: 250px; max-width: calc(100vw - 16px); background: #fff;
  border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  box-shadow: 0 10px 34px rgba(0,0,0,.20);
}
.popover[hidden] { display: none; }
.popover::before {
  content: ""; position: absolute; top: -6px; right: 15px; width: 12px; height: 12px;
  background: #fff; border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg);
}
.pop-id { display: flex; flex-direction: column; margin-bottom: 12px; }
.pop-name { font-weight: 700; font-size: 15px; color: var(--ink); font-family: var(--display); }
.pop-email { font-size: 12.5px; color: var(--ink-70); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover .btn { width: 100%; }

/* Sign-in overlay */
.sheet.signin { align-items: center; background: var(--bg); }
.signin-card { text-align: center; border-radius: 16px; max-width: 380px; margin: 18px; }
.signin-brand { font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: -0.01em; margin-bottom: 10px; }
.signin-btn { display: inline-flex; align-items: center; justify-content: center; width: 100%; }

/* Map */
#map { flex: 1 1 auto; width: 100%; background: #e9e9ef; }
.map-msg { display: grid; place-items: center; height: 100%; padding: 24px; text-align: center; color: var(--ink-70); font-size: 14px; }
.map-msg code { font-family: var(--mono); background: #fff; padding: 2px 6px; border-radius: 4px; }

/* HUD counters */
.hud {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(var(--bar-h) + env(safe-area-inset-top) + 10px);
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 12.5px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 10px; z-index: 9; box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.hud .recdot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
#dist { color: var(--ink-70); font-weight: 500; }

/* Bottom action bar */
.actions {
  flex: 0 0 auto; display: flex; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line); z-index: 10;
}
.act {
  flex: 1; height: var(--act-h); border: 1px solid var(--line); background: #fff; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-family: inherit; font-size: 11.5px; font-weight: 600; color: var(--ink); cursor: pointer; padding: 4px;
}
.act .ico { font-size: 22px; line-height: 1; }
.act:disabled { opacity: .4; }
.act.rec { background: var(--red); border-color: var(--red); color: #fff; }
.act.rec.on { background: var(--ink); border-color: var(--ink); }
.act.rec.on .ico .fa-solid::before { content: "\f04d"; } /* fa-stop while recording */
.act.fin { background: var(--green); border-color: var(--green); color: #fff; }
.act.fin:disabled { background: #fff; color: var(--ink); border-color: var(--line); }
.act.undo { flex: .7; }

/* Sheets (bottom modals) */
.sheet { position: fixed; inset: 0; background: rgba(38,34,56,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.sheet[hidden] { display: none; }
.sheet .card {
  width: 100%; max-width: 520px; background: #fff; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
.sheet h2 { margin: 2px 0 12px; font-size: 19px; }
.hint { color: var(--ink-70); font-size: 13px; margin: 0 0 14px; }
.hint code { font-family: var(--mono); background: var(--bg); padding: 1px 5px; border-radius: 4px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-70); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; font-family: inherit; font-size: 16px; color: var(--ink);
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(45,106,79,.3); border-color: var(--purple); }
.check { font-weight: 500; color: var(--ink); font-size: 13px; }
.check input { display: inline-block; width: auto; margin: 0 8px 0 0; vertical-align: middle; }
.row { display: flex; gap: 10px; margin-top: 8px; }
.btn {
  flex: 1; text-align: center; appearance: none; cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 13px 14px; border-radius: 11px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none;
}
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.ghost { background: #fff; }
.btn:disabled { opacity: .5; }
.msg { font-size: 13px; margin: 12px 0 0; min-height: 1em; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--act-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(38,34,56,.92); color: #fff; font-size: 13px; font-weight: 600; padding: 9px 16px; border-radius: 999px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 200; white-space: nowrap;
}
.toast.show { opacity: 1; }

/* Help screen — full-screen explainer for the bottom action buttons */
.helpscreen { position: fixed; inset: 0; z-index: 150; background: var(--bg); display: flex; flex-direction: column; }
.helpscreen[hidden] { display: none; }
.help-bar {
  height: calc(var(--bar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 12px; padding-left: 16px; padding-right: 12px;
  background: var(--purple-deep); color: #fff; flex: 0 0 auto;
}
.help-title { font-family: var(--display); font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.help-bar .iconbtn { margin-left: auto; }
.help-body {
  flex: 1 1 auto; overflow-y: auto; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
}
.help-intro { color: var(--ink-70); font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
.help-row { display: flex; align-items: flex-start; gap: 14px; padding: 13px 0; border-top: 1px solid var(--line); }
.help-btn {
  flex: 0 0 auto; width: 50px; height: 50px; border-radius: 14px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); display: grid; place-items: center; font-size: 20px;
}
.help-btn.rec { background: var(--red); border-color: var(--red); color: #fff; }
.help-btn.fin { background: var(--green); border-color: var(--green); color: #fff; }
.help-text b { font-size: 15px; font-family: var(--display); }
.help-text p { margin: 3px 0 0; font-size: 13.5px; color: var(--ink-70); line-height: 1.45; }

/* Desktop block — shown when opened on a non-mobile device */
.desktop-block { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.desktop-block[hidden] { display: none; }
.db-card { max-width: 380px; text-align: center; }
.db-icon { font-size: 44px; color: var(--purple); margin-bottom: 10px; }
.db-card h2 { font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: -0.01em; margin: 0 0 10px; }
.db-card p { color: var(--ink-70); font-size: 15px; line-height: 1.5; margin: 0 0 18px; }
.db-qr { display: block; margin: 0 auto 12px; width: 220px; height: 220px; border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: #fff; }
.db-hint { font-size: 13px; margin: 0 0 6px; }
.db-url { margin: 0; }
.db-url a { font-family: var(--mono); font-size: 12.5px; color: var(--purple); word-break: break-all; text-decoration: none; }
