/*
 * Editor screen layout: top bar, code pane, canvas, details panel.
 * Depends on tokens.css and base.css.
 */

[hidden] { display: none !important; }

.app { display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); height: 100vh; min-width: 1280px; overflow: hidden; }

/* ================================================================ top bar */
.topbar {
  display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2) 0 var(--space-3);
  border-bottom: 1px solid var(--border); background: var(--bg-chrome); z-index: var(--z-topbar); min-width: 0;
}
.topbar .logo-btn { display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-md); color: var(--fg); flex: none; }
.topbar .logo-btn:hover { background: var(--bg-hover); }
.topbar .logo-btn .icon { width: 20px; height: 20px; }
.crumbs { display: flex; align-items: center; gap: var(--space-1); min-width: 0; color: var(--fg-muted); font-size: var(--text-md); }
.crumbs a { color: var(--fg-muted); padding: 2px 4px; border-radius: var(--radius-sm); white-space: nowrap; }
.crumbs a:hover { color: var(--fg); background: var(--bg-hover); text-decoration: none; }
/* decorative, but --fg-disabled is 2.4:1 (light) and 2.8:1 (dark); --fg-subtle clears 4.5:1 in both */
.crumbs .sep { color: var(--fg-subtle); }
.docname { height: 26px; padding: 0 6px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent;
  color: var(--fg); font-weight: var(--weight-semibold); min-width: 0; max-width: 280px; field-sizing: content; }
.docname:hover { border-color: var(--border); }
.docname:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }
.lang-chip { font-family: var(--font-mono); font-size: var(--text-2xs); font-weight: var(--weight-semibold); letter-spacing: 0.04em;
  color: var(--fg-subtle); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 0 4px; height: 16px; display: inline-flex; align-items: center; }
.topbar .view-switch { margin-left: var(--space-3); }
.save-status { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--fg-subtle); font-size: var(--text-sm); white-space: nowrap; }
.lock-chip { display: inline-flex; align-items: center; gap: var(--space-1-5); height: var(--control-h); padding: 0 var(--space-2);
  border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg-muted); white-space: nowrap; }
.lock-chip.is-editing { color: var(--success-fg); }
.lock-chip.is-locked { background: var(--warning-subtle); border: 1px solid var(--warning-border); color: var(--fg); padding-right: 3px; }
.lock-chip.is-locked > .icon { color: var(--warning-fg); }
.lock-chip.is-viewing { background: var(--bg-inset); border: 1px solid var(--border); }
.topbar .label-wide { display: inline; }
@media (max-width: 1439px) { .topbar .label-wide { display: none; } }

/* ================================================================ workspace grid */
.workspace {
  --code-w: clamp(var(--code-pane-min), var(--code-pane-default), var(--code-pane-max));
  display: grid; grid-template-columns: var(--code-w) minmax(0, 1fr) auto; min-height: 0; position: relative;
}
body.code-collapsed .workspace { --code-w: var(--rail-w); }

/* ================================================================ code pane */
.codepane { display: grid; grid-template-rows: var(--pane-header-h) minmax(0, 1fr) auto; min-height: 0; min-width: 0;
  border-right: 1px solid var(--border); background: var(--code-bg); position: relative; z-index: var(--z-pane); }
.pane-header { display: flex; align-items: center; gap: var(--space-1); padding: 0 var(--space-1) 0 var(--space-3);
  border-bottom: 1px solid var(--border); background: var(--bg-subtle); min-width: 0; }
.pane-title { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.readonly-tag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--fg-subtle); margin-left: var(--space-2); white-space: nowrap; }
.splitter { position: absolute; top: 0; bottom: 0; right: calc(var(--splitter-hit) / -2); width: var(--splitter-hit); cursor: col-resize; z-index: 2; }
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px; background: transparent; transition: background var(--dur-base); }
.splitter:hover::after { background: var(--accent); }
body.code-collapsed .codepane > :not(.rail) { display: none; }
.rail { display: none; }
body.code-collapsed .codepane { grid-template-rows: 1fr; background: var(--bg-subtle); }
body.code-collapsed .rail { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding-top: var(--space-1); }
.rail-label { writing-mode: vertical-rl; transform: rotate(180deg); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-subtle); margin-top: var(--space-1); }

