:root {
  --bg-page: #ffffff;
  --bg-sidebar: #f6f7f8;
  --bg-surface: #eceef1;
  --bg-surface-hover: #e2e5e9;
  --border-subtle: #dfe3e8;
  --border-strong: #c5cbd3;
  --accent: #525866;
  --accent-dark: #2f343d;
  --accent-soft: #eaedf0;
  --accent-tint: #f8f9fa;
  --ink-primary: #1b1e23;
  --ink-secondary: #4a505c;
  --ink-muted: #6c7380;

  /* Dynamic Typography Controls */
  --reader-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --reader-size: 16.5px;
  --reader-line-height: 1.75;
  --reader-max-width: 820px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg-page);
  color: var(--ink-primary);
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--ink-primary);
  -webkit-font-smoothing: antialiased;
}

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 62px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 14px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-primary);
  text-align: left;
  text-decoration: none;
}

.brand-btn:hover {
  background: var(--bg-sidebar);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-sub {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  font-weight: 500;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--ink-primary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--bg-sidebar);
  border-color: var(--border-strong);
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.mobile-menu-btn {
  display: none;
  width: 36px;
  padding: 0;
}

/* Search Bar */
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 36px 0 36px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  color: var(--ink-primary);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(82, 88, 102, 0.16);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
  font-size: 14px;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  display: none;
}

.search-clear.visible {
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Font Settings Popover */
.font-panel {
  position: fixed;
  top: 70px;
  right: 20px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(27, 30, 35, 0.12);
  padding: 18px;
  z-index: 60;
  display: none;
}

.font-panel.open {
  display: block;
}

.font-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.font-panel-head h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.font-group {
  margin-bottom: 14px;
}

.font-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin-bottom: 7px;
}

.seg-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.seg-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn:hover {
  border-color: var(--accent);
}

.seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.size-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-controls input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--ink-secondary);
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.reset-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

.reset-link:hover {
  text-decoration: underline;
}

/* Main App Shell */
.app-shell {
  display: flex;
  min-height: calc(100vh - 62px);
}

/* Left Sidebar */
.sidebar {
  width: 292px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  padding: 16px 12px 32px;
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  overflow-y: auto;
}

.sidebar-home-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-primary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
}

.sidebar-home-btn:hover {
  background: var(--bg-surface);
}

.sidebar-home-btn.active {
  background: var(--accent-soft);
  border-color: var(--border-strong);
  color: var(--accent-dark);
}

.cat-section {
  margin-bottom: 14px;
}

.cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
}

.cat-header:hover {
  background: var(--bg-surface);
}

.cat-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 99px;
  padding: 1px 7px;
}

.nav-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.nav-item-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  border-radius: 0 8px 8px 0;
  padding: 7px 10px;
  cursor: pointer;
  color: var(--ink-secondary);
  display: block;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item-btn:hover {
  background: var(--bg-surface);
  color: var(--ink-primary);
}

.nav-item-btn.active {
  background: #ffffff;
  border-left-color: var(--accent);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(27, 30, 35, 0.06);
}

.nav-item-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.nav-item-btn.active .nav-item-title {
  font-weight: 650;
}

.nav-item-meta {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  background: var(--bg-page);
  padding: 28px 32px 64px;
}

/* Home / Library View */
.library-container {
  max-width: 1040px;
  margin: 0 auto;
}

.library-hero {
  background: linear-gradient(135deg, #f8f9fa 0%, #eef0f3 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 22px 26px;
  margin-bottom: 24px;
}

.library-hero h1 {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.library-hero p {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--ink-secondary);
  line-height: 1.55;
  max-width: 680px;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stat-pill {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 99px;
  padding: 5px 13px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-dark);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-pill {
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.lecture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(305px, 1fr));
  gap: 16px;
}

.lecture-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 18px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.lecture-card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(27, 30, 35, 0.08);
  transform: translateY(-1px);
}

.card-cat {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 6px;
}

.card-title {
  margin: 0 0 6px;
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.32;
  color: var(--ink-primary);
}

.card-doctor {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 8px;
}

.card-excerpt {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-secondary);
  margin: 0 0 14px;
  flex: 1;
}

.card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-muted);
  padding-top: 10px;
  border-top: 1px solid var(--bg-surface);
}

/* Reader View */
.reader-layout {
  display: flex;
  gap: 32px;
  max-width: 1220px;
  margin: 0 auto;
  align-items: flex-start;
}

.article-column {
  flex: 1;
  min-width: 0;
  max-width: var(--reader-max-width);
}

.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-bottom: 14px;
}

