:root {
  --mj-bg: #0b1220;
  --mj-panel: #0f172a;
  --mj-border: rgba(148, 163, 184, 0.22);
  --mj-text: #e5e7eb;
  --mj-muted: rgba(229, 231, 235, 0.70);
  --mj-user: #2563eb;
  --mj-agent: rgba(255, 255, 255, 0.06);
  --mj-control: rgba(255, 255, 255, 0.06);
  --mj-control-hover: rgba(255, 255, 255, 0.08);

  --mj-agent-nav: #22c55e;
  --mj-agent-extract: #a78bfa;
  --mj-agent-system: #f59e0b;
  --mj-agent-you: #93c5fd;

  /* Layout sizing: rule-of-thumb target is ~18% / 42% / 40% (TOC/Chat/Verbatim) */
  --mj-toc-min: 260px;
  --mj-toc-ideal: 18vw;
  --mj-toc-max: 360px;

  --mj-verb-min: 360px;
  --mj-verb-ideal: 40vw;
  --mj-verb-max: 760px;

  /* Readable text line length for verbatim */
  --mj-verbatim-max-ch: 72ch;
}

.mj-app {
  background: var(--mj-bg);
  color: var(--mj-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mj-navbar {
  background: #111827;
  border-bottom: 1px solid var(--mj-border);
}

.mj-main {
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
}

.mj-layout {
  display: grid;
  height: 100%;
  min-height: 0;
}

/* Desktop rule: static 3-panel layout (no offcanvas/overlays).
   Ratio 30:40:40 implemented as 3fr:4fr:4fr. */
@media (min-width: 992px) {
  .mj-layout {
    grid-template-columns: minmax(var(--mj-toc-min), 3fr) minmax(0, 4fr) minmax(var(--mj-verb-min), 4fr);
  }
}

/* Mobile/tablet: middle panel is primary; side panels are offcanvas */
@media (max-width: 991.98px) {
  .mj-layout {
    grid-template-columns: 1fr;
    height: 100%;
  }
}

.mj-footer {
  border-top: 1px solid rgba(245, 235, 235, 0.08);
  background: rgba(249, 250, 251, 0.6);
}

.mj-agent-badge {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--mj-text);
}

.mj-agent-switch .btn {
  border-color: rgba(255, 255, 255, 0.18);
}

.mj-agent-switch .btn.active,
.mj-agent-switch .btn[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.10);
}

.mj-bubble-tag {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 0.35rem;
}

.mj-bubble-tag-nav { color: var(--mj-agent-nav); }
.mj-bubble-tag-extract { color: var(--mj-agent-extract); }
.mj-bubble-tag-system { color: var(--mj-agent-system); }
.mj-bubble-tag-you { color: var(--mj-agent-you); }

.mj-help-card {
  margin: 0.75rem 0.75rem 0;
  padding: 0.75rem 0.9rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--mj-border);
  border-radius: 12px;
}

.mj-help-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.mj-help-body {
  color: var(--mj-text);
}

.mj-help-steps {
  margin: 0;
  padding-left: 1.2rem;
}

.mj-help-steps li {
  margin: 0.25rem 0;
}

.mj-help-pill {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--mj-text);
  font-size: 0.85em;
}

.mj-help-muted {
  margin-top: 0.5rem;
  color: var(--mj-muted);
  font-size: 0.85rem;
}


/* On desktop, the JS will remove offcanvas classes; keep CSS neutral. */

.mj-panel {
  background: var(--mj-panel);
  border-right: 1px solid var(--mj-border);
}

/* Desktop static panels should scroll within their body */
.mj-panel-left,
.mj-panel-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mj-panel-left .offcanvas-body,
.mj-panel-right .offcanvas-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mj-panel-right {
  border-right: none;
  border-left: 1px solid var(--mj-border);
}

@media (max-width: 991.98px) {
  .mj-panel {
    border-right: none;
    border-left: none;
  }
}

/* Side panel widths when in offcanvas mode (mobile/tablet) */
@media (max-width: 991.98px) {
  #tocPanel.offcanvas,
  #tocPanel.offcanvas-lg {
    width: clamp(var(--mj-toc-min), var(--mj-toc-ideal), var(--mj-toc-max));
  }

  #verbatimPanel.offcanvas,
  #verbatimPanel.offcanvas-lg {
    width: clamp(var(--mj-verb-min), var(--mj-verb-ideal), var(--mj-verb-max));
  }
}

.offcanvas,
.offcanvas-lg {
  background: var(--mj-panel);
  color: var(--mj-text);
}

.offcanvas-header {
  border-bottom: 1px solid var(--mj-border);
  position: relative;
  z-index: 10;
}

