/* =========================
   CE Projects Listing (PML)
   Merged: Plugin + HFCM
========================= */

/* Root wrapper */
.ce-pml {
  --ce-gap: 16px;
  --ce-border: #DEE2E6;
  --ce-muted: #6C757D;
  --ce-card-bg: #E9ECEF;
  --ce-radius: 3px;

  width: 100%;
}

/* Two-column layout (left list + right map) */
.ce-pml__inner {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: var(--ce-gap);
  height: calc(100dvh - clamp(4.96125rem, 4.5671rem + 1.4014vw, 6.24875rem));
}

/* LEFT column */
.ce-pml__list {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 32px 64px 24px 64px;
  height: 100%;
  overflow-y: auto;
}

/* Header */
.ce-pml__header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.ce-pml__title {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

/* Toolbar */
.ce-pml__toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
  width: 100%;
}

/* Search (merged: keep your HFCM background + padding + border overrides,
   plus plugin width + focus behavior) */
.ce-pml__search {
  width: min(420px, 100%);
  background-color: #E9ECEF !important;
  padding: 0.60em 1em !important;
  border: 1px solid var(--ce-border);
  border-color: #E9ECEF !important;
  border-radius: 10px;
  outline: none;
}

.ce-pml__search:focus {
  border-color: #6C757D;
}

/* Optional toggle button (kept from HFCM even if you don’t use it yet) */
.ce-pml__filters-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--ce-border);
  background: #F8F9FA;
  cursor: pointer;
  border-radius: 10px;
  white-space: nowrap;
}

.ce-pml__filters-toggle:hover {
  border-color: #CED4DA;
}

/* =========================
   Filters
========================= */

.ce-pml__filters {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px 10px 8px;
}

.ce-pml__filter {
  border: 1px solid #CED4DA;
  background: #DEE2E6;
  padding: 0.4em 0.7em;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}

.ce-pml__filter:hover {
  background: #CED4DA;
}

.ce-pml__filter.is-active {
  background: #6C757D;
  color: #F8F9FA;
  border-color: #6C757D;
}

.ce-pml__filters-mobile {
  display: none;
  width: 100%;
  margin-top: 12px;
  padding: 8px;
}

/* =========================
   Cards Grid + Columns
========================= */

.ce-pml__cards {
  display: grid;
  gap: 16px;
}

/* Columns based on data-ce-cols from shortcode */
.ce-pml[data-ce-cols="1"] .ce-pml__cards { grid-template-columns: repeat(1, 1fr); }
.ce-pml[data-ce-cols="2"] .ce-pml__cards { grid-template-columns: repeat(2, 1fr); }
.ce-pml[data-ce-cols="3"] .ce-pml__cards { grid-template-columns: repeat(3, 1fr); }
.ce-pml[data-ce-cols="4"] .ce-pml__cards { grid-template-columns: repeat(4, 1fr); }
.ce-pml[data-ce-cols="5"] .ce-pml__cards { grid-template-columns: repeat(5, 1fr); }
.ce-pml[data-ce-cols="6"] .ce-pml__cards { grid-template-columns: repeat(6, 1fr); }

/* Card (merged: keep plugin structure + HFCM background/border/radius/hover) */
.ce-pml-card {
  position: relative;
  background: var(--ce-card-bg);
  border: 1px solid var(--ce-border);
  border-radius: var(--ce-radius);
  overflow: hidden;
  transition: background 0.2s ease;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.ce-pml-card:hover {
  background: #DEE2E6;
}

.ce-pml-card__link {
  color: inherit;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.ce-pml-card__media {
  width: 100%;
}

/* Make sure featured image behaves like your plugin CSS intended */
.ce-pml-card__media img {
  height: auto;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  object-position: center;
}

/* Content */
.ce-pml-card__content {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}

.ce-pml-card__title {
  margin: 0 0 6px;
  font-size: clamp(1rem, 0.9809rem + 0.068vw, 1.0625rem) !important;
  line-height: 1.25;
}

.ce-pml-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--ce-muted);
  margin-bottom: 4px;
}

/* Featured label/border */
.ce-pml-card.is-featured {
  border: 2px solid #d63638;
}

.ce-pml-card.is-featured::before {
  content: "Featured";
  position: absolute;
  top: 10px;
  left: 10px;
  background: #212529;
  color: #F8F9FA;
  font-size: clamp(0.79rem, 0.8359rem + -0.1633vw, 0.64rem);
  padding: 4px 8px;
  border-radius: 3px;
  z-index: 2;
}

/* Highlighted card */
.ce-pml-card.is-highlighted {
  outline: 2px solid #d63638;
  transition: outline 0.3s ease;
}

.ce-pml-card__btn {
    font-size: clamp(0.79rem, 0.8359rem + -0.1633vw, 0.64rem);
    padding: 0.4em 0.8em;
    background-color: #212529;
    color: #f8f9fa;
    width: fit-content;
    margin-top: auto;
}

