/* Fernwork One — document viewers (Markdown, SVG, Tables / Sheets, Documents, PowerPoint, Database).
   They use the same frame as the geo viewers (tools/js/viewers/geo-frame.js + viewers-geo.css): frame bar, stage,
   optional list / inspector, live status bar, phone bottom bar + sheets. Everything here is scoped to `.dv-frame`
   (the frame of a document viewer) or to the viewer's own prefix, so the geo viewers stay untouched. */

.gv-empty .dv-sample-btn { margin-top: var(--space-3); }
.gv-empty .dv-start-row { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: var(--space-3); }
.gv-empty .dv-start-row .dv-sample-btn { margin-top: 0; }

.gv .dv-frame .gv-stage { display: flex; flex-direction: column; }
.gv .dv-frame .gv-stage > * { min-height: 0; }
.dv-frame .gv-bar__tools { gap: 4px; }
.dv-badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--radius-pill);
  background: var(--accent-subtle-bg); color: var(--accent-text); font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.dv-badge:empty { display: none; }
.dv-paper-bg { background: var(--stage); }

/* ───────── Markdown ───────── */
/* The legacy card rule (viewers.css, ≤ 900 px) capped panes at 60vh; inside the frame they fill the stage. */
.gv .mdv-pane, .gv .svgv-source { max-height: none; }
.gv .mdv-split {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; padding: 0; gap: 0;
  background: var(--bg);
}
.gv .mdv-pane { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; border: 0; border-radius: 0; box-shadow: none; margin: 0; background: var(--bg); }
.gv .mdv-pane + .mdv-pane { border-left: 1px solid var(--border-subtle); }
.gv .mdv-pane-header {
  padding: 6px 14px; font-size: var(--text-xs); font-weight: 600; letter-spacing: .01em; text-transform: none; color: var(--text-3);
  background: var(--bg); border-bottom: 1px solid var(--border-subtle);
}
.gv .mdv-editor {
  flex: 1; min-height: 0; padding: 12px 14px; background: var(--bg); color: var(--text-1); font-family: var(--font-mono);
  font-size: var(--text-sm); line-height: 1.6; border: 0; outline: none; resize: none;
}
.gv .mdv-editor:focus-visible { box-shadow: inset 0 0 0 1px var(--accent-border, var(--accent-fill)); }
.gv .mdv-preview { flex: 1; min-height: 0; padding: 20px 28px 64px; background: var(--bg); color: var(--text-1); }
.gv .mdv-preview pre, .gv .mdv-preview code, .gv .mdv-preview table th { background: var(--surface-2); }
.gv .mdv-preview a { color: var(--accent-text); }
.mdv-frame[data-view="source"] .mdv-split, .mdv-frame[data-view="preview"] .mdv-split { grid-template-columns: minmax(0, 1fr); }
.mdv-frame[data-view="source"] .mdv-pane--preview, .mdv-frame[data-view="preview"] .mdv-pane--source { display: none; }
.mdv-frame[data-view="preview"] .mdv-pane + .mdv-pane { border-left: 0; }
.mdv-frame .mdv-preview { padding-inline: max(28px, calc((100% - 820px) / 2)); }
.mdv-frame[data-view="split"] .mdv-preview { padding-inline: 28px; }
.mdv-frame:not([data-view="split"]) #mdv-sync-scroll { display: none; }

