/* Inline SVG icon spans (replaced from font ligatures at runtime by demo.js). */
.material-symbols-rounded {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Publication-style demo layout – abstract app chrome for embedding contexts */

/* Mock chrome: de-emphasized and non-interactive so only the editor is in focus.
   Stack above editor section so format bar tooltips don’t overlap the header. */
.mock-chrome {
  position: relative;
  z-index: 2;
  opacity: 0.82;
  pointer-events: none;
  user-select: none;
}

.editor-section {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  min-height: 0;
}

:root {
  --app-bar-bg: #1e3a5f;
  --app-bar-fg: #f0f4f8;
  --app-nav-bg: linear-gradient(180deg, #1e3a5f 0%, #2d4a6f 100%);
  --app-nav-fg: #e2e8f0;
  --app-nav-fg-muted: #94a3b8;
  --app-nav-active-bg: rgba(255, 255, 255, 0.12);
  --app-nav-active-fg: #ffffff;
  --app-main-bg: #ffffff;
  --app-main-fg: #1e293b;
  --app-main-muted: #64748b;
  --app-sidebar-bg: #f1f5f9;
  --app-sidebar-border: #e2e8f0;
  --app-divider: #e2e8f0;
  --status-review: #f59e0b;
  --status-unscheduled: #dc2626;
  --btn-primary-bg: #eab308;
  --btn-primary-fg: #1e293b;
  --btn-primary-hover: #facc15;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}

html {
  height: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-main-bg: #0f172a;
    --app-main-fg: #e2e8f0;
    --app-main-muted: #94a3b8;
    --app-sidebar-bg: #1e293b;
    --app-sidebar-border: rgba(148, 163, 184, 0.3);
    --app-divider: rgba(148, 163, 184, 0.35);
    --btn-primary-bg: #fbbf24;
    --btn-primary-fg: #0f172a;
    --btn-primary-hover: #fcd34d;
  }

  .editor-formatbar {
    --sciflow-formatbar-button-hover: rgba(59, 130, 246, 0.2);
    --sciflow-formatbar-button-active-background: rgba(96, 165, 250, 0.2);
  }

  .icon-button:hover {
    background: rgba(148, 163, 184, 0.2);
  }

  .outline-list li[role='button']:hover {
    background: rgba(148, 163, 184, 0.15);
  }

  sciflow-reference-list::part(meta-chip) {
    background: rgba(96, 165, 250, 0.25);
  }
}

body {
  margin: 0;
  padding: 0;
  background: var(--app-main-bg);
  color: var(--app-main-fg);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* Top app bar */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem;
  min-height: 56px;
  background: var(--app-bar-bg);
  color: var(--app-bar-fg);
  flex-shrink: 0;
}

.app-bar-branding {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-bar-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.app-bar-journal {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.85;
}

.app-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.app-bar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--app-bar-fg);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.app-bar-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.app-bar-icon .material-symbols-rounded svg {
  width: 22px;
  height: 22px;
}

.app-bar-avatar {
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.2);
}

/* App body: nav + main + sidebar */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left navigation */
.app-nav {
  width: 220px;
  flex-shrink: 0;
  background: var(--app-nav-bg);
  color: var(--app-nav-fg);
  padding: 1rem 0;
  overflow-y: auto;
}

.app-nav-section {
  margin-bottom: 1.25rem;
}

.app-nav-section-title {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--app-nav-fg-muted);
  padding: 0 1rem 0.5rem;
  margin-bottom: 0.25rem;
}

.app-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--app-nav-fg);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.app-nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--app-nav-active-fg);
}

.app-nav-link--active {
  background: var(--app-nav-active-bg);
  color: var(--app-nav-active-fg);
  font-weight: 500;
}

.app-nav-badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
}

.app-nav-link--active .app-nav-badge {
  background: rgba(255, 255, 255, 0.25);
}

/* Main content */
.app-main {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--app-main-bg);
}

/* CSS-based fullscreen (avoids native Fullscreen API so Escape stays
   available for ProseMirror's selectParentNode without exiting). */
