/**
 * Fernwork — shared styles for the Office (Docs/Sheets) and Canvas
 * (Draw/Mind Map/Mermaid) tool pages.
 *
 * Layout overview
 *   .oo-workspace      → the rounded chrome around an entire tool
 *   .oo-toolbar        → ribbon-style toolbar with grouped controls
 *   .oo-toolbar-group  → labelled cluster of related actions
 *   .oo-editor-body    → fills the remaining height of the workspace
 *   .oo-split-body     → resizable two-pane layout for Mind Map & Mermaid
 *   .oo-statusbar      → footer bar at the bottom of complex editors
 */

/* Turn the tool page into a true app shell so the workspace can fill the
   remaining viewport height instead of letting the page grow indefinitely.
   Uses :has() so it only kicks in when a tool is on the page; every other
   page keeps the original block layout. */
body:has(.main-content > .tab-content.active > .oo-workspace) {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.main-content:has(> .tab-content.active > .oo-workspace) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.tab-content.active:has(> .oo-workspace) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.oo-workspace {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--surface-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.oo-toolbar {
  flex: 0 0 auto;
}

.oo-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: var(--sp-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface-color);
  flex-wrap: wrap;
}

/* ============================================================== *
 * Ribbon — modern Office-style toolbar
 *
 * Layout per group:
 *   .oo-ribbon-group        outer column (label sits at the bottom)
 *   .oo-rb-row              one horizontal row of controls
 *   .oo-rb-col              one vertical stack of small controls
 *   .oo-rb-big              large 56×60px primary action (icon on top)
 *   .oo-rb-icon             plain icon button, 28×28 rounded square
 *   .oo-rb-text             text-button or dropdown, 28px tall
 *
 * All groups share the same height (88px including the footer label).
 * Buttons all share consistent metrics so rows align cleanly across
 * groups, the way modern Word/Excel ribbons do.
 * ============================================================== */
.oo-ribbon {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  background: var(--surface-color);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.04), 0 8px 20px -18px rgba(15, 23, 42, 0.45);
}

.oo-ribbon-tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 8px;
  background: color-mix(in srgb, var(--surface-color) 94%, var(--bg-color));
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
  scrollbar-width: none;
}
.oo-ribbon-tabs::-webkit-scrollbar { display: none; }

.oo-ribbon-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}

.oo-ribbon-tab:hover {
  color: var(--text-main);
  background: var(--hover-bg);
}

.oo-ribbon-tab[aria-selected="true"] {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
  background: var(--surface-color);
}

.oo-ribbon-quick {
  display: flex;
  margin-left: auto;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 4px 12px;
}

.oo-ribbon-quick .btn {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
}

.oo-ribbon-quick .input-field {
  height: 28px;
  padding: 0 28px 0 8px;
  font-size: 12px;
  min-height: 0;
}

.oo-ribbon-panels {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 4px 6px 0;
  height: 100px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.oo-ribbon-panel {
  display: none;
  align-items: stretch;
  gap: 0;
  flex: 0 0 max-content;
  min-height: 0;
  min-width: max-content;
}

.oo-ribbon-panel.is-active {
  display: flex;
}

.oo-ribbon-group {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 6px;
  flex: 0 0 max-content;
  flex-wrap: nowrap;
  padding: 4px 10px 16px;
  border-right: 1px solid var(--border-light);
  min-width: max-content;
  height: 92px;
}

.oo-ribbon-group:last-child {
  border-right: 0;
}

.oo-ribbon-group::after {
  content: attr(data-label);
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* Row + column primitives */
.oo-rb-row {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 0 0 max-content;
  min-width: max-content;
}

.oo-rb-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 2px;
  flex: 0 0 max-content;
  min-width: max-content;
}
.oo-rb-col > .oo-rb-btn {
  height: 22px;
  min-height: 22px;
  font-size: 11.5px;
  padding: 0 8px;
  justify-content: flex-start;
  text-align: left;
}
.oo-rb-col > .oo-rb-btn .oo-rb-glyph {
  font-size: 12px;
  width: 14px;
  text-align: center;
  flex: 0 0 auto;
}

.oo-rb-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border-light);
  margin: 4px 4px;
}

