/* ── SBN brand tokens ──────────────────────────────────────────────────────── */
:root {
  --sbn-cta:       #2d6e24;
  --sbn-cta-hover: #235a1c;
  --sbn-brand:     #3a8c2f;
  --sbn-on-dark:   #6cd22f;
  --sbn-tint:      #eef6ec;
  --sbn-tint-2:    #d4edcf;
  --ink:           #0F1E16;
  --ink-3:         #1E3528;
  --text:          #222b30;
  --muted:         #5a6e78;
  --border:        #dde4e8;
  --bg-alt:        #f4f7f9;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  /* Inter is used when installed locally; otherwise the system UI font.
     No external font CDN — the site is for authenticated users only. */
  font-family: 'Inter', -apple-system, 'Segoe UI', system-ui, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: #fff;
}

a { color: var(--sbn-cta); text-decoration: none; font-weight: 500; }
a:hover { color: var(--sbn-cta-hover); text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.sbn-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}
.sbn-header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.sbn-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  flex-shrink: 0;
}
.sbn-logo__text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
.sbn-header__right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.sbn-phone {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Search ──────────────────────────────────────────────────────────────────── */
.sbn-search-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.75rem;
  gap: 0.4rem;
  transition: border-color 0.15s;
}
.sbn-search-wrap:focus-within {
  border-color: var(--sbn-brand);
  box-shadow: 0 0 0 3px rgba(58,140,47,0.1);
}
.sbn-search-icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
}
#sbn-search {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  width: 180px;
  outline: none;
}
#sbn-search::placeholder { color: var(--muted); }

.sbn-search-results {
  position: fixed;
  top: 60px;
  right: 1.5rem;
  width: 380px;
  max-height: 480px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  z-index: 200;
  padding: 0.5rem 0;
}
.sbn-search-results[hidden] { display: none; }
.sbn-search-result {
  display: block;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.1s;
}
.sbn-search-result:last-child { border-bottom: none; }
.sbn-search-result:hover { background: var(--sbn-tint); }
.sbn-search-result__title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  display: block;
  margin-bottom: 0.2rem;
}
.sbn-search-result__excerpt {
  font-size: 0.8rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sbn-search-empty {
  padding: 1rem 1.1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ── Nav Tabs ────────────────────────────────────────────────────────────────── */
.sbn-tabs {
  background: var(--ink-3);
  position: sticky;
  top: 60px;
  z-index: 90;
}
.sbn-tabs__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0;
}
.sbn-tabs a {
  display: inline-block;
  padding: 0.75rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #d1fae5;
  text-decoration: none;
  opacity: 0.8;
  border-bottom: 3px solid transparent;
  transition: opacity 0.15s, border-color 0.15s;
}
.sbn-tabs a:hover { opacity: 1; color: #fff; text-decoration: none; }
.sbn-tabs a.active { opacity: 1; color: #fff; border-bottom-color: var(--sbn-on-dark); }

/* ── Page Body ───────────────────────────────────────────────────────────────── */
.sbn-body {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  gap: 2rem;
  align-items: start;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sbn-sidebar {
  position: sticky;
  top: 120px;
  font-size: 0.85rem;
}
.sidebar-section {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.sbn-sidebar ul {
  list-style: none;
  border-left: 2px solid var(--border);
  padding-left: 0.75rem;
}
.sbn-sidebar li { margin-bottom: 0.15rem; }
.sbn-sidebar a {
  color: var(--text);
  font-weight: 400;
  display: block;
  padding: 0.2rem 0;
}
.sbn-sidebar a:hover { color: var(--sbn-cta); text-decoration: none; }
.sbn-sidebar a.active {
  color: var(--sbn-cta);
  font-weight: 600;
}

/* ── TOC ─────────────────────────────────────────────────────────────────────── */
.sbn-toc {
  position: sticky;
  top: 120px;
  font-size: 0.82rem;
}
.toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.toc-list {
  list-style: none;
  border-left: 2px solid var(--border);
  padding-left: 0.75rem;
}
.toc-list li { margin-bottom: 0.15rem; }
.toc-list a {
  color: var(--muted);
  font-weight: 400;
  display: block;
  padding: 0.15rem 0;
  transition: color 0.15s;
}
.toc-list a:hover { color: var(--sbn-cta); text-decoration: none; }
.toc-list a.active { color: var(--sbn-cta); font-weight: 600; }
.toc-h3 { padding-left: 0.75rem; }

/* ── Content ─────────────────────────────────────────────────────────────────── */
.sbn-content { max-width: 860px; }

.sbn-content h1 {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 1.5rem;
}
.sbn-content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--sbn-tint-2);
}
.sbn-content h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--sbn-cta);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
}
.sbn-content p { margin-bottom: 1rem; }
.sbn-content strong { color: var(--ink); }
.sbn-content ul, .sbn-content ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}
.sbn-content li { margin-bottom: 0.3rem; }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.sbn-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.sbn-content th {
  background: var(--ink-3);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 0.6rem 0.9rem;
  letter-spacing: 0.02em;
}
.sbn-content td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.sbn-content tr:hover td { background: var(--sbn-tint); }