#demo-main-with-sidebar.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#demo-main-with-sidebar.is-fullscreen .main-content {
  padding: 0;
}

#demo-main-with-sidebar.is-fullscreen .main-content > .mock-chrome {
  display: none;
}

#demo-main-with-sidebar.is-fullscreen .editor-section {
  flex: 1;
  min-height: 0;
}

#demo-main-with-sidebar.is-fullscreen .editor-area {
  height: 100%;
  border-top: 0;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0;
}

#demo-main-with-sidebar.is-fullscreen #demo-fullscreen-btn {
  display: none;
}

/* Fullscreen close button — small window-chrome-style X in the top-right */
.fullscreen-close {
  display: none;
}

#demo-main-with-sidebar.is-fullscreen > .fullscreen-close {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10000;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--app-sidebar-bg, #f1f5f9);
  color: var(--app-main-muted, #64748b);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s ease, background 0.15s ease;
}

#demo-main-with-sidebar.is-fullscreen > .fullscreen-close:hover {
  opacity: 1;
  background: var(--app-sidebar-border, #e2e8f0);
}

.main-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2rem 2rem;
  overflow: hidden;
}

.submission-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.submission-back {
  display: inline-flex;
  color: var(--app-main-muted);
  text-decoration: none;
  padding: 0.25rem;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.submission-back:hover {
  background: var(--app-sidebar-bg);
  color: var(--app-main-fg);
}

.submission-back .material-symbols-rounded svg {
  width: 20px;
  height: 20px;
}

.submission-id {
  font-size: 0.9rem;
  color: var(--app-main-muted);
}

.submission-authors {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--app-main-fg);
}

.submission-title {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--app-main-fg);
}

.submission-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.submission-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--app-main-muted);
}

.submission-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-review);
}

.submission-status-dot--unscheduled {
  background: var(--status-unscheduled);
}

.submission-actions {
  display: flex;
  gap: 0.5rem;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--app-divider);
  margin: 0 0 1.25rem;
}

/* Editor section */
.editor-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1rem;
}

.editor-section-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--app-main-muted);
  width: 100%;
}

.editor-section-meta {
  font-size: 0.875rem;
  color: var(--app-main-muted);
  pointer-events: auto;
}

.editor-section-change {
  margin-left: 0.5rem;
  color: var(--app-bar-bg);
  text-decoration: none;
}

.editor-section-change:hover {
  text-decoration: underline;
}

.editor-section-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.editor-section-status {
  font-size: 0.875rem;
  color: var(--app-main-muted);
}

/* Editor area (the “green” embed zone) */
.editor-area {
  border: 1px solid var(--app-sidebar-border);
  border-radius: 0;
  background: var(--app-main-bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* JATS side-by-side panel */
.jats-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--app-sidebar-border);
  border-left: 0;
  background: var(--app-sidebar-bg);
  overflow: hidden;
}

.jats-panel[hidden] {
  display: none;
}

.jats-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem 0 0;
  border-bottom: 1px solid var(--app-sidebar-border);
  background: var(--app-sidebar-bg);
}

.jats-panel-tabs {
  display: flex;
  gap: 0;
}

.jats-panel-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--app-main-muted);
  cursor: pointer;
}

.jats-panel-tab:hover {
  color: var(--app-main-fg);
}

.jats-panel-tab.active {
  color: var(--app-main-fg);
  border-bottom-color: var(--btn-primary-bg);
}

.jats-panel-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--app-main-muted);
  padding: 0 0.25rem;
}

.jats-panel-close:hover {
  color: var(--app-main-fg);
}

.jats-panel-code {
  flex: 1;
  margin: 0;
  padding: 0;
  overflow: auto;
  tab-size: 2;
}

.jats-panel-code code {
  display: block;
  padding: 0.75rem;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  background: transparent !important;
}

/* --------------------------------------------------------- */
/*  HTML Preview — academic article styling                   */
/* --------------------------------------------------------- */

