:root {
  --map-bg: #0B0E0C;
  --map-panel: #141A16;
  --map-panel-raised: #1A231D;
  --map-line: #2A362E;
  --map-text: #F0EFE8;
  --map-muted: #9AA89D;
  --map-dim: #6C7B70;
  --map-blaze: #FF5A24;
  --map-green: #45C989;
  --map-blue: #6FAAFF;
  --map-gold: #EFB854;
  --map-slate: #9DB4CE;
  --map-display: "Archivo", system-ui, sans-serif;
  --map-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--map-text);
  background: var(--map-bg);
  color-scheme: dark;
  font-family: var(--map-display);
}

button,
select { font: inherit; }

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

a { color: inherit; }

[hidden] { display: none !important; }

.map-skip {
  position: fixed;
  top: 0;
  left: -100vw;
  z-index: 100;
  padding: .65rem 1rem;
  color: #fff;
  background: var(--map-blaze);
  border-radius: 0 0 8px 0;
  font-size: .82rem;
  font-weight: 700;
  text-decoration: none;
}

.map-skip:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--map-blaze);
  outline-offset: 2px;
}

.map-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--map-bg);
}

.map-topbar {
  position: relative;
  z-index: 20;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: max(.7rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .7rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--map-line);
  background:
    radial-gradient(500px 90px at 50% 130%, rgba(69, 201, 137, .08), transparent 75%),
    rgba(11, 14, 12, .98);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .28);
}

.map-brand {
  width: max-content;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .46rem;
  color: var(--map-text);
  text-decoration: none;
}

.map-brand-mark {
  width: 25px;
  height: 25px;
  flex: none;
  color: var(--map-blaze);
}

.map-brand-mark circle { color: var(--map-green); }

.map-brand-name {
  overflow: hidden;
  font-size: 1.08rem;
  font-weight: 830;
  letter-spacing: .055em;
  text-overflow: ellipsis;
}

.map-brand-state {
  color: var(--map-muted);
  font-family: var(--map-mono);
  font-size: .56rem;
  letter-spacing: .26em;
}

.map-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  color: #D8E5DC;
  font-family: var(--map-mono);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .15em;
  white-space: nowrap;
}

.map-live-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--map-green);
  box-shadow: 0 0 0 3px rgba(69, 201, 137, .12), 0 0 13px rgba(69, 201, 137, .75);
  animation: map-pulse 2.2s ease-in-out infinite;
}

@keyframes map-pulse {
  0%, 100% { opacity: .72; transform: scale(.92); }
  50% { opacity: 1; transform: scale(1.08); }
}

.map-exit {
  justify-self: end;
  color: var(--map-muted);
  font-size: .78rem;
  font-weight: 620;
  text-decoration: none;
  transition: color .15s ease;
}

.map-exit:hover { color: var(--map-text); }

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(70% 50% at 50% 45%, #17211b, var(--map-bg));
}

.permit-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.permit-map .maplibregl-canvas { outline: none; }

.map-filters {
  position: absolute;
  z-index: 8;
  top: 16px;
  left: 50%;
  width: min(1120px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: .7rem .78rem;
  border: 1px solid rgba(73, 91, 79, .72);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(15, 20, 17, .94), rgba(20, 26, 22, .87));
  box-shadow: 0 14px 45px rgba(0, 0, 0, .38), inset 0 1px rgba(255, 255, 255, .025);
  backdrop-filter: blur(15px) saturate(125%);
}

.filter-line {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: .62rem;
}

.filter-line + .filter-line {
  margin-top: .54rem;
  padding-top: .54rem;
  border-top: 1px solid rgba(54, 68, 59, .58);
}