/* Big primary button (icon on top, label below) */
.oo-rb-big {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 64px;
  height: 72px;
  align-self: center;
  transition: background .12s, border-color .12s;
}
.oo-rb-big > span:not(.oo-rb-glyph) {
  display: block;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  line-height: 1.15;
}
.oo-rb-big:hover { background: var(--hover-bg); border-color: var(--border-light); }
.oo-rb-big.active,
.oo-rb-big[aria-pressed="true"] {
  background: rgba(var(--accent-rgb), 0.10);
  border-color: rgba(var(--accent-rgb), 0.40);
  color: var(--accent-color);
}
.oo-rb-big .oo-rb-glyph {
  font-size: 22px;
  line-height: 1;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Compact text/icon button */
.oo-rb-btn {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 24px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.oo-rb-btn:hover { background: var(--hover-bg); border-color: var(--border-light); }
.oo-rb-btn:active { background: var(--accent-color); color: #fff; }
.oo-rb-btn.is-icon { width: 24px; padding: 0; }
.oo-rb-btn.is-wide { padding: 0 10px; min-width: 96px; justify-content: flex-start; }
.oo-rb-btn.active,
.oo-rb-btn[aria-pressed="true"] {
  background: rgba(var(--accent-rgb), 0.10);
  border-color: rgba(var(--accent-rgb), 0.40);
  color: var(--accent-color);
}
.oo-rb-btn .oo-rb-glyph { font-size: 14px; line-height: 1; }

/* Shared outline SVG icons keep ribbon slots aligned with the header. */
.oo-rb-glyph svg {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: middle;
}
.oo-rb-big .oo-rb-glyph svg { width: 20px; height: 20px; }
.oo-rb-btn .oo-rb-glyph svg { width: 14px; height: 14px; }

/* Native select / inputs inside the ribbon */
.oo-ribbon select.input-field,
.oo-ribbon input.input-field {
  height: 26px;
  min-height: 26px;
  padding: 0 24px 0 8px;
  font-size: 12px;
  background-position: right 6px center;
  background-size: 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
.oo-ribbon input.input-field:not([type="color"]) {
  padding-right: 8px;
  background-image: none;
}
.oo-ribbon input.input-field[type="number"] {
  width: 60px;
}

.oo-ribbon select.oo-narrow-select { width: 110px; min-width: 110px; max-width: 110px; }
.oo-ribbon select.oo-medium-select { width: 140px; min-width: 140px; max-width: 140px; }
.oo-ribbon select.oo-wide-select { width: 170px; min-width: 170px; max-width: 170px; }

/* Inline color/checkbox label */
.oo-rb-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.oo-rb-inline:hover { background: var(--hover-bg); }
.oo-rb-inline input[type="color"] {
  width: 20px; height: 20px;
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}
.oo-rb-inline input[type="checkbox"] { margin: 0; }

/* Color swatch button (e.g. font color, highlight) */
.oo-rb-color {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: var(--text-main);
  font-size: 13px;
}
.oo-rb-color:hover { background: var(--hover-bg); border-color: var(--border-light); }
.oo-rb-color > .oo-rb-color-bar {
  position: absolute;
  bottom: 2px;
  left: 4px;
  right: 4px;
  height: 3px;
  background: currentColor;
  border-radius: 2px;
}
.oo-rb-color input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Backwards compat shims for older HTML */
.oo-ribbon-group .btn {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
}
.oo-ribbon-group .btn.btn-primary { font-weight: 600; }
.oo-ribbon-group .btn.is-icon { width: 28px; padding: 0; justify-content: center; }
.oo-ribbon-group .btn.active {
  color: var(--accent-color);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.10);
}
.oo-ribbon-group .oo-inline-field {
  height: 28px;
  font-size: 11.5px;
  color: var(--text-secondary);
  gap: 4px;
}

.oo-ribbon-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: center;
}
.oo-ribbon-row {
  display: flex;
  gap: 3px;
  align-items: center;
}

/* Tablet width: shrink padding so more groups fit */
@media (max-width: 1100px) {
  .oo-ribbon-group { padding: 4px 8px 18px; gap: 4px; }
  .oo-rb-divider { margin: 4px 2px; }
}

/* Phone width: collapse the big primary buttons to compact, allow scroll */
@media (max-width: 720px) {
  .oo-ribbon-tab {
    padding: 8px 10px;
    font-size: 12px;
  }
  .oo-ribbon-panels {
    padding: 4px 6px 0;
    height: 136px;
    min-height: 136px;
    overflow-x: auto;
  }
  .oo-ribbon-group {
    padding: 4px 8px 16px;
    gap: 3px;
    height: 128px;
  }
  .oo-rb-big { min-width: 48px; height: 56px; font-size: 10px; }
  .oo-rb-big .oo-rb-glyph { font-size: 18px; height: 22px; }
  .oo-rb-btn,
  .oo-rb-col > .oo-rb-btn {
    height: 36px;
    min-height: 36px;
  }
  .oo-rb-btn.is-icon { width: 36px; }
  .oo-ribbon select.input-field,
  .oo-ribbon input.input-field {
    height: 36px;
    min-height: 36px;
  }
  .oo-rb-inline,
  .oo-rb-color {
    height: 36px;
  }
  .oo-rb-color { width: 36px; }
  .oo-rb-inline input[type="color"] {
    width: 32px;
    height: 32px;
  }
  .oo-ribbon-quick .btn,
  .oo-ribbon-quick .input-field {
    height: 36px;
    min-height: 36px;
  }
}

.oo-toolbar-group {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
  padding: 18px 8px 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-color) 88%, var(--bg-color));
}

