:root {
  --navy-900: #0f243d;
  --navy-800: #1e3a5f;
  --navy-700: #2c5282;
  --blue-600: #2563eb;
  --blue-100: #dbeafe;
  --blue-50: #eff6ff;
  --amber-50: #fffbeb;
  --amber-700: #b45309;
  --emerald-700: #047857;
  --emerald-50: #ecfdf5;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --header-h: 54px;
  --left-w: 300px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Calibri', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--slate-800);
  background: var(--slate-100);
}

/* HEADER */
.app-header {
  height: var(--header-h);
  background: var(--navy-900);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  gap: 12px;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover {
  background: rgba(255,255,255,0.2);
}

.brand-block {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: #ffffff;
  min-width: 0;
}
.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-subtitle {
  font-size: 11px;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-quick-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.quick-pill {
  background: rgba(255,255,255,0.09);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.quick-pill:hover {
  background: rgba(255,255,255,0.2);
  color: #ffffff;
}
.quick-pill.active {
  background: #ffffff;
  color: var(--navy-900);
  border-color: #ffffff;
}

/* WORKSPACE 3-PANE LAYOUT */
.workspace {
  display: flex;
  height: calc(100vh - var(--header-h));
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* LEFT NAVIGATOR PANE (300px) */
.left-pane {
  width: var(--left-w);
  min-width: var(--left-w);
  max-width: var(--left-w);
  background: #ffffff;
  border-right: 1px solid var(--slate-200);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
  z-index: 25;
  flex-shrink: 0;
}
.left-pane.collapsed {
  margin-left: calc(-1 * var(--left-w));
}

.nav-search-box {
  padding: 10px;
  border-bottom: 1px solid var(--slate-200);
  background: var(--slate-50);
}
.nav-search-box input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--slate-300);
  border-radius: 5px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}
.nav-search-box input:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 24px;
}

.nav-group {
  border-bottom: 1px solid var(--slate-200);
}
.nav-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--slate-50);
  border: none;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy-800);
  cursor: pointer;
  text-align: left;
}
.nav-group-header:hover {
  background: var(--slate-100);
}

.nav-list {
  padding: 4px 6px;
}
.nav-list.collapsed {
  display: none;
}

.nav-item-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin-bottom: 2px;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  border-radius: 4px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--slate-800);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.28;
  min-width: 0;
}
.nav-item:hover {
  background: var(--slate-100);
}
.nav-item.active-main {
  background: var(--blue-50);
  color: var(--navy-900);
  font-weight: 700;
  border-left: 3px solid var(--blue-600);
}
.nav-item.active-ref {
  background: var(--emerald-50);
  border-left: 3px solid var(--emerald-700);
}
.nav-item-code {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--slate-500);
  text-transform: uppercase;
}
.nav-item-label {
  word-break: break-word;
}
.nav-side-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--slate-500);
  font-size: 11px;
  padding: 0 6px;
  cursor: pointer;
}
.nav-side-btn:hover {
  background: var(--blue-50);
  border-color: var(--blue-100);
  color: var(--blue-600);
}

.toc-link {
  display: block;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--slate-700);
  text-decoration: none;
  border-radius: 4px;
  line-height: 1.3;
}
.toc-link:hover {
  background: var(--slate-100);
  color: var(--navy-800);
}
.toc-link.toc-h3 {
  padding-left: 18px;
  font-size: 11.5px;
  color: var(--slate-600);
}

.lib-subgroup {
  margin: 4px 0;
}
.lib-subheader {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--slate-100);
  border: none;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--slate-700);
  cursor: pointer;
}
.lib-subheader:hover {
  background: var(--slate-200);
}
.lib-sublist {
  padding: 3px 0 3px 4px;
}
.lib-sublist.collapsed {
  display: none;
}

/* EQUAL-SIZED LEFT & RIGHT DOCUMENT PANES (50% / 50% OF REMAINING WORKSPACE) */
.main-pane {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--slate-100);
  overflow: hidden;
}

