/* pgkiln builder: code editor (public/code-editor.js). The textarea's text is
   transparent and lies exactly over the highlighted copy (.ce-code), so both
   must share font, size, line height, padding and tab size. */
:root {
  /* the colours (--ce-bg, --ce-kw, …, --ce-line, --ce-select) are tokens in builder.css, light and dark */
  --ce-font: 0.84rem;
  --ce-lh: 20px; /* whole pixels: fractional line heights drift apart over thousands of lines */
}
@media (pointer: coarse) {
  :root { --ce-font: 16px; --ce-lh: 24px; } /* the same as other fields: no zoom on focus in iOS */
}

.ce {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr);
  min-width: 0; max-width: 100%; border: 1px solid var(--field-border, var(--border)); border-radius: var(--radius-sm, 6px); background: var(--ce-bg);
}
.ce:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring, transparent); }
.ce-gutter {
  --ce-digits: 2;
  width: calc(var(--ce-digits) * 1ch + 1.1rem); overflow: hidden; position: relative;
  background: var(--ce-gutter); border-right: 1px solid var(--border); border-radius: var(--radius-sm, 6px) 0 0 0;
  color: var(--ce-gutter-text); user-select: none;
}
.ce-gutter, .ce .ce-code, .ce textarea.ce-input {
  font-family: var(--mono); font-size: var(--ce-font); line-height: var(--ce-lh); tab-size: 2;
  font-variant-ligatures: none; letter-spacing: 0; font-kerning: none;
}
.ce-nums { position: absolute; top: 0; left: 0; right: 0; white-space: pre; text-align: right; padding: 0.5rem 0.45rem 0 0; will-change: transform; }
/* the caret's line (sprint 108): a band behind the text and its number in the gutter, while the editor has the focus */
.ce-cur, .ce-cur-num { position: absolute; left: 0; right: 0; top: 0; height: var(--ce-lh); will-change: transform; display: none; }
.ce-cur { background: var(--ce-line); }
.ce-cur-num { padding-right: 0.45rem; text-align: right; color: var(--ce-gutter-active); background: var(--ce-gutter); font-weight: 650; }
.ce:focus-within :is(.ce-cur, .ce-cur-num):not([hidden]) { display: block; }
.ce-main { position: relative; min-width: 0; }
.ce .ce-hl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.ce .ce-code {
  margin: 0; padding: 0.5rem 0.65rem; white-space: pre; color: var(--ce-text); background: none;
  width: max-content; min-width: 100%; will-change: transform; border: 0; border-radius: 0; overflow: visible; max-height: none;
}
.ce textarea.ce-input {
  display: block; position: relative; width: 100%; min-height: 4.5rem; margin: 0;
  padding: 0.5rem 0.65rem; border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: none;
  color: transparent; caret-color: var(--ce-text); white-space: pre; overflow: auto; overflow-wrap: normal;
  resize: vertical;
}
.ce textarea.ce-input::selection { background: var(--ce-select); color: transparent; }
.ce textarea.ce-input::placeholder { color: var(--muted); }
.ce textarea.ce-input:focus-visible { outline: none; }
.ce textarea.sql-editor { min-height: 18rem; }

/* tokens: in the editor and in read-only code (<pre data-code-view>, sprint 108) */
:is(.ce-code, .ce-view) .t-kw { color: var(--ce-kw); font-weight: 600; }
:is(.ce-code, .ce-view) .t-type { color: var(--ce-type); }
:is(.ce-code, .ce-view) .t-fn { color: var(--ce-fn); }
:is(.ce-code, .ce-view) .t-str { color: var(--ce-str); }
:is(.ce-code, .ce-view) .t-key { color: var(--ce-fn); }
:is(.ce-code, .ce-view) .t-num { color: var(--ce-num); }
:is(.ce-code, .ce-view) .t-com { color: var(--ce-com); font-style: italic; }
:is(.ce-code, .ce-view) .t-bind, :is(.ce-code, .ce-view) .t-sub { color: var(--ce-bind); font-weight: 600; }
:is(.ce-code, .ce-view) .t-qid { color: var(--ce-qid); }
:is(.ce-code, .ce-view) .t-dol { color: var(--ce-str); font-weight: 600; }
:is(.ce-code, .ce-view) .t-tag { color: var(--ce-tag); }
:is(.ce-code, .ce-view) .t-attr { color: var(--ce-attr); }
:is(.ce-code, .ce-view) .t-ent { color: var(--ce-num); }
:is(.ce-code, .ce-view) .t-err { color: var(--ce-err); text-decoration: wavy underline; }
:is(.ce-code, .ce-view) .t-op { color: var(--ce-op); }
:is(.ce-code, .ce-view) .t-pun, :is(.ce-code, .ce-view) .t-br, :is(.ce-code, .ce-view) .t-id { color: var(--ce-text); }
.ce-code .t-match { background: var(--ce-match); border-radius: 2px; outline: 1px solid var(--ce-match-ring); }