.oo-toolbar-group::before {
  content: attr(data-label);
  position: absolute;
  top: 4px;
  left: 8px;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.oo-toolbar-group:not([data-label]) {
  padding-top: 8px;
}

.oo-toolbar-group:not([data-label])::before {
  content: none;
}

.oo-toolbar .btn.active {
  color: var(--accent-color);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.10);
}

.oo-toolbar select.input-field,
.oo-toolbar input.input-field {
  min-height: 30px;
  line-height: 1.2;
  font-family: var(--font-main);
}

.oo-toolbar select.input-field {
  min-width: 132px;
  padding-right: 34px;
  background-position: right 12px center;
  text-overflow: ellipsis;
}

.oo-toolbar select.oo-narrow-select {
  min-width: 116px;
  width: auto;
  padding-left: 10px;
  padding-right: 30px;
  font-size: 12px;
}

.oo-toolbar input.oo-numeric-field {
  width: 64px !important;
  min-width: 0;
  padding: 4px 8px;
  font-size: 12px;
  text-align: right;
}

.oo-status {
  color: var(--text-tertiary);
  font-size: 12px;
  font-family: var(--font-mono);
}

.oo-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.04), 0 8px 20px -18px rgba(15, 23, 42, 0.45);
}

.oo-editor-body {
  flex: 1;
  min-height: 0;
  background: var(--bg-color);
}

/* ---------- Docs (paper editor) ---------- */

.oo-paper-wrap {
  min-width: 0;
  padding: clamp(16px, 3vw, 36px);
  overflow: auto;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg-color) 96%, transparent) 0%,
    var(--bg-color) 12%);
}

.oo-paper {
  box-sizing: border-box;
  width: min(100%, 820px);
  max-width: 100%;
  min-height: 1100px;
  margin: 0 auto;
  padding: clamp(28px, 5vw, 64px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-color);
  color: var(--text-main);
  box-shadow: var(--shadow-md);
  line-height: 1.65;
  outline: none;
  overflow-wrap: anywhere;
}

.oo-paper.oo-paper-columns-2 {
  column-count: 2;
  column-gap: 36px;
  column-rule: 1px solid var(--border-light);
}

.oo-paper.oo-paper-columns-3 {
  column-count: 3;
  column-gap: 28px;
  column-rule: 1px solid var(--border-light);
}

.oo-paper-wrap.oo-paper-letter .oo-paper { max-width: 8.5in; min-height: 11in; }
.oo-paper-wrap.oo-paper-a4 .oo-paper { max-width: 210mm; min-height: 297mm; }
.oo-paper-wrap.oo-paper-legal .oo-paper { max-width: 8.5in; min-height: 14in; }

.oo-paper:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}

.oo-paper h1,
.oo-paper h2,
.oo-paper h3 {
  margin: 0.8em 0 0.35em;
}