/* ───────── SVG ───────── */
.gv .svgv-canvas-wrap {
  position: absolute; inset: 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 0; border-radius: 0; cursor: grab; touch-action: none;
  /* Today's inspection backgrounds: dark checkerboard, "Light background" = light checkerboard (both themes). */
  background: repeating-conic-gradient(#202020 0% 25%, #151515 0% 50%) 50% / 20px 20px;
}
.gv .svgv-canvas-wrap.svgv-bg-light { background: repeating-conic-gradient(#e0e0e0 0% 25%, #f0f0f0 0% 50%) 50% / 20px 20px; }
.gv .svgv-canvas-wrap svg { max-width: calc(100% - 48px); max-height: calc(100% - 48px); display: block; }
.gv .svgv-source { display: flex; flex-direction: column; height: 100%; padding: 0; border: 0; margin: 0; border-radius: 0; box-shadow: none; background: transparent; }
.gv .svgv-source textarea {
  flex: 1; min-height: 240px; width: 100%; padding: 10px 12px; border: 0; border-top: 1px solid var(--border-subtle); border-radius: 0;
  background: var(--bg); color: var(--text-1); font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.55; resize: none; outline: none;
}
.gv .svgv-source textarea:focus-visible { box-shadow: inset 0 0 0 1px var(--accent-border, var(--accent-fill)); }
.svgv-frame .fw-wb-main { --inspector-w: 380px; }
.svgv-frame [data-toggle-panel="inspector"] { display: none; }
.svgv-frame .gv-insp .gv-panel__body { display: flex; flex-direction: column; }

/* ───────── Database ───────── */
.gv .dbv-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
.gv .dbv-query-bar { display: flex; gap: var(--space-2); padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); align-items: flex-end; background: var(--bg); }
.gv .dbv-query {
  flex: 1; min-height: 40px; max-height: 200px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-1); color: var(--text-1); font-family: var(--font-mono); font-size: var(--text-xs); resize: vertical;
}
.gv .dbv-query:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--accent-fill); }
.gv .dbv-result-wrap { flex: 1; min-height: 0; overflow: auto; }
.gv .dbv-result-wrap .tblv-table { font-size: var(--text-sm); }
.gv .dbv-result-wrap .tblv-table th { background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.gv .dbv-result-wrap .tblv-table td.tblv-rownum, .gv .dbv-result-wrap .tblv-table th.tblv-rownum { color: var(--text-3); background: var(--surface-2); }
.gv .dbv-error { padding: 12px; color: var(--danger); font-family: var(--font-mono); font-size: var(--text-xs); white-space: pre-wrap; }
.gv .dbv-note { padding: 12px; color: var(--text-3); font-size: var(--text-sm); }
.gv .dbv-tables { max-height: none; overflow: visible; gap: 1px; font-size: var(--text-sm); }
.gv .dbv-table-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 32px; padding: 4px 8px;
  border-radius: 6px; cursor: pointer; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-1); width: 100%; text-align: left;
  background: transparent; border: 0;
}
@media (hover: hover) { .gv .dbv-table-row:hover { background: var(--surface-hover); } }
.gv .dbv-table-row.is-active { background: var(--accent-subtle-bg); color: var(--accent-text); }
.gv .dbv-table-row .fw-icon { color: var(--text-3); }
.gv .dbv-table-row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gv .dbv-table-row .dbv-table-cols { color: var(--text-3); font-size: var(--text-2xs); margin: 0; font-family: var(--font-ui); }
.gv .dbv-tables-head { margin: 0 8px 6px; }
.gv .dbv-help { margin: var(--space-3) 8px 0; font-size: var(--text-xs); color: var(--text-3); line-height: 1.5; }
.gv .dbv-help strong { color: var(--text-2); font-weight: 600; }
.dbv-frame .fw-wb-main { --list-w: 220px; }

