:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #23282d;
  --muted: #6b7280;
  --line: #e6e0d6;
  --accent: #2f6f6b;
  --accent-dark: #245a56;
  --warm: #c2703c;
  --shadow: 0 1px 2px rgba(35, 40, 45, .06), 0 8px 24px rgba(35, 40, 45, .08);
  --radius: 12px;
}

* { box-sizing: border-box; }

/* A class that sets `display` outranks the UA's [hidden] rule, so anything using
   `display: flex` stays visible when hidden. This keeps [hidden] authoritative. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -.01em; }

a { color: var(--accent); }

/* ------------------------------------------------------------- header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.portrait {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow);
}

.site-header h1 {
  font-size: 22px;
  font-weight: 700;
}

.site-header h1::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warm);
  margin-left: 10px;
  vertical-align: middle;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 300;
}

/* Every group belongs to the same run, so the date belongs to the page. */
.next-run {
  margin-inline-start: auto;
  flex: none;
  text-align: end;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: #edf3f2;
  border: 1px solid #d5e4e2;
  border-radius: var(--radius);
  padding: 8px 16px;
}

.next-run-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--accent-dark);
  text-transform: uppercase;
}

.next-run-date { font-size: 17px; font-weight: 700; color: var(--ink); }
.next-run-sub { font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------ buttons */

.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f1ede6; }

