/*
 * App styles on top of design/ (tokens.css, base.css, editor.css, diagram.css).
 * Colours, sizes and type come from the tokens only; nothing here defines a
 * colour of its own. Mostly: CodeMirror themed to match the design's code
 * pane, and the few app parts the mockups draw as static HTML.
 */

/* ================================================================ code pane host */
.code-host { position: relative; min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--code-bg); }
.code-host > .cm-editor { flex: 1; min-height: 0; }
.code-loading { padding: var(--space-3); font-size: var(--text-sm); }
.codepane.is-dragging, .codepane.is-dragging * { user-select: none; cursor: col-resize; }
.codepane.is-dragging .splitter::after { background: var(--accent); }
.splitter:focus-visible { outline-offset: -2px; }

/* ================================================================ CodeMirror theme */
/* design/editor.css styles static mockup markup that reuses CodeMirror's class
   names (.cm-line, .cm-gutter, .cm-cursor, .cm-content); undo the layout parts
   of those rules for the real editor and keep the look. */
.code-host .cm-line { display: block; position: static; }
.code-host .cm-gutter {
  width: auto; padding: 0; position: static; text-align: initial; justify-content: flex-start;
  align-items: stretch; gap: 0; background: transparent; color: inherit;
}
.code-host .cm-cursor { display: block; height: auto; vertical-align: baseline; margin: 0; }
.code-host .cm-content { min-width: 0; color: var(--code-fg); font-size: var(--code-size); line-height: var(--code-line); }
.code-host .cm-lineNumbers .cm-gutterElement { text-align: right; }
.code-host .cm-editor { background: var(--code-bg); color: var(--code-fg); font-size: var(--code-size); }
.code-host .cm-editor.cm-focused { outline: none; }
.code-host .cm-scroller {
  font-family: var(--font-mono); line-height: var(--code-line); font-variant-ligatures: none;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
}
.code-host .cm-content { padding: var(--space-1) 0 var(--space-6); caret-color: var(--code-cursor); }
.code-host .cm-line { padding: 0 var(--space-4) 0 var(--space-1); }
.code-host .cm-gutters { background: var(--code-gutter-bg); color: var(--code-gutter-fg); border-right: 0; }
.code-host .cm-lineNumbers .cm-gutterElement { min-width: 36px; padding: 0 var(--space-1) 0 var(--space-2); }
.code-host .cm-foldGutter .cm-gutterElement { color: var(--fg-disabled); }
.code-host .cm-activeLine { background: var(--code-line-active); }
.code-host .cm-activeLineGutter { background: var(--code-line-active); color: var(--code-gutter-fg-active); }
.code-host .cm-cursor, .code-host .cm-dropCursor { border-left: 2px solid var(--code-cursor); }
.code-host .cm-selectionBackground,
.code-host .cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground,
.code-host .cm-content ::selection { background: var(--code-selection) !important; }
.code-host .cm-selectionMatch { background: var(--code-selection-match); }
.code-host .cm-matchingBracket, .code-host .cm-focused .cm-matchingBracket { background: var(--code-bracket-match); color: inherit; outline: 0; }
.code-host .cm-nonmatchingBracket, .code-host .cm-focused .cm-nonmatchingBracket { background: var(--danger-subtle); color: inherit; }
.code-host .cm-searchMatch { background: var(--warning-subtle); outline: 1px solid var(--warning-border); }
.code-host .cm-searchMatch-selected { background: var(--code-selection); }
.code-host .cm-foldPlaceholder { background: var(--bg-inset); border: 1px solid var(--border); color: var(--fg-muted); }
.code-host.is-readonly .cm-editor,
.code-host.is-readonly .cm-gutters { background: var(--code-readonly-bg); }
.code-host.is-readonly .cm-activeLine,
.code-host.is-readonly .cm-activeLineGutter { background: transparent; }