.oo-paper p,
.oo-paper ul,
.oo-paper ol,
.oo-paper blockquote,
.oo-paper table {
  margin: 0 0 1em;
}

.oo-paper table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
}

.oo-paper td,
.oo-paper th {
  border: 1px solid var(--border-color);
  padding: 6px 8px;
  overflow-wrap: anywhere;
}

.oo-paper img,
.oo-paper video,
.oo-paper canvas,
.oo-paper svg {
  max-width: 100%;
  height: auto;
}

.oo-paper .oo-task-list {
  list-style: none;
  padding-left: 0;
}

.oo-paper .oo-task-list input {
  width: auto;
  margin-right: 8px;
}

.oo-doc-comment {
  background: rgba(var(--accent-rgb), 0.18);
  color: inherit;
  border-bottom: 1px dotted var(--accent-color);
}

.oo-doc-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.oo-doc-grid {
  display: grid;
  /* Three fixed-width gutters + an elastic paper column.
     Keeping these constant means hiding the outline / focus mode never
     reflows the document — the paper stays exactly where it was. */
  grid-template-columns: 240px minmax(0, 1fr) 0;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Anchor children to explicit columns so hiding one doesn't reshuffle the layout */
.oo-doc-grid > #doc-outline { grid-column: 1; grid-row: 1; }
.oo-doc-grid > #doc-paper-wrap { grid-column: 2; grid-row: 1; min-width: 0; }
.oo-doc-grid > #doc-comments { grid-column: 3; grid-row: 1; }

/* When the outline is hidden the column stays the same width so the
   paper doesn't shift; we just paint nothing in it apart from the rehinge tab. */
.oo-doc-grid.oo-doc-grid-noaside #doc-outline { display: none; }

.oo-doc-grid:has(.oo-doc-sidebar-comments:not([hidden])) {
  grid-template-columns: 240px minmax(0, 1fr) 240px;
}

.oo-doc-sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--surface-color) 96%, var(--bg-color));
  overflow-y: auto;
  min-width: 0;
}

.oo-doc-sidebar[hidden] { display: none; }

.oo-doc-sidebar-comments {
  border-right: 0;
  border-left: 1px solid var(--border-light);
}

.oo-doc-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--surface-color) 88%, var(--bg-color));
  position: sticky;
  top: 0;
  z-index: 1;
}

.oo-doc-sidebar-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.oo-doc-sidebar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
  display: inline-block;
}

.oo-doc-sidebar-collapse {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-tertiary);
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.oo-doc-sidebar-collapse:hover {
  background: var(--hover-bg);
  color: var(--text-main);
  border-color: var(--border-light);
}

.oo-doc-sidebar-body {
  display: flex;
  flex-direction: column;
  padding: 6px 0 12px;
}

.oo-doc-outline-empty {
  padding: 12px 14px 6px;
  margin: 0;
}

/* Floating "show outline" tab that appears when the outline is collapsed.
   Anchored inside the grid so it always sits below the sticky ribbon. */
.oo-doc-sidebar-rehinge {
  appearance: none;
  border: 1px solid var(--border-light);
  background: var(--surface-color);
  color: var(--text-secondary);
  width: 22px;
  height: 60px;
  position: sticky;
  top: calc(56px + 96px + 16px);
  align-self: start;
  margin: 16px 0 0 0;
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 6;
  transition: background .12s, color .12s, border-color .12s;
  box-shadow: 0 4px 12px -8px rgba(15, 23, 42, 0.45);
}
.oo-doc-sidebar-rehinge:hover {
  background: var(--hover-bg);
  color: var(--text-main);
  border-color: rgba(var(--accent-rgb), 0.45);
}
.oo-doc-sidebar-rehinge[hidden] { display: none; }
.oo-doc-shell { position: relative; }

.oo-doc-outline-item {
  display: block;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
}

.oo-doc-outline-item:hover {
  background: var(--hover-bg);
  color: var(--text-main);
  border-left-color: rgba(var(--accent-rgb), 0.45);
}

.oo-doc-outline-h1 { font-weight: 600; font-size: 14px; }
.oo-doc-outline-h2 { padding-left: 28px; }
.oo-doc-outline-h3 { padding-left: 42px; font-size: 12px; color: var(--text-tertiary); }
.oo-doc-outline-h4 { padding-left: 56px; font-size: 12px; color: var(--text-tertiary); }

