.dwr-wrap {
  font-family: var(--wp--preset--font-family--body, sans-serif);
  position: relative;
}
.dwr-wrap[data-layout="page"] {
  /* ไม่ cap ความกว้างเอง (direction #1) — client ครอบผ่าน Page editor */
}
.dwr-wrap[data-layout="header"] {
  display: inline-flex;
  flex-direction: column;
  width: auto;
  max-width: 100%;
  transition: width 0.28s ease;
}
.dwr-wrap[data-layout="header"].is-open {
  width: 100%;
  flex: 1 1 auto;
}

.dwr-wrap .dwr-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  outline: none;
  box-sizing: border-box;
}
.dwr-wrap .dwr-input:focus {
  border-color: var(--wp--preset--color--contrast-3);
  box-shadow: 0 0 0 3px rgba(7, 145, 218, 0.15);
}

.dwr-wrap .dwr-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dwr-wrap[data-layout="page"] .dwr-results {
  margin-top: 12px;
}
.dwr-wrap[data-layout="header"] .dwr-results {
  position: static;
  max-height: none;
  overflow-y: visible;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.dwr-wrap .dwr-doc {
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: var(--wp--preset--color--base);
  transition: box-shadow 0.15s;
}
.dwr-wrap .dwr-doc:hover {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.dwr-wrap .dwr-doc-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--wp--preset--color--contrast-3);
  margin-bottom: 4px;
}
.dwr-wrap .dwr-doc h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}
.dwr-wrap .dwr-doc p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--wp--preset--color--contrast-2);
  line-height: 1.5;
}
.dwr-wrap .dwr-doc a {
  font-size: 13px;
  color: var(--wp--preset--color--contrast);
  text-decoration: none;
  font-weight: 500;
}
.dwr-wrap .dwr-doc a:hover {
  text-decoration: underline;
}

.dwr-wrap .dwr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.dwr-wrap .dwr-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: #fef3c7;
  color: var(--wp--preset--color--tag-amber);
  font-weight: 500;
}
.dwr-wrap .dwr-cat {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--wp--preset--color--background-alt);
  color: var(--wp--preset--color--contrast-2);
  font-weight: 500;
}

.dwr-wrap .dwr-msg {
  font-size: 14px;
  color: var(--wp--preset--color--contrast-2);
  padding: 8px 0;
}

/* ── Pagination (page layout) ────────────────────────────────────── */
.dwr-wrap .dwr-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}
.dwr-wrap .dwr-pagination:empty {
  margin-top: 0;
}
.dwr-wrap .dwr-page-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--wp--preset--color--contrast);
  background: var(--wp--preset--color--base);
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.dwr-wrap .dwr-page-btn:hover:not(:disabled) {
  background: var(--wp--preset--color--base-2);
  border-color: var(--wp--preset--color--contrast-2);
}
.dwr-wrap .dwr-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.dwr-wrap .dwr-page-status {
  font-size: 13px;
  color: var(--wp--preset--color--contrast-2);
}

/* ── Header layout: bar (trigger + expanding panel) ─────────────── */
.dwr-wrap[data-layout="header"] .dwr-header-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.dwr-wrap[data-layout="header"] .dwr-search-trigger {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  color: var(--wp--preset--color--contrast);
  transition:
    background 0.15s,
    border-color 0.15s;
}
.dwr-wrap[data-layout="header"] .dwr-search-trigger:hover {
  background: var(--wp--preset--color--base-2);
  border-color: var(--wp--preset--color--contrast-2);
}
.dwr-wrap[data-layout="header"] .dwr-icon-close {
  display: none;
}
.dwr-wrap[data-layout="header"].is-open .dwr-icon-search {
  display: none;
}
.dwr-wrap[data-layout="header"].is-open .dwr-icon-close {
  display: block;
}

/* ── Expanding search panel ──────────────────────────────────────── */
.dwr-wrap[data-layout="header"] .dwr-header-panel {
  flex: 0 0 auto;
  width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition:
    flex-basis 0.28s ease,
    width 0.28s ease,
    opacity 0.2s ease;
}
.dwr-wrap[data-layout="header"].is-open .dwr-header-panel {
  flex: 1 1 auto;
  width: 100%;
  opacity: 1;
  pointer-events: auto;
}