/* The preview container scrolls and provides the grey "desk" background.
   The actual page is a child pseudo-element-like div created by the
   .jats-panel-preview-page wrapper added in the JS. We style both here
   so the CSS works even without the wrapper (plain content in the div). */
.jats-panel-preview {
  flex: 1;
  overflow: auto;
  padding: 2rem 2.5rem;
  background: #e0e2e6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview {
    background: #1a1d23;
  }
}

.jats-panel-preview[hidden] {
  display: none;
}

/* A4-like page card */
.jats-panel-preview-page,
.jats-panel-preview > section,
.jats-panel-preview > :not(.jats-panel-preview-page) {
  /* Fallback: if JS doesn't wrap in a page div, direct children still look ok */
}

.jats-panel-preview-page {
  width: 100%;
  max-width: 400px;               /* A5-ish column */
  margin: 0.5rem auto;
  background: white;
  color: #1a1a1a;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 6px 20px rgba(0,0,0,0.08);
  border-radius: 3px;
  padding: 2.5rem 2.25rem;
  font-family: 'STIX Two Text', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  font-size: 0.62rem;
  line-height: 1.7;
  transform-origin: top center;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page {
    background: #23272e;
    color: #d8dce3;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.15);
  }
}

/* All content selectors target the page card */

/* Title — first heading is the article title */
.jats-panel-preview-page > h1:first-child,
.jats-panel-preview-page > section:first-child > h1:first-child {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 0.15rem;
  letter-spacing: -0.01em;
}

.jats-panel-preview-page > h1:first-child + p,
.jats-panel-preview-page > section:first-child > h1:first-child + p {
  font-size: 0.68rem;
  color: #666;
  margin-bottom: 1.25rem;
}

/* Headings */
.jats-panel-preview-page h1 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 1.4rem 0 0.35rem;
  letter-spacing: -0.005em;
}

.jats-panel-preview-page h2 {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 1.1rem 0 0.3rem;
}

.jats-panel-preview-page h3 {
  font-size: 0.78rem;
  font-weight: 600;
  font-style: italic;
  line-height: 1.4;
  margin: 0.9rem 0 0.2rem;
}

.jats-panel-preview-page h4,
.jats-panel-preview-page h5,
.jats-panel-preview-page h6 {
  font-size: 0.72rem;
  font-weight: 600;
  margin: 0.7rem 0 0.15rem;
}