pre.ce-view { background: var(--ce-bg); color: var(--ce-text); border-color: var(--border); }
pre.ce-view::selection, pre.ce-view ::selection { background: var(--ce-select); }

/* status bar: language, hint, caret position, check */
.ce-bar {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.75rem;
  padding: 0.2rem 0.5rem; border-top: 1px solid var(--border); background: var(--ce-gutter);
  border-radius: 0 0 var(--radius-sm, 6px) var(--radius-sm, 6px); font-size: 0.75rem; color: var(--muted); min-width: 0;
}
.ce-lang { font-weight: 650; letter-spacing: 0.02em; }
.ce-hint { flex: 1 1 12rem; min-width: 0; }
.ce-pos { font-family: var(--mono); }
.ce-bar .ce-check, .ce-bar .ce-suggest { padding: 0.1rem 0.6rem; min-height: 0; font-size: 0.75rem; margin: 0; }
.ce-msg { flex: 1 1 100%; min-width: 0; overflow-wrap: anywhere; }
.ce-msg:empty { display: none; }
.ce-msg-ok { color: var(--success); }
.ce-msg-warn { color: var(--text); }
.ce-msg-error { color: var(--danger); }

/* completion list */
.ce-pop {
  position: absolute; z-index: 30; left: 0; top: 0; margin: 0; padding: 0.25rem 0; list-style: none;
  width: max-content; min-width: 14rem; max-width: min(34rem, calc(100% - 0.5rem)); max-height: 15rem; overflow: auto;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow-lg, 0 8px 24px rgb(16 24 40 / 18%)); font-size: 0.82rem;
}
.ce-opt { display: flex; align-items: baseline; gap: 0.75rem; padding: 0.2rem 0.6rem 0.2rem 0.4rem; cursor: pointer; white-space: nowrap; }
.ce-opt::before {
  flex: none; width: 1.15rem; text-align: center; font: 600 0.68rem/1.4 var(--mono); border-radius: 3px;
  color: var(--muted); background: var(--surface-3); content: "·";
}
.ce-opt[aria-selected="true"] { background: var(--accent-soft); }
.ce-opt[aria-selected="true"] .ce-opt-label { color: var(--accent); }
.ce-opt-label { font-family: var(--mono); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ce-opt-detail { margin-left: auto; color: var(--muted); font-size: 0.74rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ce-k-column::before { content: "c"; color: var(--ce-type); }
.ce-k-table::before { content: "T"; color: var(--ce-fn); }
.ce-k-view::before { content: "V"; color: var(--ce-fn); }
.ce-k-schema::before { content: "S"; color: var(--ce-qid); }
.ce-k-alias::before { content: "a"; color: var(--ce-qid); }
.ce-k-function::before { content: "f"; color: var(--ce-fn); }
.ce-k-keyword::before { content: "k"; color: var(--ce-kw); }
.ce-k-type::before { content: "t"; color: var(--ce-type); }
.ce-k-item::before { content: "P"; color: var(--ce-bind); }
.ce-k-builtin::before { content: "$"; color: var(--ce-bind); }

@media (pointer: coarse) {
  .ce-opt { padding-block: 0.55rem; }
  .ce-bar .ce-check, .ce-bar .ce-suggest { min-height: 36px; }
}
@media print {
  .ce-gutter, .ce-bar, .ce-pop { display: none; }
  .ce { display: block; }
  .ce .ce-hl { display: none; }
  .ce textarea.ce-input { color: var(--text); }
}
