/* Code editor component (js/components/editor.js).
   Host layout, the CodeMirror "jp-dark" theme and the textarea fallback.
   Token colours match the tok-* colours used for static code blocks in css/app.css. */

/* ---------- Host ---------- */
.jp-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  /* Floor for containers without an explicit height; keep it low so a short fixed container is still respected. */
  min-height: 120px;
  background: var(--code-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  /* Native scrollbars (CodeMirror and the fallback textarea) follow the dark surface. */
  color-scheme: dark;
}
.jp-editor:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.jp-editor-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}
.jp-editor-caption {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 3px 12px;
  background: var(--code-gutter);
  border-top: 1px solid #34363d;
  color: #aeb1b8;
  font-size: 11.5px;
  line-height: 1.4;
}
.jp-editor-caption-mode { color: #f2b56b; font-weight: 600; }

/* ---------- CodeMirror theme: jp-dark ---------- */
.jp-editor .CodeMirror {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}
.cm-s-jp-dark.CodeMirror {
  background: var(--code-bg);
  color: var(--code-text);
}
.cm-s-jp-dark .CodeMirror-lines { padding: 8px 0; }
/* "pre" is needed to outrank the vendor rule ".CodeMirror pre.CodeMirror-line { padding: 0 4px }". */
.cm-s-jp-dark pre.CodeMirror-line,
.cm-s-jp-dark pre.CodeMirror-line-like { padding: 0 12px; }
.cm-s-jp-dark .CodeMirror-gutters {
  background: var(--code-gutter);
  border-right: 1px solid #34363d;
  color: #8a8f99;
}
.cm-s-jp-dark .CodeMirror-linenumber {
  color: #8a8f99;
  padding: 0 8px 0 10px;
  min-width: 26px;
}
.cm-s-jp-dark .CodeMirror-activeline-gutter .CodeMirror-linenumber { color: #c3c6cc; }
.cm-s-jp-dark .CodeMirror-activeline-background { background: var(--code-line); }
.cm-s-jp-dark .CodeMirror-guttermarker { color: var(--code-text); }
.cm-s-jp-dark .CodeMirror-guttermarker-subtle { color: #8a8f99; }

/* selection */
.cm-s-jp-dark .CodeMirror-selected { background: #33415c; }
.cm-s-jp-dark.CodeMirror-focused .CodeMirror-selected { background: #3b4f78; }
.cm-s-jp-dark .CodeMirror-line::selection,
.cm-s-jp-dark .CodeMirror-line > span::selection,
.cm-s-jp-dark .CodeMirror-line > span > span::selection { background: #3b4f78; }
.cm-s-jp-dark .CodeMirror-line::-moz-selection,
.cm-s-jp-dark .CodeMirror-line > span::-moz-selection,
.cm-s-jp-dark .CodeMirror-line > span > span::-moz-selection { background: #3b4f78; }

/* cursor */
.cm-s-jp-dark .CodeMirror-cursor { border-left: 2px solid #f0f1f4; }
.cm-s-jp-dark .CodeMirror-secondarycursor { border-left: 1px solid #aeb1b8; }
.cm-s-jp-dark.cm-fat-cursor .CodeMirror-cursor { background: #7fb4ff; }
.cm-s-jp-dark .cm-animate-fat-cursor { background: #7fb4ff; }

/* read-only: keep the cursor visible so the selection point is clear, but dim it */
.jp-editor-readonly .cm-s-jp-dark .CodeMirror-cursor { border-left-color: #8b909a; }

/* tokens (clike Java mode) */
.cm-s-jp-dark span.cm-keyword { color: #7fb4ff; }
.cm-s-jp-dark span.cm-atom { color: #7fb4ff; }
.cm-s-jp-dark span.cm-string,
.cm-s-jp-dark span.cm-string-2 { color: #c8e58f; }
.cm-s-jp-dark span.cm-comment { color: #8b909a; font-style: italic; }
.cm-s-jp-dark span.cm-number { color: #f2b56b; }
.cm-s-jp-dark span.cm-type,
.cm-s-jp-dark span.cm-def,
.cm-s-jp-dark span.cm-builtin,
.cm-s-jp-dark span.cm-variable-3 { color: #9ee3d8; }
.cm-s-jp-dark span.cm-meta,
.cm-s-jp-dark span.cm-attribute,
.cm-s-jp-dark span.cm-qualifier { color: #d3a5ff; }
.cm-s-jp-dark span.cm-variable,
.cm-s-jp-dark span.cm-variable-2,
.cm-s-jp-dark span.cm-property,
.cm-s-jp-dark span.cm-operator,
.cm-s-jp-dark span.cm-punctuation,
.cm-s-jp-dark span.cm-bracket { color: var(--code-text); }
.cm-s-jp-dark span.cm-error { color: #f2b56b; text-decoration: underline; text-decoration-style: dotted; }

/* bracket matching (addon) */
.cm-s-jp-dark span.CodeMirror-matchingbracket {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  background: rgba(127, 180, 255, 0.18);
}
.cm-s-jp-dark span.CodeMirror-nonmatchingbracket {
  color: #ff9d95;
  text-decoration: underline;
  text-decoration-style: wavy;
}

/* scrollbars inside the dark surface */
.cm-s-jp-dark .CodeMirror-scrollbar-filler,
.cm-s-jp-dark .CodeMirror-gutter-filler { background: var(--code-bg); }

/* ---------- Textarea fallback ---------- */
.jp-editor-fb {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--code-bg);
}
.jp-editor-fb-gutter {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 8px 0 40px;
  overflow: hidden;
  background: var(--code-gutter);
  border-right: 1px solid #34363d;
  color: #8a8f99;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  text-align: right;
  user-select: none;
  -webkit-user-select: none;
}
.jp-editor-fb-gutter-inner { padding: 0 8px 0 10px; white-space: pre; }
.jp-editor-fb-text {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 0;
  resize: none;
  outline: none;
  background: var(--code-bg);
  color: var(--code-text);
  caret-color: #f0f1f4;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
  -moz-tab-size: 4;
}
.jp-editor-fb-text::selection { background: #3b4f78; }
.jp-editor-fb-text:focus { outline: none; }
.jp-editor-fb-text[readonly] { caret-color: #8b909a; }