.oo-doc-page-header,
.oo-doc-page-footer {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 6px 24px;
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  outline: none;
  border-bottom: 1px dashed transparent;
}

.oo-doc-page-header[contenteditable="true"]:empty::before,
.oo-doc-page-footer[contenteditable="true"]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
  opacity: 0.7;
}

.oo-doc-page-header { border-bottom: 1px dashed var(--border-light); }
.oo-doc-page-footer { border-top: 1px dashed var(--border-light); }

.oo-doc-find {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
  flex-wrap: wrap;
}

.oo-doc-find[hidden] { display: none; }

.oo-doc-pagebreak {
  display: block;
  margin: 18px 0;
  padding: 12px 0;
  border-top: 2px dashed var(--border-color);
  color: var(--text-tertiary);
  text-align: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.oo-doc-pagebreak::before {
  content: 'Page break';
}

.oo-doc-footnotes {
  margin-top: 32px;
  font-size: 90%;
  color: var(--text-secondary);
}

.oo-find-hit {
  background: rgba(var(--accent-rgb), 0.18);
  color: inherit;
}

.oo-find-hit.current {
  background: var(--accent-color);
  color: #fff;
}

.oo-doc-table {
  border: 1px solid var(--border-color);
}

.oo-doc-table thead {
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
  font-weight: 600;
}

/* ---------- Docs presets, watermark, equations, TOC, citations ---------- */
.oo-paper.oo-paper-landscape { width: min(100%, 1180px); }

.oo-paper .oo-style-callout,
.oo-paper .oo-style-note,
.oo-paper .oo-style-warning,
.oo-paper .oo-style-success {
  padding: 12px 14px;
  border-left: 4px solid var(--accent-color);
  background: rgba(var(--accent-rgb), 0.06);
  border-radius: var(--radius-sm);
  margin: 14px 0;
}
.oo-paper .oo-style-note { border-left-color: #6366f1; background: rgba(99, 102, 241, 0.08); }
.oo-paper .oo-style-warning { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.10); }
.oo-paper .oo-style-success { border-left-color: #10b981; background: rgba(16, 185, 129, 0.10); }
.oo-paper .oo-style-dropcap::first-letter {
  font-size: 3.4em;
  float: left;
  line-height: 0.9;
  margin: 4px 8px 0 0;
  font-weight: 700;
  color: var(--accent-color);
}

.oo-paper .oo-doc-toc {
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin: 16px 0;
  background: color-mix(in srgb, var(--surface-color) 96%, var(--bg-color));
}
.oo-paper .oo-doc-toc ul { list-style: none; padding-left: 0; margin: 8px 0 0; }
.oo-paper .oo-doc-toc li { padding: 2px 0; }
.oo-paper .oo-doc-toc .oo-toc-h2 { padding-left: 12px; }
.oo-paper .oo-doc-toc .oo-toc-h3 { padding-left: 24px; font-size: 13px; }
.oo-paper .oo-doc-toc .oo-toc-h4 { padding-left: 36px; font-size: 12px; color: var(--text-secondary); }

.oo-paper .oo-doc-cover { text-align: center; padding: 80px 0 60px; }
.oo-paper .oo-doc-cover h1 { font-size: 2.6em; margin-bottom: 12px; }
.oo-paper .oo-doc-cover-subtitle { color: var(--text-secondary); font-size: 1.1em; }

.oo-paper .oo-doc-equation {
  display: inline-block;
  padding: 2px 8px;
  margin: 0 2px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--surface-color);
  font-family: 'Cambria Math', 'Latin Modern Math', serif;
  font-style: italic;
}

.oo-paper .oo-doc-citation {
  color: var(--accent-color);
  cursor: help;
}
.oo-paper .oo-doc-bookmark {
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 0.8em;
}
.oo-paper .oo-doc-xref { color: var(--accent-color); text-decoration: none; border-bottom: 1px dotted var(--accent-color); }

.oo-paper .oo-doc-bibliography ol { padding-left: 22px; }
.oo-paper .oo-doc-bibliography li { margin-bottom: 6px; }

.oo-paper .oo-doc-page-number::after { content: attr(data-page) " " counter(page); counter-increment: page; }

.oo-doc-watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: 10vw;
  font-weight: 800;
  color: rgba(var(--accent-rgb), 0.10);
  transform: rotate(-30deg);
  user-select: none;
  z-index: 1;
}

