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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #f8fafc;
  color: #1e293b;
}

/* ── Header ─────────────────────────────────────── */

header {
  background: #1e293b;
  color: #f1f5f9;
  padding: 0.75rem 1.25rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#header-left h1 {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, #f0f0f0 0%, #909090 50%, #d0d0d0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter:
    drop-shadow(-1px -1px 0 #111)
    drop-shadow( 1px -1px 0 #111)
    drop-shadow(-1px  1px 0 #111)
    drop-shadow( 1px  1px 0 #111);
}

#header-left p {
  font-size: 0.78rem;
  color: #94a3b8;
  margin-top: 2px;
}

#header-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#header-nav a {
  font-size: 0.82rem;
  color: #94a3b8;
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid #334155;
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#header-nav a:hover {
  color: #f1f5f9;
  border-color: #64748b;
}

.yt-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Main layout ─────────────────────────────────── */

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#map {
  flex: 0 0 60%;
  height: 100%;
  z-index: 1;
}

#sidebar {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid #e2e8f0;
}

#sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}

#filter-heading {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.75rem;
}

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

#sidebar-title-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

#inventory-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
}

#item-count {
  font-size: 0.78rem;
  color: #64748b;
}

.filter-pill {
  font-size: 0.72rem;
  font-family: inherit;
  padding: 3px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #475569;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.filter-pill:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.filter-pill.active {
  background: var(--pill-color, #1e293b);
  color: #f1f5f9;
  border-color: var(--pill-color, #1e293b);
}

/* SVG teardrop map pins — reset Leaflet's default div background */
.map-marker {
  background: transparent;
  border: none;
}

#table-container {
  overflow-y: auto;
  flex: 1;
}

/* ── Status messages ─────────────────────────────── */

.status-msg {
  padding: 2rem;
  text-align: center;
  color: #64748b;
  font-size: 0.875rem;
}

/* ── Yard sections ───────────────────────────────── */

.yard-section {
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  transition: background 0.15s;
}

.yard-section.active {
  background: #eff6ff;
  border-left: 3px solid #3b82f6;
}

.yard-section.collapsed .vehicle-table,
.yard-section.collapsed .yard-footer {
  display: none;
}

.yard-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  user-select: none;
}

.yard-header:hover {
  background: #f1f5f9;
}

.yard-chevron {
  color: #94a3b8;
  font-size: 1.1rem;
  display: inline-block;
  transition: transform 0.2s ease;
  line-height: 1;
  flex-shrink: 0;
}

.yard-section:not(.collapsed) .yard-chevron {
  transform: rotate(90deg);
}

.yard-name {
  font-weight: 600;
  font-size: 0.875rem;
  flex: 1;
}

.chain-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chain-badge.pullapart {
  background: #fee2e2;
  color: #991b1b;
}

.chain-badge.pullnsave {
  background: #dcfce7;
  color: #166534;
}

.yard-count {
  font-size: 0.75rem;
  color: #64748b;
  white-space: nowrap;
}

.yard-address {
  font-size: 0.775rem;
  color: #64748b;
  padding: 0 1rem 0.5rem;
}

/* ── Vehicle table ───────────────────────────────── */

.vehicle-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.775rem;
}

.vehicle-table th {
  background: #334155;
  color: #f1f5f9;
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
  font-weight: 500;
}

.vehicle-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.vehicle-table tr:last-child td {
  border-bottom: none;
}

.vehicle-table tr:hover td {
  background: #f8fafc;
}

.vin {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  color: #475569;
}

/* ── Print button ────────────────────────────────── */

.yard-footer {
  padding: 0.5rem 1rem 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.print-btn,
.directions-btn {
  font-size: 0.75rem;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
}

.print-btn {
  background: #334155;
  color: #f1f5f9;
  border: none;
}

.print-btn:hover {
  background: #1e293b;
}

.directions-btn {
  background: #fff;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.directions-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

/* ── Leaflet popup ───────────────────────────────── */

.popup-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.popup-chain {
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 4px;
}

.popup-address {
  font-size: 0.78rem;
  color: #475569;
  margin-bottom: 6px;
}

.popup-vehicle-list {
  list-style: none;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.popup-vehicle-list li {
  padding: 2px 0;
  border-bottom: 1px solid #f1f5f9;
}

.popup-vehicle-list li:last-child {
  border-bottom: none;
}

.popup-footer {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 4px;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 768px) {
  body {
    overflow: auto;
    height: auto;
  }

  main {
    flex-direction: column;
    overflow: visible;
  }

  #map {
    flex: none;
    height: 50vh;
    width: 100%;
  }

  #sidebar {
    flex: none;
    width: 100%;
    overflow: visible;
  }

  #table-container {
    overflow: visible;
  }
}