.breadcrumb button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.breadcrumb button:hover {
  text-decoration: underline;
}

.article-header {
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.article-badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.badge-cat {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 99px;
}

.badge-doctor {
  display: inline-block;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  color: var(--ink-primary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 99px;
}

.article-title {
  margin: 0 0 12px;
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 780;
  line-height: 1.22;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.article-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-muted);
}

.meta-items {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.article-tools {
  display: flex;
  gap: 8px;
}

/* Article Typography (controlled by Font Panel) */
.article-body {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-line-height);
  color: var(--ink-primary);
}

.article-body h2 {
  font-size: 1.38em;
  font-weight: 750;
  line-height: 1.3;
  color: var(--ink-primary);
  margin: 1.8em 0 0.65em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
  scroll-margin-top: 82px;
}

.article-body h3 {
  font-size: 1.14em;
  font-weight: 700;
  line-height: 1.35;
  color: var(--accent-dark);
  margin: 1.4em 0 0.5em;
  scroll-margin-top: 82px;
}

.article-body p {
  margin: 0 0 1em;
}

.article-body p.rtl-text {
  direction: rtl;
  text-align: right;
  font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg-sidebar);
  padding: 10px 14px;
  border-radius: 8px;
  border-right: 3px solid var(--accent);
}

.article-body ul {
  margin: 0 0 1.1em;
  padding-left: 1.45em;
}

.article-body li {
  margin-bottom: 0.45em;
}

.callout-box {
  background: var(--accent-tint);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 1.2em 0;
  color: var(--ink-primary);
}

/* Inline Cross-Link Style */
.crosslink-inline {
  color: var(--accent-dark);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.12s ease;
}

.crosslink-inline:hover {
  background: var(--accent-soft);
  text-decoration-style: solid;
}

.crosslinks-disabled .crosslink-inline {
  color: inherit;
  text-decoration: none;
  font-weight: inherit;
  pointer-events: none;
}

/* Figures Gallery */
.figure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin: 1.4em 0;
}

.figure-grid.single {
  grid-template-columns: minmax(0, 560px);
}

.figure-card {
  margin: 0;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.figure-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(27, 30, 35, 0.08);
}

.figure-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  background: #ffffff;
}

.figure-card figcaption {
  padding: 8px 12px;
  font-family: "Inter", sans-serif;
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-subtle);
}

/* Right TOC & Cross-Link Rail */
.right-rail {
  width: 248px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
  padding-left: 16px;
  border-left: 1px solid var(--border-subtle);
}

.rail-section {
  margin-bottom: 22px;
}

.rail-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin: 0 0 8px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 4px 0;
  font-size: 12.5px;
  line-height: 1.38;
  color: var(--ink-secondary);
  cursor: pointer;
}

.toc-link.level-3 {
  padding-left: 12px;
  font-size: 12px;
  color: var(--ink-muted);
}

.toc-link:hover {
  color: var(--accent-dark);
}

.rail-link-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.rail-link-card:hover {
  border-color: var(--accent);
}

.rail-link-title {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-primary);
  line-height: 1.3;
}

.rail-link-sub {
  display: block;
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Bottom Cross-Linkage Hub */
.crosslink-hub {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
}

.hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.hub-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-primary);
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.related-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 13px 15px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.related-card:hover {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.related-cat {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
}

.related-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--ink-primary);
  margin: 4px 0;
  line-height: 1.3;
}

.related-meta {
  font-size: 12px;
  color: var(--ink-muted);
}

.topic-chip {
  display: inline-block;
  font-size: 11px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--accent-dark);
  border-radius: 99px;
  padding: 2px 8px;
  margin: 4px 4px 0 0;
}

/* Prev / Next Navigation */
.pager-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.pager-btn {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 13px 16px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease;
}

.pager-btn:hover {
  border-color: var(--accent);
}

.pager-btn.next {
  text-align: right;
}

.pager-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 3px;
}

.pager-title {
  display: block;
  font-size: 14px;
  font-weight: 650;
  color: var(--accent-dark);
}