/* ── Code ────────────────────────────────────────────────────────────────────── */
.sbn-content code {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85em;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  color: var(--ink);
}
.sbn-content pre {
  background: var(--ink);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}
.sbn-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 0.875rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.1rem;
  margin: 1.5rem 0;
}
.card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.card:hover {
  border-color: var(--sbn-brand);
  box-shadow: 0 6px 20px rgba(58,140,47,0.12);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--text);
}
.card strong {
  display: block;
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 0.4rem;
}
.card p {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.card-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sbn-cta);
}
.contact-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.contact-card strong {
  display: block;
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 0.4rem;
}
.contact-card p {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0;
}

/* ── Admonitions ─────────────────────────────────────────────────────────────── */
.sbn-content .admonition {
  border-left: 4px solid var(--sbn-cta);
  background: var(--sbn-tint);
  border-radius: 0 8px 8px 0;
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
}
.sbn-content .admonition-title {
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sbn-cta);
  margin-bottom: 0.35rem;
}
.sbn-content .admonition.warning { border-left-color: #c87800; background: #fffbeb; }
.sbn-content .admonition.warning .admonition-title { color: #c87800; }
.sbn-content .admonition.danger { border-left-color: #c0392b; background: #fef2f2; }
.sbn-content .admonition.danger .admonition-title { color: #c0392b; }

/* ── Prev / Next navigation ──────────────────────────────────────────────────── */
.sbn-pagination {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  max-width: 860px;
}
.sbn-pagination__prev,
.sbn-pagination__next {
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
  max-width: 48%;
}
.sbn-pagination__prev { align-items: flex-start; }
.sbn-pagination__next { align-items: flex-end; margin-left: auto; }
.sbn-pagination__prev:hover,
.sbn-pagination__next:hover {
  border-color: var(--sbn-brand);
  box-shadow: 0 2px 10px rgba(58,140,47,0.1);
  text-decoration: none;
}
.pag-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.pag-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--sbn-cta);
}

/* ── Mobile menu button (hidden on desktop) ──────────────────────────────────── */
.sbn-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--ink);
  flex-shrink: 0;
}
.sbn-menu-toggle svg { display: block; }

/* ── Tablet: hide TOC, 2-col layout ─────────────────────────────────────────── */
@media (max-width: 1100px) {
  .sbn-body {
    grid-template-columns: 200px 1fr;
  }
  .sbn-toc { display: none; }
}