/* CodeMirror-equivalent content */
.code-scroll { overflow: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.cm-content { font-family: var(--font-mono); font-size: var(--code-size); line-height: var(--code-line); color: var(--code-fg);
  padding: var(--space-1) 0 var(--space-6); min-width: max-content; font-variant-ligatures: none; }
.cm-content.is-readonly { background: var(--code-readonly-bg); }
.cm-line { display: flex; white-space: pre; position: relative; }
.cm-line.is-active { background: var(--code-line-active); }
.cm-line.is-linked { background: var(--code-selection-match); }
.cm-gutter { flex: none; width: 52px; padding-right: var(--space-3); text-align: right; color: var(--code-gutter-fg);
  position: sticky; left: 0; background: inherit; display: flex; justify-content: flex-end; align-items: center; gap: 6px; user-select: none; }
.cm-content .cm-line:not(.is-active):not(.is-linked) .cm-gutter { background: var(--code-gutter-bg); }
.cm-content.is-readonly .cm-line:not(.is-active):not(.is-linked) .cm-gutter { background: var(--code-readonly-bg); }
.cm-line.is-active .cm-ln { color: var(--code-gutter-fg-active); }
.cm-gutter-mark { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.cm-gutter-mark.is-error { background: var(--danger); }
.cm-gutter-mark.is-warning { background: var(--warning); }
.cm-text { position: relative; padding-right: var(--space-4); }
.cm-guide { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--code-indent-guide); }
.cm-cursor { display: inline-block; width: 0; height: 17px; vertical-align: -3px; border-left: 2px solid var(--code-cursor); margin-right: -2px; }
.cm-diag { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-skip-ink: none; }
.cm-diag-error { text-decoration-color: var(--danger); }
.cm-diag-warning { text-decoration-color: var(--warning); }
.cm-diag-eol { display: inline-block; width: 1ch; }
.cm-swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 3px; vertical-align: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.cm-remote { position: relative; display: inline-block; width: 0; height: 17px; vertical-align: -3px; border-left: 2px solid var(--presence-2); margin-right: -2px; }
.cm-remote::after { content: attr(data-name); position: absolute; left: -2px; top: -14px; padding: 0 4px; border-radius: 3px 3px 3px 0;
  background: var(--presence-2); color: var(--fg-on-presence); font: 600 10px/14px var(--font-ui); white-space: nowrap; }
.tok-kw { color: var(--syn-keyword); }
.tok-def { color: var(--syn-definition); }
.tok-name { color: var(--syn-name); }
.tok-type { color: var(--syn-type); }
.tok-setting { color: var(--syn-setting); }
.tok-str { color: var(--syn-string); }
.tok-num { color: var(--syn-number); }
.tok-comment { color: var(--syn-comment); font-style: italic; }
.tok-op { color: var(--syn-operator); }
.tok-punct { color: var(--syn-punct); }
.tok-color { color: var(--syn-color); }

/* diagnostic tooltip and autocomplete popovers anchored in the code */
.cm-tooltip { position: absolute; z-index: var(--z-popover); max-width: 380px; padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-2);
  font-size: var(--text-sm); line-height: var(--lh-sm); display: grid; gap: 4px; }
.cm-tooltip .code-id { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); }
.cm-complete { position: absolute; z-index: var(--z-popover); width: 280px; padding: var(--space-1); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-2); font-family: var(--font-mono); font-size: var(--text-sm); }
.cm-complete .opt { display: flex; align-items: center; gap: var(--space-2); height: 24px; padding: 0 var(--space-2); border-radius: var(--radius-xs); }
.cm-complete .opt.is-active { background: var(--accent-subtle); }
.cm-complete .opt .kind { width: 16px; height: 16px; border-radius: 3px; display: grid; place-items: center; font: 600 9px/1 var(--font-ui); background: var(--bg-inset); color: var(--fg-muted); }
.cm-complete .opt .detail { margin-left: auto; color: var(--fg-subtle); font-size: var(--text-xs); }
.cm-complete .opt mark { background: none; color: var(--accent-fg); font-weight: 700; }

/* problems strip */
.problems { border-top: 1px solid var(--border); background: var(--bg-subtle); min-width: 0; }
.problems-bar { display: flex; align-items: center; gap: var(--space-3); height: var(--problems-h); padding: 0 var(--space-1) 0 var(--space-3);
  font-size: var(--text-sm); color: var(--fg-muted); width: 100%; border: 0; background: transparent; cursor: pointer; text-align: left; }
