/* ============================================================
   template_filter.css — Shared "Shelf" search + filter bar.
   Used by /kundangan (server mode) and /dashboard (client mode)
   so every template-search surface shares the same layout.
   Tokens fall back to the kdg defaults so it works on both the
   storefront and the dashboard shell.
   ============================================================ */

.tmpl-shelf {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .625rem;
  margin-bottom: 1.25rem;
}

/* ─── Toolbar row ──────────────────────────────────────────── */
.tmpl-shelf__bar {
  display: flex;
  gap: .625rem;
  align-items: stretch;
  flex-wrap: wrap;
}

/* The search field stretches, the pills sit beside it. */
.tmpl-shelf .tmpl-search--shelf { flex: 1 1 260px; max-width: none; }
.tmpl-shelf .tmpl-search--shelf .tmpl-search__field {
  height: 100%;
  min-height: 44px;
  border-radius: 12px;
}
.tmpl-shelf .tmpl-search--shelf .tmpl-search__input { padding: .5625rem 0; }

.tmpl-shelf__tools {
  display: flex;
  gap: .375rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ─── Pills ────────────────────────────────────────────────── */
.tmpl-popwrap { position: relative; }
.tmpl-pill {
  display: inline-flex;
  align-items: center;
  gap: .4375rem;
  height: 44px;
  padding: 0 .875rem;
  background: var(--kdg-color-surface, #fff);
  border: 1.5px solid var(--kdg-color-border-strong, #d9d9de);
  border-radius: 12px;
  font-size: .8125rem;
  font-weight: 600;
  font-family: var(--kdg-font-family-sans, inherit);
  color: var(--kdg-color-text-primary, #1f2024);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.tmpl-pill:hover { border-color: var(--kdg-color-text-tertiary, #8a8f99); }
.tmpl-pill.is-on { border-color: var(--kdg-color-text-primary, #1f2024); background: var(--kdg-color-state-neutral-soft, #f1f1f4); }
.tmpl-pill__caret { font-size: .5625rem; color: var(--kdg-color-text-tertiary, #8a8f99); transition: transform .15s ease; }
.tmpl-pill[aria-expanded="true"] .tmpl-pill__caret { transform: rotate(180deg); }
.tmpl-pill__badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--kdg-color-brand-primary, #ff5555);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
}
.tmpl-pill__badge[hidden] { display: none; }

/* ─── Popover ──────────────────────────────────────────────── */
.tmpl-pop {
  position: absolute;
  top: calc(100% + .4375rem);
  right: 0;
  z-index: 80;
  width: 280px;
  max-width: 78vw;
  background: var(--kdg-color-surface, #fff);
  border: 1px solid var(--kdg-color-border-subtle, #ececef);
  border-radius: var(--kdg-radius-md, 14px);
  box-shadow: 0 20px 48px -16px rgba(15, 23, 42, .22), 0 2px 0 rgba(15, 23, 42, .04);
  padding: .625rem;
  animation: tmpl-pop-in .16s cubic-bezier(.2, .7, .2, 1);
}
.tmpl-pop[hidden] { display: none; }
@keyframes tmpl-pop-in {
  from { opacity: 0; transform: translateY(-5px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tmpl-pop__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 8px;
}
.tmpl-pop__head b {
  font-size: .6875rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--kdg-color-text-secondary, #5b6068);
  font-weight: 700;
}
.tmpl-pop__clear {
  background: none;
  border: none;
  color: var(--kdg-color-text-tertiary, #8a8f99);
  font-size: .71875rem;
  font-weight: 600;
  font-family: var(--kdg-font-family-sans, inherit);
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.tmpl-pop__clear:hover { color: var(--kdg-color-brand-primary, #ff5555); }
.tmpl-pop__list {
  max-height: 250px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior: contain;
}
.tmpl-pop__foot {
  border-top: 1px solid var(--kdg-color-border-subtle, #ececef);
  margin-top: 8px;
  padding-top: 9px;
}
.tmpl-pop__apply {
  width: 100%;
  border: none;
  border-radius: 10px;
  background: var(--kdg-color-text-primary, #1f2024);
  color: #fff;
  padding: 9px;
  font-size: .78125rem;
  font-weight: 700;
  font-family: var(--kdg-font-family-sans, inherit);
  cursor: pointer;
  transition: background .15s ease;
}
.tmpl-pop__apply:hover { background: #111; }

/* Facet rows (native checkbox, styled) */
.tmpl-fopt {
  display: flex;
  align-items: center;
  gap: .5625rem;
  padding: 7px 9px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s ease;
  position: relative;
}
.tmpl-fopt:hover { background: var(--kdg-color-state-neutral-soft, #f1f1f4); }
.tmpl-fopt input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}
.tmpl-fopt__box {
  width: 17px;
  height: 17px;
  border: 1.5px solid var(--kdg-color-border-strong, #d9d9de);
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  color: transparent;
  transition: all .12s ease;
}
.tmpl-fopt input:checked ~ .tmpl-fopt__box {
  background: var(--kdg-color-brand-primary, #ff5555);
  border-color: var(--kdg-color-brand-primary, #ff5555);
  color: #fff;
}
.tmpl-fopt input:focus-visible ~ .tmpl-fopt__box {
  outline: 2px solid var(--kdg-color-brand-primary, #ff5555);
  outline-offset: 1px;
}
.tmpl-fopt__label { flex: 1; font-size: .8125rem; font-weight: 550; color: var(--kdg-color-text-primary, #1f2024); }
.tmpl-fopt__count {
  font-size: .71875rem;
  font-style: normal;
  font-weight: 600;
  color: var(--kdg-color-text-tertiary, #8a8f99);
}
.tmpl-fopt:has(input:checked) .tmpl-fopt__label { font-weight: 650; }

/* ─── Sort ─────────────────────────────────────────────────── */
.tmpl-sort {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--kdg-color-text-tertiary, #8a8f99);
  white-space: nowrap;
}
.tmpl-sort select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--kdg-color-border-strong, #d9d9de);
  background: var(--kdg-color-surface, #fff);
  border-radius: 9px;
  padding: 7px 28px 7px 10px;
  font-size: .78125rem;
  font-weight: 600;
  font-family: var(--kdg-font-family-sans, inherit);
  color: var(--kdg-color-text-primary, #1f2024);
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235b6068' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.tmpl-sort select:focus { outline: 2px solid rgba(255, 85, 85, .35); outline-offset: 1px; }

/* ─── Count + active chips ─────────────────────────────────── */
.tmpl-shelf__count {
  font-size: .78125rem;
  font-weight: 600;
  color: var(--kdg-color-text-tertiary, #8a8f99);
}
.tmpl-shelf__active {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .375rem;
  animation: tmpl-shelf-fade .25s ease both;
}
.tmpl-shelf__active[hidden] { display: none; }
@keyframes tmpl-shelf-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tmpl-shelf__active-label {
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--kdg-color-text-tertiary, #8a8f99);
  margin-right: 2px;
}
.tmpl-active-chip {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  background: var(--kdg-color-text-primary, #1f2024);
  color: #fff;
  border: none;
  padding: 5px 10px 5px 12px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  font-family: var(--kdg-font-family-sans, inherit);
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease;
}
.tmpl-active-chip:hover { background: #111; transform: translateY(-1px); color: #fff; }
.tmpl-active-chip i { font-style: normal; opacity: .75; }
.tmpl-active-chip i:hover { opacity: 1; }
.tmpl-active-clear {
  background: none;
  border: none;
  color: var(--kdg-color-text-tertiary, #8a8f99);
  font-size: .75rem;
  font-weight: 600;
  font-family: var(--kdg-font-family-sans, inherit);
  padding: 5px 8px;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}
.tmpl-active-clear:hover { color: var(--kdg-color-brand-primary, #ff5555); }

/* Hidden cards/columns — used by both surfaces (client filter + search). */
.tmpl-card.is-hidden,
[data-tmpl-col].is-hidden { display: none !important; }

/* Recovery chip on the zero-result state (brand variant). */
.tmpl-facet-chip--brand {
  background: var(--kdg-color-brand-primary, #ff5555) !important;
  border-color: var(--kdg-color-brand-primary, #ff5555) !important;
  color: #fff !important;
}
.tmpl-facet-chip--brand:hover {
  background: var(--kdg-color-brand-primary-hover, #ff3d3d) !important;
}

/* ─── Responsive: pills become a swipeable rail ────────────── */
@media (max-width: 720px) {
  .tmpl-shelf__bar { gap: .5rem; }
  .tmpl-shelf__tools {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .tmpl-popwrap { flex-shrink: 0; }
  .tmpl-pop { right: auto; left: 0; }
  .tmpl-sort { flex-shrink: 0; }
  .tmpl-shelf .tmpl-search--shelf .tmpl-search__field { min-height: 42px; }
  .tmpl-pill { height: 40px; }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .tmpl-pop { animation: none; }
  .tmpl-shelf__active { animation: none; }
}
