/* =========================================================================
   Лёгкий редактор кода (public/code-surface.js), 26.09.2026.
   Графит кабинета, приглушённая подсветка по макету AlertsCode.dc.html.
   ВАЖНО: <pre> с подсветкой и прозрачный <textarea> над ним обязаны иметь
   одинаковые шрифт, кегль, интерлиньяж, отступы и tab-size — иначе каретка
   «уедет» от букв. Все эти значения — только через переменные ниже.
   ========================================================================= */

.code-surface {
  --cs-bg: #131519;
  --cs-gutter-bg: #16181c;
  --cs-line: #24272d;
  --cs-tx: #d8dde5;
  --cs-num: #59606b;
  --cs-caret: #edf0f5;
  --cs-sel: #5b7bb055;
  --cs-focus: #ff6a2bb3;
  --cs-err: #ef8f86;
  --cs-err-bg: #ef8f8614;
  --cs-hit: #e3b25e2e;
  --cs-hit-line: #e3b25e59;
  --cs-hit-cur: #e3b25e61;
  --cs-hit-cur-line: #e3b25e;
  --cs-font: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;
  --cs-size: 12.5px;
  --cs-lh: 22px;
  --cs-pad-y: 12px;
  --cs-pad-x: 16px;
  --cs-tab: 2;
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 180px;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--cs-bg);
  color: var(--cs-tx);
  isolation: isolate;
}

/* Рамка фокуса поверх содержимого (у самого textarea обводки нет — он во всю площадь). */
.code-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .12s;
}
.code-surface:focus-within::after { box-shadow: inset 0 0 0 2px var(--cs-focus); }