/* ── Mobile: single column, collapsible sidebar ──────────────────────────────── */
@media (max-width: 768px) {
  /* Header */
  .sbn-header__inner { padding: 0 1rem; }
  .sbn-phone { display: none; }
  #sbn-search { width: 130px; }
  .sbn-menu-toggle { display: block; }

  /* Nav tabs — scroll horizontally */
  .sbn-tabs__inner {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    gap: 0;
  }
  .sbn-tabs__inner::-webkit-scrollbar { display: none; }
  .sbn-tabs a { white-space: nowrap; padding: 0.65rem 0.85rem; font-size: 0.82rem; }

  /* Body: single column */
  .sbn-body {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 0;
  }

  /* Sidebar: hidden by default, slides in when open */
  .sbn-sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 260px;
    height: 100vh;
    background: #fff;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 20px rgba(0,0,0,0.12);
    z-index: 300;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    transition: left 0.25s ease;
  }
  .sbn-sidebar.open { left: 0; }

  /* Overlay when sidebar is open */
  .sbn-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 299;
  }
  .sbn-sidebar-overlay.open { display: block; }

  /* TOC hidden on mobile */
  .sbn-toc { display: none; }

  /* Cards stack */
  .card-grid { grid-template-columns: 1fr; }

  /* Search results full width */
  .sbn-search-results { right: 1rem; left: 1rem; width: auto; }
}


/* ── Header search form + user badge (Django port) ───────────────────────────── */
.sbn-search-form { display: contents; }
.sbn-whoami {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--sbn-cta);
  background: var(--sbn-tint);
  border: 1px solid var(--sbn-tint-2);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  white-space: nowrap;
}
.sbn-search-results mark { background: var(--sbn-tint-2); color: var(--ink); }

/* ── Search results page ─────────────────────────────────────────────────────── */
.results { list-style: none; margin: 0; }
.results li { margin-bottom: 0.75rem; }

/* ── AskSBN chat widget ──────────────────────────────────────────────────────── */
#asksbn-toggle {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 400;
  padding: 0.65rem 1.2rem; border: 0; border-radius: 999px;
  background: var(--sbn-cta); color: #fff; font-weight: 600; font-family: inherit;
  font-size: 0.9rem; cursor: pointer; box-shadow: 0 2px 10px rgba(15,30,22,0.3);
}
#asksbn-toggle:hover { background: var(--sbn-cta-hover); }
#asksbn-widget[hidden] { display: none; }  /* author display:flex would beat UA [hidden] */
#asksbn-widget {
  position: fixed; right: 1.25rem; bottom: 4.75rem; z-index: 401;
  width: 372px; height: 500px; display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 36px rgba(15,30,22,0.22); overflow: hidden;
}
#asksbn-messages { flex: 1; overflow-y: auto; padding: 0.85rem; }
#asksbn-form { display: flex; gap: 0.5rem; padding: 0.65rem; border-top: 1px solid var(--border); }
#asksbn-form input {
  flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: 0.875rem;
}
#asksbn-form input:focus { outline: none; border-color: var(--sbn-brand); }
#asksbn-form button {
  border: 0; border-radius: 8px; background: var(--sbn-cta); color: #fff;
  padding: 0 1rem; cursor: pointer; font-family: inherit; font-weight: 600;
}
#asksbn-form button:hover { background: var(--sbn-cta-hover); }
.asksbn-msg {
  margin: 0.4rem 0; padding: 0.55rem 0.75rem; border-radius: 10px;
  max-width: 90%; font-size: 0.9rem; line-height: 1.55;
}
.asksbn-user { background: var(--sbn-cta); color: #fff; margin-left: auto; white-space: pre-wrap; }
.asksbn-assistant p { margin: 0 0 0.5rem; }
.asksbn-assistant p:last-child { margin-bottom: 0; }
.asksbn-assistant ol, .asksbn-assistant ul { margin: 0 0 0.5rem 1.2rem; padding: 0; }
.asksbn-assistant li { margin-bottom: 0.2rem; }
.asksbn-assistant code {
  font-size: 0.85em; background: #fff; border: 1px solid var(--border);
  border-radius: 4px; padding: 0.05em 0.3em;
}
.asksbn-assistant { background: var(--bg-alt); }
.asksbn-citations {
  margin-top: 0.55rem; font-size: 0.8rem;
  display: flex; flex-direction: column; gap: 0.2rem;
}
@media (max-width: 480px) {
  #asksbn-widget { right: 0.5rem; left: 0.5rem; width: auto; }
}