.problems-bar:hover { background: var(--bg-hover); }
.problems-bar .count { display: inline-flex; align-items: center; gap: 4px; font-weight: var(--weight-medium); }
.problems-bar .count .icon { width: 14px; height: 14px; }
.problems-bar .count.is-error { color: var(--danger-fg); }
.problems-bar .count.is-warning { color: var(--warning-fg); }
.problems-bar .count.is-none { color: var(--fg-subtle); }
.problems-bar .pos { margin-left: auto; color: var(--fg-subtle); font-family: var(--font-mono); font-size: var(--text-xs); }
.problems-list { max-height: var(--problems-max-h); overflow: auto; border-top: 1px solid var(--border); padding: var(--space-1) 0; background: var(--bg-chrome); }
.problem { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: start; gap: var(--space-2); padding: 3px var(--space-3);
  font-size: var(--text-sm); line-height: 18px; cursor: pointer; }
.problem:hover { background: var(--bg-hover); }
.problem.is-active { background: var(--bg-selected); }
.problem .icon { width: 14px; height: 14px; margin-top: 2px; }
.problem.is-error .icon { color: var(--danger-fg); }
.problem.is-warning .icon { color: var(--warning-fg); }
.problem .where { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); white-space: nowrap; }
.problem .code-id { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); }

/* ================================================================ canvas */
.canvas { position: relative; overflow: hidden; min-width: 0; background-color: var(--bg-canvas);
  background-image: radial-gradient(circle, var(--canvas-grid) 1px, transparent 1.2px); background-size: 20px 20px; z-index: var(--z-canvas); }
.canvas > svg.dg { position: absolute; inset: 0; width: 100%; height: 100%; cursor: default; }
.canvas.is-grabbing > svg.dg { cursor: grabbing; }
.canvas-tools { position: absolute; top: var(--space-3); left: var(--space-3); right: var(--space-3); display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-2);
  z-index: var(--z-canvas-overlay); pointer-events: none; }
.canvas-tools > * { pointer-events: auto; }
.toolbar { display: flex; align-items: center; gap: 2px; height: 36px; padding: 0 var(--space-1); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.toolbar .input-group { height: var(--control-h); border-color: transparent; background: transparent; width: 220px; }
.toolbar .input-group:hover { background: var(--bg-hover); }
.toolbar .btn { height: var(--control-h); }
.toolbar .divider-v { margin: 6px 2px; }
.search-results { position: absolute; top: 40px; left: 0; width: 280px; }
.canvas-banner { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: var(--z-canvas-overlay); box-shadow: var(--shadow-1); white-space: nowrap; }
/* in the app the banner is a row of the canvas-tools flow, centred under the toolbars */
.canvas-tools > .tools-break { flex-basis: 100%; height: 0; }
.canvas-tools > .canvas-banner { position: static; transform: none; margin: 0 auto; pointer-events: auto; }
.canvas-tools > .tools-break:has(+ [hidden]) { display: none; }
/* toolbar button labels give way first when the canvas is narrow */
@media (max-width: 1439px) { .canvas-tools .label-wide { display: none; } }
@media (max-width: 1599px) { body:not(.details-closed):not(.code-collapsed) .canvas-tools .label-wide { display: none; } }
.canvas-corner { position: absolute; right: var(--space-3); bottom: var(--space-3); display: grid; justify-items: end; gap: var(--space-2); z-index: var(--z-canvas-overlay); }
.minimap { width: var(--minimap-w); height: var(--minimap-h); background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-1); overflow: hidden; position: relative; }
.minimap svg { width: 100%; height: 100%; display: block; }
.minimap .mm-view { fill: var(--accent); fill-opacity: 0.08; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.minimap .mm-shade { fill: var(--bg-canvas); fill-opacity: 0.0; }
.zoombar { display: flex; align-items: center; gap: 1px; height: 32px; padding: 0 2px; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.zoombar .btn { height: 26px; }
.zoombar .btn-icon { width: 26px; }
.zoombar .zoom-val { min-width: 48px; font-variant-numeric: tabular-nums; font-size: var(--text-sm); color: var(--fg-muted); }
.canvas-legend { position: absolute; left: var(--space-3); bottom: var(--space-3); z-index: var(--z-canvas-overlay); display: flex; align-items: center; gap: var(--space-3);
  height: 32px; padding: 0 var(--space-3); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); font-size: var(--text-sm); color: var(--fg-muted); }
.legend-swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid currentColor; vertical-align: middle; margin-right: 4px; }
.canvas-hover-tip { position: absolute; z-index: var(--z-popover); }