/* colour literal swatch (the bridge sets --cg-swatch to the literal) */
.code-host .tok-color::before {
  content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 3px;
  background: var(--cg-swatch, transparent); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.code-host .tok-error { color: var(--danger-fg); }

/* diagnostics: wavy underline as in the mockups, gutter dot */
.code-host .cm-lintRange {
  background-image: none; padding-bottom: 0;
  text-decoration-line: underline; text-decoration-style: wavy; text-decoration-thickness: 1px;
  text-underline-offset: 3px; text-decoration-skip-ink: none;
}
.code-host .cm-lintRange-error { text-decoration-color: var(--danger); }
.code-host .cm-lintRange-warning { text-decoration-color: var(--warning); }
.code-host .cm-lintRange-info, .code-host .cm-lintRange-hint { text-decoration-color: var(--accent); }
.code-host .cm-gutter-lint { width: 12px; }
.code-host .cm-gutter-lint .cm-gutterElement { padding: 0; display: flex; align-items: center; justify-content: center; }
.code-host .cm-lint-marker { content: none; width: 7px; height: 7px; border-radius: 50%; }
.code-host .cm-lint-marker-error { background: var(--danger); }
.code-host .cm-lint-marker-warning { background: var(--warning); }
.code-host .cm-lint-marker-info { background: var(--accent); }

/* tooltips (lint hover, autocomplete): design .cm-tooltip look */
.code-host .cm-tooltip { padding: 0; display: block; max-width: 380px; background: var(--bg-elevated); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-2); }
.code-host .cm-tooltip-lint { padding: var(--space-1) 0; }
.code-host .cm-diagnostic { padding: var(--space-1) var(--space-3); border-left: 0; font-family: var(--font-ui);
  font-size: var(--text-sm); line-height: var(--lh-sm); display: grid; gap: 2px; }
.code-host .cm-diagnostic-error { border-left: 0; }
.code-host .cm-diagnostic-warning { border-left: 0; }
.code-host .cm-diagnosticSource { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); opacity: 1; }
.code-host .cm-tooltip-arrow { display: none; }

.code-host .cm-tooltip.cm-tooltip-autocomplete { padding: var(--space-1); min-width: 240px; }
.code-host .cm-tooltip.cm-tooltip-autocomplete > ul { font-family: var(--font-mono); font-size: var(--text-sm); max-height: 240px; }
.code-host .cm-tooltip.cm-tooltip-autocomplete > ul > li {
  display: flex; align-items: center; gap: var(--space-2); height: 24px; padding: 0 var(--space-2); border-radius: var(--radius-xs); line-height: 24px;
}
.code-host .cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected] { background: var(--accent-subtle); color: var(--fg); }
.code-host .cm-completionMatchedText { text-decoration: none; color: var(--accent-fg); font-weight: 700; }
.code-host .cm-completionDetail { margin-left: auto; padding-left: var(--space-3); color: var(--fg-subtle); font-size: var(--text-xs); font-style: normal; font-family: var(--font-ui); }
.code-host .cm-completionIcon {
  width: 16px; height: 16px; padding: 0; margin: 0; flex: none; border-radius: 3px; display: grid; place-items: center;
  font: 600 9px/1 var(--font-ui); background: var(--bg-inset); color: var(--fg-muted); opacity: 1;
}
.code-host .cm-completionIcon::after { content: "·"; }
.code-host .cm-completionIcon-keyword::after { content: "K"; }
.code-host .cm-completionIcon-setting::after { content: "S"; }
.code-host .cm-completionIcon-value::after { content: "V"; }
.code-host .cm-completionIcon-type::after { content: "Ty"; }
.code-host .cm-completionIcon-table::after { content: "T"; }
.code-host .cm-completionIcon-column::after { content: "C"; }
.code-host .cm-completionIcon-enum::after { content: "E"; }
.code-host .cm-completionIcon-schema::after { content: "Sc"; }
.code-host .cm-completionIcon-direction::after { content: "D"; }
.code-host .cm-completionIcon-node::after { content: "N"; }
.code-host .cm-completionIcon-class::after { content: "Cl"; }

