/* ══════════════════════════════════════════════════════════════════════════════
   Knowledge Hub  ·  knowledge-hub.css
   Loaded only on the knowledge-hub page slug.
   Depends on dynamic-pages.css (.wrap, footer, body resets).
══════════════════════════════════════════════════════════════════════════════ */

/* ── Page shell ─────────────────────────────────────────────────────────────── */
.kh-page {
  --kh-section-gap: 56px;
  /* Card image accent strip height */
  --kh-img-h: 72px;

  --bg: #fff;
  --text: #0b1220;
  --muted: #5b677a;
  --border: rgba(15,23,42,.10);
  --brand: #F97316;
  --brand2: #EA580C;

  padding-bottom: 80px;
}

/* ── Masthead ────────────────────────────────────────────────────────────────── */
.kh-masthead {
  padding: 52px 0 44px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}

.kh-masthead__eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .10em;
  color: #9a3412;
}

.kh-masthead__title {
  margin: 0 0 10px;
  font-size: clamp(30px, 4.5vw, 46px);
  line-height: 1.08;
  letter-spacing: -.03em;
  color: var(--text);
}

.kh-masthead__lead {
  margin: 0 0 32px;
  font-size: clamp(15px, 1.8vw, 17px);
  line-height: 1.6;
  color: var(--muted);
  max-width: 52ch;
}

/* ── Controls row (search + filter) ─────────────────────────────────────────── */
.kh-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* ── Search ─────────────────────────────────────────────────────────────────── */
.kh-search__field {
  position: relative;
  display: flex;
  align-items: center;
  width: 320px;
}

.kh-search__icon {
  position: absolute;
  left: 13px;
  color: var(--muted);
  pointer-events: none;
}

.kh-search__input {
  width: 100%;
  height: 42px;
  padding: 0 36px 0 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  box-shadow: 0 1px 3px rgba(15,23,42,.06);
  transition: border-color .18s, box-shadow .18s;
  appearance: none;
  -webkit-appearance: none;
}
.kh-search__input::placeholder { color: #94a3b8; }
.kh-search__input::-webkit-search-cancel-button,
.kh-search__input::-webkit-search-decoration { display: none; }
.kh-search__input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(249,115,22,.12);
}

.kh-search__clear {
  position: absolute;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  transition: background .15s, color .15s;
}
.kh-search__clear:hover { background: #f1f5f9; color: var(--text); }
.kh-search__clear[hidden] { display: none; }

/* ── Filter dropdown (nav-style) ─────────────────────────────────────────── */
.kh-filter-dropdown {
  position: static;
  display: inline-block;
}

/* Trigger */
.kh-filter-trigger {
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text);
  transition: color .2s ease, background .2s ease;
}
.kh-filter-trigger:hover {
  background: #f1f5f9;
  color: #0b1220;
}

/* Underline animation on trigger text — mirrors .nav-dropdown-trigger-text */
.kh-filter-trigger-text {
  position: relative;
}
.kh-filter-trigger-text::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform .25s ease;
}
.kh-filter-dropdown.open .kh-filter-trigger-text::before { transform: scaleX(1); }

/* Arrow state — mirrors .nav-dropdown.open arrow swap */
.kh-filter-dropdown.open .nav-arrow-down { opacity: 0; }
.kh-filter-dropdown.open .nav-arrow-up  { opacity: 1; }

/* Panel — mirrors .nav-dropdown-menu */
.kh-filter-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 10px;
  min-width: min(760px, calc(100vw - 40px));
  width: max-content;
  max-width: min(920px, calc(100vw - 40px));
  overflow: visible;
  padding: 12px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0;
  box-shadow: 0 12px 40px rgba(15,23,42,.12), 0 4px 12px rgba(15,23,42,.06);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  z-index: 30;
}
.kh-filter-dropdown.open .kh-filter-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.kh-filter-menu-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 28px;
  padding: 0 4px;
}

.kh-filter-column {
  flex: 1 1 180px;
  min-width: 180px;
  max-width: 240px;
}

.kh-filter-column--reset {
  flex: 0 0 140px;
  min-width: 140px;
  max-width: 160px;
}

/* Section subheadings — mirrors .nav-dropdown-menu .nav-dropdown-subhead */
.kh-filter-subhead {
  display: block;
  min-height: 2.6em;
  padding: 4px 12px 8px;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
  white-space: normal;
}

/* Options — mirrors .nav-dropdown-menu .nav-dropdown-item */
.kh-filter-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  margin: 4px 0;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  border-radius: 10px;
  transition: background .2s ease, color .2s ease;
  line-height: 1.3;
  white-space: normal;
}
.kh-filter-option:hover,
.kh-filter-option--active {
  background: rgba(249,115,22,.08);
  color: var(--brand);
}

/* "All articles" reset option — slightly softer weight */
.kh-filter-option--all {
  font-weight: 500;
  color: var(--muted);
}

/* ── Section ─────────────────────────────────────────────────────────────────── */
.kh-filter-clear {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin: 8px 0 0;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.3;
  transition: color .2s ease;
}
.kh-filter-clear:hover {
  color: var(--brand);
}

.kh-section {
  margin-bottom: var(--kh-section-gap);
}
.kh-section[hidden] { display: none; }

