:root {
  --bg: #14170f;
  --panel: #1e2317;
  --panel2: #262c1e;
  --line: #37402b;
  --text: #e8e6d8;
  --muted: #9aa285;
  --accent: #ffb52e;
  --accent-dark: #cc8a10;
  --danger: #e5533d;
  --ok: #4caf50;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.86em; }
.pad { padding: 0 14px 8px; }
.err { color: var(--danger); min-height: 1.2em; margin-top: 8px; text-align: center; }
.warn { color: var(--accent); }
.ico-inline { height: 1em; width: auto; vertical-align: -0.15em; display: inline-block; }
.ico-badge { height: 1.1em; width: auto; vertical-align: -0.2em; display: inline-block; margin-left: 2px; }
.empty-state { text-align: center; padding: 32px 20px; }
.empty-state img { width: 100%; max-width: 220px; height: auto; margin-bottom: 14px; }
.empty-state p { color: var(--muted); max-width: 340px; margin: 0 auto; }
button { font: inherit; cursor: pointer; }
.slim { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
.slim.ok { border-color: var(--ok); color: var(--ok); }
.slim.danger { border-color: var(--danger); color: var(--danger); }
.slim.mini { padding: 2px 8px; font-size: 0.78rem; margin-left: 6px; }
.ok { border-color: var(--ok) !important; color: var(--ok) !important; }
.price { color: var(--accent); font-weight: 700; white-space: nowrap; }

/* ---------- auth ---------- */
.auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 20% 10%, #2a301f 0%, transparent 55%),
    radial-gradient(ellipse at 90% 90%, #241d10 0%, transparent 50%),
    var(--bg);
  padding: 16px;
}
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.auth-card h1 { text-align: center; font-size: 2.2rem; letter-spacing: 2px; }
.auth-card h1 span, header h2 span { color: var(--accent); }
.tagline { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 8px 0 18px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tabs button {
  flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--muted);
}
.auth-tabs button.active { background: var(--panel2); color: var(--text); border-color: var(--accent-dark); }
.link-btn {
  width: 100%; margin-top: 10px; border: none; background: transparent; color: var(--accent);
  text-align: center; font: inherit;
}
.auth-reset { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.auth-note { color: var(--muted); font-size: 0.86rem; margin-top: 8px; text-align: center; min-height: 1.2em; }
form input, form textarea, form select, .eta {
  width: 100%; padding: 11px 12px; margin-bottom: 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
form input:focus, form textarea:focus, form select:focus { outline: none; border-color: var(--accent-dark); }
.btn-primary {
  width: 100%; padding: 11px; border: none; border-radius: 8px;
  background: var(--accent); color: #201700; font-weight: 700;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-primary.slim { width: auto; padding: 8px 14px; }

/* ---------- app frame ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
header h2 { font-size: 1.15rem; letter-spacing: 1.5px; }
.head-right { display: flex; align-items: center; gap: 10px; }
#who { color: var(--muted); font-size: 0.9rem; }
#btn-logout, .head-btn { background: none; border: none; color: var(--muted); font-size: 1.1rem; padding: 2px 4px; }
.head-btn.on { color: var(--accent); }

.frame { flex: 1; display: flex; flex-direction: column-reverse; overflow: hidden; }
main { flex: 1; overflow: hidden; position: relative; display: flex; flex-direction: column; }
.view { flex: 1; overflow-y: auto; position: relative; }

/* phone: bottom tab bar */
nav {
  display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1; padding: 8px 2px; background: none; border: none;
  color: var(--muted); font-size: 0.72rem; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.nav-icon {
  width: 1.05rem; height: 1.05rem; display: block;
  opacity: 0.6; filter: saturate(0.35) brightness(0.8);
  transition: opacity .15s, filter .15s;
}
nav button.active { color: var(--accent); }
nav button.active .nav-icon { opacity: 1; filter: none; }
.dot {
  position: absolute; top: 4px; right: 22%; width: 9px; height: 9px;
  border-radius: 50%; background: var(--danger);
}

/* tablet / desktop: side rail + roomier layouts */
@media (min-width: 768px) {
  .frame { flex-direction: row; }
  nav {
    flex-direction: column; justify-content: flex-start; gap: 4px;
    width: 96px; border-top: none; border-right: 1px solid var(--line); padding: 10px 6px;
  }
  nav button { flex: 0 0 auto; padding: 12px 4px; border-radius: 10px; font-size: 0.78rem; }
  nav button.active { background: var(--panel2); }
  .nav-icon { width: 1.35rem; height: 1.35rem; }
  .dot { right: 26px; top: 8px; }
  #trail-list, #job-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px; padding: 12px;
  }
  #trail-list .card, #job-list .card { margin: 0; }
  #vet-queue .card { margin: 12px 12px 0; }
}

/* ---------- bars ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px; }
.bar h3 { font-size: 1.05rem; }

/* ---------- map ---------- */
#view-map { overflow: hidden; }
#map { height: 100%; background: #0c0e09; }
.leaflet-container { font: inherit; }
.trail-pin { font-size: 18px; text-align: center; line-height: 24px; filter: drop-shadow(0 1px 2px #000); }
.fab-stack {
  position: absolute; right: 14px; bottom: 18px; z-index: 800;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.fab {
  padding: 12px 18px; border: none; border-radius: 999px;
  background: var(--accent); color: #201700; font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
.fab.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.fab.rec { background: var(--danger); color: #fff; }
.draw-bar {
  position: absolute; left: 10px; right: 10px; bottom: 14px; z-index: 800;
  display: flex; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.draw-bar span { flex: 1; color: var(--muted); font-size: 0.85rem; padding-left: 4px; }
.draw-bar button { padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
.draw-bar .btn-primary { width: auto; border: none; }
#rec-status { color: var(--danger); font-weight: 600; }

/* map tools (weather, ride check-in, offline) */
.map-tools {
  position: absolute; left: 10px; top: 80px; z-index: 800;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start; max-width: 240px;
}
.tool-btn {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 0.82rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.tool-btn:disabled { opacity: 0.7; }
.weather-chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 0.78rem; color: var(--muted);
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.weather-chip .mud { color: var(--accent); }
.rides-banner {
  position: absolute; left: 10px; right: 10px; top: 10px; z-index: 810;
  display: flex; flex-direction: column; gap: 6px;
}
.ride-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; font-size: 0.85rem; box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.ride-row.overdue { border-color: var(--danger); background: rgba(229,83,61,0.16); }

/* filters */
.filter-bar { display: flex; gap: 8px; padding: 10px 14px 0; }
.filter-bar input, .filter-bar select {
  flex: 1; padding: 9px 10px; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 0;
}
.filter-bar input { flex: 2; }

/* ---------- cards / trails ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 12px; }
.card h3 { margin-bottom: 6px; }
.trail-card { cursor: pointer; }
.trail-card:active { background: var(--panel2); }
.trail-head { display: flex; justify-content: space-between; gap: 8px; }
.trail-head span { font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.trail-meta { margin-top: 6px; font-size: 0.86rem; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.btn-row { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.btn-row button, .btn-row .upload-btn { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); text-align: center; min-width: 110px; }
.btn-row .danger { color: var(--danger); border-color: var(--danger); }
.upload-btn { cursor: pointer; font-size: 0.95rem; }
.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; vertical-align: middle; white-space: nowrap; }
.badge.pending { background: rgba(255,181,46,0.15); color: var(--accent); border: 1px solid var(--accent-dark); }
.badge.rejected { background: rgba(229,83,61,0.15); color: var(--danger); border: 1px solid var(--danger); }
.badge.private { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }

/* verification lobby */
.verify-card { max-width: 560px; margin: 16px auto; }
.verify-card p { margin-bottom: 12px; }
.verify-card .thumbs img { width: 96px; height: 96px; }
#v-status { margin-top: 10px; }
.vet-row a { color: var(--accent); }

/* vet queue */
.vet { border-color: var(--accent-dark); }
.vet-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.vet-row:first-of-type { margin-top: 8px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.65); display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 20px; position: relative;
}
@media (min-width: 640px) { .modal { align-items: center; } .modal-card { border-radius: 16px; } }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 1.1rem; z-index: 5; }
.modal-card h3 small { color: var(--muted); font-weight: 400; font-size: 0.75em; }
.bigstars { color: var(--accent); font-size: 1.15rem; margin: 6px 0; }
.access { background: var(--panel2); border-left: 3px solid var(--accent-dark); padding: 8px 10px; border-radius: 6px; margin: 8px 0; font-size: 0.9rem; }

/* media strip (helmet cam footage, photos) */
.media-strip { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0; }
.media-strip img, .media-strip video {
  height: 130px; border-radius: 10px; border: 1px solid var(--line); flex: 0 0 auto; max-width: 240px; object-fit: cover;
}
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.file-label { display: block; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); margin-bottom: 10px; cursor: pointer; }
.file-label input { display: none; }

/* conditions + permission */
.cond { color: var(--text); }
.cond-box { background: var(--panel2); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.cond-latest { font-size: 0.9rem; margin-bottom: 8px; }
.cond-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.cond-btns .slim { font-size: 0.78rem; padding: 5px 9px; }
.perm-line { font-size: 0.88rem; margin: 6px 0; }
#perm-editor { margin: 6px 0; }
.pin-row { display: block; color: var(--muted); font-size: 0.88rem; margin-bottom: 10px; cursor: pointer; }
.pin-row input { width: auto; margin-right: 6px; }

/* ---------- posts ---------- */
.post { border-top: 1px solid var(--line); padding: 10px 2px; }
.post-head { display: flex; justify-content: space-between; font-size: 0.86rem; margin-bottom: 3px; }
.post-head span { color: var(--muted); }
.post.warning { background: rgba(229,83,61,0.08); border-left: 3px solid var(--danger); padding-left: 10px; border-radius: 4px; }
.post.warning .post-head span { color: var(--danger); font-weight: 700; }
.post.warning.resolved { opacity: 0.55; border-left-color: var(--ok); }
.post.warning.resolved .post-head span { color: var(--ok); }
.post.review .post-head span { color: var(--accent); }
.post [data-resolve] { margin-top: 6px; }

/* ---------- events ---------- */
.event.past { opacity: 0.55; }
.rsvp-row button.picked { border-color: var(--accent); color: var(--accent); background: rgba(255,181,46,0.1); }

/* ---------- profiles / emergency card ---------- */
.ice-card { background: rgba(229,83,61,0.1); border: 1px solid var(--danger); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.ice-card h3 { margin-bottom: 6px; }
.ice-card div { padding: 2px 0; }
.linky { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

/* ---------- stats ---------- */
.stats-row { display: grid; grid-template-columns: 2fr repeat(5, 1fr); gap: 4px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.88rem; }
.stats-row.stats-head { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 1px; border-top: none; margin-top: 8px; }
.rider.banned { opacity: 0.5; }
.rider.banned b { text-decoration: line-through; }
.audit-row { display: flex; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 0.82rem; flex-wrap: wrap; }
.audit-row b { color: var(--accent); }

/* ---------- v6: navigation, closures, unread, elevation ---------- */
.offroute {
  position: absolute; left: 50%; transform: translateX(-50%); top: 64px; z-index: 850;
  background: var(--danger); color: #fff; font-weight: 700;
  padding: 10px 18px; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
.tool-btn.live { border-color: #4aa3ff; color: #4aa3ff; }
.closed-banner {
  background: rgba(229,83,61,0.15); border: 1px solid var(--danger); color: var(--danger);
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-weight: 700;
}
.spark { margin: 8px 0; }
.spark svg { width: 100%; height: 56px; display: block; background: var(--panel2); border-radius: 8px; }
.spark span { font-size: 0.75rem; }
.mention { color: var(--accent); }
.trail-link { color: var(--accent); font-weight: 700; text-decoration: none; border-bottom: 1px dotted var(--accent-dark); }
.maps-link { color: var(--accent); }
.unread {
  background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; margin-left: 6px; display: inline-block;
}
nav .dot {
  width: auto; height: auto; min-width: 16px; text-align: center;
  font-size: 0.62rem; font-weight: 700; color: #fff; font-style: normal;
  padding: 1px 4px; line-height: 1.3;
}
#btn-nearest { flex: 0 0 auto; }

/* ---------- v7: reports & geofenced zones ---------- */
.tool-btn.report { border-color: var(--danger); color: var(--danger); font-weight: 700; }
.tool-btn.sos { border-color: var(--danger); background: var(--danger); color: #fff; font-weight: 800; letter-spacing: 1px; }
.msg-flag { background: none; border: none; color: var(--muted); font-size: 0.72rem; padding: 0 2px; opacity: 0.55; }
.msg-flag:hover { opacity: 1; }
.flag-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; font-size: 0.9rem; }
#flag-card { border-color: var(--danger); }
.zonealert {
  position: absolute; left: 10px; right: 10px; top: 50%; transform: translateY(-50%);
  z-index: 900; text-align: center;
  background: var(--danger); color: #fff; font-weight: 800; font-size: 1.05rem;
  padding: 16px; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
.placing-hint {
  position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 900;
  background: var(--panel); border: 1px solid var(--accent-dark); color: var(--accent);
  padding: 9px 14px; border-radius: 999px; font-size: 0.9rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5); white-space: nowrap;
}
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.report-grid .rk {
  padding: 12px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 0.92rem; text-align: left;
}
.report-grid .rk.picked { border-color: var(--accent); color: var(--accent); background: rgba(255,181,46,0.08); }

/* ---------- marketplace ---------- */
.listing-grid { padding: 0 12px 12px; display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .listing-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); } }
.listing { margin: 0; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.listing img { width: 100%; height: 170px; object-fit: cover; }
.listing .ph { width: 100%; height: 110px; display: flex; align-items: center; justify-content: center; font-size: 2.6rem; background: var(--panel2); }
.listing-body { padding: 12px 14px; }
.listing .desc { font-size: 0.9rem; margin-top: 6px; color: var(--text); }
.listing.sold { opacity: 0.55; }
.listing.sold .price { color: var(--danger); }

/* ---------- chat ---------- */
#view-chat { display: flex; overflow: hidden; }
.chat-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; }
#convo-list { background: var(--panel); border-bottom: 1px solid var(--line); }
#convo-list .bar { padding: 10px 12px 6px; }
#convos { display: flex; overflow-x: auto; }
#convo-list .convo-item {
  padding: 8px 12px; cursor: pointer; border-radius: 10px; margin: 0 4px 8px;
  flex: 0 0 auto; max-width: 180px; border: 1px solid transparent;
}
.convo-item b { display: block; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-item small { color: var(--muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.convo-item.active { background: var(--panel2); border-color: var(--accent-dark); }
#convo-list > .convo-item { margin: 0 8px 8px; }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-title { padding: 8px 14px; font-size: 0.85rem; color: var(--muted); border-bottom: 1px solid var(--line); }
#chat-log { flex: 1; overflow-y: auto; padding: 12px; }
.chat-line { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; max-width: 85%; }
.chat-line.mine { margin-left: auto; background: var(--panel2); border-color: var(--accent-dark); }
.chat-line b { color: var(--accent); font-size: 0.85rem; }
#chat-form { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); }
#chat-form input { flex: 1; margin: 0; }
#chat-form .btn-primary { width: auto; padding: 11px 18px; }

@media (min-width: 768px) {
  .chat-wrap { flex-direction: row; }
  #convo-list { width: 260px; border-bottom: none; border-right: 1px solid var(--line); overflow-y: auto; }
  #convos { display: block; overflow-x: visible; }
  #convo-list .convo-item { max-width: none; margin: 0 8px 6px; }
}

/* rider picker */
.rider-picker { max-height: 240px; overflow-y: auto; margin-bottom: 10px; }
.rider-picker label { display: block; padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.rider-picker input { width: auto; margin-right: 8px; }

/* ---------- jobs ---------- */
.job.done { opacity: 0.55; }
.job .eta { width: 150px; flex: 0 1 150px; margin-bottom: 0; padding: 8px 10px; }
.claim-info { background: var(--panel2); border-radius: 8px; padding: 8px 10px; margin-top: 8px; font-size: 0.9rem; }

/* ---------- riders ---------- */
.invite { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.92rem; }
.invite:first-of-type { margin-top: 10px; }
.invite code { background: var(--bg); padding: 3px 8px; border-radius: 6px; color: var(--accent); letter-spacing: 1px; }
.invite.used { opacity: 0.75; }
.invite .copy { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 0.8rem; }
.rider { padding: 5px 0; font-size: 0.95rem; }
.pwreset-notice {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--accent-dark); background: rgba(255,181,46,0.1);
  border-radius: 8px; padding: 8px 10px; margin: 8px 0 10px; font-size: 0.9rem;
}
.pwreset-notice code { color: var(--accent); user-select: all; }
#btn-new-invite { margin: 10px 0 4px; }
