:root {
  color-scheme: light;
  --bg: #f7f8f4;
  --surface: #ffffff;
  --ink: #1f2725;
  --muted: #68716e;
  --line: #d9ded5;
  --green: #177245;
  --green-soft: #dff1e6;
  --teal: #0c6670;
  --amber: #bb6a16;
  --amber-soft: #fff0d9;
  --red: #a63d2e;
  --red-soft: #ffe5df;
  --shadow: 0 18px 48px rgba(24, 36, 28, 0.11);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(90deg, rgba(12, 102, 112, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 114, 69, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1380px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.court-mark {
  position: relative;
  width: 54px;
  height: 54px;
  border: 2px solid var(--green);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 47%, rgba(23, 114, 69, 0.9) 47% 53%, transparent 53%),
    linear-gradient(0deg, transparent 20%, rgba(23, 114, 69, 0.45) 20% 22%, transparent 22% 78%, rgba(23, 114, 69, 0.45) 78% 80%, transparent 80%),
    #eff8f2;
  flex: 0 0 auto;
}

.court-mark span {
  position: absolute;
  inset: 14px 7px;
  border-left: 1px solid rgba(23, 114, 69, 0.65);
  border-right: 1px solid rgba(23, 114, 69, 0.65);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.icon-button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--green);
  background: #f8fcf8;
}

.icon-button:active,
.text-button:active {
  transform: translateY(1px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  font-size: 23px;
  line-height: 1;
}

.controls {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.85fr 1.35fr 0.8fr;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.safety-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid rgba(12, 102, 112, 0.28);
  border-radius: 8px;
  background: rgba(237, 246, 244, 0.94);
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.safety-panel strong {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #dff1e6;
  color: var(--green);
  padding: 4px 9px;
  font-size: 12px;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 12px;
}

.toggle-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--green);
}

.toggle-field span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-transform: none;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 114, 69, 0.14);
}

.location-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr);
  gap: 12px;
  margin-top: 12px;
}

.location-readout,
.location-search {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 10px 12px;
}

.location-readout {
  display: grid;
  align-content: center;
  gap: 4px;
}

#locationStatus {
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 850;
}

#locationAccuracy {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.location-search {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.location-search input {
  min-height: 36px;
}

.location-search .text-button {
  min-height: 36px;
  white-space: nowrap;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, auto)) minmax(180px, 1fr);
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.status-strip > div,
.status-strip > p {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 12px;
}

.metric-value {
  display: block;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.15;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#statusText {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 0.72fr) minmax(0, 1.28fr);
  gap: 16px;
  margin-top: 16px;
}

.map-panel,
.results-panel {
  min-width: 0;
}

.map-panel {
  position: sticky;
  top: 14px;
  align-self: start;
}

.map-canvas {
  position: relative;
  overflow: hidden;
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(12, 102, 112, 0.08), rgba(23, 114, 69, 0.08)),
    #fdfefb;
}

.leaflet-map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-canvas:not(.has-leaflet) .leaflet-map {
  display: none;
}

.map-canvas.has-leaflet .map-grid,
.map-canvas.has-leaflet .map-pin,
.map-canvas.has-leaflet .home-pin {
  display: none;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  font: inherit;
  background: #eef4ed;
  overflow: hidden;
}

/* Local Leaflet layout fallback. Some WebViews load the JS but drop the CDN CSS,
   which leaves map tiles as one small square instead of a full map. */
.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  max-width: none !important;
  max-height: none !important;
}

.leaflet-container img.leaflet-tile {
  border: 0;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  margin: 10px;
  border: 1px solid rgba(31, 39, 37, 0.18);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(20, 30, 25, 0.16);
}

