/* The shared code editor (TRK-1007, code-editor.js). Colors follow the app's theme: light-dark() picks by the page's
   color-scheme, which every light and dark theme sets. */
.code-editor {
  --ce-keyword: light-dark(#b42318, #ff8f85);
  --ce-tag: light-dark(#116329, #7ee787);
  --ce-attr: light-dark(#6639ba, #d2a8ff);
  --ce-string: light-dark(#0a3069, #a5d6ff);
  --ce-number: light-dark(#0550ae, #79c0ff);
  --ce-comment: light-dark(#5b6474, #9aa3ae);
  --ce-def: light-dark(#953800, #ffa657);
  --ce-height: 320px;
  display: grid;
  gap: 8px;
  min-width: 0;
}
.code-editor-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.code-editor-space { flex: 1 1 auto; }
.code-editor-tabs { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--sunken); border: 1px solid var(--border); }
.code-editor-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 600 13px/1 inherit;
  cursor: pointer;
}
.code-editor-tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.code-editor-tab:focus-visible, .code-editor-btn:focus-visible, .code-editor-goto:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-editor-count { min-width: 18px; padding: 2px 5px; border-radius: 999px; background: color-mix(in srgb, var(--high) 16%, transparent); color: var(--high); font-size: 11px; text-align: center; }
.code-editor-btn { min-height: 30px; padding: 4px 10px; font-size: 13px; }

.code-editor-body { display: grid; gap: 10px; min-width: 0; }
.code-editor-body.has-side { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: stretch; }
.code-editor-code { min-width: 0; }
.code-editor-panel { display: grid; gap: 6px; min-width: 0; }
.code-editor-panel[hidden] { display: none; }
.code-editor-note { margin: 0; padding: 6px 10px; border-radius: 6px; background: var(--sunken); font-size: 12px; color: var(--muted); }

.code-editor-plain,
.code-editor .cm-editor {
  width: 100%;
  height: var(--ce-height);
  min-height: 160px;
  resize: vertical;
  overflow: hidden;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.code-editor-plain { padding: 10px 12px; tab-size: 2; }
.code-editor .cm-editor.cm-focused { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-editor .cm-scroller { font-family: inherit; line-height: inherit; overflow: auto; }
.code-editor .cm-content { padding: 8px 0; caret-color: var(--text); }
.code-editor .cm-cursor { border-left-color: var(--text); }
.code-editor .cm-gutters { background: var(--surface); color: var(--muted); border-right: 1px solid var(--border); }
.code-editor .cm-activeLine { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.code-editor .cm-activeLineGutter { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text); }
.code-editor .cm-selectionBackground, .code-editor .cm-focused .cm-selectionBackground, .code-editor .cm-content ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent) !important; }
.code-editor .cm-selectionMatch { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.code-editor .cm-matchingBracket { background: color-mix(in srgb, var(--pass) 24%, transparent); outline: 1px solid color-mix(in srgb, var(--pass) 60%, transparent); }
.code-editor .cm-nonmatchingBracket { background: color-mix(in srgb, var(--danger) 24%, transparent); }
.code-editor .cm-placeholder { color: var(--muted); }
.code-editor-fold { display: inline-block; width: 12px; color: var(--muted); cursor: pointer; }
.code-editor .cm-foldPlaceholder { background: var(--surface); border: 1px solid var(--border); color: var(--muted); }

/* Find and replace */
.code-editor .cm-panels { background: var(--surface); color: var(--text); border-color: var(--border); }
.code-editor .cm-panels-top { border-bottom: 1px solid var(--border); }
.code-editor .cm-search { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 6px 8px; font-size: 13px; }
.code-editor .cm-search input, .code-editor .cm-search button { font: inherit; min-height: 26px; }
.code-editor .cm-search label { display: inline-flex; align-items: center; gap: 4px; }
.code-editor .cm-search button[name="close"] { margin-left: auto; }
.code-editor .cm-searchMatch { background: color-mix(in srgb, var(--medium) 26%, transparent); outline: 1px solid color-mix(in srgb, var(--medium) 50%, transparent); }
.code-editor .cm-searchMatch-selected { background: color-mix(in srgb, var(--medium) 45%, transparent); }

/* Warnings: the wavy line, the gutter mark and the pop-up */
.code-editor .cm-lintRange-warning { background-image: none; text-decoration: wavy underline var(--high) 1.5px; text-underline-offset: 3px; }
.code-editor .cm-lintRange-error { background-image: none; text-decoration: wavy underline var(--danger) 1.5px; text-underline-offset: 3px; }
.code-editor .cm-lint-marker { width: 10px; height: 10px; border-radius: 50%; content: none; }
.code-editor .cm-lint-marker-warning { background: var(--high); }
.code-editor .cm-lint-marker-error { background: var(--danger); }
.code-editor .cm-tooltip { background: var(--dialog, var(--surface)); color: var(--text); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.16); }
.code-editor .cm-diagnostic { padding: 6px 10px; font: 13px/1.4 system-ui, sans-serif; max-width: 420px; }
.code-editor .cm-diagnostic-warning { border-left: 4px solid var(--high); }
.code-editor .cm-diagnostic-error { border-left: 4px solid var(--danger); }

/* Highlighting (classHighlighter's tok- classes) */
.code-editor .tok-keyword, .code-editor .tok-operatorKeyword, .code-editor .tok-modifier { color: var(--ce-keyword); }
.code-editor .tok-typeName, .code-editor .tok-tagName { color: var(--ce-tag); }
.code-editor .tok-propertyName, .code-editor .tok-attributeName { color: var(--ce-attr); }
.code-editor .tok-string, .code-editor .tok-string2, .code-editor .tok-url, .code-editor .tok-attributeValue { color: var(--ce-string); }
.code-editor .tok-number, .code-editor .tok-bool, .code-editor .tok-atom, .code-editor .tok-literal { color: var(--ce-number); }
.code-editor .tok-comment, .code-editor .tok-meta { color: var(--ce-comment); font-style: italic; }
.code-editor .tok-definition, .code-editor .tok-className, .code-editor .tok-labelName, .code-editor .tok-macroName { color: var(--ce-def); }
.code-editor .tok-invalid { color: var(--danger); }
.code-editor .tok-heading, .code-editor .tok-strong { font-weight: 700; }

/* The list of warnings under the code */
.code-editor-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.code-editor-warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 160px; overflow: auto; }
.code-editor-warnings[hidden] { display: none; }
.code-editor-warning { display: flex; align-items: baseline; gap: 8px; padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--high); background: color-mix(in srgb, var(--high) 8%, transparent); font-size: 13px; min-width: 0; }
.code-editor-warning.is-error { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.code-editor-warning > span { min-width: 0; overflow-wrap: anywhere; }
.code-editor-goto { flex: none; padding: 0; border: 0; background: none; color: var(--text); font: 600 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-decoration: underline; cursor: pointer; }
.code-editor-keys { margin: 0; font-size: 12px; }

/* Full screen: the editor and its preview fill the window */
.code-editor.is-full {
  position: fixed;
  inset: 0;
  z-index: 2000;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
}
html:has(.code-editor.is-full) { overflow: hidden; }
.code-editor.is-full .code-editor-body,.code-editor.is-full .code-editor-code, .code-editor.is-full .code-editor-panel:not([hidden]) { min-height: 0; height: 100%; }
.code-editor.is-full .code-editor-panel { grid-template-rows: auto minmax(0, 1fr); }
.code-editor.is-full .code-editor-panel:not(:has(.code-editor-note)) { grid-template-rows: minmax(0, 1fr); }
.code-editor.is-full .cm-editor, .code-editor.is-full .code-editor-plain { height: 100%; resize: none; }
.code-editor.is-full .code-editor-body.has-side > :last-child { height: 100%; min-height: 0; }

@media (max-width: 760px) {
  .code-editor-body.has-side { grid-template-columns: minmax(0, 1fr); }
}