/* ================================================================ details panel */
.details { width: var(--details-w); min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); background: var(--bg-chrome);
  border-left: 1px solid var(--border); z-index: var(--z-pane); }
body.details-closed .details { display: none; }
/* below the dock width the panel overlays the canvas */
@media (max-width: 1599px) {
  .details { position: absolute; top: 0; right: 0; bottom: 0; z-index: var(--z-panel-overlay); box-shadow: var(--shadow-2); }
  .workspace { grid-template-columns: var(--code-w) minmax(0, 1fr); }
  /* keep canvas overlays clear of the overlaying panel */
  body:not(.details-closed) .canvas-corner { right: calc(var(--details-w) + var(--space-3)); }
  body:not(.details-closed) .canvas-banner { left: calc(50% - var(--details-w) / 2); }
  body:not(.details-closed) .canvas-tools { right: calc(var(--details-w) + var(--space-3)); }
}
.details-header { display: flex; align-items: center; gap: var(--space-2); height: 44px; padding: 0 var(--space-2) 0 var(--space-4); border-bottom: 1px solid var(--border); }
.details-header .kind { display: grid; place-items: center; width: 24px; height: 24px; border-radius: var(--radius-sm); background: var(--bg-inset); color: var(--fg-muted); flex: none; }
.details-header h2 { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); }
.details-body { overflow: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.details .tabs { padding: 0 var(--space-4); }
.col-list { display: grid; }
.col-item { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); height: 28px; padding: 0 var(--space-2);
  margin: 0 calc(-1 * var(--space-2)); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.col-item:hover { background: var(--bg-hover); }
.col-item.is-selected { background: var(--bg-selected); }
.col-item .type { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-subtle); }
.col-item .icon { color: var(--fg-subtle); }
.col-item .icon.is-pk { color: var(--dg-pk); }
.mini-badge { font-size: 9px; font-weight: 600; letter-spacing: 0.02em; color: var(--fg-muted); border: 1px solid var(--border-strong); border-radius: 3px; padding: 0 3px; line-height: 12px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 20px; height: 20px; border-radius: var(--radius-sm); border: 0; box-shadow: inset 0 0 0 1px var(--swatch-edge); cursor: pointer; padding: 0; position: relative; }
/* selected: a check mark in the auto-contrast colour; focus keeps the normal ring */
.swatches button[aria-checked="true"]::after { content: ""; position: absolute; left: 6px; top: 3px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); filter: drop-shadow(0 0 1px rgba(0,0,0,.9)); }
body.is-readonly .swatches button:not([aria-checked="true"]) { opacity: 0.35; cursor: not-allowed; }
.swatches .none { background: var(--bg-chrome) !important; box-shadow: inset 0 0 0 1px var(--border-strong); position: relative; overflow: hidden; }
.swatches .none::after { content: ""; position: absolute; left: -2px; right: -2px; top: 9px; height: 1.5px; background: var(--danger); transform: rotate(-45deg); }
.rel-item { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); font-size: var(--text-sm); height: 28px; }
.rel-item .mono { font-size: var(--text-xs); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rel-item > :last-child { white-space: nowrap; }
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-chrome); }

/* comment threads (used in the details panel and panels.html) */
.thread { display: grid; gap: var(--space-3); }
.comment { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: var(--space-2); }
.comment-meta { display: flex; align-items: baseline; gap: var(--space-2); font-size: var(--text-sm); }
.comment-meta .who { font-weight: var(--weight-semibold); }
.comment-meta .when { color: var(--fg-subtle); font-size: var(--text-xs); }
.comment-body { font-size: var(--text-md); line-height: var(--lh-md); }
.anchor-chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--bg-inset);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-muted); }
.anchor-chip.is-detached { text-decoration: line-through; color: var(--fg-muted); }
.composer { border: 1px solid var(--border-input); border-radius: var(--radius-md); background: var(--bg-chrome); }
.composer:focus-within { outline: 2px solid var(--focus-ring); outline-offset: -1px; border-color: transparent; }
.composer textarea { width: 100%; border: 0; background: transparent; resize: none; padding: var(--space-2); min-height: 56px; outline: none; }
.composer-foot { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-1) var(--space-1) var(--space-2); }

/* small screens */
.too-small { display: none; }
@media (max-width: 1279px), (max-height: 719px) {
  .app { display: none; }
  .too-small { display: grid; }
}
