:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f9fafc;
  --ink: #1b2431;
  --ink-2: #3d4757;
  --muted: #6b7688;
  --line: #e2e7f0;
  --line-2: #eef1f7;
  --brand: #2f62e8;
  --brand-ink: #ffffff;
  --brand-soft: #eaf0ff;
  --ok: #1c8f4d;
  --ok-soft: #e7f6ed;
  --warn: #b07308;
  --warn-soft: #fdf3e0;
  --err: #cf3b3b;
  --err-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 34, 60, .06), 0 8px 24px -16px rgba(20, 34, 60, .25);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141b;
    --panel: #171d26;
    --panel-2: #1c232e;
    --ink: #e8edf5;
    --ink-2: #c3ccda;
    --muted: #8b97a8;
    --line: #263041;
    --line-2: #202836;
    --brand: #5b86ff;
    --brand-ink: #0c1220;
    --brand-soft: #1b2743;
    --ok: #46c07f;
    --ok-soft: #16301f;
    --warn: #e0a437;
    --warn-soft: #33290f;
    --err: #ff6b6b;
    --err-soft: #33191b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -18px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(140deg, var(--brand), #7aa2ff);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px; letter-spacing: .02em;
  box-shadow: 0 6px 16px -8px var(--brand);
}

.brand-txt h1 { font-size: 15.5px; }
.brand-txt .sub { margin: 1px 0 0; font-size: 11.5px; color: var(--muted); }
.brand-txt .sub b { color: var(--ink-2); font-weight: 600; }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.progress {
  font-size: 11.5px; color: var(--muted);
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2);
  white-space: nowrap;
}
.progress.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); background: var(--ok-soft); }
.progress.bad { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, var(--line)); background: var(--err-soft); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, transform .05s;
}
.btn:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 250px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex; flex-direction: column;
  z-index: 50;
}
.menu-list.hidden { display: none; }
.menu-list button, .menu-list a {
  text-align: left;
  border: 0; background: transparent;
  padding: 8px 10px; border-radius: 8px;
  font: inherit; font-size: 13px; color: var(--ink-2);
  cursor: pointer; text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover { background: var(--brand-soft); color: var(--ink); }
.menu-list hr { border: 0; border-top: 1px solid var(--line-2); margin: 5px 4px; }

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 18px 20px 40px;
  max-width: 1680px;
  margin: 0 auto;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static !important; max-height: none !important; }
}

/* ----------------------------------------------------------------- sidebar */
.sidebar {
  position: sticky;
  top: 68px;
  max-height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-search input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit; font-size: 13px;
}
.side-search input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; }

.nav {
  overflow: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  border: 0; background: transparent; text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--brand-soft); color: var(--ink); }
.nav-item .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--line); flex: 0 0 auto;
}
.nav-item.ok .dot { background: var(--ok); }
.nav-item.miss .dot { background: var(--warn); }
.nav-item .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .req { margin-left: auto; color: var(--err); font-size: 11px; }

.side-foot { font-size: 11px; color: var(--muted); padding: 0 4px; }

/* ----------------------------------------------------------------- content */
.content { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.status {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.status.hidden { display: none; }
.status.ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: var(--ok-soft); color: var(--ok); }
.status.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); background: color-mix(in srgb, var(--warn) 12%, var(--panel)); color: var(--warn); }
.status.err { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); background: var(--err-soft); color: var(--err); }
.status .status-head { font-weight: 650; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.status ul { margin: 8px 0 0; padding-left: 18px; max-height: 320px; overflow: auto; }
.status li { margin: 3px 0; color: var(--ink-2); cursor: pointer; }
.status li:hover { text-decoration: underline; }
.status .status-sub { margin-top: 10px; font-weight: 650; font-size: 12.5px; color: var(--ink-2); }
.status .path { color: var(--muted); font-family: var(--mono); font-size: 11px; }

.form { display: flex; flex-direction: column; gap: 14px; }

/* -------------------------------------------------------------------- card */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: clip;
}

.card > .card-h {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-2);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
}
.card > .card-h .titles { min-width: 0; flex: 1; }
.card > .card-h h2 {
  font-size: 14px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card > .card-h .code { font: 11px var(--mono); color: var(--muted); }
.card > .card-h .card-tools { display: flex; gap: 6px; align-items: center; }
.card > .card-b { padding: 12px 14px 14px; }

.badge {
  font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted); background: var(--panel-2);
  white-space: nowrap;
}
.badge.req { color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, var(--line)); background: var(--err-soft); }
.badge.multi { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); background: var(--brand-soft); }

/* -------------------------------------------------------------- подблоки */
.blocks { display: flex; flex-direction: column; gap: 10px; }