/* Body text */
.jats-panel-preview-page p {
  margin: 0 0 0.55rem;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* Sections */
.jats-panel-preview-page section {
  margin-bottom: 0.15rem;
}

/* Blockquote */
.jats-panel-preview-page blockquote {
  margin: 0.8rem 0;
  padding: 0.5rem 0.85rem;
  border-left: 2px solid #c0c0c0;
  background: #f9f9fb;
  border-radius: 0 3px 3px 0;
  font-size: 0.68rem;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page blockquote {
    background: rgba(255,255,255,0.03);
    border-left-color: #555;
  }
}

.jats-panel-preview-page blockquote p:last-child {
  margin-bottom: 0;
}

/* Figures */
.jats-panel-preview-page figure {
  margin: 1.25rem 0;
  padding: 0;
  text-align: center;
  break-inside: avoid;
}

.jats-panel-preview-page figure img {
  max-width: 80%;
  height: auto;
  border-radius: 1px;
}

.jats-panel-preview-page figure > div {
  text-align: center;
}

/* Figcaption */
.jats-panel-preview-page figcaption {
  margin-top: 0.45rem;
  padding: 0 1rem;
  font-size: 0.65rem;
  line-height: 1.5;
  color: #666;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page figcaption { color: #999; }
}

/* Label inside figcaption (e.g. "Figure 1", "Table 2") */
.jats-panel-preview-page figcaption label {
  display: inline;
  font-weight: 700;
  color: inherit;
  margin-right: 0.25em;
}

.jats-panel-preview-page figcaption label::after {
  content: '.';
}

.jats-panel-preview-page figcaption p {
  display: inline;
  text-align: center;
  margin: 0;
}

/* Tables */
.jats-panel-preview-page table {
  border-collapse: collapse;
  margin: 1rem auto;
  font-size: 0.65rem;
  line-height: 1.45;
  width: auto;
  min-width: 40%;
  max-width: 100%;
}

.jats-panel-preview-page th,
.jats-panel-preview-page td {
  padding: 0.3rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.jats-panel-preview-page th {
  font-weight: 600;
  border-bottom: 1.5px solid currentColor;
}

.jats-panel-preview-page td {
  border-bottom: 0.5px solid #d0d0d0;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page td { border-bottom-color: #444; }
}

.jats-panel-preview-page tbody tr:last-child td {
  border-bottom: 1.5px solid currentColor;
}

/* Code blocks */
.jats-panel-preview-page pre {
  background: #f5f6f8;
  border: 1px solid #e5e7ea;
  border-radius: 3px;
  padding: 0.5rem 0.7rem;
  margin: 0.85rem 0;
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 0.6rem;
  line-height: 1.5;
  overflow-x: auto;
  tab-size: 2;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page pre {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.08);
  }
}

.jats-panel-preview-page code {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: #f0f1f3;
  padding: 0.08em 0.25em;
  border-radius: 2px;
}

@media (prefers-color-scheme: dark) {
  .jats-panel-preview-page code { background: rgba(255,255,255,0.06); }
}

.jats-panel-preview-page pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* Lists */
.jats-panel-preview-page ul,
.jats-panel-preview-page ol {
  margin: 0.4rem 0 0.6rem;
  padding-left: 1.4rem;
}

.jats-panel-preview-page li {
  margin-bottom: 0.2rem;
}

.jats-panel-preview-page li p {
  margin-bottom: 0.15rem;
}

/* Horizontal rule */
.jats-panel-preview-page hr {
  border: none;
  border-top: 0.5px solid #c0c0c0;
  margin: 1.25rem 2rem;
}

/* Footnotes — rendered as inline superscript spans */
.jats-panel-preview-page span[data-type="footnote"] {
  font-size: 0.65em;
  vertical-align: super;
  line-height: 0;
  color: #2563eb;
}

/* Math — placeholder styling */
.jats-panel-preview-page math {
  font-family: 'STIX Two Math', 'Cambria Math', serif;
  font-style: italic;
}

/* Links */
.jats-panel-preview-page a {
  color: #2563eb;
  text-decoration: none;
}

/* Superscript / subscript */
.jats-panel-preview-page sup { font-size: 0.75em; }
.jats-panel-preview-page sub { font-size: 0.75em; }

/* References (bibliography entries) */
.jats-panel-preview-page p[data-type="reference"] {
  padding-left: 1.5em;
  text-indent: -1.5em;
  margin-bottom: 0.35rem;
  font-size: 0.65rem;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--app-sidebar-bg);
  border-bottom: 1px solid var(--app-sidebar-border);
  position: sticky;
  top: 0;
  z-index: 3;
}

.editor-formatbar {
  --sciflow-formatbar-background: transparent;
  --sciflow-formatbar-border: transparent;
  --sciflow-formatbar-button-color: var(--app-main-fg);
  --sciflow-formatbar-button-hover: rgba(30, 58, 95, 0.1);
  --sciflow-formatbar-button-active: var(--app-bar-bg);
  --sciflow-formatbar-button-active-background: rgba(30, 58, 95, 0.1);
  --sciflow-formatbar-select-background: var(--app-main-bg);
  --sciflow-formatbar-select-color: var(--app-main-fg);
  --sciflow-formatbar-select-border-disabled: var(--app-sidebar-border);
  --sciflow-formatbar-select-background-disabled: var(--app-sidebar-bg);
}

.editor-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

sciflow-editor {
  --sciflow-editor-background: var(--app-main-bg);
  --sciflow-editor-border: transparent;
  --sciflow-editor-border-active: var(--app-bar-bg);
  min-height: 0;
  flex: 1;
  display: block;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.editor-actions,
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--app-sidebar-bg);
  border-top: 1px solid var(--app-sidebar-border);
  font-size: 0.875rem;
  color: var(--app-main-muted);
}

