/**
 * FooGallery Image Filter Modal
 * File: wp-content/themes/genesis-sample/css/filter-modal.css
 *
 * v2.0 — paged 3×3 grid using PO-table markup; click commits + closes.
 *        Footer/Apply/Clear styles removed (no longer needed).
 * v2.0.5 — trigger button turns black with white text when a filter is active.
 * v2.1.0 — "Filter & Sort" master toggle button; all filters hidden on load.
 * v2.1.1 — hover/focus locked into base selector to prevent outside CSS override.
 */

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --fm-overlay:        rgba(10, 14, 20, 0.82);
  --fm-modal-bg:       #ffffff;
  --fm-border:         #e2e2e2;
  --fm-brand:          #000;
  --fm-accent:         #8a51a5;
  --fm-accent-light:   #000;
  --fm-text:           #fff;
  --fm-text-mid:       #555555;
  --fm-radius:         4px;
  --fm-modal-radius:   8px;
  --fm-transition:     0.18s ease;
  --fm-shadow:         0 20px 60px rgba(0,0,0,0.22), 0 4px 16px rgba(0,0,0,0.10);
}

/* ── Filter & Sort master button ────────────────────────────────────────── */
.fm-filter-sort-btn,
.fm-filter-sort-btn:hover,
.fm-filter-sort-btn:focus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 24px;
  background: #fff;
  border: 2px solid #000;
  border-radius: 0;
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  color: #000;
  transition: background var(--fm-transition), color var(--fm-transition),
              border-color var(--fm-transition);
  box-sizing: border-box;
  margin-bottom: 8px;
}

/* Active state (any filter selected) — black button, white text */
.fm-filter-sort-btn.fm-has-filters,
.fm-filter-sort-btn.fm-has-filters:hover,
.fm-filter-sort-btn.fm-has-filters:focus {
  background: #000 !important;
  color: #fff !important;
  border-color: #000 !important;
}

.fm-filter-sort-btn.fm-has-filters .fm-fs-label {
  color: #fff !important;
}

.fm-filter-sort-btn .fm-fs-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-image: url('https://www.pivotdoorcompany.com/wp-content/themes/genesis-sample/images/clear-filter.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Swap to white icon when button is black — no hover change */
.fm-filter-sort-btn.fm-has-filters .fm-fs-icon {
  background-image: url('https://www.pivotdoorcompany.com/wp-content/themes/genesis-sample/images/clear-filter-white.svg');
}

/* ── Hide the original FooGallery dropdown content ──────────────────────── */
.fg-toolbar-item-dropdown .fg-toolbar-item-dropdown-content,
.foogallery-filtering-dropdown-content {
  display: none !important;
}

/* ── Trigger button (replaces the native <select>) ──────────────────────── */
.fm-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  padding: 9px 18px;
  background: #ffffff;
  border: 1.5px solid var(--fm-border);
  border-radius: var(--fm-radius);
  color: var(--fm-text);
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color var(--fm-transition), box-shadow var(--fm-transition);
  white-space: nowrap;
  position: relative;
}

.fm-trigger:hover {
  border-color: var(--fm-accent);
  box-shadow: 0 2px 8px rgba(46, 117, 182, 0.12);
}

.fm-trigger.fm-active {
  border-color: var(--fm-accent);
  background: #000 !important;
  color: #fff !important;
}

.fm-trigger.fm-active .fm-trigger-label {
  color: #fff !important;
}

.fm-trigger-label {
  flex: 1;
  text-align: left;
  color: inherit;
  cursor: inherit;
  font-size: 16px;
  font-family: inherit;
  line-height: inherit;
  text-transform: uppercase;
  font-weight: 700 !important;
}

/* Native FooGallery SVG arrow — rotates 180° when modal is open */
.fm-trigger .fg-tag-dropdown-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform var(--fm-transition);
}

.fm-trigger.fm-open .fg-tag-dropdown-icon {
  transform: rotate(180deg);
}

/* ── Overlay ────────────────────────────────────────────────────────────── */
.fm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--fm-overlay);
  z-index: 1000000; /* above the page header (z-index: 999999) */
  opacity: 0;
  transition: opacity 0.22s ease;
}

.fm-overlay.fm-visible { display: block; }
.fm-overlay.fm-in      { opacity: 1; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.fm-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%);
  z-index: 1000001; /* one above the overlay, both above the header */
  background: var(--fm-modal-bg);
  border-radius: var(--fm-modal-radius);
  box-shadow: var(--fm-shadow);
  width: min(550px, 92vw);
  /* Height grows to fit content (so both chevrons + 3 rows fit without
     scrolling), capped only by the viewport. */
  max-height: 95vh;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.fm-modal.fm-visible {
  display: flex;
}

.fm-modal.fm-in {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* ── Modal header ───────────────────────────────────────────────────────── */
.fm-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  flex-shrink: 0;
}

.fm-modal-title {
  font-family: 'Roboto', sans-serif;
  font-size: 18px;
  color: var(--fm-brand);
  letter-spacing: 0.02em;
  margin: 0;
}

