/* ============================================================
   site-overrides.css
   ------------------------------------------------------------
   Custom site-wide overrides on top of the design-system CSS.
   Load order: colors_and_type.css → pipo-experience.css → THIS FILE.
   This file survives design-system updates.
   ============================================================ */


/* ============================================================
   1. Remove global "blue underline" from nav/chrome links
   ------------------------------------------------------------
   colors_and_type.css applies a global `border-bottom: 1px solid blue 35%`
   to every <a> element. That treatment is meant for inline links inside
   body copy — NOT for navigation, brand lockup, buttons, footer cols,
   or card links. Override here.
   ============================================================ */

.site-header a,
.site-footer a,
.toc-rail a,
.brand-lockup,
.path-card a,
.sys-card a,
.pc-cta a,
.foot-col a,
.foot-brand a,
.closing-cta a {
  border-bottom: none;
}
a.btn { border-bottom: none; }
a.btn.btn-secondary { border-bottom: 1px solid var(--line-2); }
a.btn.btn-secondary:hover { border-bottom-color: var(--accent); }


/* ============================================================
   2. Nav-links — Option C: tiny eyebrow caps
   ------------------------------------------------------------
   Replace default button-pill nav style with architectural
   all-caps eyebrow tracking + yellow underline indicator
   on hover/active.
   ============================================================ */

.nav-links {
  /* display: kept as `none` from design-system CSS for mobile;
     switched to `flex` by min-width:1000px media query below. */
  align-items: center;
  gap: 22px;
  margin-left: 24px;
}

@media (min-width: 1000px) {
  .nav-links { display: flex; }
}

.nav-links a {
  position: relative;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 10px 0;
  text-decoration: none;
  border-bottom: none;
  background: transparent;
  border-radius: 0;
  transition: color 180ms ease;
}

/* Yellow underline indicator — shows only on hover / active */
.nav-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 4px;
  width: 0;
  height: 2px;
  background: var(--yellow-400);
  transition: width 220ms ease;
}

.nav-links a:hover,
.nav-links a:focus,
.nav-links a:focus-visible {
  color: var(--ink);
  text-decoration: none;
  background: transparent;
  outline: none;
}
.nav-links a:hover::after { width: 18px; }

.nav-links a.active {
  color: var(--ink);
  font-weight: 700;
  background: transparent;
}
.nav-links a.active::after { width: 18px; }


/* ============================================================
   3. Mobile hamburger menu + slide-in drawer
   ------------------------------------------------------------
   Below 1000px the horizontal nav-links is hidden by the design
   system already. Show a hamburger button instead; tap opens a
   right-side drawer with all nav items + CTA.
   ============================================================ */

/* --- Hamburger button (visible only < 1000px) --- */
.nav-burger {
  display: none;       /* hidden on desktop */
  width: 44px;
  height: 44px;
}

/* --- Hide desktop-only CTA below the breakpoint --- */
@media (max-width: 999px) {
  .nav-burger { display: inline-flex; align-items: center; justify-content: center; }
  .nav-cta-desktop { display: none; }
}

/* --- Backdrop scrim --- */
.nav-backdrop {
  position: fixed;
  inset: 0;
  /* Pure black with alpha — works in both light & dark mode */
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  z-index: 180;  /* site-header is 150 — backdrop must sit above it */
  transition: opacity 200ms ease, visibility 0s linear 200ms;
}
.nav-open .nav-backdrop {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease, visibility 0s;
}

/* --- Drawer panel --- */
.nav-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(86vw, 340px);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 36px rgba(30, 34, 43, 0.12);
  z-index: 200;  /* above site-header (150) and backdrop (180) */
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-open .nav-drawer { transform: translateX(0); }

/* Lock background scroll when drawer is open */
.nav-open body,
html.nav-open { overflow: hidden; }