.editor-unsaved {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.editor-unsaved[hidden] {
  display: none !important;
}

.editor-unsaved .material-symbols-rounded svg {
  width: 18px;
  height: 18px;
}

.editor-actions-buttons,
.editor-footer-actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--app-sidebar-border);
  background: var(--app-main-bg);
  color: var(--app-main-fg);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--app-sidebar-bg);
  border-color: var(--app-main-muted);
}

.btn-secondary {
  background: transparent;
  border-color: transparent;
  color: var(--app-main-muted);
}

.btn-secondary:hover {
  background: var(--app-sidebar-bg);
  border-color: var(--app-sidebar-border);
  color: var(--app-main-fg);
}

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--app-sidebar-border);
  border-radius: 8px;
  background: var(--app-main-bg);
  color: var(--app-main-fg);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover {
  background: rgba(30, 58, 95, 0.08);
  border-color: var(--app-main-muted);
}

.icon-button .material-symbols-rounded svg {
  width: 20px;
  height: 20px;
}

/* Right sidebar */
.app-sidebar {
  width: min(320px, 28vw);
  flex-shrink: 0;
  min-height: 0;
  height: 100%;
  background: var(--app-sidebar-bg);
  border-left: 1px solid var(--app-sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.sidebar-panel {
  padding: 1rem 1.25rem;
}

.sidebar-document-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.sidebar-document-bar .sidebar-panel-title {
  margin: 0;
}

.sidebar-document-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
  font-size: 0.8rem;
  color: var(--app-main-muted);
}

.sidebar-document-actions-buttons {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  margin-left: auto;
}

.sidebar-document-actions-buttons #demo-save-btn {
  margin-left: auto;
}

.sidebar-document-actions .editor-unsaved {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--status-review) 45%, transparent);
  background: color-mix(in srgb, var(--status-review) 18%, transparent);
  color: var(--status-review);
  font-weight: 600;
}

.sidebar-document-actions-buttons .btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.sidebar-document-actions .editor-unsaved .material-symbols-rounded svg {
  width: 16px;
  height: 16px;
}

.sidebar-panel-title {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #475569;
}

.sidebar-section {
  border-radius: 8px;
  background: var(--app-main-bg);
  border: 1px solid var(--app-sidebar-border);
  overflow: hidden;
  transition: margin 0.15s ease;
}

details[open].sidebar-section {
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
}

.sidebar-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--app-main-fg);
  background: var(--app-main-bg);
  border: none;
  cursor: pointer;
  list-style: none;
  transition: background 0.15s ease;
}

.sidebar-summary::-webkit-details-marker {
  display: none;
}

.sidebar-summary-chevron {
  color: var(--app-main-muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
  display: inline-flex;
}

.sidebar-summary-chevron svg {
  width: 20px;
  height: 20px;
}

details[open] > .sidebar-summary .sidebar-summary-chevron {
  transform: rotate(180deg);
}

.sidebar-summary-icon {
  color: var(--app-main-muted);
  flex-shrink: 0;
  display: inline-flex;
}

.sidebar-summary-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-summary:hover {
  background: var(--app-sidebar-bg);
}

.sidebar-summary-title {
  flex: 1;
}

.sidebar-summary-subtext {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--app-main-muted);
}

.sidebar-section-body {
  padding: 0.75rem 0.85rem;
  border-top: 1px solid var(--app-sidebar-border);
}

.sidebar-description {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--app-main-muted);
}

.sidebar-section h3 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  flex: 1;
}

.sidebar-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.sidebar-subtext {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--app-main-muted);
}

.feature-toggle-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
}

.feature-toggle-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.feature-toggle-input {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  accent-color: var(--app-bar-bg);
}

.feature-toggle-label {
  cursor: pointer;
}