.pane-splitter {
  width: 8px;
  background: var(--slate-200);
  border-left: 1px solid var(--slate-300);
  border-right: 1px solid var(--slate-300);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 20;
}
.pane-splitter:hover, .pane-splitter.dragging {
  background: var(--blue-600);
  border-color: var(--blue-600);
}
.splitter-grip {
  width: 2px;
  height: 34px;
  border-radius: 2px;
  background: var(--slate-500);
}
.pane-splitter:hover .splitter-grip, .pane-splitter.dragging .splitter-grip {
  background: #ffffff;
}

.ref-pane {
  flex: 1 1 0%;
  min-width: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ref-pane.maximized {
  flex: 2.2 1 0% !important;
}

/* SINGLE-DOCUMENT WINDOW MODE (< 2360px — Instant CSS Media Query + JS State Sync) */
.single-only-btn {
  display: none !important;
}
body.single-doc-mode .single-only-btn {
  display: inline-flex !important;
}
body.single-doc-mode #pane-splitter,
body.single-doc-mode #btn-maximize-ref,
body.single-doc-mode .nav-side-btn,
body.single-doc-mode #ref-chain-banner,
body.single-doc-mode #btn-promote-ref,
body.single-doc-mode .cite-hint {
  display: none !important;
}
body.single-doc-mode:not(.showing-ref) #ref-pane {
  display: none !important;
}
body.single-doc-mode:not(.showing-ref) #main-pane {
  display: flex !important;
  flex: 1 1 100% !important;
  width: 100% !important;
}
body.single-doc-mode.showing-ref #main-pane {
  display: none !important;
}
body.single-doc-mode.showing-ref #ref-pane {
  display: flex !important;
  flex: 1 1 100% !important;
  width: 100% !important;
}

@media (max-width: 1179px) {
  .quick-pill {
    padding: 4px 8px;
    font-size: 11.5px;
  }
}

@media (max-width: 2359px) {
  .single-only-btn {
    display: inline-flex !important;
  }
  #pane-splitter,
  #btn-maximize-ref,
  .nav-side-btn,
  #ref-chain-banner,
  #btn-promote-ref,
  .cite-hint {
    display: none !important;
  }
  body:not(.showing-ref) #ref-pane {
    display: none !important;
  }
  body:not(.showing-ref) #main-pane {
    display: flex !important;
    flex: 1 1 100% !important;
    width: 100% !important;
  }
  body.showing-ref #main-pane {
    display: none !important;
  }
  body.showing-ref #ref-pane {
    display: flex !important;
    flex: 1 1 100% !important;
    width: 100% !important;
  }
}

.pane-toolbar {
  min-height: 40px;
  background: #ffffff;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  gap: 8px;
  flex-shrink: 0;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.toolbar-right {
  flex-shrink: 0;
}
.toolbar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--blue-100);
  color: var(--navy-800);
  flex-shrink: 0;
}
.ref-kind-badge {
  background: var(--emerald-50);
  color: var(--emerald-700);
  border: 1px solid #a7f3d0;
}

.cite-hint {
  font-size: 11.5px;
  color: var(--slate-500);
  white-space: nowrap;
}
@media (max-width: 1440px) {
  .cite-hint { display: none; }
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--slate-700);
  background: var(--slate-50);
  border: 1px solid var(--slate-300);
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.toolbar-btn:hover:not(:disabled) {
  background: var(--slate-200);
  color: var(--slate-900);
}
.toolbar-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.toolbar-btn.active {
  background: var(--navy-800);
  color: #ffffff;
  border-color: var(--navy-800);
}
.toolbar-btn.primary-outline {
  color: var(--navy-800);
  border-color: var(--navy-700);
  background: var(--blue-50);
}
.toolbar-btn.promote-btn {
  background: var(--amber-50);
  color: var(--amber-700);
  border-color: #fcd34d;
}
.toolbar-btn.promote-btn:hover {
  background: #fef3c7;
}
.toolbar-btn.close-btn:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 54px 20px;
}

