/* ── Layout ──────────────────────────────────────────────────────────────── */

#ria-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--bs-primary);
  z-index: 2000;
  transition: width 0.1s linear;
}

body {
  padding-top: 56px; /* navbar height */
}

#ria-app {
  display: flex;
  align-items: flex-start;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

#ria-sidebar {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  border-right: 1px solid var(--bs-border-color);
  padding: 0.75rem 0.5rem 2rem;
  scrollbar-width: thin;
  background-color: var(--bs-body-bg);
  transition: transform 0.25s ease;
}

@media (max-width: 991.98px) {
  #ria-sidebar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    z-index: 1045;
    height: calc(100vh - 56px);
    box-shadow: 4px 0 16px rgba(0, 0, 0, .15);
  }
  #ria-sidebar.show {
    display: block;
  }
}

/* ── Main content ────────────────────────────────────────────────────────── */

#ria-main {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.5rem 4rem;
  max-width: 860px;
  margin: 0 auto;
}

@media (min-width: 992px) {
  #ria-main {
    padding: 2rem 2.5rem 4rem;
  }
}

/* ── TOC styles ──────────────────────────────────────────────────────────── */

.toc-list {
  font-size: 0.8rem;
}

.toc-section-link {
  display: block;
  padding: 0.2rem 0.5rem;
  color: var(--bs-secondary-color);
  text-decoration: none;
  border-radius: 4px;
  margin-bottom: 2px;
}

.toc-section-link:hover {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}

.toc-chapter {
  margin-bottom: 2px;
}

.toc-chapter-btn {
  font-size: 0.8rem;
  color: var(--bs-body-color) !important;
  text-decoration: none !important;
  padding: 0.25rem 0.5rem !important;
  border-radius: 4px;
  line-height: 1.3;
}

.toc-chapter-btn:hover {
  background-color: var(--bs-tertiary-bg);
}

.toc-chevron {
  font-size: 1rem;
  line-height: 1;
  margin-top: 1px;
  flex-shrink: 0;
  transition: transform 0.2s;
  display: inline-block;
}

.toc-chapter-btn.expanded .toc-chevron,
[aria-expanded="true"] .toc-chevron {
  transform: rotate(90deg);
}

.toc-num {
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--bs-secondary-color);
}

.toc-title {
  color: var(--bs-body-color);
}

.toc-articles {
  font-size: 0.75rem;
}

.toc-art-link {
  display: block;
  padding: 0.15rem 0.4rem;
  color: var(--bs-secondary-color);
  text-decoration: none;
  border-radius: 3px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-art-link:hover {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}

.toc-art-link.active {
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  font-weight: 500;
}

.toc-art-num {
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--bs-primary);
}

/* ── Navbar ──────────────────────────────────────────────────────────────── */

.ria-navbar {
  border-bottom: 1px solid var(--bs-border-color);
}

.ria-brand {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--bs-body-color) !important;
  text-decoration: none;
}

.ria-brand span {
  color: var(--bs-primary);
}

/* ── Search ──────────────────────────────────────────────────────────────── */

.ria-search-wrap {
  position: relative;
}

#ria-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 340px;
  max-height: 420px;
  overflow-y: auto;
  z-index: 1060;
  list-style: none;
  padding: 0.25rem 0;
  margin: 0;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  display: none;
}

#ria-search-results.show {
  display: block;
}

#ria-search-results .dropdown-item {
  padding: 0.5rem 0.75rem;
  white-space: normal;
  border-bottom: 1px solid var(--bs-border-color-translucent);
}

#ria-search-results .dropdown-item:last-child {
  border-bottom: none;
}

#ria-search-results mark {
  background-color: var(--bs-warning);
  padding: 0 2px;
  border-radius: 2px;
}

/* ── Typography ──────────────────────────────────────────────────────────── */

.oj-normal {
  line-height: 1.75;
  text-align: justify;
  font-size: 0.95rem;
  hyphens: auto;
}

.oj-ti-art {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 0.25rem;
  color: var(--bs-primary);
}

.oj-sti-art {
  font-size: 0.95rem;
  font-weight: 600;
  font-style: italic;
  color: var(--bs-secondary-color);
  margin-bottom: 0.75rem;
}

.oj-ti-section-1 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bs-secondary-color);
  margin-top: 2.5rem;
  margin-bottom: 0;
}

.oj-ti-section-2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.oj-separator {
  margin: 2rem 0;
  border-color: var(--bs-border-color);
}

/* ── Article containers ──────────────────────────────────────────────────── */

[id^="art_"],
[id^="rct_"],
[id^="anx_"] {
  scroll-margin-top: 70px;
}

[id^="art_"]:target,
[id^="rct_"]:target,
[id^="anx_"]:target {
  animation: highlight-fade 2s ease forwards;
  border-radius: 6px;
}

@keyframes highlight-fade {
  0%   { background-color: var(--bs-warning-bg-subtle); }
  100% { background-color: transparent; }
}

/* ── Term tooltips ───────────────────────────────────────────────────────── */

a.ria-term {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: help;
}

a.ria-term:hover {
  text-decoration-style: solid;
}

/* ── Back to top ─────────────────────────────────────────────────────────── */

#ria-back-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1040;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  font-size: 1.1rem;
}

#ria-back-top.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Intro alert ─────────────────────────────────────────────────────────── */

.ria-intro {
  font-size: 0.875rem;
}

/* ── Print ───────────────────────────────────────────────────────────────── */

@media print {
  #ria-progress,
  #ria-sidebar,
  .ria-navbar,
  #ria-back-top {
    display: none !important;
  }
  body { padding-top: 0; }
  #ria-main { max-width: 100%; padding: 0; }
  [id^="cpt_"] { page-break-before: always; }
  a[href]::after { content: ''; }
}