.fm-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  color: var(--fm-text-mid);
  font-size: 20px;
  line-height: 1;
  transition: background var(--fm-transition), color var(--fm-transition);
  padding: 0;
}

.fm-modal-close:hover {
  background: #f0f0f0;
  color: var(--fm-text);
}

/* ── Modal body ─────────────────────────────────────────────────────────── */
.fm-modal-body {
  overflow-y: auto;
  padding: 24px;
  flex: 1;
}

/* ── Paged table layout (PO-* classes shared with the rest of the site) ── */
/* Scoped to .fm-modal-body so we don't leak rules to the existing PO modal
   on other pages. If the site already styles .PO-table globally, those rules
   will still apply alongside these. */
.fm-modal-body .PO-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 8px;
  margin: 0 auto;
}

.fm-modal-body .PO-table-td {
  vertical-align: top;
  text-align: center;
  cursor: pointer;
  padding: 0;
  width: 33.33%;
}

.fm-modal-body .image-border {
  display: inline-block;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: var(--fm-radius);
  transition: border-color var(--fm-transition);
  width: 100%;
  box-sizing: border-box;
}

.fm-modal-body .PO-image-notselected { border-color: transparent; }
.fm-modal-body .PO-image-selected    { border-color: var(--fm-accent); }
.fm-modal-body .image-border:hover   { border-color: var(--fm-accent); }

.fm-modal-body .image-border img {
  display: inline-block;
  max-width: 100%;
  height: auto;
}

.fm-modal-body .wood-text-box {
  margin-top: 6px;
  text-align: center;
}

.fm-modal-body .wood-title {
  font-size: 12px;
  font-family: 'Roboto', sans-serif;
  color: #000;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  font-weight: 600;
}

.fm-modal-body .wood-subtitle {
  font-size: 8px;
  font-family: 'Roboto', sans-serif;
  color: #000;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  font-weight: 400;
  margin-top: 1px;
}

/* Chevron rows — make sure the cursor reads as clickable */
.fm-modal-body .PO-table tr td img[src*="pivot-chevron"] {
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
}

/* ── Map-regions layout (e.g. Region) ───────────────────────────────────── */
.fm-map-container {
  text-align: center;
  margin-bottom: 16px;
}

.fm-map-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: var(--fm-radius);
}

.fm-map-regions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.fm-map-region-btn,
.fm-map-region-btn:hover,
.fm-map-region-btn:focus {
  padding: 8px 18px;
  border: 2px solid #000;
  border-radius: 0;
  background: #fff;
  color: #000;
  font-family: 'Roboto', sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  cursor: pointer;
  transition: background var(--fm-transition), color var(--fm-transition);
}

.fm-map-region-btn:hover,
.fm-map-region-btn.fm-map-region-selected {
  background: #000 !important;
  color: #fff !important;
}

/* ── Radio-groups layout (e.g. Sizing) ──────────────────────────────────── */
.fm-radio-columns {
  display: flex;
  gap: 24px;
}

.fm-radio-col {
  flex: 1;
  min-width: 0;
}

.fm-radio-col-header {
  font-family: 'Roboto', sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #000;
  margin-bottom: 6px;
}

.fm-radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  cursor: pointer;
  border-radius: var(--fm-radius);
  transition: background var(--fm-transition);
}

.fm-radio-row:hover {
  background: #f5f5f5;
}

.fm-radio-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--fm-border);
  flex-shrink: 0;
  transition: border-color var(--fm-transition), background var(--fm-transition);
  position: relative;
  box-sizing: border-box;
}

.fm-radio-btn.fm-radio-checked {
  border-color: var(--fm-brand);
  background: var(--fm-brand);
}

.fm-radio-btn.fm-radio-checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.fm-radio-label {
  font-family: 'Roboto', sans-serif;
  font-size: 13px;
  color: #000;
  font-weight: 400;
  line-height: 1.3;
}

.fm-radio-row.fm-radio-selected .fm-radio-label {
  font-weight: 700;
}

/* ── Text-only tile (no image, e.g. Sizing) ─────────────────────────────── */
.fm-text-tile {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 10px;
  font-family: 'Roboto', sans-serif;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #000;
  text-align: center;
  line-height: 1.35;
}

/* ── Fallback tile when an image file is missing ────────────────────────── */
.fm-item-fallback {
  width: 100%;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fm-accent-light);
  color: var(--fm-brand);
  font-family: 'Georgia', serif;
  font-size: 11px;
  text-align: center;
  padding: 6px;
  line-height: 1.2;
  word-break: break-word;
}

/* ── Region DOM-filter fallback ─────────────────────────────────────────── */
/* Applied by JS to .fg-item elements that don't match the selected region.  */
.fm-region-hidden {
  display: none !important;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .fm-modal-header,
  .fm-modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .fm-modal-body .PO-table {
    border-spacing: 6px;
  }

  .fm-modal-body .wood-title {
    font-size: 12px;
  }
}