.doc-article {
  max-width: 940px;
  margin: 0 auto;
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  padding: 28px 34px;
  font-size: 16px;
  line-height: 1.54;
  color: #1f2937;
}
.ref-article {
  max-width: 940px;
  padding: 26px 32px;
  font-size: 15.5px;
  line-height: 1.5;
}

/* DOCUMENT TYPOGRAPHY & TABLES */
.doc-article h1 {
  font-size: 23px;
  font-weight: 700;
  color: var(--navy-800);
  border-bottom: 2px solid var(--navy-800);
  padding-bottom: 8px;
  margin-top: 0;
  margin-bottom: 16px;
  line-height: 1.26;
}
.doc-article h2 {
  font-size: 19px;
  font-weight: 700;
  color: var(--navy-800);
  border-bottom: 1px solid var(--slate-300);
  padding-bottom: 5px;
  margin-top: 24px;
  margin-bottom: 11px;
  line-height: 1.3;
  scroll-margin-top: 16px;
}
.doc-article h3 {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--navy-700);
  margin-top: 18px;
  margin-bottom: 7px;
  scroll-margin-top: 16px;
}
.doc-article h4 {
  font-size: 15.2px;
  font-weight: 700;
  color: var(--slate-800);
  margin-top: 14px;
  margin-bottom: 6px;
}
.doc-article p {
  margin-top: 0;
  margin-bottom: 9px;
}
.doc-article ul, .doc-article ol {
  margin-top: 4px;
  margin-bottom: 10px;
  padding-left: 24px;
}
.doc-article li {
  margin-bottom: 4.5px;
}
.doc-article hr {
  border: 0;
  border-top: 1px solid var(--slate-300);
  margin: 16px 0;
}
.doc-article blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3.5px solid var(--blue-600);
  background: var(--slate-50);
  color: var(--slate-800);
  font-size: 14.5px;
}
.doc-article blockquote p:last-child {
  margin-bottom: 0;
}
.doc-article pre {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 8.6pt;
  line-height: 1.25;
  background: var(--slate-50);
  border: 1px solid var(--slate-300);
  border-radius: 4px;
  padding: 10px 12px;
  overflow-x: auto;
}
.doc-article code {
  font-family: 'Calibri', 'Segoe UI', sans-serif;
  background: #f1f5f9;
  padding: 0 3px;
  border-radius: 3px;
  font-size: 0.96em;
}
.doc-article pre code {
  font-family: 'Consolas', 'Courier New', monospace;
  background: transparent;
  padding: 0;
  font-size: inherit;
}

/* CITATION LINKS */
.doc-article a.cite-link {
  color: var(--blue-600);
  text-decoration: none;
  border-bottom: 1.5px solid rgba(37, 99, 235, 0.4);
  background: rgba(219, 234, 254, 0.35);
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s;
  cursor: pointer;
}
.doc-article a.cite-link:hover {
  background: var(--blue-100);
  border-bottom-color: var(--blue-600);
  color: var(--navy-900);
}
.doc-article a.cite-link.cite-doc {
  color: var(--navy-800);
  background: rgba(254, 243, 199, 0.55);
  border-bottom-color: rgba(180, 83, 9, 0.45);
}
.doc-article a.cite-link.cite-doc:hover {
  background: #fde68a;
  border-bottom-color: var(--amber-700);
}
.doc-article a.cite-link.active-citation {
  outline: 2px solid var(--blue-600);
  background: var(--blue-100);
}

/* TABLES */
.table-scroll-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 8px 0 14px 0;
}
.doc-article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.8px;
  line-height: 1.35;
}
.doc-article table.cols-medium {
  font-size: 13px;
}
.doc-article table.cols-wide {
  font-size: 12.2px;
  line-height: 1.28;
}
.doc-article th {
  background: var(--navy-800);
  color: #ffffff;
  font-weight: 600;
  text-align: left;
  padding: 6px 7px;
  border: 1px solid var(--navy-800);
  vertical-align: bottom;
}
.doc-article th code {
  background: rgba(255,255,255,0.16);
  color: #ffffff;
}
.doc-article td {
  padding: 5px 7px;
  border: 1px solid var(--slate-300);
  vertical-align: top;
  overflow-wrap: break-word;
}
.doc-article tbody tr:nth-child(even) {
  background: var(--slate-50);
}

