/* Page layout */
.inventory-page {
  padding-top: var(--space-6);
  padding-bottom: var(--space-8);
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Sticks the toolbar, filter panel, and results bar to the top of the
   scrolling main area so they stay visible while the unit grid scrolls. */
.inventory-sticky-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-bg);
  padding-top: var(--space-6);
  margin-top: calc(var(--space-6) * -1);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

/* Toolbar: filters toggle (left) / search (center) / view toggle + add unit (right) */
.toolbar {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 480px) 1fr;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.toolbar-left {
  justify-self: start;
}

.toolbar-center {
  justify-self: stretch;
}

.toolbar-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.filters-toggle-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.filters-toggle-btn .filter-count {
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Filter panel: collapsible, opened by the Filters toggle */
.filter-panel {
  display: none;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.filter-panel.open {
  display: flex;
}

.filter-panel select,
.filter-panel .filter-select {
  width: auto;
  min-width: 140px;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-size: var(--font-size-sm);
  border-color: var(--color-border);
}

.filter-panel .range-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-panel .range-group input {
  width: 100px;
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-size: var(--font-size-sm);
}

.filter-panel .range-group span {
  color: var(--color-text-faint);
  font-size: var(--font-size-sm);
}

.filter-dropdown {
  position: relative;
}

.filter-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.filter-dropdown-caret {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

.filter-dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3) var(--space-4);
  z-index: var(--z-popover);
}

.filter-dropdown-panel.open {
  display: block;
}

.filter-dropdown-row {
  padding: 6px 0;
}

.filter-dropdown-range {
  display: flex;
  gap: var(--space-3);
  width: 220px;
}

.filter-dropdown-range .field {
  margin-bottom: 0;
  flex: 1;
}

.filter-dropdown-range input {
  width: 100%;
}

.filter-panel .checkbox-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  cursor: pointer;
}

.filter-panel .checkbox-pill input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

/* Floating Map/Sort pill + Add-Unit FAB, and the Sort popover it opens —
   mobile-only, built by inventoryPage.js and shown via the
   max-width:640px block below. */
.mobile-floating-bar,
.mobile-fab,
.mobile-sort-popover,
.mobile-popover-backdrop {
  display: none;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--color-surface-alt);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}

.view-toggle button {
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.view-toggle button.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* Card grid - desktop-first, responsive columns */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-5);
}

@media (max-width: 1100px) {
  .unit-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 800px) {
  .unit-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.unit-card {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
}

.unit-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.unit-card .card-photo {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--color-surface-alt);
  overflow: hidden;
}

.unit-card .card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-photo-carousel {
  width: 100%;
  height: 100%;
}

.card-photo-carousel > div:first-child {
  width: 100%;
  height: 100%;
}

/* Nav arrows/dots only make sense on the full-width mobile card (enabled in
   the max-width:640px block below) — hidden here so the desktop grid keeps
   its current compact look even though every card now renders this markup. */
.card-photo-nav {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  color: var(--color-text);
  padding: 0;
}

.card-photo-prev {
  left: var(--space-3);
}

.card-photo-next {
  right: var(--space-3);
}

.card-photo-nav svg {
  width: 18px;
  height: 18px;
}

.card-photo-dots {
  display: none;
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  gap: 6px;
  z-index: 2;
}

.card-photo-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
}

.card-photo-dot.active {
  background: #fff;
}

.card-title-line {
  display: none;
}