.oo-doc-show-marks p::after { content: '¶'; color: var(--text-tertiary); margin-left: 4px; opacity: 0.4; }
.oo-doc-show-marks br::after { content: '↵'; color: var(--text-tertiary); opacity: 0.4; }

/* Focus mode hides the outline & rehinge but keeps grid columns intact so the
   paper does not reflow. The padding around the paper just becomes blank. */
.oo-doc-shell.oo-doc-focus .oo-doc-sidebar { visibility: hidden; }
.oo-doc-shell.oo-doc-focus .oo-doc-sidebar-rehinge { display: none; }
.oo-doc-shell.oo-doc-focus .oo-paper { box-shadow: var(--shadow-lg); }

@media print {
  /* When the user prints from inside Docs, only the document paper
     should make it to paper — chrome, sidebars, ribbons, status,
     breadcrumbs, the global app header are all noise. */
  body:has(.oo-doc-shell) > header,
  body:has(.oo-doc-shell) > footer,
  body:has(.oo-doc-shell) .sidebar,
  body:has(.oo-doc-shell) #sidebar,
  body:has(.oo-doc-shell) .breadcrumb,
  body:has(.oo-doc-shell) .breadcrumbs,
  body:has(.oo-doc-shell) .toast-container,
  body:has(.oo-doc-shell) .oo-dialog-host,
  body:has(.oo-doc-shell) .oo-doc-sidebar-rehinge,
  .oo-doc-shell .oo-ribbon,
  .oo-doc-shell .oo-doc-sidebar,
  .oo-doc-shell .oo-doc-find,
  .oo-doc-shell .oo-statusbar { display: none !important; }

  body:has(.oo-doc-shell),
  body:has(.oo-doc-shell) .app-container,
  body:has(.oo-doc-shell) .main-content,
  body:has(.oo-doc-shell) .oo-workspace,
  body:has(.oo-doc-shell) .tab-content,
  body:has(.oo-doc-shell) .oo-doc-shell,
  body:has(.oo-doc-shell) .oo-doc-grid,
  body:has(.oo-doc-shell) .oo-paper-wrap {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    overflow: visible !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    box-shadow: none !important;
    border: 0 !important;
    display: block !important;
    grid-template-columns: 0 1fr 0 !important;
  }

  .oo-paper { box-shadow: none !important; border: 0 !important; padding: 0 !important; max-width: none !important; width: 100% !important; color: #000 !important; }
  .oo-doc-pagebreak { page-break-after: always; }
  body { counter-reset: page; }

  /* Same idea for Sheets: hide chrome, only print the grid. */
  body:has(.oo-sheet-shell) > header,
  body:has(.oo-sheet-shell) > footer,
  body:has(.oo-sheet-shell) .sidebar,
  body:has(.oo-sheet-shell) #sidebar,
  body:has(.oo-sheet-shell) .breadcrumb,
  body:has(.oo-sheet-shell) .breadcrumbs,
  body:has(.oo-sheet-shell) .toast-container,
  body:has(.oo-sheet-shell) .oo-dialog-host,
  body:has(.oo-sheet-shell) .oo-ribbon,
  body:has(.oo-sheet-shell) .oo-statusbar,
  body:has(.oo-sheet-shell) .oo-sheet-formula-bar,
  body:has(.oo-sheet-shell) .oo-sheet-tabs { display: none !important; }
  body:has(.oo-sheet-shell) .oo-sheet-grid { overflow: visible !important; }
}

/* ---------- Sheets extras: sparklines, no-grid, no-headings ---------- */
.oo-sparkline {
  display: inline-block;
  vertical-align: middle;
  margin-right: 4px;
}
.oo-spark-label {
  font-size: 11px;
  color: var(--text-tertiary);
}

.oo-sheet-shell.oo-sheet-no-grid .oo-sheet th,
.oo-sheet-shell.oo-sheet-no-grid .oo-sheet td {
  border-color: transparent;
}
.oo-sheet-shell.oo-sheet-no-headings thead,
.oo-sheet-shell.oo-sheet-no-headings .oo-sheet-row-head { display: none; }

/* ---------- Sheets ---------- */

.oo-sheet-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.oo-sheet-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
}

