/* ═══════════════════════════════════════════════════════
   layout.css — Header, Main Grid, Sidebar, Map Area
═══════════════════════════════════════════════════════ */

/* ── Header ── */
#app-header {
  position: relative;
  z-index: 200;
  flex-shrink: 0;
  height: var(--header-h);
  background: rgba(11, 17, 32, 0.88);
  backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.logo-icon {
  width: 31px; height: 31px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.logo em {
  color: var(--accent);
  font-style: normal;
}
.logo-usa {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
  margin-left: 2px;
}

/* Search Bar */
.search-wrap {
  flex: 1;
  max-width: 520px;
  position: relative;
}
.search-wrap input {
  width: 100%;
  background: rgba(26, 36, 64, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 90px 10px 40px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--t-normal), box-shadow var(--t-normal);
}
.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(101, 188, 219, 0.20);
}
.search-wrap input::placeholder { color: var(--muted); }
.search-icon-left {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}
.search-btn {
  position: absolute;
  right: 5px; top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  border-radius: 7px;
  color: #0a0c10;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 6px 14px;
  transition: background var(--t-fast);
}
.search-btn:hover { background: #7bd2f2; }
.search-btn:hover { box-shadow: 0 8px 16px rgba(101, 188, 219, 0.32); }

.geo-btn {
  border: 1px solid var(--border);
  background: rgba(26, 36, 64, 0.75);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 8px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}
.geo-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Header Pills */
.header-pills {
  display: flex;
  gap: 0.6rem;
  margin-left: auto;
  flex-shrink: 0;
}
.hpill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(18, 26, 44, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 4px 11px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Dots */
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.free { background: var(--free); box-shadow: 0 0 5px var(--free); }
.dot.occ  { background: var(--occupied); }
.dot.live { background: var(--accent); }

/* ── Main Layout ── */
#app-main {
  display: grid;
  grid-template-columns: minmax(280px, 370px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
  background: linear-gradient(180deg, rgba(18, 26, 44, 0.94), rgba(16, 24, 42, 0.94));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  align-self: stretch;
}

.sidebar-top {
  padding: 1rem 1.1rem 0.8rem;
  border-bottom: 1px solid var(--border);
  flex: 0 1 auto;
  min-height: 0;
  /* Leave vertical room for “Lots” header + scrollable list (aligned with map column) */
  max-height: min(38vh, 420px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.filter-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.radius-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.9rem;
}
.radius-row label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
.radius-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}
.radius-val {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
  min-width: 42px;
  text-align: right;
}

.filter-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.stats-strip {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.ss-item {
  background: rgba(11, 17, 32, 0.45);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px;
  display: grid;
  gap: 2px;
}
.ss-k {
  font-family: var(--font-mono);
  font-size: 0.54rem;
  color: var(--muted);
  text-transform: uppercase;
}
.ss-v {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}
.recent-wrap { margin-top: 0.7rem; }

.list-header {
  padding: 0.65rem 1.1rem 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.list-header-left {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  display: flex;
  align-items: center;
}
.list-header-right {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--accent);
  cursor: pointer;
  transition: opacity var(--t-fast);
}
.list-header-right:hover { opacity: 0.75; }

.lot-list {
  flex: 1 1 0%;
  min-height: 0;
  /* Cannot grow past sidebar: scroll inside this box only */
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.6rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(101, 188, 219, 0.45) rgba(11, 17, 32, 0.5);
}

/* Results list — scrollbar easy to see (global ::-webkit-scrollbar is 4px) */
.lot-list::-webkit-scrollbar {
  width: 8px;
}
.lot-list::-webkit-scrollbar-track {
  background: rgba(11, 17, 32, 0.55);
  border-radius: 6px;
}
.lot-list::-webkit-scrollbar-thumb {
  background: rgba(101, 188, 219, 0.4);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.lot-list::-webkit-scrollbar-thumb:hover {
  background: rgba(101, 188, 219, 0.6);
  background-clip: padding-box;
}

/* ── Map Wrapper ── */
.map-wrap {
  position: relative;
  overflow: hidden;
  flex: 1;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  align-self: stretch;
  background: radial-gradient(800px 420px at 70% -20%, rgba(127, 140, 255, 0.2), transparent 60%), #0d1222;
}

@media (max-width: 1220px) and (min-width: 821px) {
  #app-main {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  }
  .header-pills {
    gap: 0.35rem;
  }
  .hpill {
    padding: 4px 8px;
    font-size: 0.6rem;
  }
}

@media (max-width: 1040px) and (min-width: 821px) {
  #app-header {
    padding: 0 0.8rem;
    gap: 0.6rem;
  }
  .logo {
    font-size: 1.12rem;
  }
  .logo-icon {
    width: 27px;
    height: 27px;
    font-size: 13px;
  }
  .search-wrap input {
    font-size: 0.82rem;
    padding: 9px 84px 9px 34px;
  }
  .search-btn {
    padding: 6px 10px;
    font-size: 0.68rem;
  }
  .search-icon-left {
    left: 11px;
    font-size: 13px;
  }
  .geo-btn {
    padding: 7px 9px;
    font-size: 0.66rem;
  }
  .header-pills .hpill:last-child {
    display: none;
  }
}

/* Fill the map column so tiles/canvas match sidebar height (no gray strip) */
#gmap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100% !important;
  min-height: 100% !important;
  z-index: 0;
  background: #0d1222;
}

/* Leaflet / Mapbox often default to a white canvas — force dark fill so no strip shows through */
#gmap .leaflet-container,
.leaflet-container {
  height: 100% !important;
  min-height: 100% !important;
  width: 100% !important;
  background: #0d1222 !important;
}
.mapboxgl-map,
.mapboxgl-canvas {
  background: #0d1222 !important;
}

/* ── Responsive ── */
@media (max-width: 820px) {
  #app-main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 42vh) minmax(0, 1fr);
    top: var(--header-h);
    bottom: 0;
  }
  .header-pills .hpill:last-child { display: none; }
  .search-wrap { max-width: none; }
  .sidebar {
    border-right: none;
    border-top: 1px solid var(--border);
    min-height: 0;
    max-height: 100%;
  }
  /* Leave room for lot cards: filters scroll in top block */
  .sidebar-top {
    max-height: min(36vh, 260px);
  }
  .map-wrap {
    height: 100%;
    max-height: 100%;
    min-height: 0;
  }
  #gmap {
    position: absolute;
    inset: 0;
    height: 100%;
    min-height: 0;
  }
}

