:root {
  --on-accent: #ffffff;
  --on-mark-cur: #ffffff;
  --w-key: normal;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs: 13px;
  --lh: 20px;
}

/* Производные токены: пересчитываются для любой палитры из themes.css */
:root,
[data-palette] {
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --sel: color-mix(in srgb, var(--accent) 15%, transparent);
  --guide: var(--border);
  --guide-hover: color-mix(in srgb, var(--border), var(--text) 25%);
  --err-soft: color-mix(in srgb, var(--err) 14%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 14%, transparent);
  --c-idx: var(--c-punct);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  overflow: hidden;
}

button, select, input {
  font: inherit;
  color: inherit;
}

button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--guide-hover); background: var(--panel-2); }
button:active { transform: translateY(1px); }
button:focus-visible, select:focus-visible, input:focus-visible, .tree:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
button.icon { width: 28px; padding: 0; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
button.primary:hover { background: color-mix(in srgb, var(--accent), var(--text) 12%); border-color: transparent; }
button:disabled { opacity: 0.5; cursor: default; }
button:disabled:active { transform: none; }
button.toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
button.link {
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
}

select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}

.muted { color: var(--muted); }

/* ---- шапка ---- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  margin: 0;
  font-size: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 14px;
  margin-right: auto;
}
.logo {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  font: 700 11px var(--mono);
}

.group { display: flex; gap: 4px; align-items: center; }

/* ---- раскладка ---- */

.split {
  flex: 1;
  display: flex;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.input-pane { width: 38%; min-width: 220px; }
.input-pane.hidden { display: none; }
.view-pane { flex: 1; }

.splitter {
  width: 5px;
  flex: none;
  cursor: col-resize;
  background: var(--border);
  border-left: 2px solid var(--bg);
  border-right: 2px solid var(--bg);
}
.splitter:hover, .splitter.drag { background: var(--accent); }
.input-pane.hidden + .splitter { display: none; }

.pane-head, .toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.pane-head .title { font-weight: 600; }
.pane-head .muted { margin-right: auto; font-size: 12px; }

.pane-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.pane-tools .spacer { flex: 1; }
.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.field select { color: var(--text); }

/* ---- редактор ---- */

.editor {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.gutter, #input {
  margin: 0;
  padding: 8px 0;
  font: var(--fs)/var(--lh) var(--mono);
  tab-size: 2;
}

.gutter {
  flex: none;
  min-width: 44px;
  padding-left: 8px;
  padding-right: 8px;
  text-align: right;
  color: var(--c-punct);
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
}
.gutter .e { color: var(--err); font-weight: 700; }
.gutter .w { color: var(--warn); font-weight: 700; }

.text-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  background: var(--panel);
}

.hl-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.hl {
  position: absolute;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.hl.first { border-top-left-radius: 3px; border-top-right-radius: 3px; }
.hl.last { border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; }

#input {
  position: relative;
  outline: none;
  flex: 1;
  min-width: 0;
  padding-left: 10px;
  padding-right: 10px;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  white-space: pre;
  overflow: auto;
}

/* ---- список проблем ---- */

.issues {
  flex: none;
  max-height: 34%;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}
