*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:   #1e3a5f;
  --blue:   #2563eb;
  --blue-l: #dbeafe;
  --green:  #16a34a;
  --gray-1: #f1f5f9;
  --gray-2: #e2e8f0;
  --gray-3: #94a3b8;
  --gray-4: #475569;
  --text:   #0f172a;
  --white:  #ffffff;
  --radius: 6px;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--gray-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100dvh;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost  { background: rgba(255,255,255,.15); color: var(--white); }
.btn-ghost:hover { background: rgba(255,255,255,.25); }
.btn-outline { background: var(--white); color: var(--gray-4); border: 1px solid var(--gray-2); }
.btn-outline:hover { background: var(--gray-1); }
.icon-btn {
  width: 36px; height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  font-size: 20px;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }

/* ── Header ── */
header {
  background: var(--navy);
  color: var(--white);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header h1 span { color: #93c5fd; font-weight: 400; }

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-row input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  background: rgba(255,255,255,.15);
  color: var(--white);
  min-width: 0;
}
.search-row input::placeholder { color: #93c5fd; }
.search-row input:focus { outline: 2px solid #60a5fa; background: rgba(255,255,255,.2); }

.search-row select {
  height: 38px;
  padding: 0 8px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  background: rgba(255,255,255,.15);
  color: var(--white);
  cursor: pointer;
  max-width: 130px;
}
.search-row select option { background: #1e3a5f; color: #fff; }

/* Desktop tabs */
.tabs {
  display: flex;
  gap: 4px;
}
.tab-btn {
  height: 30px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  background: transparent;
  color: #93c5fd;
  transition: background .15s;
}
.tab-btn.active { background: rgba(255,255,255,.18); color: var(--white); }
.tab-btn:hover:not(.active) { background: rgba(255,255,255,.1); }

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
aside {
  width: 210px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--gray-2);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
aside h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-3);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 500; color: var(--gray-4); }
.field input, .field select {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--gray-2);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  width: 100%;
  background: var(--white);
}
.field input:focus, .field select:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

.range-row { display: flex; gap: 6px; align-items: center; }
.range-row span { color: var(--gray-3); font-size: 12px; flex-shrink: 0; }
.range-row input { min-width: 0; }

aside .btn { width: 100%; }
#filter-tab-panel { display: none; flex-direction: column; gap: 14px; }
#search-hint { display: flex; flex-direction: column; gap: 6px; }

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.results-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--gray-2);
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 40px;
}
.results-count { font-size: 13px; color: var(--gray-4); }
.results-count strong { color: var(--text); }

/* Mobile filter button (hidden on desktop) */
#mobile-filter-btn { display: none; }

/* ── Table ── */
.table-wrap { flex: 1; overflow: auto; }

table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--gray-1);
  border-bottom: 2px solid var(--gray-2);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-4);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--gray-2);
  cursor: pointer;
  transition: background .1s;
}
tbody tr:hover { background: var(--blue-l); }
tbody tr.selected { background: #bfdbfe; }

td {
  padding: 9px 12px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.county-tag { color: var(--navy); font-weight: 500; }
td.mono { font-family: ui-monospace, monospace; font-size: 12px; }

/* ── Pagination ── */
.pagination {
  padding: 8px 14px;
  border-top: 1px solid var(--gray-2);
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.page-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border: 1px solid var(--gray-2);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
}
.page-btn:hover { background: var(--gray-1); }
.page-btn.active { background: var(--blue); color: var(--white); border-color: var(--blue); }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-info { font-size: 12px; color: var(--gray-3); margin-left: auto; }

/* ── Detail panel ── */
#detail-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--white);
  border-left: 1px solid var(--gray-2);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
#detail-panel.open { display: flex; }

.detail-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-2);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.detail-head h3 { font-size: 14px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close-btn {
  width: 28px; height: 28px;
  border: none;
  background: var(--gray-1);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: var(--gray-4);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.close-btn:hover { background: var(--gray-2); }

#map { height: 200px; flex-shrink: 0; background: var(--gray-2); }

.detail-body { flex: 1; overflow-y: auto; padding: 12px 14px; }
.detail-row {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--gray-1);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 120px; flex-shrink: 0; color: var(--gray-4); font-size: 12px; padding-top: 2px; }
.detail-value { flex: 1; word-break: break-word; }
.detail-value.mono { font-family: ui-monospace, monospace; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: 11px; font-weight: 500; }
.badge-blue  { background: var(--blue-l); color: var(--blue); }
.badge-green { background: #dcfce7; color: var(--green); }

/* ── Empty / loading ── */
.state-msg { text-align: center; padding: 48px 20px; color: var(--gray-3); }
.state-msg svg { display: block; margin: 0 auto 12px; }
.state-msg p { font-size: 14px; line-height: 1.5; max-width: 280px; margin: 0 auto; }
.no-geom {
  height: 200px;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-3); font-size: 13px; background: var(--gray-1);
}

/* ── Mobile overlay for sidebar ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 40;
}
.sidebar-overlay.open { display: block; }

/* ════════════════════════════════════════════════════════
   MOBILE  (≤ 700px)
   ════════════════════════════════════════════════════════ */
@media (max-width: 700px) {

  body { overflow: hidden; }

  /* Header: stack search below title row */
  header { padding: 10px 12px; gap: 8px; }
  .tabs { display: none; }          /* use filter button instead */

  .search-row select { display: none; } /* county select moves to filter panel */
  .search-row .btn { padding: 0 12px; font-size: 13px; height: 38px; }

  #mobile-filter-btn {
    display: flex;
    flex-shrink: 0;
    background: rgba(255,255,255,.15);
    border: none;
    border-radius: var(--radius);
    color: var(--white);
    height: 38px;
    padding: 0 10px;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
  }
  #mobile-filter-btn:hover { background: rgba(255,255,255,.25); }

  /* Sidebar: slide in from left as overlay */
  aside {
    position: fixed;
    left: -240px;
    top: 0;
    bottom: 0;
    width: 240px;
    z-index: 50;
    transition: left .25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.2);
    overflow-y: auto;
    padding-top: 54px; /* below mobile header close button */
  }
  aside.open { left: 0; }

  .sidebar-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px; height: 32px;
    background: var(--gray-1);
    border: none;
    border-radius: 50%;
    font-size: 20px;
    color: var(--gray-4);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }

  #search-hint { display: none; }
  #filter-tab-panel { display: flex !important; }

  /* Detail panel: full-screen bottom sheet */
  #detail-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 60;
    border-left: none;
  }
  #detail-panel.open { display: flex; }
  #map { height: 240px; }

  /* Table: fewer visible columns */
  thead th:nth-child(4),   /* City */
  thead th:nth-child(5),   /* Zoning */
  td:nth-child(4),
  td:nth-child(5) { display: none; }

  td { padding: 10px 8px; font-size: 13px; }
  thead th { padding: 8px 8px; }

  .pagination { gap: 3px; padding: 8px; }
  .page-btn { height: 32px; min-width: 32px; font-size: 13px; }
  .page-info { display: none; }
}