@media (max-width: 700px) {
  :root {
    --header-h: 112px;
  }
  #app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "logo geo"
      "search search";
    align-items: center;
    gap: 0.5rem 0.6rem;
    padding: 0.5rem 0.7rem;
    height: var(--header-h);
  }
  .logo {
    grid-area: logo;
    min-width: 0;
    font-size: 1.15rem;
  }
  .search-wrap {
    grid-area: search;
    width: 100%;
    max-width: none;
  }
  .search-wrap input {
    padding-right: 94px;
  }
  .geo-btn {
    grid-area: geo;
    justify-self: end;
  }
  .header-pills {
    display: none;
  }
  .sidebar-top {
    max-height: min(40vh, 300px);
  }
}

@media (max-width: 500px) {
  .logo-usa { display: none; }
  :root {
    --header-h: 106px;
  }
  #app-header { padding: 0.45rem 0.55rem; gap: 0.45rem; }
  .logo {
    font-size: 1rem;
    gap: 6px;
  }
  .logo-icon {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }
  .header-pills { display: none; }
  .search-btn {
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    margin-top: 0;
    width: auto;
    padding: 6px 10px;
    font-size: 0.68rem;
  }
  .search-wrap input {
    padding-right: 84px;
    font-size: 0.84rem;
  }
  .search-wrap { display: block; }
  .search-icon-left { top: 50%; transform: translateY(-50%); }
  .geo-btn { padding: 7px 8px; font-size: 0.68rem; }
  #app-main {
    grid-template-rows: minmax(170px, 38vh) minmax(0, 1fr);
  }
  .sidebar-top {
    padding: 0.85rem 0.75rem 0.65rem;
    max-height: min(42vh, 280px);
  }
  .list-header {
    padding: 0.6rem 0.75rem 0.4rem;
  }
  .lot-list {
    padding: 0.5rem;
  }
}

@media (max-height: 760px) {
  #app-main {
    min-height: 0;
  }
  .sidebar-top {
    max-height: min(34vh, 250px);
  }
}