/* --- Drawer header --- */
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head .brand-text .brand-sub { display: none; }
.drawer-head .brand-avatar img { width: 34px; height: 34px; }
.nav-close {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Drawer links — vertical list, eyebrow caps style --- */
.drawer-links {
  display: flex;
  flex-direction: column;
  padding: 16px 8px;
  flex: 1;
}
.drawer-links a {
  position: relative;
  padding: 16px 20px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: none;
  border-radius: var(--r-8);
  transition: color 180ms ease, background 180ms ease;
}
.drawer-links a:hover,
.drawer-links a:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
}
.drawer-links a.active {
  color: var(--ink);
  font-weight: 700;
}
.drawer-links a.active::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--yellow-400);
}

/* --- Drawer footer (CTA pinned to bottom) --- */
.drawer-foot {
  padding: 16px 20px 24px;
  border-top: 1px solid var(--line);
  flex: none;
}
.drawer-foot .btn { width: 100%; justify-content: center; text-align: center; }

/* --- Respect reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .nav-drawer { transition: none; }
  .nav-backdrop { transition: opacity 0s, visibility 0s; }
}


/* ============================================================
   4. Resource page — filter pills wrap on small screens
   ------------------------------------------------------------
   Design system sets `.res-bar-in` to a fixed-height 56px
   horizontal-scroll row. On mobile this shows an ugly scrollbar.
   Switch to wrap + auto height instead.
   ============================================================ */

@media (max-width: 999px) {
  .res-bar-in {
    flex-wrap: wrap;
    height: auto;
    overflow-x: visible;
    row-gap: 10px;
    padding-block: 10px;
    align-items: center;
  }
}


/* ============================================================
   5. Blog page — search icon + filter buttons on mobile
   ------------------------------------------------------------
   Desktop: search input always visible inline; toggle/close hidden.
   Mobile:  search input hidden by default; show a search icon and
            "Lọc" filter button right-aligned on the last row.
            Tap icon → input expands to full row width with × close.
   ============================================================ */

/* --- Default (desktop) — icon & close hidden, input visible --- */
.rb-search-toggle,
.rb-search-close {
  display: none;
}

/* --- Search toggle pill (icon + placeholder label) --- */
.rb-search-toggle {
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  height: 40px;
  padding: 0 18px 0 14px;
  border-radius: var(--r-full);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-3);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  flex: none;
  transition: border-color 150ms, color 150ms, background 150ms;
}
.rb-search-toggle .rbt-label {
  color: var(--ink-3);
}
.rb-search-toggle:hover,
.rb-search-toggle:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.rb-search-toggle:hover .rbt-label,
.rb-search-toggle:focus-visible .rbt-label {
  color: var(--accent);
}

/* --- Close button inside expanded search --- */
.rb-search-close {
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  border-radius: var(--r-full);
  flex: none;
  transition: color 150ms, background 150ms;
}
.rb-search-close:hover,
.rb-search-close:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
}


/* On desktop, "Tầng PIPO" select inside filter sidebar is redundant
   with the inline chip pills — hide it. On mobile it's the primary control. */
@media (min-width: 1000px) {
  .bf-group-stage {
    display: none;
  }
}


/* ============================================================
   6. Article prose — code blocks styled to match design system
   ------------------------------------------------------------
   Markdown ``` code blocks ``` render as <pre><code> inside
   .art-prose. Without explicit styling they fall back to ugly
   browser default (dark bar, invisible selection).
   ============================================================ */

.art-prose pre {
  position: relative;
  margin: 24px 0;
  padding: 18px 20px;
  /* Soft navy from dark theme — easier on the eyes than pure black */
  background: #1A1F27;
  color: #E8EAED;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-12);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 2px 8px rgba(30, 34, 43, 0.06);
}
.art-prose pre code {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  background: transparent;
  border: none;
  padding: 0;
  white-space: pre;
}

/* Text selection on dark code blocks — needs a contrasting highlight
   so the user can see what they've selected. */
.art-prose pre ::selection,
.art-prose pre code ::selection {
  background: var(--yellow-400, #efae37);
  color: var(--ink, #1e222b);
}

/* Inline code (`backtick` inside prose) — light/warm style on cream bg */
.art-prose :not(pre) > code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--ink);
}


