/* Biblioteca de Salud — Layout tipo glosario */

:root {
  --bib-bg: #ffffff;
  --bib-text: #111827;
  --bib-muted: #667085;
  --bib-soft: #98a2b3;
  --bib-line: #e5e7eb;
  --bib-primary: #155eef;
  --bib-primary-dark: #0f3fa8;
}

/* Page shell */
.bib-page {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 56px 32px 80px;
}

/* Header */
.bib-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 48px;
  align-items: center;
  padding: 44px 48px;
  border: 1px solid rgba(21, 94, 239, 0.1);
  border-radius: 30px;
  background:
    radial-gradient(circle at top right, rgba(21, 94, 239, 0.12), rgba(21, 94, 239, 0) 34%),
    linear-gradient(180deg, rgba(247, 250, 255, 0.96) 0%, rgba(255, 255, 255, 1) 100%);
  box-shadow: 0 24px 60px rgba(16, 33, 70, 0.08);
  position: relative;
  overflow: hidden;
}

.bib-header::before {
  content: "";
  position: absolute;
  inset: auto auto -80px -50px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(21, 94, 239, 0.1), rgba(21, 94, 239, 0));
  pointer-events: none;
}

.bib-eyebrow {
  margin: 0 0 14px;
  color: var(--bib-primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.bib-title {
  max-width: 760px;
  margin: 0;
  color: var(--bib-text);
  font-size: clamp(2.3rem, 4.8vw, 4.45rem);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.05em;
}

.bib-lead {
  max-width: 700px;
  margin: 22px 0 0;
  color: var(--bib-muted);
  font-size: 1.02rem;
  line-height: 1.72;
}

.bib-header-img {
  position: relative;
  display: grid;
  align-self: start;
}

.bib-header-img img {
  display: block;
  max-width: 100%;
  height: auto;
}

.bib-header-counter {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 22px 12px;
  background: #00194C;
  color: rgba(255,255,255,0.8);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  border-radius: 14px;
  box-shadow: 0 14px 32px rgba(0,25,76,.28);
  white-space: nowrap;
}

.bib-header-counter strong {
  display: block;
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 760;
  line-height: 1;
  letter-spacing: -0.04em;
  margin-bottom: 2px;
}

.bib-count {
  color: var(--bib-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.bib-count strong {
  display: block;
  margin-bottom: 6px;
  color: var(--bib-text);
  font-size: 2.15rem;
  font-weight: 760;
  line-height: 1;
  letter-spacing: -0.05em;
}

/* Two-column body */
.bib-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 64px;
  align-items: start;
  padding-top: 36px;
}

/* Sidebar */
.bib-sidebar {
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--bib-line) transparent;
}

/* WebKit scrollbar (Chrome, Edge, Safari) */
.bib-sidebar::-webkit-scrollbar {
  width: 6px;
}

.bib-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.bib-sidebar::-webkit-scrollbar-thumb {
  background: var(--bib-line);
  border-radius: 3px;
}

.bib-sidebar-label {
  margin: 0 0 18px;
  color: var(--bib-soft);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ── Section tree ── */
.bib-section-tree {
  display: grid;
  gap: 0;
}

/* Section header row */
.bib-section-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 0;
  color: var(--bib-muted);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.35;
  cursor: pointer;
  transition: color 160ms ease;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
  width: 100%;
  gap: 8px;
}

.bib-section-row:hover,
.bib-section-row.is-expanded {
  color: var(--bib-text);
}

.bib-section-row.is-expanded {
  font-weight: 620;
}

.bib-section-caret {
  font-size: 0.6rem;
  color: var(--bib-soft);
  transition: transform 200ms ease;
  flex-shrink: 0;
}

.bib-section-row.is-expanded .bib-section-caret {
  transform: rotate(90deg);
}

/* Children container (chapters + questions) */
.bib-section-children {
  display: none;
  padding-left: 16px;
  border-left: 1px solid var(--bib-line);
  margin-left: 6px;
  margin-bottom: 2px;
}

.bib-section-row.is-expanded + .bib-section-children {
  display: block;
}

.bib-tree-chapter {
  padding: 14px 0 4px;
}

.bib-tree-chapter-title {
  margin: 0 0 6px;
  color: var(--bib-text);
  font-size: 0.78rem;
  font-weight: 680;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.bib-tree-chapter-num {
  color: var(--bib-primary);
  font-size: 0.62rem;
  font-weight: 760;
  letter-spacing: 0.06em;
  margin-right: 6px;
}

.bib-tree-questions {
  display: grid;
  gap: 1px;
  padding-left: 12px;
}

.bib-tree-question {
  display: block;
  padding: 4px 0;
  color: var(--bib-soft);
  font-size: 0.76rem;
  font-weight: 350;
  line-height: 1.42;
  cursor: pointer;
  transition: color 160ms ease;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
  width: 100%;
}

.bib-tree-question:hover,
.bib-tree-question.is-active {
  color: var(--bib-primary-dark);
}

.bib-tree-question.is-active {
  font-weight: 620;
}

/* Content area */
.bib-content {
  max-width: 860px;
  padding-bottom: 80px;
}

.bib-breadcrumb {
  margin: 0 0 18px;
  color: var(--bib-soft);
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.bib-content-title {
  margin: 0;
  color: var(--bib-text);
  font-size: clamp(2rem, 3.8vw, 3.75rem);
  font-weight: 760;
  line-height: 1.03;
  letter-spacing: -0.06em;
}

.bib-answer {
  margin-top: 32px;
  color: #263447;
  font-size: 1.08rem;
  line-height: 1.78;
}

.bib-answer p {
  margin: 0 0 20px;
}

.bib-inline-cta {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin: 6px 0 22px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: linear-gradient(180deg, #0f2f73 0%, #0b255e 100%);
  color: var(--white);
  text-decoration: none;
  box-shadow: 0 12px 26px rgba(8, 28, 73, 0.22);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.bib-inline-cta:hover {
  border-color: rgba(142, 197, 255, 0.28);
  background: linear-gradient(180deg, #12357f 0%, #0d2967 100%);
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(8, 28, 73, 0.3);
  color: var(--white);
}

.bib-inline-cta__icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #9bc2ff;
  font-size: 15px;
}

.bib-inline-cta__content {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.bib-inline-cta__content strong {
  color: var(--white);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.bib-inline-cta__content small {
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
  line-height: 1.45;
}

.bib-inline-cta__arrow {
  color: #9bc2ff;
  font-size: 12px;
}

.bib-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 32px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--bib-line);
}

.bib-block h3 {
  margin: 0 0 10px;
  color: var(--bib-text);
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.bib-block ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  color: var(--bib-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  list-style: none;
}

.bib-block li {
  position: relative;
  padding-left: 14px;
}

.bib-block li::before {
  position: absolute;
  top: 0.6em;
  left: 0;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--bib-primary);
  content: "";
}

.bib-summary {
  margin-top: 42px;
  padding-top: 26px;
  border-top: 1px solid var(--bib-line);
  color: var(--bib-text);
  font-size: 1.05rem;
  line-height: 1.7;
}

.bib-summary strong {
  color: var(--bib-primary-dark);
}

.bib-sources {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--bib-line);
  color: var(--bib-muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

.bib-sources-label {
  font-weight: 680;
  color: var(--bib-text);
  margin-right: 6px;
}

.bib-source-link {
  color: var(--bib-primary);
  text-decoration: none;
  margin-right: 16px;
}

.bib-source-link::after {
  content: " ↗";
  font-size: 0.68rem;
}

.bib-source-link:hover {
  text-decoration: underline;
}

/* Related questions */
.bib-related {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--bib-line);
}

.bib-related h3 {
  margin: 0 0 8px;
  color: var(--bib-text);
  font-size: 0.76rem;
  font-weight: 680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bib-related ul {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bib-related-link {
  display: block;
  padding: 3px 0;
  color: var(--bib-primary);
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
  width: 100%;
  transition: color 160ms ease;
}

.bib-related-link:hover {
  color: var(--bib-primary-dark);
  text-decoration: underline;
}

.bib-related-badge {
  flex-shrink: 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--bib-primary);
  font-size: 0.64rem;
  font-weight: 680;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bib-cta-wrap {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--bib-line);
}

/* Welcome screen */
.bib-welcome {
  padding: 20px 0;
}

.bib-welcome-title {
  margin: 0 0 12px;
  color: var(--bib-text);
  font-size: 1.6rem;
  font-weight: 760;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.bib-welcome-lead {
  max-width: 620px;
  margin: 0 0 36px;
  color: var(--bib-muted);
  font-size: 1.02rem;
  line-height: 1.7;
}

.bib-welcome-search {
  margin: 0 0 28px;
}

.bib-welcome-search__label {
  display: block;
  margin: 0 0 12px;
  color: var(--bib-primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.bib-welcome-search__form {
  position: relative;
  width: 100%;
}

.bib-welcome-search__input {
  width: 100%;
  height: 46px;
  padding: 0 44px 0 14px;
  border: 1px solid rgba(50, 75, 125, 0.18);
  border-radius: 8px;
  background: #f7f9fc;
  color: var(--bib-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.bib-welcome-search__input:focus {
  background: #fff;
  border-color: var(--bib-primary);
  box-shadow: 0 0 0 3px rgba(21, 94, 239, .06);
}

.bib-welcome-search__button {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: var(--bib-primary);
  color: #fff;
  cursor: pointer;
  transition: background 160ms ease;
}

.bib-welcome-search__button:hover {
  background: var(--bib-primary-dark);
}

.bib-welcome-search__button i {
  display: block;
  line-height: 1;
}

.bib-welcome-search__hint {
  margin: 10px 0 0;
  color: var(--bib-muted);
  font-size: 13px;
  line-height: 1.5;
}

.bib-welcome-search__hint.is-error {
  color: #b42318;
}

.bib-welcome-search__results {
  margin-top: 10px;
}

.bib-welcome-search__list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--bib-line) transparent;
}

.bib-welcome-search__list::-webkit-scrollbar {
  width: 6px;
}

.bib-welcome-search__list::-webkit-scrollbar-track {
  background: transparent;
}

.bib-welcome-search__list::-webkit-scrollbar-thumb {
  background: var(--bib-line);
  border-radius: 999px;
}

.bib-welcome-search__result {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(50, 75, 125, 0.12);
  border-radius: 8px;
  background: #fff;
  color: var(--bib-text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.bib-welcome-search__result:hover {
  background: #f7faff;
  border-color: rgba(21, 94, 239, 0.22);
  transform: translateY(-1px);
}

.bib-welcome-search__result-title {
  display: block;
  font-size: 0.86rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--bib-text);
}

.bib-welcome-search__result-meta {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--bib-soft);
}

.bib-welcome-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.bib-welcome-card {
  padding: 28px 24px;
  border-radius: 0;
  background: #f9fafb;
}

.bib-welcome-card-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 16px;
  border-radius: 50%;
  background: #eef2ff;
  color: var(--bib-primary);
  font-size: 1rem;
  font-weight: 760;
}

.bib-welcome-card h3 {
  margin: 0 0 8px;
  color: var(--bib-text);
  font-size: 0.94rem;
  font-weight: 680;
  line-height: 1.3;
}

.bib-welcome-card p {
  margin: 0;
  color: var(--bib-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

@media (max-width: 640px) {
  .bib-welcome-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .bib-welcome-lead {
    margin-bottom: 20px;
  }

  .bib-welcome-card {
    padding: 14px 12px;
  }

  .bib-welcome-card-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 10px;
    font-size: 0.82rem;
  }

  .bib-welcome-card h3 {
    margin-bottom: 4px;
    font-size: 0.84rem;
  }

  .bib-welcome-card p {
    font-size: 0.76rem;
    line-height: 1.45;
  }
}

/* Loading / empty states */
.bib-loading {
  display: grid;
  place-items: center;
  min-height: 400px;
  color: var(--bib-muted);
  font-size: 1.1rem;
}

.bib-error {
  display: grid;
  place-items: center;
  min-height: 400px;
  color: #dc2626;
  font-size: 1.1rem;
  text-align: center;
}

/* ── Mobile: sidebar drawer overlay ── */
.bib-sidebar-backdrop {
  display: none;
}

.bib-mobile-toggle {
  display: none;
}

.bib-mobile-nav {
  display: none;
}

.bib-drawer-close {
  display: none;
}

.bib-mobile-nav__top {
  display: none;
}

/* Responsive */
@media (max-width: 980px) {
  .bib-welcome {
    padding: 12px 0;
  }

  .bib-welcome-title {
    margin-bottom: 10px;
    font-size: 1.35rem;
  }

  .bib-welcome-search {
    margin-bottom: 18px;
  }

  .bib-header {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 34px 32px;
  }

  .bib-shell {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Sidebar → drawer overlay */
  .bib-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85vw;
    max-width: 340px;
    height: 100%;
    height: 100dvh;
    z-index: 1050;
    background: #fff;
    box-shadow: 4px 0 40px rgba(0,0,0,.15);
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 24px 20px 32px;
    border-radius: 0;
    max-height: none;
  }

  .bib-sidebar.is-open {
    transform: translateX(0);
  }

  .bib-sidebar-label {
    font-size: 0.68rem;
    margin: -30px 0 14px;
    padding-right: 44px;
  }

  /* Close button inside drawer (mobile only) */
  .bib-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-bottom: 0;
    margin-left: auto;
    border: none;
    background: none;
    color: var(--bib-soft);
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 50%;
    transition: background 160ms ease, color 160ms ease;
  }

  .bib-drawer-close:hover {
    background: #f3f4f6;
    color: var(--bib-text);
  }

  /* Backdrop */
  .bib-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(0,0,0,.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s ease;
  }

  .bib-sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Floating toggle button */
  .bib-mobile-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1030;
    padding: 10px 16px;
    background: var(--bib-primary);
    color: #fff;
    border: none;
    border-radius: 22px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(21,94,239,.28);
    transition: background 160ms ease, box-shadow 160ms ease, opacity .25s ease, transform .25s ease;
  }

  .bib-mobile-toggle:hover {
    background: var(--bib-primary-dark);
    box-shadow: 0 6px 30px rgba(21,94,239,.45);
  }

  .bib-mobile-toggle.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(12px);
  }

  .bib-content {
    max-width: none;
  }

  /* Mobile nav: top back-to-questions button */
  .bib-mobile-nav__top {
    display: block;
    margin-bottom: 16px;
  }

  .bib-mobile-nav__top .bib-mobile-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #f3f4f6;
    color: var(--bib-text);
    border: none;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 580;
    cursor: pointer;
    transition: background 160ms ease;
  }

  .bib-mobile-nav__top .bib-mobile-back:hover {
    background: #e5e7eb;
  }

  /* Mobile nav: prev / next at bottom of answer */
  .bib-mobile-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--bib-line);
  }

  .bib-mobile-nav__arrow {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: #f3f4f6;
    color: var(--bib-text);
    border: none;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 580;
    cursor: pointer;
    transition: background 160ms ease;
  }

  .bib-mobile-nav__arrow:hover {
    background: #e5e7eb;
  }

  .bib-mobile-nav__arrow:disabled {
    opacity: .35;
    cursor: default;
  }
}

@media (max-width: 640px) {
  .bib-page {
    padding: 24px 20px 64px;
  }

  .bib-header {
    padding: 28px 22px;
    border-radius: 22px;
    gap: 22px;
  }

  .bib-title {
    font-size: 2.15rem;
    line-height: 1.05;
  }

  .bib-lead {
    font-size: 0.96rem;
    line-height: 1.68;
  }

  .bib-header-img {
    max-width: 260px;
    margin: 0 auto;
  }

  .bib-shell {
    padding-top: 14px;
  }

  .bib-columns {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .bib-section-children {
    padding-left: 12px;
  }
}
