/* Light, content-first UI */
:root {
  --canvas: #f1edee;
  --page: #f9f6f7;
  --text: #3d5467;
  --text-muted: #686963;
  --border: #d7d2d3;
  --border-strong: #b8b2b4;
  --accent: #3d5467;
  --accent-soft: #d9e0e3;
  --success-bg: #ecfdf5;
  --success-text: #047857;
  --review-bg: #fffbeb;
  --draft-bg: #f3f4f6;
  --shadow-page: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --header-h: 52px;
  --font: "Geist", sans-serif;
  --fmt-font-family: "Geist", sans-serif;
  --fmt-base-size: 17px;
  --fmt-p-font-family: var(--fmt-font-family);
  --fmt-p-size: var(--fmt-base-size);
  --fmt-h1-font-family: var(--fmt-font-family);
  --fmt-h2-font-family: var(--fmt-font-family);
  --fmt-h3-font-family: var(--fmt-font-family);
  --fmt-h4-font-family: var(--fmt-font-family);
  --fmt-h5-font-family: var(--fmt-font-family);
  --fmt-h6-font-family: var(--fmt-font-family);
  --fmt-h1-size: 2.2rem;
  --fmt-h2-size: 2rem;
  --fmt-h3-size: 1.6rem;
  --fmt-h4-size: 1.35rem;
  --fmt-h5-size: 1.15rem;
  --fmt-h6-size: 1rem;
  --fmt-heading-weight: 700;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

.app-header {
  min-height: var(--header-h);
  padding: 0.45rem 1.25rem 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-main {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

.product-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-family: "DM Serif Display", serif;
  letter-spacing: 0.01em;
}

.header-sep { color: var(--border-strong); }

.doc-breadcrumb {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(40vw, 420px);
  font-family: "DM Serif Display", serif;
  letter-spacing: 0.01em;
}

.context-breadcrumbs,
.breadcrumb-publication,
.breadcrumb-document {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

.breadcrumb-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
}

.account-menu { position: relative; }
.account-menu summary { display: inline-flex; align-items: center; gap: 0.45rem; }
.account-avatar { width: 1.3rem; height: 1.3rem; border-radius: 50%; object-fit: cover; }
.account-panel { position: absolute; right: 0; top: calc(100% + 0.4rem); z-index: 20; min-width: 7rem; padding: 0.5rem; background: var(--page); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-page); }

.discussion-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.65rem; }
.discussion-item { padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--canvas); }
.discussion-item p { margin: 0 0 0.35rem; white-space: pre-wrap; }
.discussion-item span { font-size: 0.75rem; color: var(--text-muted); }
.discussion-item-actions { display: flex; gap: 0.6rem; margin-top: 0.35rem; }