.oo-formula-bar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface-color);
}

.oo-cell-ref {
  min-width: 56px;
  padding: 5px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}

.oo-formula-prefix {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

.oo-sheet-tab {
  border: 1px solid var(--border-color);
  background: var(--surface-color);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.oo-sheet-tab.active {
  color: var(--accent-color);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.08);
}

.oo-sheet-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg-color);
}

.oo-sheet {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
  background: var(--surface-color);
  table-layout: fixed;
}

.oo-sheet th,
.oo-sheet td {
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  width: 96px;
  min-width: 96px;
  max-width: 96px;
  height: 30px;
  padding: 4px 8px;
  vertical-align: middle;
}

.oo-sheet th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sidebar-bg);
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  user-select: none;
  cursor: pointer;
}

.oo-sheet th[data-resizing="1"] {
  cursor: col-resize;
}

.oo-sheet th:first-child {
  left: 0;
  z-index: 3;
  width: 48px;
  min-width: 48px;
  max-width: 48px;
  text-align: center;
}

.oo-sheet-row-head {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  background: var(--sidebar-bg);
  color: var(--text-tertiary);
  text-align: center;
  font-size: 12px;
  user-select: none;
  cursor: pointer;
}

.oo-sheet-cell {
  outline: none;
  background: var(--surface-color);
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.oo-sheet-cell:focus {
  box-shadow: inset 0 0 0 2px var(--accent-color);
  background: rgba(var(--accent-rgb), 0.05);
}

.oo-sheet-cell.active {
  box-shadow: inset 0 0 0 2px var(--accent-color);
}

.oo-sheet-cell.in-range {
  background: rgba(var(--accent-rgb), 0.12);
}

.oo-sheet-cell.has-comment::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 8px 8px 0;
  border-color: transparent var(--accent-color) transparent transparent;
}

.oo-sheet-cell.has-comment {
  position: relative;
}

.oo-sheet-cell.has-validation {
  outline: 1px dotted rgba(var(--accent-rgb), 0.45);
  outline-offset: -3px;
}

.oo-sheet-cell.has-link a {
  color: var(--accent-color);
  text-decoration: underline;
}

.oo-sheet-cell.is-merged-source {
  z-index: 1;
}

.oo-sheet-cell.is-merged-hidden {
  display: none;
}

.oo-sheet-cell.is-frozen-col {
  position: sticky;
  z-index: 1;
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
}

.oo-sheet-cell.is-frozen-row {
  position: sticky;
  z-index: 1;
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
}

.oo-sheet-thumb {
  display: block;
  max-width: 120px;
  max-height: 80px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.oo-sheet-fill-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent-color);
  border: 1px solid var(--surface-color);
  border-radius: 1px;
  cursor: crosshair;
  z-index: 4;
}

.oo-sheet-context-menu {
  position: absolute;
  z-index: 100;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--surface-color);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
}

.oo-sheet-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.oo-sheet-context-menu button:hover {
  background: var(--hover-bg);
}

.oo-sheet-context-menu hr {
  border: 0;
  border-top: 1px solid var(--border-light);
  margin: 4px 0;
}

/* ---------- Draw (Excalidraw shell) ---------- */

.oo-draw-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.oo-draw-host {
  position: relative;
  height: 100%;
  min-height: 0;
  background: var(--surface-color);
}

.oo-draw-host .excalidraw {
  --color-primary: var(--accent-color);
  --color-primary-darker: var(--accent-hover);
  --color-primary-light: rgba(var(--accent-rgb), 0.12);
}

.oo-inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.oo-inline-field input[type="color"] {
  width: 30px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--surface-color);
}

.oo-inline-field input[type="number"] {
  width: 64px !important;
  min-height: 30px;
  padding: 4px 8px;
}

/* ---------- Mind Map & Mermaid (split editor) ---------- */

.oo-split-tool {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.oo-split-body {
  display: grid;
  grid-template-columns: 38% 6px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.oo-split-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-color);
  overflow: hidden;
}

.oo-split-pane-input {
  border-right: 0;
}