/* Custom Cross-Link Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 30, 35, 0.45);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  padding: 20px;
  box-shadow: 0 20px 50px rgba(27, 30, 35, 0.2);
}

.modal-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--ink-primary);
}

.field-group {
  margin-bottom: 12px;
}

.field-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-bottom: 5px;
}

.field-group select,
.field-group input {
  width: 100%;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  padding: 0 10px;
  font-size: 13.5px;
  background: #ffffff;
  color: var(--ink-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

/* Image Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(18, 20, 23, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox.open {
  display: flex;
}

.lightbox-bar {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #eceff2;
  font-size: 13.5px;
}

.lightbox-controls {
  display: flex;
  gap: 8px;
}

.lb-btn {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.lb-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.lightbox-stage {
  max-width: 92vw;
  max-height: 80vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 6px;
  background: #ffffff;
  transition: transform 0.18s ease;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink-primary);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 13px;
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 1120px) {
  .right-rail {
    display: none;
  }
}

@media (max-width: 820px) {
  .mobile-menu-btn {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    left: -310px;
    top: 62px;
    z-index: 55;
    transition: left 0.2s ease;
    box-shadow: 12px 0 32px rgba(27, 30, 35, 0.16);
  }
  .sidebar.open {
    left: 0;
  }
  .main-content {
    padding: 20px 16px 48px;
  }
  .brand-sub {
    display: none;
  }
  .pager-nav {
    grid-template-columns: 1fr;
  }
}

.rtl-inline {
  direction: rtl;
  unicode-bidi: isolate;
  font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  display: inline-block;
}

/* Collapsible Sidebar, Right Rail, Category Accordions & Clean View */
.sidebar {
  transition: width 0.2s ease, padding 0.2s ease, opacity 0.18s ease, left 0.2s ease;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: none;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.cat-chevron {
  display: inline-block;
  margin-right: 5px;
  font-size: 10px;
  transition: transform 0.16s ease;
}

.cat-section.collapsed .cat-chevron {
  transform: rotate(-90deg);
}

.cat-section.collapsed .nav-list {
  display: none;
}

.sidebar-collapse-all {
  display: flex;
  justify-content: flex-end;
  margin: -4px 4px 10px;
}

.right-rail {
  transition: width 0.2s ease, opacity 0.18s ease, padding 0.2s ease;
}

body.rail-collapsed .right-rail {
  display: none;
}

body.rail-collapsed .article-column,
body.clean-view .article-column {
  margin: 0 auto;
}

/* Full Clean View: collapses topbar, left sidebar, and right rail */
body.clean-view .topbar {
  display: none;
}

body.clean-view .sidebar,
body.clean-view .right-rail {
  display: none;
}

body.clean-view .main-content {
  padding-top: 36px;
}

.clean-view-bar {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 55;
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 6px 20px rgba(27, 30, 35, 0.1);
}

body.clean-view .clean-view-bar {
  display: flex;
}

body.clean-view .font-panel {
  top: 62px;
}

@media (max-width: 820px) {
  body.sidebar-collapsed .sidebar {
    width: 292px;
    padding: 16px 12px 32px;
    opacity: 1;
    pointer-events: auto;
  }
  .btn-label {
    display: none;
  }
}

/* Warm Espresso & Light-Brown Dark Mode */
body.dark-mode {
  --bg-page: #121417;
  --bg-sidebar: #181b1f;
  --bg-surface: #21252b;
  --bg-surface-hover: #2b3038;
  --border-subtle: #2e333b;
  --border-strong: #414854;
  --accent: #a6aeb8;
  --accent-dark: #d2d7de;
  --accent-soft: #282d35;
  --accent-tint: #1b1e23;
  --ink-primary: #eceff2;
  --ink-secondary: #b8c0ca;
  --ink-muted: #8a93a0;
  background: var(--bg-page);
  color: var(--ink-primary);
}

body.dark-mode .topbar {
  background: rgba(18, 20, 23, 0.95);
}

body.dark-mode .icon-btn,
body.dark-mode .filter-pill,
body.dark-mode .lecture-card,
body.dark-mode .pager-btn,
body.dark-mode .font-panel,
body.dark-mode .modal-card,
body.dark-mode .field-group select,
body.dark-mode .field-group input,
body.dark-mode .stat-pill,
body.dark-mode .cat-count,
body.dark-mode .topic-chip,
body.dark-mode .nav-item-btn.active,
body.dark-mode .search-input:focus {
  background: var(--bg-surface);
  color: var(--ink-primary);
}

body.dark-mode .filter-pill.active,
body.dark-mode .seg-btn.active,
body.dark-mode .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #121417;
}

body.dark-mode .brand-mark {
  background: var(--accent);
  color: #121417;
}

body.dark-mode .library-hero {
  background: linear-gradient(135deg, #1b1f24 0%, #242930 100%);
}

body.dark-mode .clean-view-bar {
  background: rgba(24, 27, 31, 0.94);
}

body.dark-mode .toast {
  background: var(--accent);
  color: #121417;
}

body.dark-mode .figure-card img {
  background: #0d0f12;
}