.card-contact-row {
  display: none;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.card-contact-row .agent-btn {
  flex: 1;
}

.unit-card .card-photo .no-photo {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  background: var(--color-surface-alt);
}

/* Code + status stacked in one corner (instead of side-by-side) so they
   never collide on narrow cards. */
.unit-card .card-photo-topleft {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  right: calc(var(--space-3) + 36px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.unit-card .card-photo .code-chip {
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-text);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-card .card-photo .status-badge {
  max-width: 100%;
  font-size: 10px;
  padding: 4px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-card .card-photo .status-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.unit-card .card-photo .favourite-btn {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-text);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  z-index: 1;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.unit-card .card-photo .favourite-btn svg {
  width: 16px;
  height: 16px;
}

.unit-card .card-photo .favourite-btn:hover {
  background: #ffffff;
}

.favourite-group-popover {
  z-index: var(--z-modal, 1000);
  width: 220px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.favourite-group-popover-title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.favourite-group-popover-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}

.favourite-group-option {
  text-align: left;
  background: var(--color-surface-alt);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  cursor: pointer;
}

.favourite-group-option:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.favourite-group-option.active {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

.favourite-group-option.active:hover {
  background: var(--color-primary-dark);
  color: #fff;
}

.favourite-group-popover-new {
  display: flex;
  gap: 6px;
}

.favourite-group-new-input {
  flex: 1;
  min-width: 0;
}

.favourite-group-skip {
  align-self: center;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-decoration: underline;
  cursor: pointer;
  padding: 2px;
}

/* A unit can be in several client groups at once, so these stack instead
   of a single chip. */
.favourite-group-chip-stack {
  position: absolute;
  bottom: var(--space-3);
  right: var(--space-3);
  max-width: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.favourite-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-radius: var(--radius-pill);
  padding: 4px 6px 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  max-width: 100%;
}

.favourite-group-chip > :first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favourite-group-chip-remove {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.6);
  color: var(--color-primary-dark);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.favourite-group-chip-remove:hover {
  background: #fff;
}

.unit-card .card-photo .agent-chip {
  position: absolute;
  bottom: var(--space-3);
  left: var(--space-3);
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-text);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-card .card-photo .broker-chip {
  position: absolute;
  bottom: var(--space-3);
  right: var(--space-3);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  white-space: nowrap;
}

.unit-card .card-body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.unit-card .card-price {
  font-size: var(--font-size-lg);
  font-weight: 800;
  color: var(--color-primary-dark);
}

.unit-card .card-compound {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* Results bar: match count (left) + pagination controls (right), one row */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.results-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.sort-controls {
  display: flex;
  align-items: center;
}

.sort-group-row {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  padding: 2px;
}

.sort-group-row .pagination-select {
  height: 30px;
  border: none;
  box-shadow: none;
  background: transparent;
  border-radius: var(--radius-pill);
}

.sort-group-row .pagination-select + .pagination-select {
  border-left: 1px solid var(--color-border);
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.pagination-bottom {
  margin-top: var(--space-6);
}

.results-count {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.pagination-select {
  width: 130px;
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: var(--font-size-xs, 12px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pagination-select:hover {
  border-color: var(--color-border-strong);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: 130px;
  height: 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 0 6px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.pager-btn {
  min-width: 26px;
  height: 26px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text);
  font-size: var(--font-size-xs, 12px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.pager-btn:hover:not(:disabled) {
  background: var(--color-surface-alt);
}

.pager-btn:disabled {
  color: var(--color-text-faint);
  cursor: default;
}

.pager-nav {
  color: var(--color-text-muted);
  font-weight: 500;
}

.pager-num.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.pager-ellipsis {
  color: var(--color-text-faint);
  font-size: var(--font-size-xs, 12px);
  padding: 0 2px;
}

/* Results area: fills remaining vertical space so the map can go edge-to-edge */
#results {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Split view: unit list + map side by side */
#results.split-view {
  flex-direction: row;
  gap: var(--space-4);
}

.split-list {
  width: 400px;
  flex-shrink: 0;
  overflow-y: auto;
  padding-right: var(--space-1);
}

.split-list .unit-grid {
  grid-template-columns: 1fr;
}

.split-map {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Map view */
.map-shell {
  position: relative;
  /* Establishes a local stacking context so the Leaflet pane z-indices below
     (up to 700) stay contained here and can never outrank page-level UI like
     modals — without this, position:relative alone doesn't isolate them. */
  z-index: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 480px;
}

#leaflet-map {
  width: 100%;
  height: 100%;
}

/* Defensive reinforcement: guarantee the popup/pin panes always paint above
   the tile layer and our own floating map-note, regardless of stacking
   context quirks introduced by the marker-cluster plugin or the browser. */
.leaflet-popup-pane {
  z-index: 700 !important;
}

.leaflet-marker-pane,
.leaflet-marker-shadow-pane {
  z-index: 600 !important;
}

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

.map-note {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-4);
  z-index: 500;
  background: var(--color-surface);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.map-pin-popover {
  min-width: 220px;
}

.map-pin-popover .popover-price {
  font-weight: 800;
  color: var(--color-primary-dark);
  font-size: var(--font-size-md);
  margin-bottom: 4px;
}

.map-pin-popover .popover-compound {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  margin-bottom: var(--space-2);
}

.map-type-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  padding: 3px;
  gap: 2px;
}

.map-type-btn {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.map-type-btn.active {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.leaflet-div-icon.unit-pin {
  background: var(--color-primary);
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  width: 26px;
  height: 26px;
  box-shadow: var(--shadow-md);
}

/* Marker clusters — restyle the plugin's default yellow theme to match brand */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: var(--color-primary-light);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
}

/* Responsive */
@media (max-width: 900px) {
  .toolbar {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }
  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    justify-self: stretch;
  }
  .filter-panel.open {
    flex-direction: column;
    align-items: stretch;
  }
  .map-shell {
    height: 480px;
  }
  #results.split-view {
    flex-direction: column;
  }
  .split-list {
    width: 100%;
    max-height: 400px;
  }
}

@media (max-width: 600px) {
  .unit-grid {
    grid-template-columns: 1fr;
  }
  .container {
    padding: 0 var(--space-4);
  }
}

@media (max-width: 640px) {
  .inventory-page {
    padding-top: var(--space-4);
    /* Clears the floating Map/Sort pill + Add-Unit FAB so they never cover
       the last card's contact row or the map's own controls. */
    padding-bottom: 96px;
  }

  .inventory-sticky-header {
    /* The mobile topbar (js/sidebar.js's .mobile-topbar) is also sticky at
       top:0 and paints above this (z-index 100 vs 5) — without this offset
       it covers the first ~65px of this header once both are pinned. */
    top: 65px;
    padding-top: var(--space-4);
    margin-top: calc(var(--space-4) * -1);
  }

  /* Search stretches from the left; Filters stays a small pill on the
     right, both on one row — .toolbar's grid (set above at 900px) would
     otherwise stack every toolbar section onto its own row. */
  .toolbar {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: var(--space-2);
  }

  .toolbar-center {
    flex: 1;
    min-width: 0;
    order: -1;
  }

  .toolbar-left {
    width: auto;
    flex: 0 0 auto;
  }

  /* Same fixed height on both so the search pill and Filters button line
     up seamlessly instead of the button being visibly shorter. */
  .search-pill,
  .filters-toggle-btn {
    height: 44px;
  }

  .search-pill {
    padding: 0 4px 0 16px;
  }

  .filters-toggle-btn {
    width: auto;
    padding: 0 14px;
    font-size: var(--font-size-xs);
  }

  /* List/Split/Map + Add Unit move out of the sticky toolbar and into the
     floating pill + FAB (below) so the toolbar itself stays compact. */
  .toolbar-right {
    display: none;
  }

  .mobile-floating-bar {
    display: flex;
    position: fixed;
    bottom: var(--space-5);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-surface);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: var(--z-popover);
  }

  .mobile-pill-btn {
    border: none;
    background: transparent;
    padding: 12px 20px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-text);
    cursor: pointer;
  }

  .mobile-pill-btn + .mobile-pill-btn {
    border-left: 1px solid var(--color-border);
  }

  .mobile-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: var(--z-popover);
  }

  .mobile-popover-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(43, 38, 34, 0.4);
    z-index: var(--z-drawer-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-popover-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sort-popover {
    display: block;
    position: fixed;
    left: var(--space-4);
    right: var(--space-4);
    bottom: calc(var(--space-5) + 62px);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    z-index: var(--z-drawer);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
  }

  .mobile-sort-popover.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .mobile-sort-popover-title {
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-2);
  }

  .mobile-sort-popover-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .mobile-sort-popover-row .sort-controls {
    flex: 1;
    min-width: 0;
  }

  .mobile-sort-popover .pagination-select {
    width: 100%;
  }

  .sort-dir-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    font-weight: 700;
    cursor: pointer;
  }

  .sort-dir-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-primary-contrast);
  }

  /* Bottom pagination: keep unit count + Prev/Next, drop the numbered
     page buttons for a minimal, compact bar. */
  .pagination-bottom {
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-4);
  }

  .pagination-bottom .pagination-select {
    width: auto;
    height: 30px;
    font-size: var(--font-size-xs);
    padding: 0 var(--space-2);
  }

  .pagination-bottom .pager {
    height: 30px;
    min-width: 0;
    padding: 0 4px;
  }

  .pagination-bottom .pager-num,
  .pagination-bottom .pager-ellipsis {
    display: none;
  }

  .pagination-bottom .pager-btn {
    font-size: var(--font-size-xs);
    padding: 0 var(--space-2);
  }

  .filter-panel.open {
    padding: var(--space-3);
    gap: var(--space-2);
  }

  .filter-panel select,
  .filter-panel .filter-select,
  .filter-dropdown {
    width: 100%;
    min-width: 0;
  }

  .filter-panel select,
  .filter-panel .filter-select {
    padding: 8px 12px;
    font-size: var(--font-size-xs);
  }

  .filter-dropdown-btn {
    justify-content: space-between;
  }

  .filter-dropdown-panel {
    left: 0;
    right: 0;
    width: auto;
    min-width: 0;
  }

  .filter-dropdown-range {
    width: auto;
  }

  .filter-panel .checkbox-pill {
    width: 100%;
    padding: 7px 10px;
    font-size: var(--font-size-xs);
  }

  .results-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .results-count {
    font-size: var(--font-size-xs);
  }

  /* Sort moved to the floating Sort popover on mobile — the inline
     dropdown row would otherwise duplicate it right above the list. */
  .results-controls {
    display: none;
  }

  /* Card redesign: full-bleed photo carousel + prominent price, matching the
     agreed reference layout. Chrome (toolbar/pills/buttons above) stays
     compact — only the listing content itself gets bigger here. */
  .unit-card .card-photo {
    aspect-ratio: 4 / 3;
  }

  .card-photo-nav {
    display: flex;
  }

  .card-photo-dots {
    display: flex;
  }

  .unit-card .card-photo .favourite-btn {
    top: auto;
    bottom: var(--space-3);
    right: var(--space-3);
  }

  /* The +/add button moves to the bottom on mobile, so the top-left stack
     no longer needs to leave room for it up top. */
  .unit-card .card-photo-topleft {
    right: var(--space-3);
  }

  .unit-card .card-body {
    padding: var(--space-4);
    gap: var(--space-2);
  }

  .unit-card .card-price {
    font-size: var(--font-size-xl);
  }

  .stat-row {
    font-size: var(--font-size-sm);
    color: var(--color-text);
  }

  .card-title-line {
    display: block;
    font-weight: 700;
    font-size: var(--font-size-base);
  }

  .card-compound {
    margin-bottom: 0;
  }

  .card-contact-row {
    display: flex;
  }

  /* .map-shell inherits `flex: 1` (flex-basis: 0%) from the desktop rule
     above, which — now that .main-area is auto-height on mobile instead of a
     fixed 100vh flex column — collapses an otherwise-empty container (the
     Leaflet div has no content of its own to size against) to ~0 height.
     min-height alone doesn't fix this because flex-basis still starts at 0;
     flex: none makes height/min-height apply the normal, non-flex way. */
  .map-shell {
    flex: none;
    width: 100%;
    height: 360px;
    min-height: 320px;
  }

  .split-list {
    max-height: 320px;
  }
}

/* "New" corner ribbon — shown for a month after a unit is added. */
.unit-card .card-photo { overflow: hidden; }
.unit-card .new-ribbon {
  position: absolute;
  bottom: 14px;
  right: -34px;
  width: 120px;
  transform: rotate(-45deg);
  transform-origin: center;
  background: var(--color-primary);
  color: #fff;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 0;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 2;
}