.oo-pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--surface-color) 96%, var(--bg-color)),
    color-mix(in srgb, var(--surface-color) 90%, var(--bg-color)));
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.oo-pane-header::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
  flex-shrink: 0;
}

.oo-pane-header .oo-pane-meta {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--text-tertiary);
  font-size: 11px;
}

.oo-pane-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--surface-color) 92%, var(--bg-color));
  color: var(--text-secondary);
  font-size: 12px;
  display: none;
  white-space: pre-wrap;
}

.oo-pane-footer.is-visible {
  display: block;
  color: var(--danger-color, #b91c1c);
}

.oo-tool-editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--surface-color);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 14px 16px;
  resize: none;
  outline: none;
}

.oo-tool-editor:focus {
  box-shadow: inset 2px 0 0 var(--accent-color);
}

.oo-pane-footer-info {
  padding: 8px 14px;
  border-top: 1px dashed var(--border-light);
  background: color-mix(in srgb, var(--surface-color) 96%, var(--bg-color));
  color: var(--text-tertiary);
  font-size: 11.5px;
  line-height: 1.45;
}

.oo-pane-footer-info code {
  font-family: var(--font-mono);
  background: color-mix(in srgb, var(--accent-color) 12%, transparent);
  color: var(--text-main);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.oo-preview-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: var(--bg-color);
}

.oo-preview-card {
  padding: 22px;
  background:
    radial-gradient(circle at 12px 12px, color-mix(in srgb, var(--text-tertiary) 18%, transparent) 1px, transparent 1.5px) 0 0 / 24px 24px,
    var(--bg-color);
}

.oo-preview-card > svg,
.oo-preview-card > .oo-preview-stage {
  background: var(--surface-color);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 8px 32px -16px rgba(15, 23, 42, 0.25);
  padding: 18px;
  display: block;
  margin: 0 auto;
}

.oo-preview-panel.is-error {
  display: grid;
  place-items: center;
}

.oo-preview-panel svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  transform-origin: top left;
}

.oo-mermaid-shell .oo-preview-panel {
  position: relative;
}

.oo-mindmap-shell #mindmap-svg {
  width: 100%;
  height: 100%;
  min-height: 480px;
}

.oo-split-resizer {
  width: 6px;
  cursor: col-resize;
  background: var(--border-light);
  transition: background 0.15s;
  align-self: stretch;
}

.oo-split-resizer:hover,
.oo-split-resizer:focus {
  background: rgba(var(--accent-rgb), 0.4);
}

body.oo-splitter-dragging {
  user-select: none;
  cursor: col-resize !important;
}

/* ---------- Misc ---------- */

.oo-empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--text-tertiary);
  text-align: center;
  padding: var(--sp-6);
}

.oo-file-input {
  display: none;
}

@media (max-width: 720px) {
  .oo-workspace {
    min-height: calc(100vh - 96px);
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .oo-toolbar {
    align-items: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .oo-toolbar-group {
    width: auto;
    flex: 0 0 auto;
  }

  .oo-toolbar .btn,
  .oo-toolbar select.input-field,
  .oo-toolbar input.input-field {
    min-height: 40px;
  }

  .oo-inline-field input[type="color"] {
    width: 40px;
    height: 40px;
  }

  .oo-sheet-tab {
    min-height: 36px;
  }

  .oo-sheet th,
  .oo-sheet td {
    height: 36px;
  }

  .oo-paper-wrap {
    padding: 12px;
  }

  .oo-paper {
    min-height: 720px;
    padding: 24px;
  }

  .oo-split-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 42vh) 6px minmax(320px, 1fr);
  }

  .oo-split-resizer {
    width: 100%;
    height: 6px;
    cursor: row-resize;
  }

}

/* Keep the paper as the only scrolling surface on narrow screens. */
@media (max-width: 720px) {
  .oo-doc-grid,
  .oo-doc-grid.oo-doc-grid-noaside,
  .oo-doc-grid:has(.oo-doc-sidebar-comments:not([hidden])) {
    grid-template-columns: 1fr;
  }
  .oo-doc-grid > #doc-outline,
  .oo-doc-grid > #doc-comments,
  .oo-doc-sidebar-rehinge {
    display: none;
  }
  .oo-doc-grid > #doc-paper-wrap { grid-column: 1; }
}