.issues[hidden] { display: none; }
.issues-head {
  padding: 6px 10px;
  font-weight: 600;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.issues ul {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}
.issues li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 4px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.issues li:hover { background: var(--panel-2); }
.issues .sev {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}
.issues .error .sev { background: var(--err-soft); color: var(--err); }
.issues .warning .sev { background: var(--warn-soft); color: var(--warn); }
.issues .loc { flex: none; color: var(--muted); font: 12px var(--mono); min-width: 56px; }
.issues .more-issues { color: var(--muted); cursor: default; }

/* ---- панель поиска ---- */

.toolbar { flex-wrap: wrap; }

.search {
  flex: 1 1 460px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.search > * { flex: none; }
.levels { flex: none; margin-left: auto; }
.search input {
  flex: 1 1 auto;
  min-width: 120px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
.search input.bad { border-color: var(--err); }
.search .count {
  min-width: 52px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.levels select { max-width: 170px; }

.toggle .box {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1.5px solid var(--muted);
  border-radius: 3px;
}
button.toggle[aria-pressed="true"] .box {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 2px var(--panel);
}

/* ---- дерево ---- */

.tree-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

.tree {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 8px 8px 40px;
  font: var(--fs)/var(--lh) var(--mono);
}
.tree:focus { outline: none; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
  pointer-events: none;
}
.empty button { pointer-events: auto; }
.empty[hidden] { display: none; }

.n.closed > .kids, .n.closed > .close { display: none; }
.tree[hidden], .table-scroll[hidden] { display: none; }
.n[hidden] { display: none; }

.kids {
  margin-left: 9px;
  padding-left: 9px;
  border-left: 1px solid var(--guide);
}
.kids:hover { border-left-color: var(--guide-hover); }

.row {
  position: relative;
  padding-left: 16px;
  border-radius: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: default;
}
.row:hover { background: var(--panel-2); }
.row.sel { background: var(--sel); }
.row.cur { box-shadow: inset 2px 0 0 var(--mark-cur); }

.tg {
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: var(--lh);
  cursor: pointer;
}
.tg::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 7px;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(90deg);
  transition: transform 0.1s;
}
.n.closed > .row > .tg::before { transform: none; }

.k { color: var(--c-key); font-weight: var(--w-key); }
.s { color: var(--c-str); }
.num { color: var(--c-num); }
.bool { color: var(--c-bool); }
.nul { color: var(--c-null); font-style: italic; }
.p, .b { color: var(--c-punct); }
.idx { color: var(--c-idx); }
.grp { color: var(--muted); }
.ctor { color: var(--accent); font-weight: 600; }
.expr { color: var(--c-bool); font-style: italic; }
.inv, .bad {
  text-decoration: underline wavy var(--err);
  text-underline-offset: 3px;
}
.inv { color: var(--err); }

.sum {
  color: var(--muted);
  padding: 0 2px;
}

.cnt, .tag, .more, .emb, .mb, .iss {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 10px;
  font: 11px/16px var(--sans);
  vertical-align: 1px;
}
.cnt { color: var(--muted); padding: 0; }
.tag { background: var(--accent-soft); color: var(--accent); }
.more, .emb {
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
.more:hover, .emb:hover { color: var(--accent); border-color: var(--accent); }
.mb { background: var(--mark); color: var(--text); font-weight: 600; }
.iss { cursor: help; font-weight: 700; padding: 0 5px; }
.iss.err { background: var(--err-soft); color: var(--err); }
.iss.warn { background: var(--warn-soft); color: var(--warn); }

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
}
.row.cur mark { background: var(--mark-cur); color: var(--on-mark-cur); }

/* ---- статус ---- */

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 3px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 12px;
}
.status button { height: 24px; font-size: 12px; padding: 0 8px; }
.status .path-style { height: 24px; font-size: 12px; padding: 0 4px; flex: none; }
.path {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
}
.status-actions { display: flex; gap: 4px; }
.status-actions[hidden] { display: none; }
.stats { margin-left: auto; white-space: nowrap; }

/* ---- перетаскивание файла и уведомления ---- */

.drop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--accent-soft);
  border: 3px dashed var(--accent);
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  z-index: 10;
  pointer-events: none;
}
.drop.on { display: grid; }
.drop > div {
  padding: 16px 24px;
  border-radius: 10px;
  background: var(--panel);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translate(-50%, 8px);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 11;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---- узкие экраны ---- */

@media (max-width: 760px) {
  body { overflow: auto; }
  .split { flex-direction: column; }
  .input-pane { width: auto !important; height: 40vh; min-width: 0; }
  .splitter { display: none; }
  .view-pane { min-height: 60vh; }
  .top { padding: 8px 16px; }
  .brand { width: 100%; }
  .search { flex-basis: 100%; flex-wrap: wrap; }
  .levels { margin-left: 0; flex: 1 1 100%; flex-wrap: wrap; }
  .levels button { flex: 1; padding: 0 6px; }
  .levels select { flex: 1 1 100%; min-width: 0; max-width: none; }
  .search input { flex-basis: 100%; }
  .stats { display: none; }
}

/* ---- меню тем ---- */

.theme-wrap, .convert-wrap { position: relative; }

.convert-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 100%;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.convert-menu[hidden] { display: none; }
.cm-item {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
}
.cm-item:hover { background: var(--panel-2); }

.theme-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 300px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 70px);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.theme-menu[hidden] { display: none; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--panel-2);
}
.seg button {
  height: 26px;
  border: 0;
  background: none;
  border-radius: 6px;
}
.seg button[aria-pressed="true"] {
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--border);
  font-weight: 600;
}