.leaflet-control-zoom a {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-tooltip {
  position: absolute;
  pointer-events: none;
}

.venue-name-tooltip {
  max-width: 220px;
  overflow: hidden;
  border: 1px solid rgba(31, 39, 37, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(15, 29, 23, 0.18);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  padding: 7px 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaflet-control-attribution {
  right: 0;
  bottom: 0;
  margin: 0;
  background: rgba(255, 255, 255, 0.78);
  padding: 2px 5px;
  font-size: 10px;
}

.map-grid {
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(23, 114, 69, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(23, 114, 69, 0.38) 49.7% 50.3%, transparent 50.3%),
    linear-gradient(0deg, transparent 18%, rgba(23, 114, 69, 0.2) 18% 18.5%, transparent 18.5% 81.5%, rgba(23, 114, 69, 0.2) 81.5% 82%, transparent 82%),
    linear-gradient(90deg, transparent 19%, rgba(12, 102, 112, 0.18) 19% 19.5%, transparent 19.5% 80.5%, rgba(12, 102, 112, 0.18) 80.5% 81%, transparent 81%);
}

.map-pin,
.home-pin {
  position: absolute;
  z-index: 2;
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(15, 29, 23, 0.25);
}

.map-pin {
  background: var(--amber);
}

.map-pin:hover {
  z-index: 5;
}

.map-pin::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  max-width: 220px;
  overflow: hidden;
  border: 1px solid rgba(31, 39, 37, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(15, 29, 23, 0.18);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  opacity: 0;
  padding: 7px 9px;
  pointer-events: none;
  text-overflow: ellipsis;
  transform: translateX(-50%) translateY(3px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  white-space: nowrap;
}

.map-pin:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.map-pin.available {
  width: 18px;
  height: 18px;
  background: var(--green);
}

.map-pin.selected {
  width: 24px;
  height: 24px;
  border-color: #d22f27;
  border-width: 5px;
  z-index: 4;
}

.home-pin {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(90deg, transparent 45%, var(--teal) 45% 55%, transparent 55%),
    linear-gradient(0deg, transparent 45%, var(--teal) 45% 55%, transparent 55%);
  box-shadow: none;
}

.home-pin::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
}

.origin-crosshair-icon {
  position: relative;
  width: 34px !important;
  height: 34px !important;
  border: 0;
  background: transparent;
}

.origin-crosshair-icon::before,
.origin-crosshair-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: var(--teal);
  transform: translate(-50%, -50%);
}

.origin-crosshair-icon::before {
  width: 34px;
  height: 3px;
}

.origin-crosshair-icon::after {
  width: 3px;
  height: 34px;
}

.origin-crosshair-icon span {
  position: absolute;
  inset: 8px;
  border: 2px solid var(--teal);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 3px 12px rgba(12, 102, 112, 0.28);
}

.source-panel {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

#sourceBadge {
  justify-self: start;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

#sourceText {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.results-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  padding: 14px;
  box-shadow: var(--shadow);
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 12px;
}

.results-header h2 {
  font-size: 20px;
}

#lastUpdated {
  color: var(--muted);
  font-size: 13px;
}

.venue-list {
  display: grid;
  gap: 10px;
}

.venue-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.venue-card.is-available {
  border-color: rgba(23, 114, 69, 0.45);
}

.venue-card.is-selected {
  border-color: #111917;
  box-shadow: 0 0 0 3px rgba(17, 25, 23, 0.08);
}

.card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.card-head h3 {
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.25;
}

.address {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.distance {
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.availability-pill.available {
  background: var(--green-soft);
  color: var(--green);
}

.availability-pill.pending {
  background: #edf2f2;
  color: var(--teal);
}

.availability-pill.full {
  background: var(--amber-soft);
  color: var(--amber);
}

.availability-pill.unknown,
.availability-pill.blocked,
.availability-pill.error {
  background: var(--red-soft);
  color: var(--red);
}

.source-pill,
.type-pill,
.confidence-pill {
  background: #edf2f2;
  color: var(--teal);
}

.type-pill {
  background: #f4f0e8;
  color: #6a542a;
}

.confidence-pill {
  background: var(--green-soft);
  color: var(--green);
}

.next-slot-pill {
  background: #f4f0e8;
  color: #6a542a;
}

.booking-stats {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.7fr;
  gap: 8px;
  margin-top: 12px;
}

.booking-stats > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  padding: 9px 10px;
}

.stat-value,
.stat-label {
  display: block;
}

.stat-value {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.2;
}

.stat-label {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.slot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 34px;
  margin-top: 12px;
}

.slot {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 750;
}

.slot.available {
  border-color: rgba(23, 114, 69, 0.3);
  background: var(--green-soft);
  color: var(--green);
}

.slot.booked {
  background: #f3f4f1;
  color: var(--muted);
}

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

.range-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.range-summary {
  color: var(--ink);
  font-weight: 750;
}

.range-days {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.range-day {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f4f1;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.range-day.available {
  border-color: rgba(23, 114, 69, 0.3);
  background: var(--green-soft);
  color: var(--green);
}

.venue-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.primary-action {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.primary-action:hover {
  background: #115b37;
  color: #ffffff;
}

a[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.diagnostics {
  overflow: auto;
  max-height: 220px;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111917;
  color: #d9f4e3;
  padding: 10px;
  font-size: 12px;
  white-space: pre-wrap;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .safety-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .location-panel {
    grid-template-columns: 1fr;
  }

  .search-field,
  .toggle-field {
    grid-column: 1 / -1;
  }

  .status-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  #statusText {
    grid-column: 1 / -1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .map-panel {
    position: static;
  }

  .map-canvas {
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1380px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .court-mark {
    width: 46px;
    height: 46px;
  }

  .controls,
  .location-search,
  .status-strip {
    grid-template-columns: 1fr;
  }

  .card-head {
    grid-template-columns: 1fr;
  }

  .booking-stats {
    grid-template-columns: 1fr;
  }

  .distance {
    justify-self: start;
  }

  .card-actions {
    justify-content: stretch;
  }

  .text-button {
    flex: 1;
  }
}