.btn-danger { background: transparent; color: #b3261e; border-color: #f0d4d2; }
.btn-danger:hover { background: #fdf2f1; }

.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn:disabled { opacity: .55; cursor: progress; }

/* ------------------------------------------------------------- layout */

.layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.map-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
  background: #f2efe9;
  z-index: 0;
  cursor: crosshair;
}

/* Discoverability: the map is the only way to start a team. */
.map-hint {
  position: absolute;
  z-index: 400;
  inset-block-end: 16px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  margin: 0;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 13px;
  color: var(--ink);
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}

/* Route drawing takes over the map; its controls replace the add button. */
.draw-bar {
  position: absolute;
  z-index: 1001;
  inset-block-end: 22px;
  inset-inline: 22px;
  margin: 0 auto;
  width: fit-content;
  max-width: calc(100% - 44px);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(35, 40, 45, .28);
}

body:has(.draw-bar:not([hidden])) .map-hint { display: none; }

.nearby {
  background: #fdf3ec;
  border: 1px solid #f0d9c6;
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nearby p { margin: 0; font-size: 14px; }
.nearby-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.route-field {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f6f3ee;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.route-field > div { flex: 1; min-width: 0; }
.route-field .dialog-hint { margin: 2px 0 0; }

/* Primary action, floating over the map rather than tucked in the header —
   above Leaflet's own controls, which sit at z-index 1000. */
.fab {
  position: absolute;
  z-index: 1001;
  inset-block-end: 22px;
  inset-inline-start: 22px;
  border: none;
  border-radius: 999px;
  padding: 15px 28px;
  background: var(--accent);
  color: #fff;
  font: 500 16px/1 'Heebo', sans-serif;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(35, 40, 45, .28), 0 1px 3px rgba(35, 40, 45, .2);
  transition: background .15s, transform .15s, box-shadow .15s;
}

.fab:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(35, 40, 45, .32), 0 1px 3px rgba(35, 40, 45, .2);
}

.fab:active { transform: translateY(0); }

.fab:focus-visible { outline: 3px solid rgba(47, 111, 107, .45); outline-offset: 3px; }

.leaflet-container { font-family: inherit; }

.panel {
  width: 380px;
  flex: none;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.panel-head h2 { font-size: 16px; }

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

.team-list {
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.team-card {
  text-align: start;
  font: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.team-card:hover, .team-card.active {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.team-card h3 { font-size: 15px; font-weight: 700; }

.team-meta {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  background: #edf3f2;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 8px;
}

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

/* ----------------------------------------------------------- map bits */

.pin {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  display: grid;
  place-items: center;
}

.pin span {
  transform: rotate(45deg);
  color: #fff;
  font: 700 11px/1 'Heebo', sans-serif;
}

.pin.temp { background: var(--warm); }

/* ------------------------------------------------------------ dialogs */

.dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: min(88vh, 900px);
  box-shadow: 0 24px 60px rgba(20, 25, 30, .25);
  color: var(--ink);
  background: var(--surface);
}

.dialog::backdrop { background: rgba(25, 30, 35, .45); }

.dialog form, .dialog > div {
  padding: 22px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog h2 { font-size: 19px; font-weight: 700; }

.dialog-hint { margin: -6px 0 0; color: var(--muted); font-size: 13px; }

/* The negative margin above is tuned for a hint under a heading; a hint that
   follows an input needs normal spacing. */
.dialog-hint.hint-below { margin: 0; }

.dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.dialog input, .dialog textarea, .dialog select {
  font: inherit;
  color: var(--ink);
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fdfcfa;
  width: 100%;
}

.dialog input:focus, .dialog textarea:focus, .dialog select:focus {
  outline: 2px solid rgba(47, 111, 107, .35);
  border-color: var(--accent);
}

.dialog textarea { resize: vertical; }

.req { color: var(--warm); }

.map-point {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  direction: ltr;
  text-align: start;
  unicode-bidi: plaintext;
}

/* ------------------------------------------------------ location picker */

.locate {
  background: #f6f3ee;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.locate .section-title { color: var(--ink); }

.locate .row { gap: 10px; }

.combo {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.combo label { font-size: 13px; color: var(--muted); }
.combo input { background: #fff; }
.combo input:disabled { background: #f0ece5; color: var(--muted); cursor: not-allowed; }

.combo-results {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 10;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.combo-results li + li { border-top: 1px solid var(--line); }

.combo-hit {
  display: block;
  width: 100%;
  text-align: start;
  font: inherit;
  font-size: 14px;
  background: none;
  border: none;
  padding: 8px 11px;
  cursor: pointer;
  color: var(--ink);
}

.combo-hit:hover, .combo-hit.active { background: #eef4f3; }

.combo-status {
  padding: 8px 11px;
  font-size: 13px;
  color: var(--muted);
}

.row { display: flex; gap: 12px; }
.row > label { flex: 1; }

.checkbox {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.checkbox input { width: auto; margin-top: 3px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.form-error {
  margin: 0;
  color: #b3261e;
  background: #fdf2f1;
  border: 1px solid #f0d4d2;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

/* ------------------------------------------------------- team details */

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 14px;
  margin: 0;
}

.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; }

.notes {
  background: #f6f3ee;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  white-space: pre-wrap;
  margin: 0;
}

.share-row { display: flex; gap: 8px; flex-wrap: wrap; }

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

.members li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.members li:last-child { border-bottom: none; }
.members .who { flex: 1; }
.members .tel { color: var(--muted); font-size: 13px; direction: ltr; }

hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

.section-title { font-size: 14px; font-weight: 700; }

/* -------------------------------------------------------------- footer */

.site-footer {
  flex: none;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------------------------------------- mobile */

@media (max-width: 820px) {
  .layout { flex-direction: column; }

  /* The desktop layout pins body to the viewport so the panel scrolls inside
     itself. On mobile the panel grows instead, and a viewport-height body would
     leave the footer laid out at the bottom of the screen while content overflows
     past it — so it appears to climb over the list as you scroll. Let the page
     grow and the footer lands after the content, where it belongs. */
  /* min-height in % needs a resolved parent height; with html at auto it computes
     against nothing. dvh is absolute, and tracks the address bar showing/hiding. */
  html, body { height: auto; min-height: 100dvh; }

  /* dvh, so the map does not resize as the browser's address bar hides. */
  .map-wrap { flex: none; height: 52vh; height: 52dvh; }

  .fab { padding: 13px 22px; font-size: 15px; inset-block-end: 16px; inset-inline-start: 16px; }

  /* Bottom centre would sit under the button on a narrow screen. */
  .map-hint {
    inset-block-end: auto;
    inset-block-start: 12px;
    font-size: 12px;
    padding: 6px 14px;
  }
  .panel { width: auto; border-inline-start: none; border-top: 1px solid var(--line); }
  .team-list { overflow: visible; }
  .header-inner { padding: 12px 16px; flex-wrap: wrap; gap: 10px 12px; }
  .site-header h1 { font-size: 19px; }

  /* Full width on its own row rather than squeezed beside the title. */
  .next-run {
    order: 3;
    width: 100%;
    margin-inline-start: 0;
    text-align: start;
    padding: 8px 14px;
  }

  .next-run-date { font-size: 15px; }
  .portrait { width: 42px; height: 42px; }
  .row { flex-direction: column; gap: 12px; }
}