.advanced-menu { position: relative; }
.advanced-menu > summary { list-style: none; }
.advanced-menu > summary::-webkit-details-marker { display: none; }
.advanced-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  width: min(380px, calc(100vw - 2rem));
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 14px 38px rgba(29, 39, 48, 0.16);
  z-index: 40;
}
.advanced-warning,
.advanced-error {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.advanced-error { color: #a33a3a; overflow-wrap: anywhere; }
.advanced-actions { display: flex; gap: 0.5rem; }
.advanced-ids { margin: 0; display: grid; gap: 0.3rem; font-size: 0.72rem; }
.advanced-ids div { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0.5rem; }
.advanced-ids dt { color: var(--text-muted); }
.advanced-ids dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, monospace; }

.ctl { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.75rem; }
.ctl-label { color: var(--text-muted); font-weight: 500; }
.ctl-input, .ctl-select {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  color: var(--text);
  min-width: 11rem;
}

.btn {
  font: inherit;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  color: #f1edee;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary {
  background: #f1edee;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { background: #e7e2e3; }
.btn-outline {
  background: #f1edee;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--text-muted); background: #e7e2e3; }
.btn-block { width: 100%; }
.btn-danger-outline {
  background: transparent;
  color: #9f3434;
  border-color: #d7a5a5;
}
.btn-danger-outline:hover { background: #fff1f1; }
.save-state-unsaved { color: #9a6700; }
.save-state-saving { color: var(--text-muted); }
.save-state-saved { color: var(--success-text); }
.save-state-failed { color: #a33a3a; }
.empty-section-action { margin-top: 1rem; }

.workspace-overview {
  min-height: calc(100vh - var(--header-h));
  padding: clamp(2rem, 5vw, 4.5rem) clamp(1.25rem, 6vw, 6rem);
  background:
    radial-gradient(circle at top right, rgba(61, 84, 103, 0.08), transparent 34rem),
    var(--canvas);
}

.workspace-page {
  width: min(1080px, 100%);
  margin: 0 auto;
}

.workspace-page-narrow {
  width: min(680px, 100%);
  padding: clamp(2rem, 5vw, 4rem);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--page);
  box-shadow: var(--shadow-page);
}

.workspace-title-row,
.workspace-section-heading,
.workspace-title-with-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.publication-action-status {
  min-height: 1.5rem;
  margin: -2rem 0 1.25rem;
}

.workspace-title-row {
  align-items: flex-start;
  margin-bottom: 2.75rem;
}

.workspace-title-row h1,
.workspace-page-narrow h1 {
  margin: 0.1rem 0 0.55rem;
  font-family: "DM Serif Display", serif;
  font-size: clamp(2.1rem, 5vw, 3.8rem);
  line-height: 1.05;
  color: var(--text);
}

.workspace-eyebrow {
  margin: 0 0 0.25rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.workspace-lede {
  max-width: 680px;
  margin: 0;
  color: var(--text-muted);
  font-size: 1.02rem;
}

.workspace-section {
  margin-top: 2rem;
}

.workspace-section-heading {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.workspace-section-heading h2 {
  margin: 0;
  font-family: "DM Serif Display", serif;
  font-size: 1.65rem;
}

.count-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 1.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: capitalize;
}

.count-pill {
  color: var(--text-muted);
  background: var(--page);
  border: 1px solid var(--border);
}

.status-draft { background: var(--draft-bg); color: var(--text-muted); }
.status-ready { background: var(--review-bg); color: #92400e; }
.status-current { background: var(--success-bg); color: var(--success-text); }
.status-changed { background: #fef2f2; color: #b91c1c; }
.status-supporting { background: #e8e1f3; color: #5f4778; }

.workspace-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.workspace-card,
.document-card {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

button.workspace-card,
.document-card-open {
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.workspace-card {
  min-height: 170px;
  padding: 1.2rem;
}

.workspace-card:hover,
.document-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-page);
}

.workspace-card h3,
.document-card h3 {
  margin: 0.25rem 0 0.55rem;
  font-family: "DM Serif Display", serif;
  font-size: 1.3rem;
}

.workspace-card p,
.document-card p {
  margin: 0;
  color: var(--text-muted);
}

.card-meta {
  display: flex;
  gap: 0.85rem;
  margin-top: 1.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.document-card-list {
  display: grid;
  gap: 0.75rem;
}

.document-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
}

.document-card-open {
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
}

.document-card-open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 5px;
  border-radius: 2px;
}

.document-card h3 {
  margin: 0;
}

.document-card-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
}

.document-card-state {
  flex-shrink: 0;
}

.document-archive-button {
  padding: 0.35rem 0.45rem;
  color: #9f3434;
}

.document-archive-button:hover {
  text-decoration: underline;
}

.document-archive-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.archived-documents-lede {
  margin: -0.35rem 0 1rem;
  font-size: 0.9rem;
}

.supporting-documents-lede {
  margin: -0.35rem 0 1rem;
  font-size: 0.9rem;
}

.archived-document-card {
  background: #fafafa;
  border-style: dashed;
}

.archived-document-card .workspace-eyebrow {
  text-transform: none;
  letter-spacing: 0;
}

.publication-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--border);
}

.publication-summary > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 1.1rem 1.25rem;
  background: var(--page);
}

.publication-summary strong {
  font-family: "DM Serif Display", serif;
  font-size: 1.5rem;
}

.publication-summary span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.publication-outputs-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(0, 1.5fr);
  gap: 1rem;
}

.publication-output-list {
  display: grid;
  align-content: start;
  gap: 0.55rem;
}

.publication-output-button {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--page);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.publication-output-button:hover,
.publication-output-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.publication-output-button strong,
.publication-output-button span {
  display: block;
}

.publication-output-button span {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.publication-output-preview {
  min-height: 180px;
  max-height: 520px;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: #263746;
}

.workspace-empty {
  padding: 2rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
  background: rgba(249, 246, 247, 0.55);
}

@media (max-width: 720px) {
  .workspace-title-row {
    flex-direction: column;
  }

  .publication-summary {
    grid-template-columns: 1fr;
  }

  .publication-outputs-layout {
    grid-template-columns: 1fr;
  }

  .document-card {
    align-items: flex-start;
    flex-direction: column;
  }
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  height: calc(100vh - var(--header-h));
  max-height: calc(100vh - var(--header-h));
  min-height: 0;
}

@media (min-width: 1025px) {
  body.document-mode {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  body.document-mode .app-header {
    position: relative;
    top: auto;
  }

  body.document-mode .app-shell {
    height: auto;
    max-height: none;
    min-height: 0;
  }
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
  .rail-structure { order: 2; border-right: none; border-top: 1px solid var(--border); }
  .document-column { order: 0; min-height: 60vh; }
  .rail-properties { order: 1; border-left: none; border-top: 1px solid var(--border); max-height: none; }
}

.rail {
  background: var(--page);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.rail-properties {
  border-right: none;
  border-left: 1px solid var(--border);
}

.rail-header {
  padding: 0.85rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-family: "DM Serif Display", serif;
  letter-spacing: 0.04em;
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.65rem 0.75rem;
}

.tree ul {
  list-style: none;
  margin: 0;
  padding-left: 0.65rem;
}

.tree li { margin: 0.1rem 0; }

.node-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.tree button.node {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.875rem;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.node-actions {
  display: inline-flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 120ms ease-in-out;
}

.node-row:hover .node-actions,
.node-row:focus-within .node-actions {
  opacity: 1;
}

.node-mini {
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid var(--border);
  background: #f1edee;
  color: var(--text-muted);
  border-radius: 4px;
  font-size: 0.78rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.node-mini:hover { color: var(--text); border-color: var(--border-strong); }
.node-mini.drag { cursor: grab; font-size: 0.9rem; }
.node-row.drag-over > button.node { outline: 2px dashed var(--accent); outline-offset: 1px; }

.tree button.node:hover { background: #f4f6f8; }

.tree button.node.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

.tree-actions {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex-shrink: 0;
}

.document-column {
  background: var(--canvas);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.document-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem 1.5rem 3rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.document-page {
  max-width: 720px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-page);
  border: 1px solid var(--border);
  padding: 2rem 2.25rem 2.5rem;
  min-height: min(70vh, 100%);
  display: flex;
  flex-direction: column;
}

#document-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.doc-view-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}


.doc-save-wrap {
  flex-shrink: 0;
  padding-bottom: 0.85rem;
  margin-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

#btn-replace-markdown {
  margin-top: 0.55rem;
}

.document-role-field {
  margin-top: 0.75rem;
}

.save-status {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.document-status-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.document-word-count {
  margin: 0.45rem 0 0;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.save-status.ok {
  color: var(--success-text);
}

.save-status.err {
  color: #b91c1c;
}

.doc-view-toggle-wrap {
  flex-shrink: 0;
  padding-bottom: 0.85rem;
  margin-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.rail-properties .doc-view-toggle {
  margin-bottom: 0;
  justify-content: space-between;
}

.doc-view-toggle-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #e5e1e3;
}

.seg-btn {
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border: none;
  background: transparent;
  color: #4f5155;
  cursor: pointer;
}

.seg-btn:hover {
  color: #1f2730;
  background: rgba(255, 255, 255, 0.55);
}

.seg-btn.active {
  background: var(--accent);
  color: #f1edee;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}


.toolbar-icon-btn {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}

#btn-fmt-bullet { font-size: 1.15rem; }

.field-input-number {
  width: 4.8rem !important;
  min-width: 4.8rem !important;
  text-align: right;
}

#fmt-heading {
  width: 100%;
}

.document-sections {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0;
}

.document-editor {
  display: block;
  width: 100%;
  flex: 0 0 auto;
  min-height: calc(70vh - 6rem);
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  resize: none;
  background: #ffffff;
  color: #000000;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  scroll-behavior: auto;
}

.document-editor:focus {
  outline: none;
}

#document-body.view-formatted .document-editor {
  display: none;
}

#document-body.view-formatted .document-formatted {
  display: block;
}

#document-body.view-raw .document-formatted {
  display: none;
}

.document-formatted {
  display: none;
  flex: 0 0 auto;
  min-height: calc(70vh - 6rem);
  padding: 0;
  margin: 0;
  border: none;
  outline: none;
  overflow: visible;
  font-family: var(--fmt-font-family);
  color: #000000;
  font-size: var(--fmt-base-size);
  line-height: 1.7;
}

.document-formatted h1,
.document-formatted h2,
.document-formatted h3,
.document-formatted h4,
.document-formatted h5,
.document-formatted h6 {
  margin: 1.1em 0 0.45em;
  line-height: 1.25;
  font-weight: var(--fmt-heading-weight);
}
.document-formatted h1 { font-size: var(--fmt-h1-size); font-family: var(--fmt-h1-font-family); }
.document-formatted h2 { font-size: var(--fmt-h2-size); font-family: var(--fmt-h2-font-family); }
.document-formatted h3 { font-size: var(--fmt-h3-size); font-family: var(--fmt-h3-font-family); }
.document-formatted h4 { font-size: var(--fmt-h4-size); font-family: var(--fmt-h4-font-family); }
.document-formatted h5 { font-size: var(--fmt-h5-size); font-family: var(--fmt-h5-font-family); }
.document-formatted h6 { font-size: var(--fmt-h6-size); font-family: var(--fmt-h6-font-family); }
.document-formatted p { margin: 0 0 0.85em; font-family: var(--fmt-p-font-family); font-size: var(--fmt-p-size); }
.document-formatted ul, .document-formatted ol { margin: 0 0 0.85em; padding-left: 1.35rem; }
.document-formatted blockquote {
  margin: 1rem 0;
  padding: 0.15rem 0 0.15rem 1rem;
  border-left: 4px solid var(--border-strong);
  color: var(--text-muted);
}
.document-formatted blockquote > :last-child { margin-bottom: 0; }
.document-formatted .markdown-table-wrap {
  max-width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
}
.document-formatted table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.document-formatted th,
.document-formatted td {
  min-width: 6rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  text-align: left;
  vertical-align: top;
}
.document-formatted th {
  background: #f4f1f2;
  font-weight: 700;
}
.document-formatted .align-center { text-align: center; }
.document-formatted .align-right { text-align: right; }
.document-formatted pre {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f6f7f8;
  white-space: pre;
}
.document-formatted code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: #f1f3f5;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}
.document-formatted pre code {
  padding: 0;
  background: transparent;
  font-size: inherit;
}
.document-formatted hr {
  margin: 1.5rem 0;
  border: 0;
  border-top: 1px solid var(--border-strong);
}
.document-formatted img {
  max-width: 100%;
  height: auto;
}
.document-formatted .task-list-item {
  list-style: none;
}
.document-formatted .task-list-item input {
  margin-left: -1.25rem;
  margin-right: 0.35rem;
}

.document-formatted .style-match {
  background: rgba(37, 99, 235, 0.08);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}
.document-formatted strong { font-weight: 700; }
.document-formatted em { font-style: italic; }
#document-body.view-raw .document-editor {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.55;
}

.status-pill {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.status-pill.approved { background: var(--success-bg); color: var(--success-text); }
.status-pill.review { background: var(--review-bg); color: #b45309; }
.status-pill.draft { background: var(--draft-bg); color: var(--text-muted); }

.md-body {
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
}

.md-body p { margin: 0 0 0.85em; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 1em 0 0.5em; font-weight: 600; }
.md-body ul, .md-body ol { margin: 0 0 0.85em; padding-left: 1.35rem; }
.md-body code {
  font-family: ui-monospace, monospace;
  font-size: 0.9em;
  background: #f1f3f5;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.md-body pre {
  background: #f8f9fa;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.88rem;
}
.md-body blockquote {
  margin: 0.85em 0;
  padding-left: 1rem;
  border-left: 4px solid var(--border-strong);
  color: var(--text-muted);
}

.section-save-hint {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.doc-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.rail-properties {
  overflow-y: auto;
}

.properties-stack {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}


.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.2rem;
  margin-bottom: 0.55rem;
  padding: 0.2rem;
  background: #eef1f4;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.inspector-tab {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.inspector-tab.active {
  background: #fff;
  color: var(--text);
  border-color: #d6dbe1;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.inspector-tab:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 1px;
}

.inspector-pane {
  display: block;
  background: #f7f8fa;
  border: 1px solid #dfe4ea;
  border-radius: 10px;
  padding: 0.9rem;
}

.styles-tools .field {
  margin-bottom: 0.6rem;
}

.style-actions {
  display: flex;
  gap: 0.35rem;
  margin: 0.2rem 0 0.6rem;
}


.prop-card {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.inspector-pane.prop-card {
  background: #f2f2f2;
  border: 1px solid #dfe4ea;
  border-radius: 10px;
  padding: 0.9rem;
}

.prop-card-lower {
  flex: 1;
  min-height: 0;
}

.prop-card-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  font-family: "DM Serif Display", serif;
  letter-spacing: 0.04em;
}

.prop-empty {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.field { display: block; margin-bottom: 0.75rem; }
.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.field-input, .field-textarea {
  width: 100%;
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--page);
  color: var(--text);
}
.field-textarea {
  resize: vertical;
  min-height: 5rem;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}
.field-textarea-sm { min-height: 3.5rem; }

.subsection-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0.75rem 0 0.4rem;
}
.subsection-label:first-child { margin-top: 0; }

.help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.material-discovery-status:empty {
  display: none;
}

.material-discovery-status.ok {
  color: var(--success-text);
}

.material-discovery-status.err {
  color: #a33a3a;
}

.materials-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.875rem;
}
.materials-list li { margin: 0.35rem 0; }
.material-details {
  display: inline-flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.12rem;
}
.material-link {
  color: var(--accent);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.material-url {
  color: var(--text-muted);
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}
.material-url-missing {
  color: #9a5b13;
}
.materials-list button {
  font-size: 0.75rem;
  margin-left: 0.35rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--page);
  cursor: pointer;
}
.materials-list button:hover { background: #f4f6f8; }

.materials-list-wide {
  display: grid;
  gap: 0.5rem;
  padding-left: 0;
}

.materials-list-wide li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #dfe4e8;
  border-radius: 8px;
}

.publication-materials-lede {
  margin-bottom: 0.8rem;
}

.publication-material-details {
  width: 100%;
}

.material-origin-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.material-origin {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid #d8dee4;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: #f5f7f9;
  color: #52606d;
  font-size: 0.72rem;
}

.material-origin-supporting {
  background: #f6f0f7;
  border-color: #dfd1e2;
  color: #704779;
}

.materials-list .material-origin-unlink {
  margin: 0 0 0 0.1rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}

.compact-empty {
  margin: 0.35rem 0 0.75rem;
  padding: 0.8rem;
}

.material-add-panel {
  margin-top: 0.7rem;
  border-top: 1px solid #dfe4e8;
  padding-top: 0.7rem;
}

.material-add-panel summary {
  cursor: pointer;
  color: #64707c;
  font-size: 0.82rem;
  font-weight: 600;
}

.material-form {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.context-scope + .context-scope,
.context-scope + #materials-for-section,
#materials-for-section {
  border-top: 1px solid #dfe4e8;
  margin-top: 1rem;
  padding-top: 1rem;
}

.context-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.text-button {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  border-left: 2px solid var(--accent-soft);
  padding-left: 0.7rem;
}

.history-list strong,
.history-list span {
  display: block;
}

.history-list span {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.history-list-wide {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.workspace-section-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.activity-status {
  margin: 0.65rem 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.activity-status-error {
  color: #9f2f2f;
}

.activity-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.activity-item {
  border-bottom: 1px solid var(--border);
}

.activity-entry > summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0.25rem;
  cursor: pointer;
  list-style-position: outside;
}

.activity-entry > summary:hover strong {
  color: #263746;
}

.activity-entry > summary::marker {
  color: var(--text-muted);
}

.activity-summary-copy,
.activity-summary-copy strong,
.activity-summary-copy span {
  display: block;
}

.activity-summary-copy {
  min-width: 0;
}

.activity-summary-copy strong {
  font-size: 0.94rem;
  line-height: 1.35;
}

.activity-description {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.activity-meta {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.activity-detail {
  padding: 0 0.25rem 1.25rem 1.2rem;
}

.activity-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.65rem 1.25rem;
  margin: 0 0 1rem;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(217, 224, 227, 0.38);
}

.activity-facts div {
  min-width: 0;
}

.activity-facts dt {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.activity-facts dd {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
}

.activity-detail h4 {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
}

.activity-events {
  display: grid;
  gap: 0.55rem;
  max-height: 28rem;
  margin: 0;
  padding-left: 1.25rem;
  overflow-y: auto;
}

.activity-events li > span,
.activity-events li > small {
  display: block;
}

.activity-events li > small {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.activity-raw {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.activity-raw pre {
  max-height: 240px;
  margin: 0.4rem 0 0;
  padding: 0.65rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--page);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-dialog {
  width: min(1040px, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100vh - 2rem);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 3px);
  background: var(--page);
  color: var(--text);
  box-shadow: 0 20px 70px rgba(38, 55, 70, 0.22);
}

.history-dialog::backdrop {
  background: rgba(38, 55, 70, 0.42);
}

.history-dialog-shell {
  max-height: calc(100vh - 2rem);
  padding: clamp(1.1rem, 3vw, 2rem);
  overflow-y: auto;
}

.history-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.history-dialog-header h2 {
  margin: 0;
  font-family: "DM Serif Display", serif;
  font-size: 2rem;
}

.history-dialog-lede {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
}

.history-filters {
  display: grid;
  grid-template-columns: 1.1fr 2fr 1.25fr 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 1.2rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(241, 237, 238, 0.52);
}

.history-filters label > span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
}

.history-dialog-footer {
  display: flex;
  justify-content: center;
  padding-top: 1.25rem;
}

.history-result-count {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

@media (max-width: 760px) {
  .workspace-section-heading {
    align-items: flex-start;
  }

  .workspace-section-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .activity-entry > summary {
    flex-direction: column;
    gap: 0.55rem;
  }

  .history-filters {
    grid-template-columns: 1fr 1fr;
  }

  .history-filter-search {
    grid-column: span 2;
  }
}

@media (max-width: 480px) {
  .history-dialog {
    width: calc(100vw - 0.75rem);
    max-height: calc(100vh - 0.75rem);
  }

  .history-dialog-shell {
    max-height: calc(100vh - 0.75rem);
  }

  .history-filters {
    grid-template-columns: 1fr;
  }

  .history-filter-search {
    grid-column: auto;
  }
}

.publish-block, .outputs-block { margin-top: 0.5rem; }

.outputs-pre {
  margin: 0;
  padding: 0.5rem;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  max-height: 140px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.hidden { display: none !important; }

@media print {
  @page {
    margin: 18mm;
  }

  html,
  body,
  body.document-mode {
    display: block;
    width: auto;
    height: auto;
    min-height: 0;
    overflow: visible;
    background: #ffffff;
  }

  body.printing-document > *:not(#document-workspace) {
    display: none !important;
  }

  body.printing-document #document-workspace,
  body.printing-document .document-column,
  body.printing-document .document-scroll,
  body.printing-document .document-page,
  body.printing-document #document-body,
  body.printing-document .document-sections,
  body.printing-document .document-formatted {
    display: block !important;
    width: auto;
    min-width: 0;
    max-width: none;
    height: auto;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #ffffff;
    border: 0;
    box-shadow: none;
  }

  body.printing-document .rail,
  body.printing-document .document-editor {
    display: none !important;
  }

  body.printing-document .document-formatted {
    color: #000000;
  }

  body.printing-document .document-formatted h1,
  body.printing-document .document-formatted h2,
  body.printing-document .document-formatted h3,
  body.printing-document .document-formatted h4,
  body.printing-document .document-formatted h5,
  body.printing-document .document-formatted h6 {
    break-after: avoid;
    page-break-after: avoid;
  }

  body.printing-document .document-formatted img,
  body.printing-document .document-formatted table,
  body.printing-document .document-formatted pre,
  body.printing-document .document-formatted blockquote {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* Collaboration stays in the optional inspector, outside canonical text. */
.discussion-reply { margin: .75rem 0 .75rem 1rem; padding-left: .75rem; border-left: 2px solid var(--border, #ddd); }
.discussion-item p { white-space: pre-wrap; overflow-wrap: anywhere; }
.discussion-item pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: .5rem; max-height: 18rem; overflow: auto; }
.proposal-before { background: #fff0ed; color: #653025; border-left: 3px solid #b85b48; }
.proposal-after { background: #eef7ef; color: #244d30; border-left: 3px solid #54865b; }
.collaboration-warning { border-left: 3px solid #b68131; padding-left: .5rem; }
.proposal-discussion { border-top: 1px solid var(--border, #ddd); margin-top: .75rem; }
.sec-node[data-discussions]:not([data-discussions="0"])::after { content: ' · ' attr(data-discussions) ' discussions'; font-size: .75em; opacity: .75; }
