:root {
  --bg0: #0c0f14;
  --bg1: #121722;
  --surface: #161c28;
  --surface2: #1c2433;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --muted: #94a3b8;
  --accent: #a3b4c9;
  --accent-dim: rgba(163, 180, 201, 0.18);
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --touch-min: 40px;
  font-family: 'DM Sans', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg0);
}

[hidden] {
  display: none !important;
}

/* Глобальный индикатор загрузки */
.global-loading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(12, 15, 20, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.global-loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 1.35rem 1.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: min(320px, 100%);
}

.global-loading-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #cbd5e1;
}

.spinner {
  width: 2.25rem;
  height: 2.25rem;
  border: 3px solid rgba(34, 211, 238, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 0%, transparent 75%);
  z-index: 0;
}

.shell-header,
.shell,
.shell-footer {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100% - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.shell-header {
  padding: 2rem 0 1rem;
}

.brand {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  box-shadow: 0 12px 40px rgba(34, 211, 238, 0.25);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.subtitle code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.85em;
  color: #cbd5e1;
  background: var(--surface);
  padding: 0.1em 0.35em;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.shell {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding-bottom: 3rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  align-items: start;
}

.sidebar {
  display: none;
}

body.has-breadcrumb .layout {
  grid-template-columns: 1fr 3fr;
}

body.has-breadcrumb .sidebar {
  display: block;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.95rem 1rem;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.combo-box {
  position: relative;
}

.combo-input {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.combo-input:focus {
  outline: none;
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.combo-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.combo-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: min(50vh, 280px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.combo-list li {
  padding: 0.65rem 0.85rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 0.95rem;
}

.combo-list li:hover,
.combo-list li[aria-selected='true'] {
  background: rgba(34, 211, 238, 0.12);
}

.combo-list .combo-empty {
  color: var(--muted);
  cursor: default;
  font-size: 0.85rem;
}

.combo-list .combo-empty:hover {
  background: transparent;
}

.table-block {
  margin-top: 0;
}

.block-title {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #cbd5e1;
}

.muted-note {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--border);
  overscroll-behavior-x: contain;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data th,
table.data td {
  padding: 0.55rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tbody tr {
  cursor: pointer;
}

table.data tbody tr:hover td {
  background: rgba(255, 255, 255, 0.04);
}

table.data tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.error-banner {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.95rem;
}

/* Цепочка выбора — компактно в левой колонке */
.choice-chain {
  position: relative;
  padding: 0.8rem 0.85rem;
}

.choice-chain-inner {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.choice-title {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #cbd5e1;
}

.engine-side {
  margin-top: 0.9rem;
}

.engine-side-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: #cbd5e1;
}

.engine-side-sub {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.engine-side-tablewrap {
  margin-top: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.engine-side-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  line-height: 1.25;
}

.engine-side-table th,
.engine-side-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
}

.engine-side-table tr:last-child th,
.engine-side-table tr:last-child td {
  border-bottom: none;
}

.engine-side-table th {
  width: 48%;
  text-align: left;
  color: var(--muted);
  font-weight: 700;
}

.engine-side-table td {
  color: var(--text);
  font-weight: 650;
  word-break: break-word;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 32px;
  margin-bottom: 10px;
}

.section-head .card-title {
  margin: 0;
  line-height: 1;
}

.nav-back {
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.nav-back:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
}

.nav-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice-engine {
  color: var(--muted);
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.choice-engine-title {
  font-size: 0.78rem;
  line-height: 1.25;
  font-weight: 700;
  color: #cbd5e1;
  margin-top: 0.1rem;
}

.choice-engine-sub {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-filter {
  margin-top: 0.65rem;
}

.compact-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.node-item {
  appearance: none;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.node-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
}

.node-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice-engine-tablewrap {
  margin-top: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.choice-engine-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  line-height: 1.25;
}

.choice-engine-table th,
.choice-engine-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
}

.choice-engine-table tr:last-child th,
.choice-engine-table tr:last-child td {
  border-bottom: none;
}

.choice-engine-table th {
  width: 48%;
  text-align: left;
  color: var(--muted);
  font-weight: 700;
}

.choice-engine-table td {
  color: var(--text);
  font-weight: 650;
  word-break: break-word;
}

.choice-stack {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
  overflow: visible;
  padding-bottom: 0;
}

.choice-stack--row {
  flex-direction: row;
}

.choice-block {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  margin: 0;
  padding: 0.35rem 0.55rem;
  min-height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.choice-block:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.choice-block:active {
  transform: translateY(1px);
}

.choice-block:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice-block--pill .choice-v {
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.1;
}

.choice-k {
  display: none;
}

.choice-v {
  display: inline;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.1;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  /* Mobile: показываем блоки сверху вниз:
     крошки → двигатель → основной контент */
  body.has-breadcrumb .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    top: auto;
  }
}

.tile-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.tile-grid--cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.75rem;
}

.tile {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.75rem 1rem;
  min-height: var(--touch-min);
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  max-width: 100%;
  word-break: break-word;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover {
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.08);
}

.tile-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 0.8rem;
  align-items: center;
  padding: 0.85rem 0.95rem;
  min-height: 64px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, rgba(18, 23, 34, 0.95), rgba(12, 15, 20, 0.92));
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tile-card:hover {
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.06);
  transform: translateY(-1px);
}

.tile-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(34, 211, 238, 0.12);
  border: 1px solid rgba(34, 211, 238, 0.25);
  color: #c7f9ff;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.tile-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.tile-title {
  font-size: 0.98rem;
  font-weight: 650;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tile-sub {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.engine-wrap {
  margin-top: 1.1rem;
}

.engine-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.engine-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.engine-tab {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.engine-tab:hover {
  border-color: rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.06);
}

.engine-tab[aria-selected='true'] {
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(34, 211, 238, 0.10);
}

.engine-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.engine-card {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.engine-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.engine-title {
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.engine-code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.9rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.45rem;
  border-radius: 8px;
}

.engine-years {
  color: var(--muted);
  font-size: 0.85rem;
}

.engine-attrs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
}

.engine-more {
  margin-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.65rem;
}

.engine-more-summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 650;
  font-size: 0.9rem;
  list-style: none;
}

.engine-more summary::-webkit-details-marker {
  display: none;
}

.engine-more-summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.5rem;
  transform-origin: center;
  transition: transform 0.15s;
}

.engine-more[open] .engine-more-summary::before {
  transform: rotate(90deg);
}

.engine-attrs--full {
  margin-top: 0.75rem;
}

.engine-kv {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.engine-k {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.engine-v {
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.25;
  word-break: break-word;
}

/* legacy container (kept for compatibility, no longer used) */
.engine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.shell-footer {
  padding: 1.5rem 0 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.shell-footer code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  color: #cbd5e1;
}

.shell-footer .dot {
  opacity: 0.5;
}

#pick-section.is-collapsed .pick-grid,
#pick-section.is-collapsed .table-block {
  display: none;
}

body.is-embed {
  background: transparent;
  min-height: auto;
  padding: 0;
}

body.is-embed .bg-grid,
body.is-embed .shell-footer,
body.is-embed .shell-header {
  display: none !important;
}

body.is-embed .shell,
body.is-embed .shell-footer,
body.is-embed .shell-header {
  width: 100%;
}

body.is-embed .shell {
  padding: 0.75rem;
  gap: 0.85rem;
  padding-bottom: 0.75rem;
}

body.is-embed .card {
  box-shadow: none;
  padding: 1rem;
  border-radius: 16px;
}

@media (max-width: 640px) {
  .shell-header,
  .shell,
  .shell-footer {
    width: calc(100% - 1rem);
  }

  .shell-header {
    padding: 1.25rem 0 0.75rem;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .subtitle {
    font-size: 0.82rem;
    line-height: 1.4;
  }

  .subtitle code {
    word-break: break-all;
  }

  .card {
    padding: 1rem 1rem;
  }

  .card-title {
    font-size: 1rem;
  }

  .pick-grid {
    grid-template-columns: 1fr;
  }

  /* iOS: поля не меньше 16px — меньше авто-зум при фокусе */
  .combo-input {
    font-size: 16px;
  }

  .choice-v {
    font-size: 1rem;
  }

  .choice-chain-title {
    font-size: 0.78rem;
  }

  table.data {
    font-size: 0.82rem;
  }

  table.data th,
  table.data td {
    padding: 0.55rem 0.5rem;
  }

  .shell-footer {
    font-size: 0.78rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .shell-footer .dot {
    display: none;
  }
}

@media (max-width: 400px) {
  .brand {
    flex-direction: column;
    gap: 0.75rem;
  }
}