.filter-label {
  width: 3.7rem;
  flex: none;
  color: var(--map-dim);
  font-family: var(--map-mono);
  font-size: .59rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.chip-scroll {
  min-width: 0;
  display: flex;
  flex: 1;
  gap: .38rem;
  overflow-x: auto;
  padding: 2px;
  scrollbar-color: #3A4A3F transparent;
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}

.chip-scroll::-webkit-scrollbar { height: 3px; }
.chip-scroll::-webkit-scrollbar-thumb { background: #3A4A3F; border-radius: 9px; }

.map-chip {
  flex: none;
  min-height: 31px;
  padding: .36rem .74rem;
  border: 1px solid #2C3930;
  border-radius: 999px;
  color: #AEBBB1;
  background: rgba(21, 28, 23, .88);
  cursor: pointer;
  font-size: .72rem;
  font-weight: 610;
  line-height: 1;
  white-space: nowrap;
  transition: color .14s ease, border-color .14s ease, background .14s ease, box-shadow .14s ease, transform .14s ease;
}

.map-chip:hover {
  color: var(--map-text);
  border-color: #46594B;
  transform: translateY(-1px);
}

.map-chip.is-active {
  color: #F7FFF9;
  border-color: rgba(69, 201, 137, .72);
  background: rgba(33, 100, 70, .78);
  box-shadow: inset 0 0 0 1px rgba(69, 201, 137, .16), 0 0 16px rgba(69, 201, 137, .09);
}

.map-chip-trade.is-active {
  border-color: rgba(255, 90, 36, .76);
  background: rgba(119, 54, 30, .8);
  box-shadow: inset 0 0 0 1px rgba(255, 90, 36, .16), 0 0 16px rgba(255, 90, 36, .08);
}

.days-control {
  flex: none;
  display: flex;
  align-items: center;
  gap: .42rem;
  color: var(--map-dim);
  font-family: var(--map-mono);
  font-size: .58rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.days-control select {
  min-height: 31px;
  padding: .3rem 1.85rem .3rem .66rem;
  border: 1px solid #35433A;
  border-radius: 8px;
  color: var(--map-text);
  background-color: #19211C;
  cursor: pointer;
  font-family: var(--map-mono);
  font-size: .67rem;
  text-transform: none;
}

.map-readout,
.map-legend {
  position: absolute;
  z-index: 7;
  border: 1px solid rgba(64, 81, 69, .7);
  background: rgba(13, 18, 15, .88);
  box-shadow: 0 10px 32px rgba(0, 0, 0, .34);
  backdrop-filter: blur(12px);
}

.map-readout {
  bottom: 18px;
  left: max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 39px;
  padding: .52rem .76rem;
  border-radius: 10px;
  font-family: var(--map-mono);
  font-size: .67rem;
}

.map-readout strong {
  color: #EDF7F0;
  font-weight: 600;
}

.map-readout > span:last-child { color: var(--map-dim); }

.map-legend {
  right: max(58px, env(safe-area-inset-right));
  bottom: 18px;
  width: min(490px, calc(100% - 410px));
  padding: .58rem .7rem .62rem;
  border-radius: 10px;
}

.legend-heading {
  margin: 0 0 .4rem;
  color: var(--map-dim);
  font-family: var(--map-mono);
  font-size: .56rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.legend-grid {
  display: flex;
  align-items: center;
  gap: .42rem .75rem;
  flex-wrap: wrap;
}

.legend-grid span {
  display: inline-flex;
  align-items: center;
  gap: .32rem;
  color: #AAB6AD;
  font-size: .62rem;
  white-space: nowrap;
}

.legend-dot {
  width: 7px;
  height: 7px;
  display: inline-block;
  flex: none;
  border-radius: 50%;
  background: var(--map-slate);
  box-shadow: 0 0 7px currentColor;
}

.legend-build { color: var(--map-blaze); background: var(--map-blaze); }
.legend-systems { color: var(--map-green); background: var(--map-green); }
.legend-exterior { color: var(--map-gold); background: var(--map-gold); }
.legend-pool { color: var(--map-blue); background: var(--map-blue); }
.legend-other { color: var(--map-slate); background: var(--map-slate); }
.legend-big {
  width: 9px;
  height: 9px;
  color: var(--map-blaze);
  background: var(--map-blaze);
  box-shadow: 0 0 0 4px rgba(255, 90, 36, .18), 0 0 12px rgba(255, 90, 36, .75);
}

.map-flight-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 105px;
  display: flex;
  transform: translateX(-50%);
  gap: 1px;
  overflow: hidden;
  border: 1px solid rgba(71, 87, 76, .58);
  border-radius: 999px;
  color: #9EAAA1;
  background: rgba(12, 16, 14, .78);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  backdrop-filter: blur(9px);
  font-family: var(--map-mono);
  font-size: .58rem;
  letter-spacing: .04em;
  opacity: 1;
  transition: opacity .5s ease, transform .5s ease;
  pointer-events: none;
}

.map-flight-hint span { padding: .48rem .72rem; }
.map-flight-hint span + span { border-left: 1px solid rgba(71, 87, 76, .48); }
.map-flight-hint.is-gone { opacity: 0; transform: translate(-50%, 8px); }

.map-loading {
  position: absolute;
  z-index: 10;
  top: 142px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: .58rem;
  transform: translate(-50%, -8px);
  padding: .58rem .78rem;
  border: 1px solid rgba(69, 201, 137, .24);
  border-radius: 999px;
  color: #C8D7CC;
  background: rgba(12, 18, 14, .88);
  box-shadow: 0 10px 35px rgba(0, 0, 0, .4);
  font-family: var(--map-mono);
  font-size: .62rem;
  letter-spacing: .05em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.map-loading.is-visible { opacity: 1; transform: translate(-50%, 0); }

.map-loading-ring {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(69, 201, 137, .2);
  border-top-color: var(--map-green);
  border-radius: 50%;
  animation: map-spin .7s linear infinite;
}

@keyframes map-spin { to { transform: rotate(360deg); } }

.map-error {
  position: absolute;
  z-index: 15;
  top: 50%;
  left: 50%;
  width: min(390px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 1rem 1.1rem;
  border: 1px solid rgba(255, 90, 36, .6);
  border-radius: 12px;
  background: rgba(28, 20, 16, .96);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
}

.map-error strong {
  display: block;
  margin-bottom: .28rem;
  color: #FFF3EE;
  font-size: .9rem;
}

.map-error span { color: #C7AEA4; font-size: .76rem; }

/* MapLibre chrome */
.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid #334139;
  border-radius: 9px;
  background: rgba(16, 22, 18, .92);
  box-shadow: 0 7px 24px rgba(0, 0, 0, .4);
}

.maplibregl-ctrl-group:not(:empty) { box-shadow: 0 7px 24px rgba(0, 0, 0, .4); }
.maplibregl-ctrl-group button + button { border-top-color: #334139; }
.maplibregl-ctrl-group button { background-color: transparent; }
.maplibregl-ctrl-group button:hover { background-color: #253229; }
.maplibregl-ctrl-icon { filter: invert(1) brightness(1.7); opacity: .8; }
.maplibregl-ctrl-bottom-right { padding-right: max(2px, env(safe-area-inset-right)); }

.maplibregl-ctrl-attrib {
  color: #7F8D83;
  background: rgba(10, 14, 11, .82) !important;
  font-size: 10px;
}

.maplibregl-ctrl-attrib a { color: #A8B5AB; }
.maplibregl-ctrl-attrib-button { filter: invert(1); opacity: .64; }

/* Permit record popup */
.permit-popup.maplibregl-popup { z-index: 12; }

.permit-popup .maplibregl-popup-content {
  overflow: hidden;
  padding: 0;
  border: 1px solid #3A493F;
  border-radius: 13px;
  color: var(--map-text);
  background: #121813;
  box-shadow: 0 22px 65px rgba(0, 0, 0, .62), 0 0 0 1px rgba(0, 0, 0, .2);
}

.permit-popup .maplibregl-popup-close-button {
  z-index: 2;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 0 0 0 8px;
  color: #AAB7AD;
  background: rgba(25, 34, 28, .9);
  font-size: 20px;
  line-height: 1;
}

.permit-popup .maplibregl-popup-close-button:hover { color: #fff; background: #29372E; }
.permit-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #3A493F; }
.permit-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #3A493F; }
.permit-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #3A493F; }
.permit-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #3A493F; }

.permit-card { min-width: 285px; max-width: 340px; }

.permit-card-header {
  min-height: 39px;
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .65rem 2.5rem .55rem .85rem;
  border-bottom: 1px solid #2A362E;
  background: linear-gradient(90deg, rgba(69, 201, 137, .08), transparent 70%);
}

.permit-card-signal,
.permit-card-big {
  font-family: var(--map-mono);
  font-size: .56rem;
  font-weight: 600;
  letter-spacing: .12em;
}

.permit-card-signal { color: var(--map-green); }
.permit-card-big {
  padding: .17rem .35rem;
  border: 1px solid rgba(255, 90, 36, .45);
  border-radius: 4px;
  color: #FF8B62;
  background: rgba(255, 90, 36, .1);
}

.permit-card h2 {
  margin: 0;
  padding: .85rem .88rem .75rem;
  color: #F5F4ED;
  font-size: 1.03rem;
  font-weight: 720;
  line-height: 1.28;
  letter-spacing: -.01em;
}

.permit-card-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 .88rem .86rem;
  border: 1px solid #29352D;
  border-radius: 9px;
  background: #161E19;
}

.permit-card-facts > div { min-width: 0; padding: .52rem .58rem; }
.permit-card-facts > div:nth-child(even) { border-left: 1px solid #29352D; }
.permit-card-facts > div:nth-child(n + 3) { border-top: 1px solid #29352D; }

.permit-card-facts dt {
  margin-bottom: .16rem;
  color: #738177;
  font-family: var(--map-mono);
  font-size: .52rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.permit-card-facts dd {
  overflow: hidden;
  margin: 0;
  color: #D8E2DA;
  font-size: .7rem;
  font-weight: 570;
  line-height: 1.3;
  text-overflow: ellipsis;
}

.permit-card-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .72rem .88rem;
  color: #fff;
  background: var(--map-blaze);
  font-size: .75rem;
  font-weight: 720;
  text-decoration: none;
  transition: background .15s ease;
}

.permit-card-link:hover { background: #F06A3B; }
.permit-card-link span { font-size: 1rem; }

.map-noscript {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  color: var(--map-text);
  background: var(--map-bg);
  text-align: center;
}

.map-noscript a { color: var(--map-green); }

@media (max-width: 820px) {
  .map-topbar {
    min-height: 57px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .5rem;
    padding-bottom: .55rem;
  }

  .map-mode { display: none; }
  .map-brand-state { display: none; }
  .map-brand-name { font-size: .94rem; }
  .map-brand-mark { width: 22px; height: 22px; }
  .map-exit { font-size: .7rem; }

  .map-filters {
    top: 8px;
    width: calc(100% - 16px);
    padding: .5rem;
    border-radius: 11px;
  }

  .filter-line { gap: .36rem; }
  .filter-line + .filter-line { margin-top: .4rem; padding-top: .4rem; }
  .filter-label { display: none; }
  .map-chip { min-height: 29px; padding: .33rem .62rem; font-size: .66rem; }
  .days-control { gap: 0; }
  .days-control > span { display: none; }
  .days-control select { min-height: 29px; max-width: 82px; padding-left: .48rem; font-size: .62rem; }

  .map-loading { top: 99px; }
  .map-flight-hint { display: none; }

  .map-readout {
    right: auto;
    bottom: calc(55px + env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    min-height: 34px;
    max-width: calc(100% - 16px);
    padding: .46rem .6rem;
    font-size: .6rem;
  }

  .map-legend {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    min-height: 37px;
    overflow-x: auto;
    padding: .42rem .55rem;
    scrollbar-width: none;
  }

  .map-legend::-webkit-scrollbar { display: none; }
  .legend-heading { display: none; }
  .legend-grid { width: max-content; flex-wrap: nowrap; gap: .7rem; }
  .legend-grid span { font-size: .57rem; }

  .maplibregl-ctrl-bottom-right { bottom: calc(38px + env(safe-area-inset-bottom)); }
  .maplibregl-ctrl-group { transform: scale(.9); transform-origin: bottom right; }
  .maplibregl-ctrl-attrib { max-width: 82vw; }

  .permit-card { min-width: min(285px, calc(100vw - 34px)); }
}

@media (max-width: 430px) {
  .map-exit { max-width: 68px; text-align: right; line-height: 1.15; }
  .map-total-count { display: none; }
  .map-readout > span:last-child { display: none; }
}

@media (max-height: 590px) and (orientation: landscape) {
  .map-topbar { min-height: 48px; padding-top: .42rem; padding-bottom: .42rem; }
  .map-filters { top: 6px; }
  .map-legend { display: none; }
  .map-readout { bottom: 8px; }
  .maplibregl-ctrl-bottom-right { bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