.subblock {
  border: 1px solid var(--line);
  border-left: 3px solid color-mix(in srgb, var(--brand) 55%, var(--line));
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  padding: 10px 12px;
}
.subblock > .sub-h {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.subblock > .sub-h .t { font-size: 12.5px; font-weight: 650; margin-right: 7px; }
.subblock > .sub-h .code { font: 10.5px var(--mono); color: var(--muted); }
.subblock .subblock { background: var(--panel); }

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span2 { grid-column: 1 / -1; }
.field > label { font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.field > label .req { color: var(--err); font-weight: 700; }
.field > label .code { font: 10.5px var(--mono); color: color-mix(in srgb, var(--muted) 70%, transparent); }
.field .hint { font-size: 10.5px; color: var(--muted); }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font: inherit; font-size: 13px;
}
.field textarea { min-height: 62px; resize: vertical; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent);
  outline-offset: 0;
  border-color: var(--brand);
}
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--err); background: var(--err-soft); }
.field.missing input, .field.missing select, .field.missing textarea {
  border-color: color-mix(in srgb, var(--warn) 55%, var(--line));
  background: color-mix(in srgb, var(--warn-soft) 55%, var(--panel));
}
.field .fmsg { font-size: 10.5px; color: var(--err); }
.field input[readonly] { background: var(--panel-2); color: var(--muted); }

.attrs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 9px 16px;
  padding: 9px 10px;
  margin-bottom: 9px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel-2) 65%, transparent);
}
.attrs .attr { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); min-width: 0; }
.attrs .attr > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attrs .attr input, .attrs .attr select {
  width: 100%;
  padding: 5px 8px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}

/* ------------------------------------------------------------ повторяемые */
.repeat { display: flex; flex-direction: column; gap: 8px; }
.repeat-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--panel);
}
.repeat-item > .repeat-h {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--muted);
  margin-bottom: 7px;
}
.repeat-item > .repeat-h .n {
  font: 10.5px var(--mono);
  background: var(--brand-soft); color: var(--brand);
  padding: 1px 6px; border-radius: 999px;
}
.repeat-item > .repeat-h .tools { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 6px;
  width: 22px; height: 22px; line-height: 1;
  font-size: 12px; cursor: pointer; padding: 0;
  display: grid; place-items: center;
}
.icon-btn:hover { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.add-btn {
  align-self: flex-start;
  border: 1px dashed color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand-soft) 55%, transparent);
  color: var(--brand);
  padding: 6px 11px; border-radius: 7px;
  font: inherit; font-size: 12px; cursor: pointer;
}
.add-btn:hover { background: var(--brand-soft); }

/* --------------------------------------------------------------- выбор из */
.choice {
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--line));
  background: color-mix(in srgb, var(--warn-soft) 45%, transparent);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.choice > .choice-h { font-size: 11.5px; color: var(--warn); font-weight: 650; }
.choice .choice-items { display: flex; flex-direction: column; gap: 8px; }
.choice .opts { display: flex; flex-wrap: wrap; gap: 6px; }
.choice .opts button {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 4px 10px;
  font: inherit; font-size: 11.5px; color: var(--ink-2); cursor: pointer;
}
.choice .opts button:hover { border-color: var(--brand); color: var(--brand); }

/* -------------------------------------------------------------- optional */
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.toggle-row input { width: 15px; height: 15px; accent-color: var(--brand); }

/* ----------------------------------------------------------------- modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 18, 30, .55);
  display: grid; place-items: center;
  padding: 24px;
}
.modal.hidden { display: none; }
.modal-box {
  width: min(1180px, 100%);
  height: min(90vh, 100%);
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .6);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-h {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.modal-h h2 { font-size: 14px; }
.modal-tools { display: flex; gap: 7px; }
.preview-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.xml-text {
  flex: 1; margin: 0; padding: 14px;
  overflow: auto;
  font: 12px/1.5 var(--mono);
  background: var(--panel-2);
  color: var(--ink-2);
  white-space: pre;
}

.content-foot { font-size: 11px; color: var(--muted); text-align: center; }
.content-foot code { font-family: var(--mono); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel);
  padding: 9px 14px; border-radius: 999px;
  font-size: 12.5px; z-index: 200;
  box-shadow: var(--shadow);
}
.toast.hidden { display: none; }

mark { background: color-mix(in srgb, var(--warn) 45%, transparent); color: inherit; padding: 0 1px; border-radius: 3px; }

.enum-wrap { display: flex; flex-direction: column; gap: 4px; }
.enum-wrap .enum-filter {
  padding: 5px 8px; font-size: 12px;
  border: 1px dashed var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--ink);
}

.flash {
  animation: flash 1.2s ease;
  outline: 2px solid color-mix(in srgb, var(--brand) 60%, transparent);
  outline-offset: -2px;
}
@keyframes flash {
  0% { background: color-mix(in srgb, var(--brand) 18%, transparent); }
  100% { background: transparent; }
}

.repeat-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 650; color: var(--ink-2);
  margin-bottom: 2px;
}
.repeat-head .code { font: 10.5px var(--mono); color: var(--muted); font-weight: 400; }

.sub-h .titles { min-width: 0; }
