:root {
  --green: #264216; --green-2: #35591f; --yellow: #f6c41e; --bg: #f4f6f1; --card: #fff; --ink: #1d2418; --muted: #6b7564;
  --line: #e2e6dc; --red: #d63c2f; --orange: #e68a00; --blue: #2e86ab; --ok: #2e8b3e; --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--green-2); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c5ccbb; }
button.primary, .btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover { background: var(--green-2); }
button.accent { background: var(--yellow); border-color: var(--yellow); color: var(--green); font-weight: 600; }
button.danger { color: var(--red); }
button.small { padding: 4px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cfd5c6; border-radius: 7px; background: #fff; width: 100%; color: var(--ink); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 36px; width: 60px; }
textarea { min-height: 90px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #eef1ea; color: var(--muted); }
.badge.live { background: #e3f4e6; color: var(--ok); }
.badge.draft { background: #eef1ea; color: var(--muted); }
.badge.finished { background: #e6eef6; color: var(--blue); }
.badge.red { background: #fde7e5; color: var(--red); }
.badge.orange { background: #fff1d9; color: var(--orange); }
.chip { display: inline-block; background: #eef1ea; border-radius: 6px; padding: 1px 6px; font-size: 11px; margin: 1px 2px 1px 0; font-family: ui-monospace, Menlo, monospace; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbf8; position: sticky; top: 0; }
tr:hover td { background: #fafcf7; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #bbb; margin-right: 5px; vertical-align: middle; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--orange); } .dot.bad { background: var(--red); }
.empty { text-align: center; padding: 30px; color: var(--muted); }

/* barra de topo do backoffice */
.topbar { background: var(--green); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 18px; height: 54px; position: sticky; top: 0; z-index: 1000; }
.topbar .brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.topbar .brand b { color: var(--yellow); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #dfe8d6; text-decoration: none; padding: 8px 10px; border-radius: 7px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar .alert-pill { background: var(--red); color: #fff; border-radius: 99px; padding: 3px 10px; font-weight: 700; font-size: 12px; text-decoration: none; }
.page { max-width: 1300px; margin: 0 auto; padding: 20px 18px 60px; }
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin: 6px 0 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--green); border-color: var(--yellow); }

/* modal e toast */
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,15,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 3000; padding: 40px 12px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 4000; box-shadow: var(--shadow); }
.toast.err { background: var(--red); }

/* login */
.login { max-width: 360px; margin: 10vh auto; }
.login .logo { text-align: center; font-weight: 800; font-size: 22px; color: var(--green); margin-bottom: 16px; }
.login .logo b { color: #c99a00; }

/* ao vivo */
.live-layout { display: grid; grid-template-columns: 1fr 380px; gap: 14px; }
.live-layout .map { height: calc(100vh - 220px); min-height: 420px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #dde5d5; }
.side-scroll { max-height: calc(100vh - 220px); overflow: auto; }
.alert-item { border-left: 4px solid var(--orange); background: #fff; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.alert-item.sos { border-color: var(--red); background: #fff6f5; }
.alert-item.done { opacity: .55; border-color: #ccc; }
.alert-item .t { font-weight: 700; }
@media (max-width: 900px) { .live-layout { grid-template-columns: 1fr; } .live-layout .map { height: 55vh; } .side-scroll { max-height: none; } }

/* marcadores no mapa */
.bib-marker { background: var(--green); color: #fff; border: 2px solid #fff; border-radius: 14px; font-weight: 800; font-size: 11px; height: 22px; min-width: 22px; padding: 0 5px; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.4); white-space: nowrap; }
.bib-marker.finished { background: #2e86ab; }
.bib-marker.waiting { background: #7d8775; }
.bib-marker.alert { background: var(--red); animation: pulse 1s infinite; }
.bib-marker.stale { opacity: .55; }
.bib-marker.sel { background: var(--yellow); color: var(--green); transform: scale(1.25); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(214,60,47,.7); } 50% { box-shadow: 0 0 0 8px rgba(214,60,47,0); } }
.flag-marker { font-size: 18px; }
.unit-marker { background: #fff; border: 3px solid #2e86ab; border-radius: 9px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 16px; box-shadow: 0 1px 5px rgba(0,0,0,.4); }
.unit-marker.stale { opacity: .55; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.emoji-pick button { font-size: 18px; padding: 2px 6px; }
.leaflet-container { font: inherit; }

/* perfil de elevação */
.elev { background: #fff; }
.elev-head { display: flex; gap: 12px; align-items: baseline; font-size: 12px; color: var(--muted); padding: 6px 10px 0; flex-wrap: wrap; }
.elev-head b { color: var(--ink); font-size: 13px; }
.elev-info { margin-left: auto; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.elev-svg { display: block; cursor: crosshair; touch-action: pan-y; }
.elev-grid text { font-size: 9px; fill: #8a9382; }
.elev-mark circle { fill: #264216; stroke: #fff; stroke-width: 1.5; }
.elev-mark text { font-size: 9px; font-weight: 800; fill: #264216; }
.elev-mark.finished circle { fill: #2e86ab; }
.elev-mark.sel circle { fill: #f6c41e; stroke: #264216; r: 6; }
.elev-mark.sel text { font-size: 11px; }
.elev-mark.unit circle { fill: #fff; stroke-width: 2; }
.elev-mark.unit text { font-size: 11px; }
.poi-marker { background: #fff; border: 2px solid #2e86ab; border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; font-size: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.elev-mark.poi text { font-size: 12px; }

/* passagens / grupos */
.splits-bar { display: flex; gap: 6px; padding: 8px 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.splits-bar .sp-point { flex: 1 1 180px; } .splits-bar .sp-group { flex: 0 0 auto; width: auto; }
.grp { padding: 8px 14px; border-bottom: 1px solid #eef0ea; }
.grp.head { background: #fffbe8; }
.grp.unit { background: #f6f8fb; }
.grp-h { display: flex; gap: 8px; align-items: baseline; }
.grp-h b { font-size: 14px; }
.grp-n { color: var(--muted); font-size: 12px; flex: 1; }
.grp-t { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
.grp-gap { font-variant-numeric: tabular-nums; font-weight: 800; min-width: 56px; text-align: right; }
.grp-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.grp-m { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.grp-a { background: #f0f3ec; border-radius: 6px; padding: 2px 7px; font-size: 12px; cursor: pointer; }
.grp-a b { color: var(--green); }
.grp-a i { color: var(--muted); font-style: normal; font-size: 11px; }
.grp-a.sel { background: var(--yellow); }
.viewtabs { display: flex; gap: 4px; padding: 0 12px 8px; }
.viewtabs button { flex: 1; justify-content: center; font-size: 13px; padding: 5px; }
.viewtabs button.on { background: var(--green); color: #fff; border-color: var(--green); }

/* ordem de corrida */
.race-layout { grid-template-columns: minmax(420px, 1fr) 1fr; }
.race-list { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.rrow { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid #eef0ea; cursor: pointer; }
.rrow:hover { background: #fafcf6; }
.rrow.sel { background: #fff8d6; }
.rrow.head { background: #fffbe8; }
.rrow.unit-row { background: #f7f9fc; }
.rrow.unit-row.sel { background: #fff8d6; }
.rrow.stale { opacity: .7; }
.rbadge { display: flex; align-items: center; justify-content: center; font-weight: 900; color: var(--green); font-size: 15px; background: #eef1ea; border-radius: 10px; height: 36px; }
.unit-row .rbadge { background: transparent; }
.rtitle { font-weight: 700; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.rmembers { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rsub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rright { text-align: right; font-variant-numeric: tabular-nums; }
.rgap { font-weight: 900; font-size: 16px; }
.rkm { font-size: 12px; color: var(--muted); }
.rsec { padding: 6px 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f5f7f2; border-bottom: 1px solid var(--line); }
@media (max-width: 900px) { .race-layout { grid-template-columns: 1fr; } }

/* botões de navegação */
.nav-links { display: inline-flex; gap: 4px; vertical-align: middle; }
.navbtn { display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px; border-radius: 8px; background: #e8f0fe; color: #1a56c4 !important; font-size: 12px; font-weight: 700; text-decoration: none !important; border: 1px solid #c9d9f8; white-space: nowrap; }
.navbtn:hover { background: #d6e4fd; }
.navbtn.waze { background: #e6f7fd; color: #0a7ea4 !important; border-color: #bfe8f7; }
.rnav { margin-top: 3px; }
.unit-marker.me { box-shadow: 0 0 0 4px rgba(246,196,30,.9), 0 2px 6px rgba(0,0,0,.35); }

.batt { font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.batt.ok { color: #2b8a3e; }
.batt.warn { background: #fff4e0; color: #b35c00; }
.batt.bad { background: #fde8e6; color: #c92a2a; }