/* ── Advanced filters + results dropdown ─────────────────────────── */
.dwr-wrap[data-layout="header"] .dwr-header-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--wp--preset--color--base);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  box-sizing: border-box;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.dwr-wrap[data-layout="header"].is-open .dwr-header-dropdown {
  display: block;
}

/* ── Advanced search accordion ─────────────────────────────────── */
.dwr-advanced-search {
  margin-top: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.dwr-advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--wp--preset--color--contrast);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.dwr-advanced-toggle::-webkit-details-marker {
  display: none;
}
.dwr-advanced-toggle:hover {
  background: var(--wp--preset--color--base-2);
}
.dwr-advanced-search[open] .dwr-chevron {
  transform: rotate(180deg);
}
.dwr-chevron {
  margin-left: auto;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.dwr-advanced-fields {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #e5e7eb;
}

/* ── Filter field groups ────────────────────────────────────────── */
.dwr-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dwr-field-row {
  display: flex;
  gap: 12px;
}
.dwr-field-group--half {
  flex: 1;
}
.dwr-field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--wp--preset--color--contrast-2);
}
.dwr-field-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  box-sizing: border-box;
  color: var(--wp--preset--color--accent-4);
}
.dwr-field-input:focus {
  border-color: var(--wp--preset--color--contrast-3);
  box-shadow: 0 0 0 3px rgba(7, 145, 218, 0.15);
}
select.dwr-field-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235A6169' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}
input.dwr-field-input[type="date"] {
  min-height: 38px;
  font-family: inherit;
  cursor: text;
}

/* ── Advanced filter actions (ล้างค่า / ค้นหา) ───────────────────── */
.dwr-field-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.dwr-filter-btn {
  padding: 8px 20px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 6px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    opacity 0.15s;
}
.dwr-filter-reset {
  color: var(--wp--preset--color--contrast-2);
  background: var(--wp--preset--color--base);
  border: 1px solid #d1d5db;
}
.dwr-filter-reset:hover {
  background: var(--wp--preset--color--base-2);
  border-color: var(--wp--preset--color--contrast-2);
}
.dwr-filter-apply {
  color: var(--wp--preset--color--base, #fff);
  background: var(--wp--preset--color--contrast-3);
  border: 1px solid var(--wp--preset--color--contrast-3);
}
.dwr-filter-apply:hover {
  opacity: 0.88;
}
.dwr-filter-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(7, 145, 218, 0.25);
}

/* ── Field color indicators (matches result chip colors) ────────── */
.dwr-field-label--tag::after,
.dwr-field-label--category::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-left: 5px;
  vertical-align: middle;
}
.dwr-field-label--tag::after {
  background: #fef3c7;
  border: 1.5px solid var(--wp--preset--color--luminous-vivid-orange);
}
.dwr-field-label--category::after {
  background: #dbeafe;
  border: 1.5px solid var(--wp--preset--color--contrast-2);
}
.dwr-field--tag:focus {
  border-color: var(--wp--preset--color--tag-amber);
  box-shadow: 0 0 0 3px rgba(146, 64, 14, 0.12);
}
.dwr-field--category:focus {
  border-color: var(--wp--preset--color--contrast-2);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12);
}

/* ── Results inside header dropdown ──────────────────────────────── */
.dwr-header-dropdown .dwr-results {
  margin-top: 14px;
}

/* ── "View all" link (header layout) ─────────────────────────────── */
.dwr-wrap[data-layout="header"] .dwr-view-all {
  display: block;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--wp--preset--color--contrast-3);
  text-decoration: none;
}
.dwr-wrap[data-layout="header"] .dwr-view-all:hover {
  text-decoration: underline;
}

/* ── Mobile ───────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .dwr-wrap[data-layout="header"] .dwr-header-dropdown {
    left: -8px;
    right: -8px;
    max-height: calc(100vh - 100px);
  }
  .dwr-field-row {
    flex-wrap: wrap;
  }
  .dwr-field-group--half {
    min-width: calc(50% - 6px);
  }
  .dwr-filter-btn {
    flex: 1;
    padding: 10px 12px;
  }
}