/* ============================================================
   6b. Article prose — markdown tables
   ------------------------------------------------------------
   Markdown `| a | b |` tables render as plain <table> with no
   browser styling. Give them borders, padding, header background,
   and horizontal scroll on small screens.
   ============================================================ */

.art-prose table {
  width: 100%;
  margin: 24px 0;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-12);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.art-prose thead {
  background: var(--surface-2);
}
.art-prose th,
.art-prose td {
  padding: 12px 16px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.art-prose th:last-child,
.art-prose td:last-child { border-right: none; }
.art-prose tbody tr:last-child td { border-bottom: none; }
.art-prose th {
  font-family: var(--head);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.art-prose tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.015);
}
.art-prose td strong { color: var(--ink); }

/* Mobile: allow horizontal scroll for wide tables */
@media (max-width: 720px) {
  .art-prose table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .art-prose th,
  .art-prose td { white-space: normal; }
}


/* ============================================================
   7. Compact "Vấn đề liên quan" + "Liên kết tới bài này"
   ------------------------------------------------------------
   These are supplementary blocks — they shouldn't dominate the
   page. Trim heading size, card padding, and font sizes so the
   reader stays focused on the main article body.
   ============================================================ */

/* Section wrappers */
.rel-problems,
.backlinks {
  margin-top: 28px;
  padding-top: 18px;
}

/* Headings — small caption-like, lower visual weight */
.rp-head,
.bl-head {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  gap: 6px;
}
.rp-head svg,
.bl-head svg {
  width: 13px;
  height: 13px;
}
.bl-count {
  font-size: 10px;
  padding: 0 6px;
  height: 16px;
  line-height: 16px;
}

/* Subtitle below heading */
.rp-sub,
.bl-sub {
  font-size: 11px;
  margin-top: 0;
  margin-bottom: 10px;
  color: var(--ink-4);
}

/* Item cards — tighter padding, smaller text */
.rp-item,
.bl-item {
  padding: 10px 14px;
  margin-top: 6px;
  border-radius: var(--r-8);
}

/* Related-problems question + help */
.rp-q {
  font-size: 13px;
  font-weight: 500;
  font-style: italic;
  line-height: 1.4;
  gap: 6px;
  margin-bottom: 2px;
}
.rp-q .pb {
  width: 15px;
  height: 15px;
  font-size: 10px;
  flex: none;
}
.rp-help {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 3px 0 4px;
}
.rp-go {
  font-size: 11px;
  gap: 4px;
}
.rp-go svg {
  width: 10px;
  height: 10px;
}

/* Backlinks title + pill row */
.bl-top {
  gap: 6px;
  align-items: baseline;
}
.bl-title {
  font-size: 13px;
  font-weight: 700;
}
.bl-pill {
  font-size: 10px;
  padding: 0 6px;
  height: 16px;
  line-height: 16px;
}
.bl-context {
  font-size: 12.5px;
  line-height: 1.5;
  margin-top: 2px;
  color: var(--ink-2);
}
.bl-context mark {
  font-size: inherit;
  padding: 0 3px;
  border-radius: 3px;
}


/* ============================================================
   8. Sidebar lists for Related Problems + Backlinks
   ------------------------------------------------------------
   Compact title-only lists inside the article sidebar.
   ============================================================ */

.side-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-list li > a {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  margin: 0 -10px;             /* extend hit-area to widget edges */
  border-radius: var(--r-8);
  text-decoration: none;
  border-bottom: none;
  color: var(--ink);
  transition: background 150ms, color 150ms;
}
.side-list li > a:hover,
.side-list li > a:focus-visible {
  background: var(--surface-2);
  color: var(--accent);
  outline: none;
}

/* Title text — single-line truncate */
.side-text {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  line-height: 1.4;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Sub-label below title (pill text for backlinks) */
.side-meta {
  display: none;               /* hidden by default — keeps list ultra-compact */
}
.side-backlinks .side-list li > a {
  flex-direction: column;
  gap: 1px;
}
.side-backlinks .side-meta {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* P-badge for related problems */
.side-pin {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--yellow-400);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  margin-top: 1px;
}

/* Count badge in widget title (e.g. "Liên kết tới bài này 2") */
.side-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 600;
}