/* ───────── phones ───────── */
@media (max-width: 767px) {
  .gv .mdv-split { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .mdv-frame[data-view="source"] .mdv-split, .mdv-frame[data-view="preview"] .mdv-split { grid-template-rows: minmax(0, 1fr); }
  .gv .mdv-pane + .mdv-pane { border-left: 0; border-top: 1px solid var(--border-subtle); }
  .gv .mdv-preview, .mdv-frame .mdv-preview, .mdv-frame[data-view="split"] .mdv-preview { padding: 14px 16px 56px; }
  .gv .mdv-editor { font-size: var(--text-md); padding: 10px 12px; }
  /* Split stacks the panes; the preview half is ~180 px tall and the zoom HUD covered a third of it. Pinch and
     Ctrl ± still zoom; the HUD comes back in the Preview view. */
  .mdv-frame[data-view="split"] .mdv-pane--preview .gv-zoom { display: none; }
  .gv .dbv-query { font-size: var(--text-md); }
  .dv-frame .gv-file { max-width: min(48vw, 200px); }
  /* An open phone sheet (Source, Tables) covers the lower part of the stage: fit the SVG into the visible part and
     let the result table scroll its last rows above the sheet. */
  .gv .svgv-canvas-wrap { bottom: var(--gv-sheet-cover, 0px); }
  .gv .dbv-result-wrap { padding-bottom: var(--gv-sheet-cover, 0px); }
}
@media (max-width: 359px) {
  .dv-frame .gv-bar__end { gap: 2px; }
}
@media (pointer: coarse) {
  .gv .dbv-table-row { min-height: 44px; }
}

/* ───────── Sheet editor (Tables / Sheets) ─────────
   office.js keeps its ribbon, grid and status bar; here they adopt the frame look: one bordered frame, the frame bar
   on top (file chip · Undo/Redo · Export), a flat ribbon, the live status bar at the bottom. */
.tblv-editor-host.dv-office > .oo-workspace {
  margin: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg); box-shadow: none; overflow: hidden;
}
.tblv-editor-host.dv-office { height: 100%; }
.dv-officebar { flex: none; flex-wrap: nowrap; min-height: var(--framebar-h); border-bottom: 1px solid var(--border-subtle); }
.dv-officebar .gv-file__name { max-width: 240px; }
.dv-history { display: inline-flex; gap: 2px; margin-right: 4px; }
.dv-history__btn { --_s: 32px; }
.dv-officebar .gv-bar__tools { min-width: 0; flex: 1 1 auto; }
.dv-officebar .fw-spacer { flex: 0 0 0; }
@container gvbar (max-width: 640px) {
  .dv-officebar .gv-btn__label { display: none; }
  .dv-officebar .gv-btn { padding: 0 8px; }
}

/* Ribbon: part of the frame, no card of its own. */
.dv-office .oo-ribbon { border: 0; border-bottom: 1px solid var(--border-subtle); border-radius: 0; box-shadow: none; background: var(--bg); }
.dv-office .oo-ribbon-tabs { background: var(--bg); border-bottom: 1px solid var(--border-subtle); padding: 0 6px; }
.dv-office .oo-ribbon-tab { color: var(--text-2); font-size: var(--text-sm); padding: 8px 12px; }
.dv-office .oo-ribbon-tab:hover { color: var(--text-1); background: var(--surface-hover); }
.dv-office .oo-ribbon-tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent-fill); background: transparent; }
.dv-office .oo-ribbon-tab:focus-visible { outline: none; box-shadow: var(--focus-ring-inset); }
.dv-office .oo-ribbon-panels { background: var(--bg); }
.dv-office .oo-ribbon-group { border-right-color: var(--border-subtle); }
.dv-office .oo-ribbon-group::after { color: var(--text-3); font-size: var(--text-2xs); letter-spacing: .04em; }
.dv-office .oo-rb-btn, .dv-office .oo-rb-big, .dv-office .oo-rb-color { color: var(--text-1); border-radius: 6px; }
.dv-office .oo-rb-btn:hover, .dv-office .oo-rb-big:hover, .dv-office .oo-rb-color:hover, .dv-office .oo-rb-inline:hover { background: var(--surface-hover); border-color: transparent; }
.dv-office .oo-rb-btn:active { background: var(--surface-active); color: var(--text-1); }
.dv-office .oo-rb-btn[aria-pressed="true"], .dv-office .oo-rb-btn.active, .dv-office .oo-rb-big[aria-pressed="true"], .dv-office .oo-rb-big.active {
  background: var(--accent-subtle-bg); color: var(--accent-text); border-color: transparent;
}
.dv-office .oo-rb-btn:focus-visible, .dv-office .oo-rb-big:focus-visible, .dv-office .oo-rb-color:focus-within { outline: none; box-shadow: var(--focus-ring); }
.dv-office .oo-ribbon select.input-field, .dv-office .oo-ribbon input.input-field:not([type="color"]) {
  border-color: var(--border-strong); border-radius: 6px; background-color: var(--surface-1); color: var(--text-1);
}