.chart-container {
  margin: 12px 0 16px 0;
  padding: 12px 14px;
  border: 1px solid var(--slate-300);
  border-radius: 5px;
  background: #ffffff;
}
.chart-title {
  font-size: 10.8pt;
  font-weight: 700;
  color: var(--navy-800);
  margin-bottom: 2px;
}
.chart-subtitle {
  font-size: 9pt;
  color: var(--slate-600);
  margin-bottom: 6px;
}

.ref-chain-banner {
  background: var(--amber-50);
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  padding: 5px 12px;
  font-size: 11.5px;
  flex-shrink: 0;
}

.pdf-controls {
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.pdf-nav-group, .pdf-zoom-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pdf-page-label {
  font-size: 12px;
  color: var(--slate-700);
  font-variant-numeric: tabular-nums;
}
#pdf-page-input {
  width: 48px;
  padding: 2px 4px;
  border: 1px solid var(--slate-300);
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  font-family: inherit;
}
.pdf-zoom-readout {
  font-size: 11.5px;
  color: var(--slate-600);
  min-width: 42px;
  text-align: center;
}

.ref-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #e5e7eb;
}

.ref-doc-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 18px 20px 54px 20px;
  background: var(--slate-100);
}

/* PDF.js stage MUST have position: absolute scroll container */
.pdf-stage {
  position: absolute;
  inset: 0;
  background: #525659;
  display: flex;
  flex-direction: column;
}
.file-pdf-banner {
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  color: #1e3a8a;
  font-size: 11.5px;
  padding: 5px 12px;
  flex-shrink: 0;
  z-index: 12;
}
.file-pdf-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #525659;
}
.pdf-scroll-container {
  position: absolute;
  inset: 0;
  overflow: auto;
}
.pdfViewer .page {
  margin: 10px auto !important;
  box-shadow: 0 2px 10px rgba(0,0,0,0.32);
  border: none !important;
}
.pdf-status-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 41, 59, 0.72);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 10;
}

/* Image Viewer */
.img-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #334155;
}
.img-controls {
  padding: 6px 12px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  gap: 6px;
}
.img-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
  text-align: center;
}
#ref-image {
  max-width: 100%;
  height: auto;
  background: #ffffff;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
}

/* Workbook / Directory Card Stage */
.card-stage {
  height: 100%;
  overflow-y: auto;
  padding: 20px;
  background: var(--slate-100);
}
.workbook-card {
  background: #ffffff;
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  padding: 20px 24px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.workbook-card h3 {
  margin: 0 0 6px 0;
  color: var(--navy-800);
  font-size: 15px;
}
.workbook-card p {
  margin: 0 0 14px 0;
  color: var(--slate-700);
  font-size: 13px;
  line-height: 1.45;
}
.wb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.wb-item {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 5px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}
.wb-item-name {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--navy-800);
}

/* HOVER TOOLTIP */
.cite-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 390px;
  background: var(--slate-900);
  color: #f8fafc;
  padding: 10px 13px;
  border-radius: 6px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 12px;
  line-height: 1.38;
  pointer-events: none;
}
.tt-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.tt-badge {
  background: var(--blue-600);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
}
.tt-badge.tt-doc {
  background: #d97706;
}
.tt-page {
  background: rgba(255,255,255,0.16);
  color: #e2e8f0;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
}
.tt-title {
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 4px;
  word-break: break-word;
}
.tt-desc {
  color: #cbd5e1;
  margin-bottom: 6px;
}
.tt-hint {
  font-size: 11px;
  color: #93c5fd;
  font-weight: 600;
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 4px;
}

/* TOAST */
.chain-toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-900);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
  z-index: 9500;
  border: 1px solid rgba(255,255,255,0.18);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .header-quick-nav { display: none; }
  .left-pane {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    box-shadow: 4px 0 16px rgba(0,0,0,0.18);
  }
  .doc-article {
    padding: 18px 16px;
  }
}
