:root {
  --bg: #0a1119;
  --panel: #121c27;
  --panel-2: #17222f;
  --line: #22303f;
  --text: #e8eef4;
  --muted: #8ba0b3;
  --accent: #2fd4c4;
  --accent-soft: rgba(47, 212, 196, 0.15);
  --warm: #ffb347;
  --hot: #ff6b6b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --map-height: 500px;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over component rules. The UA's `[hidden]
   { display: none }` loses to *any* author `display:` declaration, so without
   this a component that sets `display` (`.track`, `.segmented`) stays on screen
   even when the page marks it hidden. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- chrome ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(10, 17, 25, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), #1c8f88);
  color: #04211f;
  font-size: 13px;
}

.topbar .link-muted { color: var(--muted); font-size: 13px; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 18px 72px;
}

/* ---------- headings ---------- */

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }

/* ---------- segmented control ---------- */

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.segmented button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active {
  background: var(--accent);
  color: #04211f;
}

h1 { font-size: 1.55rem; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 1.05rem; letter-spacing: -0.01em; margin: 0 0 14px; color: var(--text); }
h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

.subtitle { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

/* ---------- cards ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card.tight { padding: 14px; }

/* ---------- uploader ---------- */

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  background: var(--panel-2);
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }
.dropzone .hint { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--accent);
  color: #04211f;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

input[type="file"] { display: none; }

/* ---------- progress ---------- */

.progress { margin-top: 16px; display: none; }
.progress.on { display: block; }
.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.progress-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  transition: width 0.2s;
}
.progress-label { color: var(--muted); font-size: 12.5px; margin-top: 7px; }

/* ---------- results ---------- */

.result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
  margin-bottom: 8px;
}
.result .name { font-weight: 600; overflow-wrap: anywhere; }
.result .meta { color: var(--muted); font-size: 12.5px; }
.result.err { border-color: rgba(255, 107, 107, 0.45); }
.result.err .meta { color: var(--hot); }

/* ---------- stat grid ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
}
.stat .k {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat .v {
  font-size: 1.42rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .u { font-size: 0.72em; color: var(--muted); font-weight: 500; margin-left: 2px; }
.stat.accent .v { color: var(--accent); }
.stat.warm .v { color: var(--warm); }

/* ---------- charts ---------- */

.chart-box { position: relative; width: 100%; }
.chart-box.hist { height: 260px; }
.chart-box.line { height: 300px; }
.chart-box.small { height: 200px; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---------- table ---------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
tbody tr:hover { background: var(--panel-2); }

/* ---------- misc ---------- */

/* Offline fallback for the route. Sized to match the map so switching between
   them does not make the page jump. */
.track {
  width: 100%;
  height: var(--map-height);
  display: block;
  background: var(--panel-2);
  border-radius: 11px;
  border: 1px solid var(--line);
}

/* ---------- route map ---------- */

.map {
  position: relative;
  z-index: 0;               /* keep Leaflet's panes under the sticky topbar */
  width: 100%;
  height: var(--map-height);
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  overflow: hidden;
}

/* Leaflet hardcodes a light grey canvas on .leaflet-container, which wins on
   equal specificity and shows as a bright block before tiles arrive (or if they
   never do). Match the app palette instead. */
.map.leaflet-container {
  background: var(--panel-2);
  font-family: inherit;
  font-size: inherit;
}

.map .leaflet-control-attribution {
  background: rgba(10, 17, 25, 0.78);
  color: var(--muted);
  font-size: 10px;
  padding: 1px 6px;
}
.map .leaflet-control-attribution a { color: var(--accent); }

.map .leaflet-bar a,
.map .leaflet-bar a:hover {
  background: var(--panel);
  color: var(--text);
  border-bottom-color: var(--line);
}
.map .leaflet-bar a:hover { background: var(--panel-2); }

@media (max-width: 520px) {
  /* Taller on a phone, not shorter: this is the view that matters. */
  :root { --map-height: 420px; }
}

.empty { color: var(--muted); text-align: center; padding: 26px 10px; font-size: 14px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 520px) {
  .wrap { padding: 16px 13px 64px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 15px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .stat .v { font-size: 1.22rem; }
}

/* -- accounts ------------------------------------------------------------ */

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  margin-left: auto;
}

.inline-form {
  display: inline;
  margin: 0;
}

.topnav .who {
  color: var(--text);
  font-weight: 600;
}

/* The sign-out control is a POST, so it must look like the other links. */
.topnav button.link-muted {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.topnav button.link-muted:hover {
  color: var(--accent);
}

.auth-card {
  max-width: 360px;
  margin: 48px auto;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.auth-sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.auth-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--hot);
  background: color-mix(in srgb, var(--hot) 14%, transparent);
  color: var(--text);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form label {
  font-size: 13px;
  color: var(--muted);
}

.auth-form input[type="email"],
.auth-form input[type="password"] {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

.auth-form button {
  margin-top: 6px;
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.member-name { font-weight: 600; }

.member-email {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.member .tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.member-add { margin-top: 12px; }

.member-add select {
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

/* -- the admin screen ---------------------------------------------------- */

.notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 14px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 380px;
}

.admin-form label { font-size: 13px; color: var(--muted); }

.admin-form input[type="text"],
.admin-form input[type="email"],
.admin-form input[type="password"] {
  padding: 9px 12px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

.admin-form label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.admin-form button {
  align-self: flex-start;
  margin-top: 8px;
  padding: 9px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-actions .inline-form { display: inline; }

table .inline-form input[type="password"] {
  width: 150px;
  padding: 6px 9px;
  margin-right: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.muted { color: var(--muted); }