/* =========================
   Divider
========================= */

.ce-pml__divider {
  grid-column: 1 / -1;
  height: 1px;
  background: rgba(0,0,0,0.15);
  margin: 32px 0;
}

/* =========================
   Loading State
========================= */

.ce-pml__cards.is-loading {
  opacity: 0.4;
  pointer-events: none;
}

.ce-pml__cards.is-loading::after {
  content: "Loading projects…";
  display: block;
  padding: 40px;
  text-align: center;
  color: #999;
  font-size: 14px;
}

/* =========================
   Empty State
========================= */

.ce-pml__empty {
  padding: 20px;
  text-align: center;
  color: var(--ce-muted);
  border: 1px dashed var(--ce-border);
  border-radius: var(--ce-radius);
}

/* =========================
   Map wrap
========================= */

.ce-pml__map-wrap {
  min-width: 0;
}

.ce-pml__map-canvas {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border-radius: 12px;
  background: #f2f2f2;
  border: 1px dashed var(--ce-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ce-muted);
  font-size: 14px;
}

/* =========================
   Map popup
========================= */

.ce-map-popup img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
  margin-bottom: 6px;
}

.ce-map-popup__category {
  font-size: 11px;
  text-transform: uppercase;
  color: #999;
  margin-bottom: 4px;
}

.ce-map-popup__title {
  font-weight: 600;
  margin-bottom: 4px;
}

.ce-map-popup__location {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
}

.ce-map-popup__link {
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
}

.ce-map-popup.is-featured {
  border-left: 4px solid #d63638;
}

.ce-map-popup.is-featured .ce-map-popup__title {
  color: #d63638;
}

.ce-map-popup__slider {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.ce-map-popup__slider img {
  width: 100%;
  max-width: 220px;
  border-radius: 4px;
  scroll-snap-align: start;
}

/* MapLibre controls */
button.maplibregl-ctrl-zoom-in,
button.maplibregl-ctrl-zoom-out,
button.maplibregl-ctrl-compass,
button.maplibregl-ctrl-geolocate {
  background: #fff !important;
  padding: 0 7px !important;
}

span.maplibregl-ctrl-icon {
  width: 20px !important;
  height: 20px !important;
}

/* =========================
   Responsive
========================= */

@media (max-width: 1366px) {
  .ce-pml__inner {
    grid-template-columns: 0.95fr 1fr;
  }

  .ce-pml[data-ce-cols="3"] .ce-pml__cards,
  .ce-pml[data-ce-cols="4"] .ce-pml__cards,
  .ce-pml[data-ce-cols="5"] .ce-pml__cards,
  .ce-pml[data-ce-cols="6"] .ce-pml__cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1024px) {
  .ce-pml__inner {
    grid-template-columns: 1fr;
  }

  .ce-pml__list {
    padding: 24px 48px 24px 48px;
  }

  .ce-pml__toolbar {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .ce-pml__search {
    width: 100%;
  }

  .ce-pml__map-canvas {
    min-height: 360px;
  }
}

@media (max-width: 768px) {
  .ce-pml__filters {
    display: none;
  }
  .ce-pml__filters-mobile {
    display: block;
  }
}

@media (max-width: 767px) {
  .ce-pml[data-ce-cols="3"] .ce-pml__cards,
  .ce-pml[data-ce-cols="4"] .ce-pml__cards,
  .ce-pml[data-ce-cols="5"] .ce-pml__cards,
  .ce-pml[data-ce-cols="6"] .ce-pml__cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .ce-pml__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .ce-pml__inner {
    height: auto;
  }

  .ce-pml__cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .ce-pml__list {
    padding: 24px 24px 64px 24px;
  }

  .ce-pml__list,
  .ce-pml__map-wrap {
    height: 100dvh;
  }
}

@media (max-width: 520px) {

  /* Default: show list, hide map */
  .ce-pml__map-wrap { display: none; }

  /* When toggled: show map, hide list */
  .ce-pml.ce-show-map .ce-pml__map-wrap { display: block; }
  .ce-pml.ce-show-map .ce-pml__list { display: none; }

  /* Fixed bottom-center toggle */
  .ce-pml__mobile-toggle {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 98;
    display: inline-flex;
    gap: 6px;
    padding: 8px;
    border-radius: 3px;
    border: 1px solid #CED4DA;
    background: #E9ECEF;
    cursor: pointer;
  }

  .ce-pml__mobile-toggle .ce-toggle-pill {
    padding: 7px 13px;
    border-radius: 3px;
    color: #6C757D;
    font-size: 14px;
    white-space: nowrap;
  }

  .ce-pml__mobile-toggle .ce-toggle-pill.is-active {
    background: #343A40;
    color: #F8F9FA;
  }
}
