/* Shack Track — styles */
:root {
  --bg: #07131f;
  --bg-2: #0a1b2b;
  --panel: #0e2236;
  --panel-2: #132b42;
  --line: #21405c;
  --text: #eaf4fb;
  --muted: #9db5c8;
  --faint: #6f8aa0;
  --accent: #38bdf8;
  --accent-ink: #04202f;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --event: #2dd4bf;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
small, .small { font-size: 0.85rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.04em; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 6px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }

/* ---------- App shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(7, 19, 31, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; font: inherit; text-align: left; line-height: 1.25; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.brand-name { font-weight: 800; letter-spacing: 0.02em; font-size: 1.05rem; }
.brand-sub { font-size: 0.7rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
main { flex: 1 1 auto; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 16px calc(40px + var(--safe-bottom)); }
.page-wide { max-width: 1120px; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.page > div > .card { margin-bottom: 16px; }
.card h2 { font-size: 1.2rem; }
.card h3 { font-size: 1.05rem; }
.card-live { border-color: rgba(52, 211, 153, 0.55); background: linear-gradient(180deg, rgba(52, 211, 153, 0.08), var(--panel) 60%); }
.card-alert { border-color: rgba(248, 113, 113, 0.6); background: linear-gradient(180deg, rgba(248, 113, 113, 0.1), var(--panel) 60%); }
.card-note { border-color: rgba(251, 191, 36, 0.45); }
.eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-ok { background: var(--ok); color: #032318; }
.btn-event { background: var(--event); color: #03211e; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-whatsapp { background: #25d366; color: #052e16; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }
.btn-xs { min-height: 30px; padding: 4px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn-icon { min-width: 40px; min-height: 40px; padding: 6px; }

label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] { width: 54px; height: 42px; padding: 3px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; }
.field + .field { margin-top: 12px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; color: var(--text); font-size: 0.95rem; }
.check input { width: 20px; height: 20px; }
.form-error { color: var(--bad); font-size: 0.9rem; }
.form-note { color: var(--muted); font-size: 0.85rem; }

/* ---------- Chips & status ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.chip-ok { color: var(--ok); border-color: rgba(52, 211, 153, 0.45); background: rgba(52, 211, 153, 0.1); }
.chip-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.45); background: rgba(251, 191, 36, 0.1); }
.chip-bad { color: var(--bad); border-color: rgba(248, 113, 113, 0.45); background: rgba(248, 113, 113, 0.1); }
.chip-accent { color: var(--accent); border-color: rgba(56, 189, 248, 0.45); background: rgba(56, 189, 248, 0.1); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot-live { background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); } 70% { box-shadow: 0 0 0 10px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }

.status-line { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.status-line .icon { font-size: 1.25rem; line-height: 1.2; }
.status-ok { border-color: rgba(52, 211, 153, 0.45); }
.status-warn { border-color: rgba(251, 191, 36, 0.55); }
.status-bad { border-color: rgba(248, 113, 113, 0.6); background: rgba(248, 113, 113, 0.08); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.copy-box { display: flex; gap: 8px; align-items: stretch; }
.copy-box input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps > li { position: relative; padding-left: 40px; }
.steps > li + li { margin-top: 16px; }
.steps > li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 800; font-size: 0.85rem; color: var(--accent);
}
.settings-list { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 0.92rem; }
.settings-list b { color: var(--text); }
.qr { background: #fff; padding: 10px; border-radius: 12px; display: inline-block; }
.qr img, .qr canvas { display: block; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { min-height: 40px; padding: 6px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }

details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }

/* ---------- Auth ---------- */
.auth-wrap { flex: 1; display: grid; place-items: center; padding: 24px 16px calc(40px + var(--safe-bottom)); }
.auth-card { width: 100%; max-width: 430px; }
.auth-card h1 { font-size: 1.5rem; }

/* ---------- Map view ---------- */
#view-map { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.map-head { padding: 10px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.map-head h2 { font-size: 1.05rem; }
.map-body { flex: 1 1 auto; display: flex; min-height: 0; }
.map-area { position: relative; flex: 1 1 auto; display: flex; min-height: 320px; }
#map { flex: 1 1 auto; min-height: 320px; background: #aad3df; }
.map-side { width: 330px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; }
.map-alert { padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.map-alert.bad { background: #4a1515; border-bottom-color: var(--bad); }
.map-alert p { margin-top: 2px; }
.map-tools { position: absolute; z-index: 900; right: 12px; bottom: 28px; display: flex; flex-direction: column; gap: 8px; }
.map-tools .btn { box-shadow: var(--shadow); }
.paddler { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; }
.paddler + .paddler { margin-top: 8px; }
.paddler .swatch { width: 14px; height: 14px; border-radius: 4px; margin-top: 4px; flex: none; }
.paddler-name { font-weight: 800; }
.paddler-meta { font-size: 0.85rem; color: var(--muted); }
.paddler.stale { border-color: rgba(251, 191, 36, 0.6); }
.paddler.lost { border-color: rgba(248, 113, 113, 0.75); background: rgba(248, 113, 113, 0.08); }
.paddler.finished { opacity: 0.6; }

@media (max-width: 860px) {
  .map-body { flex-direction: column; }
  .map-area, #map { min-height: 55vh; }
  .map-side { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 38vh; padding-bottom: calc(12px + var(--safe-bottom)); }
}

/* Leaflet markers */
.ski-icon { background: none; border: 0; }
.ski-wrap { position: relative; width: 48px; height: 48px; }
.ski-wrap svg { position: absolute; left: 0; top: 0; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); }
.ski-ring { position: absolute; left: 4px; top: 4px; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--bad); animation: ring 1.4s infinite; }
@keyframes ring { 0% { transform: scale(0.8); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
.ski-label {
  position: absolute; top: 46px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font: 700 11px/1.3 system-ui, sans-serif; color: #fff;
  background: rgba(7, 19, 31, 0.9); border: 1px solid var(--lbl, #38bdf8); border-radius: 6px; padding: 1px 6px;
}
.ski-label.stale { color: var(--warn); border-color: var(--warn); }
.ski-label.lost { color: #fff; background: #b91c1c; border-color: #fecaca; }
.arrow-icon { background: none; border: 0; pointer-events: none; }
.finish-icon { background: none; border: 0; }
.finish-flag { white-space: nowrap; font: 800 11px/1 system-ui, sans-serif; color: #111; background: #fbbf24; border: 2px solid #fff; border-radius: 8px; padding: 4px 8px; box-shadow: 0 2px 6px rgba(0,0,0,.4); transform: translate(-50%, -50%); display: inline-block; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-control-layers { background: var(--panel) !important; color: var(--text) !important; border: 1px solid var(--line) !important; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* ---------- Admin ---------- */
.admin-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .admin-grid.two { grid-template-columns: 1fr 1fr; } }
.member-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.member-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#admin-event-map { height: 220px; border-radius: 12px; border: 1px solid var(--line); }

/* ---------- Toast & dialog ---------- */
#toast {
  position: fixed; z-index: 3000; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 460px); padding: 12px 16px; border-radius: 12px;
  background: #0b2a40; border: 1px solid var(--accent); color: var(--text); box-shadow: var(--shadow);
  font-weight: 600;
}
#toast.bad { border-color: var(--bad); background: #3a1414; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; max-width: min(92vw, 440px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.footer-note { margin-top: 22px; font-size: 0.8rem; color: var(--faint); text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dot-live, .ski-ring, .spinner { animation: none; } }