/* ============================================================
   9. Remove nested scrollbar inside article sidebar
   ------------------------------------------------------------
   Design system default: .article-side has max-height + overflow-y:auto.
   That creates an ugly inner scrollbar when sidebar is taller than
   viewport. Override so the whole sidebar flows with the page —
   sticky position handles the floating behavior up to the end of
   the article.
   ============================================================ */

@media (min-width: 1100px) {
  .article-side {
    max-height: none !important;
    overflow: visible !important;
    /* keep position: sticky from design system */
  }
}


/* ============================================================
   10. Expand/collapse for sidebar lists with > 2 items
   ------------------------------------------------------------
   Items beyond the first 2 get `.side-extra` and stay hidden
   until user clicks the toggle button.
   ============================================================ */

.side-extra { display: none; }
.side-widget.expanded .side-extra { display: list-item; }

/* Toggle button — text-only "Xem thêm X ↓" / "Thu gọn ↑" */
.side-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: var(--r-8);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  text-align: left;
  transition: background 150ms, color 150ms;
}
.side-toggle:hover,
.side-toggle:focus-visible {
  background: var(--surface-2);
  color: var(--accent);
  outline: none;
}
.side-toggle .t-arr {
  font-size: 10px;
  margin-left: 2px;
  transition: transform 150ms;
}

/* Show "more" by default, "less" when expanded */
.side-widget .t-less { display: none; }
.side-widget.expanded .t-more { display: none; }
.side-widget.expanded .t-less { display: inline-flex; align-items: center; gap: 4px; }


/* ============================================================
   11. Mobile placement of Related + Backlinks widgets
   ------------------------------------------------------------
   Desktop (≥1100px): widgets live in the right sidebar.
   Mobile (<1100px):  widgets live INLINE in the article body —
                      between content end and the author byline.

   .mobile-extras is the inline container in the article flow;
   it's hidden on desktop. The desktop sidebar (.article-side)
   stays hidden on mobile (design system default).
   ============================================================ */

.mobile-extras {
  display: none;                 /* desktop hides it */
}

@media (max-width: 1099px) {
  .mobile-extras {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 36px 0;
  }
  .mobile-extras > .side-widget {
    width: 100%;
  }
}


/* ============================================================
   12. Copy-to-clipboard toast (visible feedback)
   ------------------------------------------------------------
   Buttons also flip their internal label (.cb-default → .cb-done)
   via the `.copied` class, but a floating toast gives a stronger
   confirmation, especially on mobile.
   ============================================================ */