/*
  Section heading: styled like videos & tutorials section titles —
  clamp(22px→30px), with a brand gradient vertical bar before the text.
*/
.kh-section__title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 0 20px;
  font-size: clamp(22px, 2.6vw, 30px);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
  color: var(--text);
}
.kh-section__title::before {
  content: "";
  flex-shrink: 0;
  width: 4px;
  height: 1.1em;
  border-radius: 2px;
  background: var(--kh-color, var(--brand));
}

/* ── Carousel ────────────────────────────────────────────────────────────────── */
.kh-carousel {
  position: relative;
}

.kh-carousel__track {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* Side breathing room — cards never touch the viewport edges */
  padding: 0 20px;
  scroll-padding-left: 20px;
}
.kh-carousel__track::-webkit-scrollbar { display: none; }

/* ── Nav arrows ──────────────────────────────────────────────────────────────── */
.kh-carousel__btn {
  position: absolute;
  top: calc(var(--kh-img-h) / 2); /* centre over the image strip */
  transform: translateY(-50%);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(15,23,42,.16);
  transition: box-shadow .2s, transform .2s;
}
.kh-carousel__btn:hover {
  box-shadow: 0 8px 24px rgba(15,23,42,.22);
  transform: translateY(-50%) scale(1.1);
}
.kh-carousel__btn--prev { left: 10px; }
.kh-carousel__btn--next { right: 10px; }
.kh-carousel__btn[hidden] { display: none; }

/* ── Cards — title-focused, 5 per page ──────────────────────────────────────── */
.kh-card {
  flex: 0 0 calc((100vw - 40px) / 5);
  width: calc((100vw - 40px) / 5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  scroll-snap-align: start;
  position: relative;
  transition: box-shadow .22s, transform .22s;
}
.kh-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--kh-color, var(--brand));
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform .25s ease;
  z-index: 2;
}
.kh-card[hidden] { display: none; }
.kh-card:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: -3px;
  z-index: 1;
}

/* Hover animations */
.kh-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(15,23,42,.14);
  z-index: 1;
}
.kh-card:hover::before            { transform: scaleX(1); }
.kh-card:hover .kh-card__title   { color: var(--kh-color, var(--brand2)); }
.kh-card:hover .kh-card__img img,
.kh-card:hover .kh-card__accent { transform: scale(1.07); }
.kh-card:hover .kh-card__body    { background: #fffaf5; }

/* Image area — small accent strip at top */
.kh-card__img {
  flex: 0 0 var(--kh-img-h);
  height: var(--kh-img-h);
  overflow: hidden;
  background: linear-gradient(145deg, #e2e8f0, #f1f5f9);
}
.kh-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .4s ease;
}
.kh-card__accent {
  width: 100%;
  height: 100%;
  background: var(--kh-color, var(--brand));
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .4s ease;
}
.kh-card__accent svg {
  color: rgba(255,255,255,.88);
  flex-shrink: 0;
}

/* White body area — title is the focus */
.kh-card__body {
  flex: 1 1 auto;
  min-height: 100px;
  padding: 14px 14px 14px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 6px;
  transition: background .22s;
  overflow: hidden;
}

.kh-card__title {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  transition: color .22s;
  letter-spacing: -.01em;
}

.kh-card__sub {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── Filter column overflow (>8 options) ────────────────────────────────────── */
.kh-filter-overflow-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .3s ease;
}
.kh-filter-overflow-wrap.is-expanded {
  grid-template-rows: 1fr;
}
.kh-filter-overflow-inner {
  overflow: hidden;
}

.kh-filter-overflow-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  padding: 10px 16px;
  margin: 4px 0 0;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.3;
  transition: color .2s;
}
.kh-filter-overflow-toggle:hover { color: var(--brand); }
.kh-filter-overflow-toggle svg {
  flex-shrink: 0;
  transition: transform .3s ease;
}
.kh-filter-overflow-toggle.is-expanded svg {
  transform: rotate(180deg);
}

/* ── Empty / no-results states ───────────────────────────────────────────────── */
.kh-empty,
.kh-no-results {
  padding: 56px 0;
  color: var(--muted);
  font-size: 15px;
}
.kh-no-results[hidden] { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* 3 cards per page on tablet */
  .kh-card { flex: 0 0 calc((100vw - 40px) / 3); width: calc((100vw - 40px) / 3); }
}

@media (max-width: 760px) {
  .kh-filter-menu {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }
  .kh-filter-menu-inner {
    flex-direction: column;
    gap: 6px;
  }
  .kh-filter-column,
  .kh-filter-column--reset {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    width: 100%;
  }
  .kh-filter-subhead {
    min-height: 0;
    margin-top: 6px;
  }
}

@media (max-width: 560px) {
  /* 2 cards per page on mobile */
  .kh-card { flex: 0 0 calc((100vw - 40px) / 2); width: calc((100vw - 40px) / 2); }
  .kh-page { --kh-img-h: 56px; --kh-section-gap: 36px; }
  .kh-masthead { padding: 32px 0 28px; margin-bottom: 28px; }
  .kh-controls { flex-direction: column; align-items: flex-start; }
  .kh-search__field { width: 100%; }
}