/* ---- номера строк ---- */
.code-surface .cs-gutter {
  position: relative;
  flex: none;
  width: calc(var(--cs-digits, 2) * 1ch + 30px);
  min-width: 48px;
  overflow: hidden;
  background: var(--cs-gutter-bg);
  border-right: 1px solid var(--cs-line);
  font: 400 11.5px/var(--cs-lh) var(--cs-font);
  color: var(--cs-num);
  user-select: none;
  -webkit-user-select: none;
}
.code-surface .cs-gutter-inner { position: absolute; top: var(--cs-pad-y); left: 0; right: 0; will-change: transform; }
.code-surface .cs-num {
  position: relative;
  box-sizing: border-box;
  height: var(--cs-lh);
  padding-right: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.code-surface .cs-num:hover { color: #8f98a6; }
.code-surface .cs-num.is-err { color: var(--cs-err); font-weight: 600; }
.code-surface .cs-err-chip {
  position: absolute;
  left: 5px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--cs-err);
  color: #1d1112;
  font: 700 10px/14px var(--cs-font);
  text-align: center;
}

/* ---- код: подсветка под прозрачным полем ввода ---- */
.code-surface .cs-body { position: relative; flex: 1 1 auto; min-width: 0; }

.code-surface .cs-body .cs-pre,
.code-surface .cs-body .cs-input {
  font-family: var(--cs-font);
  font-size: var(--cs-size);
  font-weight: 400;
  font-style: normal;
  line-height: var(--cs-lh);
  letter-spacing: 0;
  word-spacing: 0;
  tab-size: var(--cs-tab);
  -moz-tab-size: var(--cs-tab);
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  font-kerning: none;
  text-transform: none;
  text-indent: 0;
  text-align: left;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  direction: ltr;
}

.code-surface .cs-pre {
  position: absolute;
  inset: 0;
  z-index: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
  color: var(--cs-tx);
}
.code-surface .cs-lines { position: absolute; top: var(--cs-pad-y); left: var(--cs-pad-x); will-change: transform; }
.code-surface .cs-ln { height: var(--cs-lh); white-space: pre; }
.code-surface .cs-probe { position: absolute; left: 0; top: 0; visibility: hidden; white-space: pre; }

/* Полоса строки с ошибкой — во всю ширину, не сдвигается горизонтальной прокруткой. */
.code-surface .cs-band {
  position: absolute;
  top: var(--cs-pad-y);
  left: 0;
  right: 0;
  height: var(--cs-lh);
  background: var(--cs-err-bg);
  box-shadow: inset 2px 0 0 var(--cs-err);
  will-change: transform;
}
.code-surface .cs-band[hidden] { display: none; }

.code-surface .cs-body .cs-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: var(--cs-pad-y) var(--cs-pad-x);
  border: 0;
  border-radius: 0;
  outline: none;
  box-shadow: none;
  resize: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--cs-caret);
  scrollbar-width: thin;
  scrollbar-color: #3a3f47 transparent;
}
.code-surface .cs-body .cs-input:focus,
.code-surface .cs-body .cs-input:focus-visible { outline: none; box-shadow: none; border-radius: 0; }
.code-surface .cs-body .cs-input::selection { background: var(--cs-sel); color: transparent; -webkit-text-fill-color: transparent; }
.code-surface .cs-body .cs-input::placeholder { color: #6c7480; -webkit-text-fill-color: #6c7480; opacity: 1; }
.code-surface .cs-body .cs-input::-webkit-scrollbar { width: 10px; height: 10px; }
.code-surface .cs-body .cs-input::-webkit-scrollbar-thumb { background: #3a3f47; border: 2px solid var(--cs-bg); border-radius: 6px; }
.code-surface .cs-body .cs-input::-webkit-scrollbar-corner { background: transparent; }
.code-surface.is-readonly .cs-body .cs-input { caret-color: #8f98a6; }

/* ---- подсветка: приглушённые токены ---- */
.code-surface .cs-k { color: #c49bff; }
.code-surface .cs-s { color: #a6d9b1; }
.code-surface .cs-f { color: #86bdfc; }
.code-surface .cs-v { color: #e7c787; }
.code-surface .cs-x { color: #7fd6d0; }
.code-surface .cs-c { color: #6c7480; font-style: italic; }
.code-surface .cs-p { color: #8f98a6; }
.code-surface .cs-hit { border-radius: 2px; background: var(--cs-hit); box-shadow: 0 0 0 1px var(--cs-hit-line); }
.code-surface .cs-hit.is-cur { background: var(--cs-hit-cur); box-shadow: 0 0 0 1px var(--cs-hit-cur-line); }

/* ---- поиск (Ctrl+F) ---- */
.code-surface .cs-find {
  position: absolute;
  top: 8px;
  right: 14px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 24px);
  box-sizing: border-box;
  padding: 4px;
  border: 1px solid #30343b;
  border-radius: 10px;
  background: #1c1f24;
  box-shadow: 0 10px 28px #00000066;
  font: 400 12px/1.4 Onest, system-ui, sans-serif;
  color: #b4bcc8;
}
.code-surface .cs-find[hidden] { display: none; }
.code-surface .cs-find .cs-find-input {
  flex: 1 1 180px;
  width: 180px;
  min-width: 0;
  height: 30px;
  box-sizing: border-box;
  margin: 0 4px 0 0;
  padding: 0 10px;
  border: 1px solid #3a3f47;
  border-radius: 8px;
  background: #16181c;
  color: #edf0f5;
  font: 400 12.5px/1 var(--cs-font);
  box-shadow: none;
}
.code-surface .cs-find .cs-find-input::placeholder { color: #6c7480; font-family: Onest, system-ui, sans-serif; }
.code-surface .cs-find .cs-find-input:focus { outline: none; border-color: #ff6a2b99; box-shadow: none; }
.code-surface .cs-find.is-empty .cs-find-input { border-color: #ef8f8666; }
.code-surface .cs-find-count { flex: none; min-width: 58px; padding: 0 4px; font-size: 11.5px; text-align: center; white-space: nowrap; color: #8f98a6; }
.code-surface .cs-find.is-empty .cs-find-count { color: var(--cs-err); }
.code-surface .cs-find .cs-find-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #b4bcc8;
  cursor: pointer;
}
.code-surface .cs-find .cs-find-btn:hover:not(:disabled) { background: #ffffff0d; color: #edf0f5; }
.code-surface .cs-find .cs-find-btn:disabled { opacity: .4; cursor: default; }
.code-surface .cs-find .cs-find-btn:focus-visible { outline: 2px solid #ff6a2b; outline-offset: 1px; box-shadow: none; }

.code-surface .cs-vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- планшет и телефон ---- */
@media (max-width: 600px) {
  .code-surface { --cs-pad-x: 12px; }
  .code-surface .cs-gutter { min-width: 40px; }
  .code-surface .cs-num { padding-right: 8px; }
  .code-surface .cs-find { left: 8px; right: 8px; top: 6px; max-width: none; }
  .code-surface .cs-find .cs-find-input { width: auto; }
}
@media (pointer: coarse) {
  .code-surface .cs-find .cs-find-btn { width: 36px; height: 36px; }
  .code-surface .cs-find .cs-find-input { height: 36px; }
}
/* iOS увеличивает страницу при фокусе на поле с кеглем меньше 16px — только там крупнее. */
@supports (-webkit-touch-callout: none) {
  .code-surface { --cs-size: 16px; --cs-lh: 24px; }
  .code-surface .cs-find .cs-find-input { font-size: 16px; }
}

/* Режим высокой контрастности Windows: подсветку прячем, текст рисует само поле ввода. */
@media (forced-colors: active) {
  .code-surface .cs-pre { display: none; }
  .code-surface .cs-body .cs-input { color: CanvasText; -webkit-text-fill-color: CanvasText; }
  .code-surface::after { box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  .code-surface::after { transition: none; }
}