/* find and replace panel */
.code-host .cm-panels { background: var(--bg-subtle); color: var(--fg); border-color: var(--border); font-family: var(--font-ui); font-size: var(--text-sm); }
.code-host .cm-panels.cm-panels-top { border-bottom: 1px solid var(--border); }
.code-host .cm-panels.cm-panels-bottom { border-top: 1px solid var(--border); }
.code-host .cm-panel.cm-search { padding: var(--space-1-5) var(--space-6) var(--space-1-5) var(--space-2); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.code-host .cm-panel.cm-search br { flex-basis: 100%; height: 0; content: ""; }
.code-host .cm-panel.cm-search label { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--fg-muted); }
.code-host .cm-textfield {
  height: var(--control-h-sm); padding: 0 var(--space-2); margin: 0; border: 1px solid var(--border-input); border-radius: var(--radius-sm);
  background: var(--bg-chrome); color: var(--fg); font: inherit; font-family: var(--font-mono); font-size: var(--text-sm); min-width: 0;
}
.code-host .cm-textfield:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -1px; border-color: transparent; }
.code-host .cm-button {
  height: var(--control-h-sm); padding: 0 var(--space-2); margin: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-chrome); background-image: none; color: var(--fg); font: inherit; font-size: var(--text-sm); cursor: pointer;
}
.code-host .cm-button:hover { background: var(--bg-hover); }
.code-host .cm-panel.cm-search [name=close] { color: var(--fg-muted); font-size: 16px; top: 4px; right: 6px; }

/* ================================================================ top bar additions */
.crumb-static { color: var(--fg-muted); padding: 2px 4px; white-space: nowrap; }
.crumb-btn { border: 0; background: transparent; color: var(--fg-muted); padding: 2px 4px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }
.crumb-btn:hover, .crumb-btn[aria-expanded="true"] { color: var(--fg); background: var(--bg-hover); }
.docname-static { display: inline-flex; align-items: center; }
.save-status.is-failed { color: var(--danger-fg); }
.menu-root { position: relative; display: inline-flex; }
.topbar-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: var(--z-menu); width: 260px; display: grid; }
.account-menu { left: auto; right: 0; width: 240px; }
.topbar-menu .menu-item { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--fg); }
.topbar-menu .menu-item .truncate { flex: 1; }
.account-head { padding: var(--space-2) var(--space-2) var(--space-1-5); }
.theme-seg-wrap { padding: 2px var(--space-2) var(--space-1-5); }
.theme-seg { width: 100%; }
.theme-seg button { flex: 1; justify-content: center; display: inline-flex; align-items: center; gap: 4px; }
.account-btn { margin-left: 2px; }

/* ================================================================ canvas slot placeholder */
.canvas-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--space-16) var(--space-6) var(--space-6); }
.placeholder-card { width: min(480px, 100%); display: grid; gap: var(--space-3); padding: var(--space-4); background: var(--bg-elevated);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.placeholder-head { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: var(--space-2); }
.placeholder-head > .t-xs { grid-column: 2; }
.placeholder-kv { grid-template-columns: 80px 1fr; }
.placeholder-list { margin: 0; padding: 0 0 0 var(--space-4); display: grid; gap: var(--space-1); color: var(--fg-muted); min-width: 0; }
.placeholder-list li { min-width: 0; overflow-wrap: anywhere; }

/* ================================================================ details panel additions */
.details-title { min-width: 0; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ================================================================ notices, small screen, not found */
.app-toast { position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%); z-index: var(--z-toast); }
.too-small { place-items: center; height: 100vh; padding: var(--space-6); text-align: center; }
.too-small-box { max-width: 360px; justify-items: center; }
.not-found { display: grid; place-content: center; gap: var(--space-2); height: 100vh; text-align: center; }