.copy-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--ink, #1e222b);
  color: var(--cream-100, #fff4de);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--r-full);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 300;
  transition: opacity 200ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 200ms;
}
.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 200ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}
.copy-toast svg {
  background: var(--yellow-400, #efae37);
  color: var(--ink);
  border-radius: 50%;
  padding: 3px;
  width: 22px;
  height: 22px;
}

/* While in `.copied` state, give the button a subtle visual confirmation
   beyond just swapping the label text */
.copybtn.copied {
  background: color-mix(in srgb, var(--ok, #22c55e) 12%, var(--surface)) !important;
  border-color: var(--ok, #22c55e) !important;
  color: var(--ok, #22c55e) !important;
}
.sw-btn.copied {
  background: color-mix(in srgb, var(--ok, #22c55e) 10%, var(--surface));
  color: var(--ok, #22c55e);
}


/* ============================================================
   13. Resource page "Browse All" filter bar — mobile layout
   ------------------------------------------------------------
   Desktop: chip filters left, search pill right (1 row).
   Mobile:  chip filters scroll horizontally on 1 line (no wrap),
            search input below as a full-width row.
   ============================================================ */

/* Mobile filter button — hidden on desktop */
.res-filter-mobile { display: none; position: relative; }

/* Resource search toggle + close — hidden on desktop */
.res-search-toggle,
.res-search-close { display: none; }

/* Search toggle icon button — same style as .res-filter-btn but icon-only */
.res-search-toggle {
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
  margin-left: auto;
  transition: border-color 150ms, color 150ms, background 150ms;
}
.res-search-toggle:hover,
.res-search-toggle:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

/* Close button inside expanded search input */
.res-search-close {
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  border-radius: var(--r-full);
  flex: none;
  margin-left: 4px;
  transition: color 150ms, background 150ms;
}
.res-search-close:hover,
.res-search-close:focus-visible {
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
}


@media (max-width: 999px) {
  .browse-bar {
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 8px !important;
  }

  /* Hide horizontal chip row — replaced by filter button */
  .browse-bar .chip-row { display: none !important; }

  /* Show filter button */
  .res-filter-mobile { display: block; flex: none; }

  /* Default state on mobile: search input hidden, show only toggle icon */
  .browse-bar .kb-search { display: none !important; }
  .res-search-toggle { display: inline-flex; }

  /* Expanded state (.search-open on .browse-bar) */
  .browse-bar.search-open .kb-search {
    display: block !important;
    position: relative;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-left: 0 !important;
  }
  /* Keep design system's built-in magnifying glass on the left */
  .browse-bar.search-open .kb-search input {
    width: 100% !important;
    padding-right: 44px !important; /* reserve room for close button */
  }
  .browse-bar.search-open .res-search-close {
    display: inline-flex;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    z-index: 2;
  }
  /* Hide toggle icon while expanded */
  .browse-bar.search-open .res-search-toggle { display: none; }
}

/* Filter button — chip-style pill */
.res-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--r-full);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 150ms, color 150ms;
}
.res-filter-btn:hover,
.res-filter-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.res-filter-btn strong {
  color: var(--ink);
  font-weight: 700;
}
.res-filter-btn .rfb-caret {
  margin-left: auto;
  transition: transform 180ms ease;
}
.res-filter-btn[aria-expanded="true"] .rfb-caret {
  transform: rotate(180deg);
}

/* Popover panel */
.res-filter-pop {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-12);
  box-shadow: 0 12px 28px rgba(30, 34, 43, 0.12);
  padding: 6px;
}
.res-filter-pop[hidden] { display: none; }

.rfp-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: var(--r-8);
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.rfp-opt:hover,
.rfp-opt:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.rfp-opt.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.rfp-opt.active::before {
  content: "✓ ";
  margin-right: 2px;
}

/* --- Mobile layout (< 1000px) --- */
@media (max-width: 999px) {
  /* Hide inline category chips — they live in the filter sidebar instead.
     Keeps the bar to a single tidy row: [Search icon] [Lọc] */
  .res-bar-in > .chip.pl {
    display: none;
  }
  /* Hide the inline text input by default on mobile.
     Use display: none directly on the wrapper. */
  .res-bar-in > .rb-search {
    display: none;
  }
  /* On mobile the search pill stretches to fill remaining row width
     so the "Lọc" button gets pushed right and the row doesn't feel empty */
  .res-bar-in > .rb-search-toggle {
    display: inline-flex;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }
  /* Truncate placeholder if container is too narrow */
  .res-bar-in > .rb-search-toggle .rbt-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* === Expanded state: input takes full row, icon hidden === */
  .res-bar-in.search-open > .rb-search {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-basis: 100%;
    order: 99;            /* push to last row */
    padding: 4px 6px 4px 14px;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--r-full);
  }
  .res-bar-in.search-open > .rb-search .blogq {
    flex: 1;
    min-width: 0;
    height: 36px;
    border: none;
    background: transparent;
    outline: none;
    font-family: var(--sans);
    font-size: 15px;
    color: var(--ink);
  }
  .res-bar-in.search-open > .rb-search .blogq::placeholder {
    color: var(--ink-3);
  }
  .res-bar-in.search-open .rb-search-close {
    display: inline-flex;
  }
  .res-bar-in.search-open > .rb-search-toggle {
    display: none;
  }
}

/* Resource card title link — inherit card heading style, no underline */
.kb-card h4 .kc-link {
  color: inherit;
  border-bottom: none;
  text-decoration: none;
}
.kb-card h4 .kc-link:hover { color: var(--accent); }
.kb-card:hover { border-color: var(--accent); }