.tm-title {
  margin: 12px 2px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.tm-list { display: grid; gap: 2px; }

.tm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 6px;
  border: 0;
  background: none;
  text-align: left;
}
.tm-item:hover { background: var(--panel-2); }
.tm-item .name { flex: 1; }
.tm-item .check { width: 14px; color: var(--accent); font-weight: 700; visibility: hidden; }
.tm-item[aria-checked="true"] .check { visibility: visible; }
.tm-item[aria-checked="true"] .name { font-weight: 600; }

.sw {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 64px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  font: 700 11px var(--mono);
}
.sw .b { color: var(--c-punct); }
.sw i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.sw .d1 { background: var(--c-key); }
.sw .d2 { background: var(--c-str); }
.sw .d3 { background: var(--c-num); }
.sw .d4 { background: var(--accent); }

/* ---- таблица ---- */

.view-seg { display: inline-grid; grid-template-columns: 1fr 1fr; flex: none; }
.view-seg button { padding: 0 10px; }

.table-tools { flex-wrap: wrap; }
.table-tools[hidden] { display: none; }
.tbl-src {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 12px var(--mono);
}
.tbl-info { font-size: 12px; white-space: nowrap; }

.table-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  font: 12.5px/1.2 var(--mono);
}
.table-scroll:focus { outline: none; }

.tbl {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
.tbl th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 30px;
  padding: 0 8px;
  text-align: left;
  font: 600 12px var(--sans);
  color: var(--text);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
}
.tbl th:hover { color: var(--accent); }
.tbl th .sort { color: var(--accent); }
.tbl td {
  height: 28px;
  padding: 0 8px;
  border-bottom: 1px solid var(--guide);
  border-right: 1px solid var(--guide);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--panel);
  cursor: default;
}
.tbl tr.sp td { padding: 0; border: 0; background: none; }
.tbl th.rk, .tbl td.rk {
  position: sticky;
  left: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--panel-2);
}
.tbl th.rk { z-index: 3; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--panel-2) 60%, var(--panel)); }
.tbl tbody tr:hover td.rk { background: var(--panel-2); }
.tbl tr.hit td.rk { box-shadow: inset 3px 0 0 var(--mark); }
.tbl tr.sel td { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.tbl tr.sel td.rk { background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); }
.tbl tr.cur td.rk { box-shadow: inset 3px 0 0 var(--mark-cur); }
.tbl td.csel { box-shadow: inset 0 0 0 2px var(--accent); }
.tbl td.sum { color: var(--muted); }
.tbl td.miss { background: color-mix(in srgb, var(--panel-2) 50%, var(--panel)); }
.tbl-open, .tblb {
  margin-left: 6px;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--sans);
}
.tblb {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 11px;
  line-height: 16px;
  vertical-align: 1px;
}
.tblb:hover, .tbl-open:hover { border-color: var(--accent); }

/* ---- превью значений ---- */

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border-radius: 3px;
  border: 1px solid color-mix(in srgb, var(--text) 25%, transparent);
}
.thumb {
  position: relative;
  display: inline-block;
  margin-right: 6px;
  vertical-align: -3px;
}
.thumb img {
  display: block;
  height: 16px;
  max-width: 48px;
  object-fit: contain;
  border-radius: 2px;
  background: repeating-conic-gradient(var(--panel-2) 0 25%, var(--panel) 0 50%) 0 0 / 8px 8px;
}
.thumb:hover img {
  position: absolute;
  z-index: 10;
  top: 18px;
  left: 0;
  height: auto;
  max-height: 220px;
  max-width: 320px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.ext {
  margin-left: 6px;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--sans);
}
.ext:hover { text-decoration: underline; }
.dec {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: 11px/16px var(--sans);
  color: var(--muted);
  cursor: pointer;
  vertical-align: 1px;
}
.dec:hover { color: var(--accent); border-color: var(--accent); }
.tbl td .swatch, .tbl td .thumb { vertical-align: middle; }

/* ---- jq ---- */

.jq-toggle { font-family: var(--mono); font-weight: 600; }
.search.jq-mode #qCase,
.search.jq-mode #qRegex,
.search.jq-mode #qFilter,
.search.jq-mode #qPrev,
.search.jq-mode #qNext { display: none; }
.search.jq-mode input { font-family: var(--mono); }
.search .count { white-space: nowrap; }

.jq-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  font-size: 12px;
}
.jq-info { color: var(--text); font-weight: 600; white-space: nowrap; }
.jq-err {
  flex: 1;
  min-width: 0;
  color: var(--err);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.jq-bar button { height: 24px; font-size: 12px; }
.jq-bar .icon { width: 24px; }