.sidebar-section ol {
  list-style: decimal;
  padding-left: 1.25rem;
  margin: 0;
  display: grid;
  gap: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.outline-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: grid;
  gap: 0.35rem;
}

.outline-list li {
  padding-left: 0.5rem;
  border-left: 2px solid var(--app-sidebar-border);
  margin: 0;
}

.outline-list li[role='button'] {
  cursor: pointer;
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  margin: -0.3rem -0.5rem;
}

.outline-list li[role='button']:hover {
  background: rgba(30, 58, 95, 0.06);
  border-left-color: var(--app-bar-bg);
}

.outline-list li .outline-text {
  font-weight: 500;
  color: var(--app-main-fg);
}

.outline-list li .outline-meta {
  font-size: 0.8rem;
  color: var(--app-main-muted);
}

.outline-list li[data-level='2'] {
  padding-left: 1.25rem;
}

.outline-list li[data-level='3'] {
  padding-left: 2rem;
}

/* Reference list (in sidebar) */
sciflow-reference-list::part(list) {
  display: grid;
  gap: 0.5rem;
  padding: 0;
}

sciflow-reference-list::part(item) {
  display: grid;
  gap: 0.3rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--app-sidebar-border);
  background: var(--app-main-bg);
  min-height: 60px;
}

sciflow-reference-list::part(title) {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  color: var(--app-main-fg);
}

sciflow-reference-list::part(meta-chip) {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(30, 58, 95, 0.12);
  color: var(--app-bar-bg);
  font-weight: 500;
  font-size: 0.75rem;
}

code {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.9em;
  background: var(--app-sidebar-bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--app-sidebar-border);
}

/* Snapshot dialog */
.snapshot-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: 0 20px 40px rgba(30, 41, 59, 0.2);
  background: var(--app-main-bg);
}

.snapshot-dialog::backdrop {
  background: rgba(30, 41, 59, 0.5);
}

.snapshot-dialog form {
  display: grid;
  gap: 1rem;
  padding: 1.5rem 1.75rem;
}

.snapshot-dialog header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.snapshot-dialog header p {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--app-main-muted);
}

.snapshot-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.snapshot-field span {
  font-weight: 600;
}

.snapshot-field input[type='url'] {
  width: 100%;
  border: 1px solid var(--app-sidebar-border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font: inherit;
}

.snapshot-field input[type='url']:focus {
  outline: 2px solid var(--app-bar-bg);
  outline-offset: 2px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-actions button {
  border: 1px solid var(--app-sidebar-border);
  border-radius: 8px;
  background: var(--app-main-bg);
  color: var(--app-main-fg);
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.dialog-actions button[type='submit'] {
  background: var(--app-bar-bg);
  border-color: var(--app-bar-bg);
  color: var(--app-bar-fg);
}

.dialog-actions button[type='submit']:hover {
  background: #2d4a6f;
  border-color: #2d4a6f;
}

/* Responsive */
@media (max-width: 1024px) {
  .app-nav {
    width: 72px;
    padding: 1rem 0;
  }

  .app-nav-section-title,
  .app-nav-link span:not(.app-nav-badge),
  .app-nav-link .app-nav-badge {
    display: none;
  }

  .app-nav-link {
    justify-content: center;
    padding: 0.6rem;
  }

  .app-sidebar {
    width: 280px;
  }
}

@media (max-width: 768px) {
  .app-body {
    flex-direction: column;
  }

  .app-nav {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
  }

  .app-nav-section {
    margin-bottom: 0;
  }

  .app-nav-section-title {
    display: none;
  }

  .app-nav-link {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }

  .app-nav-link .app-nav-badge {
    display: inline;
  }

  .app-main {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--app-sidebar-border);
  }

  .main-content {
    padding: 1rem 1.25rem;
    overflow: auto;
  }

  .editor-section {
    flex: 0 0 auto;
  }

  .editor-area {
    flex: 0 0 auto;
  }

  sciflow-editor {
    min-height: 320px;
    flex: 0 0 auto;
  }

  .editor-section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .editor-section-actions {
    margin-left: 0;
  }
}
