/* CasTech Query Filters: base filter controls without forcing a section background. */
.ctf-query-filters {
  --ctf-accent: #f7941d;
  --ctf-text: #111827;
  --ctf-border: #cfd4dc;
  --ctf-checkbox-columns: 3;
  --ctf-label-font-size: 15px;
  --ctf-heading-font-size: 16px;
  --ctf-search-width: 280px;
  --ctf-search-height: 38px;
  --ctf-gap: 14px;

  color: var(--ctf-text);
  display: flex;
  gap: calc(var(--ctf-gap) * 2);
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: transparent;
}


/* Wide/full alignment support for the root filter block. */
.wp-block-castech-query-filters.alignwide,
.wp-block-castech-query-filters.alignfull {
  max-width: none;
}

/* When filters sit left and search sits right, align the search panel to the lower edge of the filter group. */
.ctf-query-filters.ctf-layout-filters-left-search-right {
  align-items: flex-end;
}

.ctf-query-filters.ctf-layout-filters-left-search-right .ctf-search-panel {
  justify-content: flex-end;
  align-self: stretch;
  padding-bottom: 2px;
}

/* Layout option: stack all filter controls vertically. */
.ctf-query-filters.ctf-layout-stacked {
  flex-direction: column;
}

/* Layout option: search appears first, then filter choices. */
.ctf-query-filters.ctf-layout-search-top {
  flex-direction: column;
}

.ctf-query-filters.ctf-layout-search-top .ctf-search-panel {
  order: -1;
}

/* Filter group container. */
.ctf-filter-panel {
  flex: 1 1 auto;
  min-width: 0;
}

/* Search group container. */
.ctf-search-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

/* Filter heading. */
.ctf-filter-heading {
  font-size: var(--ctf-heading-font-size);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 12px;
}

/* Checkbox layout uses CSS grid so the editor setting can control column count. */
.ctf-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(var(--ctf-checkbox-columns), minmax(0, 1fr));
  gap: var(--ctf-gap);
}

/* Individual checkbox labels. */
.ctf-checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--ctf-label-font-size);
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  user-select: none;
}

/* Native checkbox styled with the brand accent color. */
.ctf-checkbox-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ctf-accent);
  flex: 0 0 auto;
}

/* Rectangular search field. */
.ctf-search-input {
  width: var(--ctf-search-width);
  max-width: 100%;
  height: var(--ctf-search-height);
  min-height: var(--ctf-search-height);
  border: 1px solid var(--ctf-border);
  border-radius: 0;
  padding: 0 10px;
  box-sizing: border-box;
  color: var(--ctf-text);
  background: #fff;
  font: inherit;
  font-size: var(--ctf-label-font-size);
  line-height: 1;
}

.ctf-search-input:focus {
  border-color: var(--ctf-accent);
  outline: 2px solid color-mix(in srgb, var(--ctf-accent) 30%, transparent);
  outline-offset: 1px;
}

/* Button and clear link row. */
.ctf-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* Hide the apply button when auto submit is enabled, while keeping form behavior available without JS. */
.ctf-auto-submit-enabled .ctf-submit-button {
  display: none;
}

.ctf-submit-button {
  border: 1px solid var(--ctf-accent);
  border-radius: 0;
  background: var(--ctf-accent);
  color: #111;
  cursor: pointer;
  font-size: var(--ctf-label-font-size);
  font-weight: 700;
  min-height: var(--ctf-search-height);
  padding: 0 14px;
}

.ctf-clear-link {
  color: var(--ctf-text);
  font-size: var(--ctf-label-font-size);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ctf-clear-link:hover,
.ctf-clear-link:focus {
  color: var(--ctf-accent);
}

/* Mobile reset: stack search and checkboxes cleanly. */
@media (max-width: 782px) {
  .ctf-query-filters {
    flex-direction: column;
    gap: 18px;
  }

  .ctf-search-panel,
  .ctf-search-input {
    width: 100%;
  }

  .ctf-checkbox-grid {
    grid-template-columns: 1fr;
  }
}


/* AJAX refresh state for connected native Query Loop results. */
.ctf-query-results {
  position: relative;
}

.ctf-query-results.ctf-is-loading {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 160ms ease-in-out;
}

.ctf-query-results.ctf-is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.28);
  z-index: 1;
}


/* Editor-only helper styling for the manual page selection panel. */
.ctf-page-search-results,
.ctf-selected-pages {
  margin-top: 10px;
}

.ctf-page-search-result,
.ctf-selected-page {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #e0e0e0;
}

.ctf-page-search-result span,
.ctf-selected-page span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ctf-selected-page-actions {
  display: inline-flex;
  gap: 4px;
  flex: 0 0 auto;
}

.ctf-page-selector-loading {
  margin: 8px 0;
}


/* v13: Keep the AJAX results target in the DOM without letting it constrain the native Query Loop grid. */
.ctf-query-results {
  display: contents;
}

/* Because display: contents is layout-neutral, the native Query Loop keeps its own width and grid behavior. */
.ctf-query-results > .wp-block-query {
  width: 100%;
  max-width: none;
}


/* v14: Stable AJAX target that preserves native Query Loop width without using display: contents. */
.ctf-query-results {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box;
}

/* Preserve theme wide/full alignment on the AJAX target. */
.ctf-query-results.alignwide {
  width: 100% !important;
  max-width: var(--wp--style--global--wide-size, 1200px) !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

.ctf-query-results.alignfull {
  width: 100% !important;
  max-width: none !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* Let the wrapped native Query Loop fill the AJAX target. */
.ctf-query-results > .wp-block-query,
.ctf-query-results .wp-block-query,
.ctf-query-results .wp-block-post-template {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box;
}

/* Keep Gutenberg grid columns from collapsing into skinny columns. */
.ctf-query-results .wp-block-post-template.is-layout-grid {
  display: grid !important;
  justify-content: stretch !important;
}