.offcanvas-body {
  overflow: auto;
}

.mj-panel-left .offcanvas-body,
.mj-panel-right .offcanvas-body {
  padding: 1rem;
}

.mj-panel-topbar {
  flex: 0 0 auto;
  height: 48px;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--mj-border);
  background: rgba(255, 255, 255, 0.02);
}

.mj-panel-topbar-title {
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mj-text);
  width: 100%;
  text-align: center;
  padding: 0 0.75rem;
}

.mj-legacy-icon-wrap {
  margin-top: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mj-legacy-icon {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--mj-border);
  background: rgba(255, 255, 255, 0.06);
  padding: 8px;
}

.mj-panel-middle {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mj-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--mj-border);
  background: rgba(255, 255, 255, 0.02);
}

#subContextLabel {
  max-width: 44ch;
  text-align: right;
}

.mj-chat-messages {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

.mj-chat-composer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--mj-border);
  background: rgba(255, 255, 255, 0.02);
}

/* Bootstrap form controls - make them match dark UI */
.form-control,
.form-select,
.input-group-text {
  background: var(--mj-control);
  color: var(--mj-text);
  border-color: var(--mj-border);
}

.form-control::placeholder {
  color: rgba(229, 231, 235, 0.55);
}

.form-control:focus,
.form-select:focus {
  background: var(--mj-control-hover);
  color: var(--mj-text);
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 0 0 0.15rem rgba(37, 99, 235, 0.18);
}

.btn-outline-secondary {
  color: var(--mj-text);
  border-color: var(--mj-border);
}

.btn-outline-secondary:hover {
  background: var(--mj-control-hover);
  border-color: rgba(148, 163, 184, 0.35);
}

.btn-close {
  filter: invert(1) grayscale(100%);
  cursor: pointer;
  pointer-events: auto !important;
  z-index: 11;
  flex-shrink: 0;
}

.btn-close:hover,
.btn-close:focus {
  opacity: 0.8;
}

.mj-bubble {
  max-width: 72ch;
  padding: 0.6rem 0.8rem;
  border-radius: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.mj-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.mj-row-user {
  justify-content: flex-end;
}

.mj-row-agent {
  justify-content: flex-start;
}

.mj-bubble-user {
  background: var(--mj-user);
  color: white;
}

.mj-bubble-agent {
  background: var(--mj-agent);
  border: 1px solid var(--mj-border);
}

.mj-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.mj-verbatim {
  margin: 0;
  padding: 1rem;
  border: none;
  background: transparent;
  color: var(--mj-text);
  white-space: pre-wrap;
  /* Readability: allow the panel to be wide, but keep text lines comfortable */
  max-width: var(--mj-verbatim-max-ch);
  margin-left: auto;
  margin-right: auto;
}

.mj-verbatim-frame {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--mj-border);
  background: rgba(0, 0, 0, 0.22);
  padding: 0.5rem;
}

.mj-verbatim-meta {
  padding: 0.35rem 0.6rem 0.1rem;
  max-width: var(--mj-verbatim-max-ch);
  margin-left: auto;
  margin-right: auto;
}

.mj-verbatim-controls {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding: 0.6rem 0.6rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: var(--mj-verbatim-max-ch);
  margin-left: auto;
  margin-right: auto;
}

#verbatimSectionsLabel {
  opacity: 0.85;
}

#btnLoadNextVerbatim[disabled] {
  opacity: 0.6;
}

.mj-toc {
  font-size: 0.95rem;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* Bootstrap accordion - dark theme */
.accordion {
  --bs-accordion-bg: var(--mj-panel);
  --bs-accordion-color: var(--mj-text);
  --bs-accordion-border-color: var(--mj-border);
  --bs-accordion-btn-color: var(--mj-text);
  --bs-accordion-btn-bg: rgba(255, 255, 255, 0.02);
  --bs-accordion-active-color: var(--mj-text);
  --bs-accordion-active-bg: rgba(37, 99, 235, 0.14);
  --bs-accordion-btn-focus-border-color: rgba(37, 99, 235, 0.55);
  --bs-accordion-btn-focus-box-shadow: 0 0 0 0.15rem rgba(37, 99, 235, 0.18);
}

.accordion-button {
  border-radius: 0;
}

.accordion-button::after {
  filter: invert(1) grayscale(100%);
}

.accordion-body {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

.mj-toc .mj-toc-title {
  cursor: pointer;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
}

.mj-toc .mj-toc-title:hover {
  background: rgba(255, 255, 255, 0.06);
}

.mj-toc .mj-toc-title[aria-current="true"] {
  background: rgba(37, 99, 235, 0.22);
  outline: 1px solid rgba(37, 99, 235, 0.35);
}