/* Status bar: same as the frame status bar. */
.dv-office .oo-statusbar {
  flex: none; min-height: var(--statusbar-h); padding: 0 12px; border: 0; border-top: 1px solid var(--border-subtle); border-radius: 0;
  box-shadow: none; background: var(--bg); color: var(--text-3); font-family: var(--font-ui); font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.dv-office .oo-statusbar > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dv-office .oo-statusbar > :empty { display: none; }

/* Sheets: formula bar under the ribbon, sheet tabs at the bottom of the grid (as in desktop spreadsheets). */
.tblv-editor-host.dv-office .oo-sheet-shell > .dv-officebar { order: 0; }
.tblv-editor-host.dv-office .oo-ribbon { order: 1; }
.tblv-editor-host.dv-office .oo-formula-bar { order: 2; }
.tblv-editor-host.dv-office .oo-sheet-wrap { order: 3; }
.tblv-editor-host.dv-office .oo-sheet-tabs { order: 4; }
.tblv-editor-host.dv-office .oo-statusbar { order: 5; }
.dv-office .oo-formula-bar { padding: 6px 10px; border-bottom: 1px solid var(--border-subtle); background: var(--bg); }
.dv-office .oo-cell-ref { border-color: var(--border-strong); border-radius: 6px; color: var(--text-2); background: var(--surface-1); }
.dv-office #sheet-formula { height: 32px; border-color: var(--border-strong); border-radius: 6px; font-family: var(--font-mono); font-size: var(--text-sm); }
.dv-office .oo-sheet-tabs { gap: 2px; padding: 4px 8px; border-top: 1px solid var(--border-subtle); border-bottom: 0; background: var(--surface-2); }
.dv-office .oo-sheet-tab { border: 0; border-radius: 6px; background: transparent; color: var(--text-2); padding: 4px 10px; font-size: var(--text-xs); min-height: 26px; }
.dv-office .oo-sheet-tab:hover { background: var(--surface-hover); color: var(--text-1); }
.dv-office .oo-sheet-tab.active { background: var(--bg); color: var(--accent-text); box-shadow: 0 0 0 1px var(--border-subtle); font-weight: 600; }
.dv-office .oo-sheet-wrap { background: var(--stage); }
.dv-office .oo-sheet { background: var(--bg); }
.dv-office .oo-sheet th { background: var(--surface-2); color: var(--text-3); font-weight: 500; text-transform: none; letter-spacing: 0; }
.dv-office .oo-sheet th, .dv-office .oo-sheet td { border-right-color: var(--border-subtle); border-bottom-color: var(--border-subtle); }

@media (max-width: 767px) {
  .tblv-editor-host.dv-office > .oo-workspace { border-radius: 0; border-inline: 0; margin-inline: calc(-1 * var(--gutter)); }
  .dv-officebar { padding: 0 6px; gap: 4px; }
  .dv-officebar .gv-bar__sep { display: none; }
  /* The tools keep their size and the file chip gives way (it ellipsizes). */
  .dv-officebar .gv-bar__tools { flex: 0 0 auto; }
  .dv-officebar .gv-file__name { max-width: none; }
  .dv-office .oo-statusbar { gap: 8px; }
  /* Six ribbon tabs and the fold chevron in one row on a 390 px phone ("View" was cut off behind the chevron). */
  .dv-office .oo-ribbon-tabs { padding: 0 0 0 4px; }
  .dv-office .oo-ribbon-tab { padding: 8px 9px; font-size: var(--text-xs); }
}
@media (pointer: coarse) { .dv-history__btn { --_s: 44px; } .dv-office .oo-sheet-tab { min-height: 40px; } }
/* iOS Safari zooms the page into any form field under 16 px on every tap (ribbon selects were 12 px, the formula
   bar 13 px, the SVG source 12 px). Touch screens only; desktop keeps the compact look. */
@media (pointer: coarse) {
  .dv-office .oo-ribbon :is(select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"])),
  .dv-office .oo-formula-bar :is(input, select), .dv-office #sheet-formula,
  .gv .svgv-source textarea, .gv .dbv-query, .gv .mdv-editor { font-size: var(--text-md); }
}
