:root {
  --bg: #0d0f12;
  --bg-2: #13161b;
  --panel: #171a20;
  --panel-2: #1d2128;
  --line: #262b34;
  --line-2: #333a45;
  --text: #e9e6df;
  --text-2: #a9adb6;
  --text-3: #6f7581;
  --accent: #ffb547;
  --accent-2: #ffcf85;
  --accent-ink: #1b1204;
  --teal: #5fd3bc;
  --red: #ff6b6b;
  --blue: #7aa8ff;
  --violet: #c49bff;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Onest', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --accent-hover: var(--accent-2);
  --warn-text: var(--accent-2);
  --error-text: #ffb3b3;
  --ok-text: #b7efe3;
  --hover: #232830;
  --grid-line: rgba(255, 255, 255, .018);
  --row-hover: rgba(255, 255, 255, .015);
  --bar-bg: rgba(13, 15, 18, .86);
  --bar-bg-2: rgba(13, 15, 18, .92);
  --code-bg: #0b0d10;
  --code-ln: #3b414c;
  --tok-k: #ff9f6e;
  --tok-s: #a5d6a7;
  --tok-c: #5d6572;
  --tok-n: #c49bff;
  --tok-a: #ffcf85;
  --tok-t: #7aa8ff;
  --tok-p: #5fd3bc;
  color-scheme: dark;
}

:root[data-theme=light] {
  --bg: #f5f3ee;
  --bg-2: #fbfaf7;
  --panel: #ffffff;
  --panel-2: #f1eee7;
  --line: #e4e0d7;
  --line-2: #d3cec2;
  --text: #1c1f24;
  --text-2: #4d535d;
  --text-3: #7b818c;
  --accent: #dc8a0e;
  --accent-2: #9a5a00;
  --accent-hover: #f2ab3a;
  --accent-ink: #1b1204;
  --teal: #0f8a74;
  --red: #d23b3b;
  --blue: #2f62d0;
  --violet: #7646d6;
  --shadow: 0 10px 40px rgba(40, 32, 18, .16);
  --warn-text: #7a4700;
  --error-text: #a52828;
  --ok-text: #0b6b5a;
  --hover: #e9e5dc;
  --grid-line: rgba(0, 0, 0, .035);
  --row-hover: rgba(0, 0, 0, .025);
  --bar-bg: rgba(245, 243, 238, .86);
  --bar-bg-2: rgba(245, 243, 238, .92);
  --code-bg: #fbfaf7;
  --code-ln: #b3b8c0;
  --tok-k: #c2410c;
  --tok-s: #2e7d32;
  --tok-c: #8a909a;
  --tok-n: #7646d6;
  --tok-a: #9a5a00;
  --tok-t: #2f62d0;
  --tok-p: #0f8a74;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  min-height: 100vh;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: rgba(255, 181, 71, .35); }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 28px;
  padding: 0 28px; height: 60px;
  background: var(--bar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--mono); font-weight: 600; font-size: 15px; }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 14px;
  box-shadow: 0 0 0 3px rgba(255, 181, 71, .15);
}
.logo .slash { color: var(--text-3); }
.logo .caret { display: inline-block; width: 8px; height: 15px; background: var(--accent); margin-left: 2px; vertical-align: -2px; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--text-2); padding: 7px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.nav .badge { margin-left: 6px; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); font-weight: 700; color: var(--accent); font-size: 13px; text-transform: uppercase; }
#app { min-height: 100vh; display: flex; flex-direction: column; }
#app > main { flex: 1; }
.site-footer { padding: 18px 28px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 13px; text-align: center; }
/* на страницах с закреплённой панелью действий приписка не должна уходить под неё */
body:has(.actionbar) .site-footer { padding-bottom: 90px; }
.announcement { background: rgba(255, 181, 71, .1); border-bottom: 1px solid rgba(255, 181, 71, .25); color: var(--warn-text); padding: 8px 28px; font-size: 14px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: 500 14px var(--sans); cursor: pointer; white-space: nowrap; transition: .12s;
}
.btn:hover { border-color: var(--text-3); background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn .kbd { font: 11px var(--mono); padding: 1px 5px; border-radius: 4px; background: rgba(0, 0, 0, .18); opacity: .8; }
.icon-btn { width: 28px; height: 28px; padding: 0; display: inline-grid; place-items: center; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--text-3); cursor: pointer; font-size: 15px; }
.icon-btn:hover { color: var(--red); border-color: var(--line-2); }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); min-width: 0; }
label.field > span.lbl { display: flex; gap: 6px; align-items: baseline; }
label.field .hint { color: var(--text-3); font-size: 12px; }
input:not([type]), input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 36px; padding: 0 11px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: 14px var(--sans); outline: none; transition: border-color .12s, box-shadow .12s;
}
input.mono, textarea.mono, select.mono { font-family: var(--mono); font-size: 13px; }
textarea { height: auto; padding: 10px 11px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 181, 71, .14); }
input.invalid { border-color: var(--red); }
select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 38px; }
.pw-wrap button { position: absolute; right: 4px; top: 4px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text-2); user-select: none; }
.switch input { display: none; }
.switch .track { width: 34px; height: 20px; border-radius: 10px; background: var(--line-2); position: relative; transition: .15s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { left: 17px; background: var(--accent-ink); }

.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { white-space: nowrap; height: 28px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--text-2); font: 500 13px var(--sans); cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel-2); color: var(--accent); box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 0 0 1px var(--line-2); }
.seg.disabled { opacity: .55; }
.seg.disabled button { cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 10px; font: 600 11px var(--mono); letter-spacing: .02em; background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line-2); white-space: nowrap; }
.badge.accent { color: var(--accent); border-color: rgba(255, 181, 71, .35); background: rgba(255, 181, 71, .08); }
.badge.teal { color: var(--teal); border-color: rgba(95, 211, 188, .35); background: rgba(95, 211, 188, .08); }
.badge.red { color: var(--red); border-color: rgba(255, 107, 107, .35); background: rgba(255, 107, 107, .08); }
.badge.blue { color: var(--blue); border-color: rgba(122, 168, 255, .35); background: rgba(122, 168, 255, .08); }
.badge.violet { color: var(--violet); border-color: rgba(196, 155, 255, .35); background: rgba(196, 155, 255, .08); }

/* ---------- Layout ---------- */
.page { max-width: 1320px; margin: 0 auto; padding: 32px 28px 140px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head h1 { font-size: 28px; }
.page-head p { margin: 6px 0 0; color: var(--text-2); max-width: 720px; }
.eyebrow { font: 600 12px var(--mono); color: var(--accent); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

.gen-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 28px; align-items: start; }
.stepper { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 2px; }
.stepper a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-size: 14px; }
.stepper a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.stepper a.current { background: var(--panel); color: var(--text); }
.stepper .num { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-2); font: 600 11px var(--mono); color: var(--text-3); }
.stepper a.done .num { border-color: var(--teal); color: var(--teal); }
.stepper a.warn .num { border-color: var(--accent); color: var(--accent); }
.stepper a.off { opacity: .45; }
.stepper .sub { display: block; font-size: 11.5px; color: var(--text-3); line-height: 1.3; }
.stepper-foot { margin-top: 18px; padding: 12px; border: 1px dashed var(--line-2); border-radius: var(--radius); font-size: 12.5px; color: var(--text-3); display: flex; flex-direction: column; gap: 8px; }

.section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 18px; scroll-margin-top: 80px; }
.section-head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.section-head .idx { font: 600 12px var(--mono); color: var(--accent); border: 1px solid rgba(255, 181, 71, .35); border-radius: 6px; padding: 3px 7px; }
.section-head h2 { font-size: 17px; }
.section-head p { margin: 2px 0 0; color: var(--text-3); font-size: 13px; }
.section-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 18px; }
.section.disabled .section-body { opacity: .55; }
.subhead { font: 600 12px var(--mono); color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.subhead::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.subhead.side { color: var(--accent); font-size: 13px; margin-top: 10px; }

/* Choice cards */
.choices { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.choice { position: relative; text-align: left; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text); cursor: pointer; font: inherit; transition: .14s; display: flex; flex-direction: column; gap: 8px; }
.choice:hover { border-color: var(--text-3); transform: translateY(-1px); }
.choice.on { border-color: var(--accent); background: linear-gradient(180deg, rgba(255, 181, 71, .08), rgba(255, 181, 71, .02)); box-shadow: 0 0 0 1px var(--accent) inset; }
.choice .ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); font: 700 13px var(--mono); color: var(--text-2); }
.choice.on .ico { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.choice .t { font-weight: 650; font-size: 15px; }
.choice .d { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.choice ul { margin: 4px 0 0; padding-left: 16px; font-size: 12.5px; color: var(--text-2); line-height: 1.55; }
.choice .check { position: absolute; top: 12px; right: 12px; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-2); }
.choice.on .check { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--bg-2); }
.choices.lib { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.choices.lib .check { display: none; }
.lib-sample { margin: 2px 0 0; max-height: 150px; overflow: hidden; padding: 8px 10px; border-radius: 8px; background: var(--code-bg); font: 11.5px/1.45 var(--mono); color: var(--text-3); white-space: pre; }

.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--bg-2); font-size: 13.5px; color: var(--text-2); }
.part-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius); border: 1px dashed var(--line-2); }
.part-bar > span { flex: 1 1 280px; }
.callout.warn { border-color: rgba(255, 181, 71, .35); background: rgba(255, 181, 71, .06); color: var(--warn-text); }
.callout.error { border-color: rgba(255, 107, 107, .35); background: rgba(255, 107, 107, .06); color: var(--error-text); }
.callout.ok { border-color: rgba(95, 211, 188, .3); background: rgba(95, 211, 188, .05); color: var(--ok-text); }
.callout ul { margin: 0; padding-left: 18px; }

/* Code-like textarea */
.editor { position: relative; }
.editor textarea { min-height: 190px; font-family: var(--mono); font-size: 12.8px; background: var(--code-bg); tab-size: 2; white-space: pre; }
.editor .editor-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }

/* Entity editor */
.entity { border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg-2); overflow: hidden; }
.entity-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); flex-wrap: wrap; }
summary.entity-head { cursor: pointer; list-style: none; }
summary.entity-head::-webkit-details-marker { display: none; }
details.entity:not([open]) summary.entity-head { border-bottom: 0; }
.entity-head .cls { font: 600 14px var(--mono); color: var(--accent); }
.entity-head input { height: 30px; font-size: 13px; }
.entity-head .toggle { cursor: pointer; color: var(--text-3); font-size: 12px; user-select: none; }
table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-table th { text-align: left; font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); padding: 9px 8px; border-bottom: 1px solid var(--line); background: var(--bg-2); position: sticky; top: 0; }
.grid-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table tr.excluded td:not(:first-child) { opacity: .35; }
.grid-table input:not([type]), .grid-table input[type=text], .grid-table input[type=number], .grid-table select { height: 30px; font-size: 12.5px; padding: 0 8px; background: transparent; border-color: transparent; }
.grid-table select { padding-right: 24px; background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px; }
.grid-table input:hover, .grid-table select:hover { border-color: var(--line-2); }
.grid-table input:focus, .grid-table select:focus { background: var(--bg); border-color: var(--accent); }
.grid-table .c { text-align: center; }
.grid-table .dbtype { font: 12px var(--mono); color: var(--text-3); white-space: nowrap; }
.grid-table tr:hover td { background: var(--row-hover); }
.pk-dot { color: var(--accent); font: 700 11px var(--mono); }
.entity-foot { padding: 10px 14px; display: flex; gap: 8px; border-top: 1px solid var(--line); }

/* Mapping */
.map-row-arrow { color: var(--text-3); font-family: var(--mono); text-align: center; }
.conv { font: 11px var(--mono); color: var(--violet); }
.tree { font: 13px var(--mono); }
.tree .node { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.tree .node .k { color: var(--text); }
.tree .node .ty { color: var(--blue); }
.tree .node input { height: 26px; font-size: 12.5px; width: 170px; }
.tree .node select { height: 26px; font-size: 12px; width: 150px; background-position: calc(100% - 13px) 11px, calc(100% - 8px) 11px; }
.tree .children { margin-left: 22px; border-left: 1px dashed var(--line-2); padding-left: 12px; }

/* Template cards */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tpl { position: relative; padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; transition: .14s; }
.tpl.selectable { cursor: pointer; background: var(--bg-2); border-color: var(--line-2); }
.tpl.selectable:hover { border-color: var(--text-3); }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: linear-gradient(180deg, rgba(255, 181, 71, .07), transparent); }
.tpl .name { font-weight: 650; }
.tpl .desc { font-size: 13px; color: var(--text-2); flex: 1; }
.tpl .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--text-3); }
.tpl .author b { color: var(--text-2); font-weight: 600; }
.tpl .author a { color: var(--accent); text-decoration: none; }
.tpl .author a:hover { text-decoration: underline; }
.tpl .files { font: 11.5px var(--mono); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Action bar */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; gap: 14px; padding: 14px 28px;
  background: var(--bar-bg-2); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.actionbar .chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chip { font: 12px var(--mono); padding: 4px 9px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line-2); color: var(--text-2); }
.chip b { color: var(--text); font-weight: 600; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 8, .72); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 28px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: calc(100vh - 56px); display: flex; flex-direction: column; animation: pop .16s; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } }
.modal.xl { width: min(1400px, 100%); height: calc(100vh - 56px); }
.modal.lg { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* Explorer */
.explorer { display: grid; grid-template-columns: 320px minmax(0, 1fr); flex: 1; min-height: 0; }
.explorer .files { border-right: 1px solid var(--line); overflow: auto; padding: 10px 6px; font: 13px var(--mono); }
.explorer .files .dir { color: var(--text-3); padding: 3px 8px; user-select: none; }
.explorer .files .file { display: flex; gap: 8px; align-items: center; padding: 3px 8px; border-radius: 5px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.explorer .files .file:hover { background: var(--panel-2); color: var(--text); }
.explorer .files .file.on { background: rgba(255, 181, 71, .12); color: var(--accent); }
.explorer .viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font: 12.5px var(--mono); color: var(--text-2); }
.code { flex: 1; overflow: auto; margin: 0; padding: 14px 0; background: var(--code-bg); font: 12.8px/1.6 var(--mono); counter-reset: ln; tab-size: 4; }
.code .ln { display: block; padding: 0 18px 0 0; white-space: pre; }
.code .ln::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 48px; padding-right: 16px; text-align: right; color: var(--code-ln); user-select: none; }
.tok-k { color: var(--tok-k); }
.tok-s { color: var(--tok-s); }
.tok-c { color: var(--tok-c); font-style: italic; }
.tok-n { color: var(--tok-n); }
.tok-a { color: var(--tok-a); }
.tok-t { color: var(--tok-t); }
.tok-p { color: var(--tok-p); }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 90px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 11px 15px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: var(--shadow); font-size: 14px; max-width: 420px; animation: pop .18s; }
.toast.ok { border-color: rgba(95, 211, 188, .5); }
.toast.error { border-color: rgba(255, 107, 107, .6); }

/* Auth */
.auth-card { padding: 30px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }

/* Admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tabs button { background: none; border: 0; color: var(--text-2); font: 500 14px var(--sans); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; gap: 8px; align-items: center; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.stat { padding: 18px; }
.stat .v { font: 700 30px var(--mono); letter-spacing: -.02em; }
.stat .l { color: var(--text-3); font-size: 13px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars .bar span { font: 10px var(--mono); color: var(--text-3); }
.bars .bar b { font: 11px var(--mono); color: var(--text-2); font-weight: 500; }
.hbar { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; margin: 6px 0; }
.hbar .track { height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--teal); border-radius: 4px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data th { text-align: left; font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); white-space: nowrap; }
.data td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data tr:last-child td { border-bottom: 0; }
.empty { padding: 40px; text-align: center; color: var(--text-3); }

.source { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg-2); }
.suggest { position: relative; }
.suggest > input { width: 100%; }
.suggest-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; }
.suggest-list[hidden] { display: none; }
.suggest-item { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); }
.suggest-item .mono { font-size: 12.5px; word-break: break-all; }
.suggest-item .small { white-space: nowrap; }
.suggest-item.on { background: var(--panel-2); color: var(--text); }
.suggest-item mark { background: none; color: var(--accent); font-weight: 600; }
.file-edit { border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; background: var(--bg-2); }
.file-edit-head { display: flex; gap: 8px; align-items: center; padding: 8px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.file-edit-head input { flex: 1; }
.file-edit textarea { border: 0; border-radius: 0; min-height: 220px; background: var(--code-bg); font-family: var(--mono); font-size: 12.5px; white-space: pre; }
.file-edit textarea:focus { box-shadow: none; }
.cheatsheet { font: 12px/1.7 var(--mono); color: var(--text-2); }
.cheatsheet code { color: var(--warn-text); }

/* Загрузка спецификации API */
.dropzone { border: 1.5px dashed var(--line-2); border-radius: var(--radius); background: var(--bg-2); padding: 30px 20px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; cursor: pointer; transition: border-color .12s, background .12s; outline: none; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--text-3); }
.dropzone.over { border-color: var(--accent); background: rgba(255, 181, 71, .08); }
.dropzone.loaded { cursor: default; align-items: stretch; text-align: left; padding: 14px 16px; gap: 12px; border-style: solid; }
.dropzone.loaded.over { border-style: dashed; }
.dz-ico { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--accent); font: 700 20px var(--mono); margin-bottom: 4px; }
.dz-ico.sm { width: 34px; height: 34px; font-size: 12px; margin: 0; flex: none; }
.dz-title { font-weight: 650; font-size: 15px; }
.dz-hint { color: var(--text-3); font-size: 13px; }
.dropzone.over .dz-ico { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.subhead.plain { text-transform: none; letter-spacing: 0; font: 600 13px var(--sans); color: var(--text-2); }
.api-ops { table-layout: fixed; }
.api-ops td { padding: 7px 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.api-ops td:nth-child(1) { width: 92px; }
.api-ops td:nth-child(2) { width: 40%; }
.api-ops td:nth-child(3) { width: 26%; }
.api-ops .badge { min-width: 56px; justify-content: center; }

/* Переключатель темы */
.theme-switch { font-size: 13px; }
.theme-switch .ico { width: 14px; text-align: center; color: var(--text-3); }
:root[data-theme=light] .modal-backdrop { background: rgba(40, 36, 28, .38); }
:root[data-theme=light] .btn .kbd { background: rgba(0, 0, 0, .08); }
:root[data-theme=light] .seg button.on { background: var(--panel); box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 0 0 1px var(--line-2); }

@media (max-width: 1000px) {
  .gen-layout { grid-template-columns: 1fr; }
  .stepper { position: static; }
  .stepper > a { display: none; }
  .stepper-foot { margin-top: 0; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .g3, .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .explorer { grid-template-columns: 220px 1fr; }
}

/* Надёжность и эксплуатация */
.feature { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
.feature > p { margin: 0 0 0 44px; line-height: 1.45; }
.feature .grid { margin: 6px 0 0 44px; }

/* Калькулятор производительности */
details.perf-calc { margin-top: 18px; }
details.perf-calc > .grid, details.perf-calc > .perf-results { padding: 0 14px; }
details.perf-calc > .grid:first-of-type { margin-top: 12px; }
.perf-results { padding-bottom: 14px !important; display: flex; flex-direction: column; gap: 10px; }
table.perf td:first-child { width: 42%; }
table.perf td.mono { color: var(--accent); font-weight: 600; }

/* Пресеты команды */
.preset-list { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow: auto; }
.preset { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; }
.preset-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.preset-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Сравнение с проектом */
.code.diff .dl { display: block; padding: 0 18px; white-space: pre; }
.code.diff .dl.add { background: rgba(95, 211, 188, .12); color: var(--teal); }
.code.diff .dl.del { background: rgba(255, 107, 107, .12); color: var(--red); }
.code.diff .dl.hunk { color: var(--text-3); margin-top: 8px; }

/* ---------- Узкие экраны (планшеты и телефоны, ≤ 900px) ---------- */
@media (max-width: 900px) {
  input, select, textarea { max-width: 100%; }
  .grid-table input, .grid-table select { max-width: none; }

  /* Шапка: логотип и пользователь — первой строкой, меню и тема — второй */
  .topbar { position: static; flex-wrap: wrap; height: auto; gap: 6px 12px; padding: 10px 14px 8px; }
  .logo { font-size: 14px; gap: 8px; min-width: 0; }
  .logo .caret { display: none; }
  .userbox { order: 2; margin-left: auto; gap: 6px; }
  .userbox > a > span:not(.avatar) { display: none; }
  .nav { order: 3; flex: 1 1 calc(100% - 96px); min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav { gap: 2px; }
  .nav a { white-space: nowrap; padding: 6px 8px; font-size: 13.5px; }
  .theme-switch { order: 4; gap: 6px; }
  .announcement { padding: 8px 14px; }

  /* Нижняя панель: сводка — одной строкой с прокруткой, кнопки — в ряд */
  .actionbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .actionbar .chips { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .actionbar .chips::-webkit-scrollbar { display: none; }
  .actionbar .chip { flex: none; white-space: nowrap; padding: 2px 8px; }
  .actionbar .chips:empty { display: none; }
  .actionbar .btn { flex: 1 1 0; min-width: 0; height: auto; min-height: 42px; padding: 4px 8px; font-size: 13px; line-height: 1.2; white-space: normal; text-align: center; }
  .btn .kbd { display: none; }

  /* Модальные окна: длинные заголовки, подвалы и пути файлов переносятся */
  .modal-head h3 { min-width: 0; overflow-wrap: anywhere; font-size: 15px; }
  .modal-foot { flex-wrap: wrap; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .modal-foot > span { flex: 1 1 100%; margin-right: 0 !important; }
  .modal-foot .btn { flex: 1 1 auto; height: auto; min-height: 36px; padding: 4px 10px; white-space: normal; text-align: center; }
  .viewer-head { flex-wrap: wrap; padding: 8px 12px; }
  .viewer-head > span:first-child { overflow-wrap: anywhere; min-width: 0; }
}

/* ---------- Телефоны (≤ 720px) ---------- */
@media (max-width: 720px) {
  /* Страница и сетки */
  .page { padding: 20px 14px 150px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 20px; }
  .page-head h1 { font-size: 23px; }
  .page-head .row { flex-wrap: wrap; }
  .g2, .g3, .g4, .g5 { grid-template-columns: minmax(0, 1fr); }
  .gen-layout { grid-template-columns: minmax(0, 1fr) !important; gap: 18px; }
  .row > * { max-width: 100%; }
  .section { border-radius: 12px; }
  .section-head { padding: 14px; gap: 10px; flex-wrap: wrap; }
  .section-head > div { min-width: 0; }
  .section-body { padding: 16px 14px; overflow-wrap: anywhere; }
  .section-body table { overflow-wrap: normal; }
  .choices { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .choices.lib, .tpl-grid { grid-template-columns: minmax(0, 1fr); }
  .feature > p, .feature .grid { margin-left: 0; }
  .editor .editor-bar, .file-edit-head { flex-wrap: wrap; }
  .file-edit-head input { flex: 1 1 180px; min-width: 0; }
  .entity { overflow-x: auto; }
  .entity-head { position: sticky; left: 0; }
  .tree { overflow-x: auto; }
  .tree .node { flex-wrap: wrap; gap: 6px; }
  .tree .node input { flex: 1 1 90px; width: auto; min-width: 0; max-width: 170px; }
  .tree .node select { flex: 1 1 90px; width: auto; min-width: 0; max-width: 150px; }
  .tree .node .icon-btn { flex: none; }
  .tree .children { margin-left: 10px; padding-left: 8px; }
  .grid-table select { min-width: 118px; }
  .grid-table input:not([type=checkbox]) { min-width: 90px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { white-space: nowrap; flex: none; }
  .table-wrap > table.data { min-width: 640px; }
  label.field > span.lbl { flex-wrap: wrap; }
  .hbar { grid-template-columns: 96px minmax(0, 1fr) 36px; }
  .hbar > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .auth-card { padding: 22px 18px; }
  .dropzone { padding: 22px 14px; }
  .preset { flex-wrap: wrap; }
  .preset-actions { flex-wrap: wrap; }
  .lib-sample { overflow-x: auto; }
  .perf-results { overflow-x: auto; }
  table.perf, table.perf tbody { display: block; }
  table.perf tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }
  table.perf tr:last-child { border-bottom: 0; }
  table.perf td { border-bottom: 0; overflow-wrap: anywhere; }
  table.perf td:first-child { width: auto; }
  table.perf td:nth-child(n+3) { grid-column: 1 / -1; padding-top: 0; }

  /* Модальные окна: почти на весь экран, большие — на весь экран */
  .modal-backdrop { padding: 10px; }
  .modal { max-height: calc(100dvh - 20px); }
  .modal-backdrop:has(.modal.xl) { padding: 0; }
  .modal.xl { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .modal-head { padding: 10px 12px; }
  .modal-body { padding: 14px; }

  /* Просмотр файлов: список сверху, код — ниже */
  .explorer { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .explorer .files { max-height: 30dvh; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 4px; font-size: 12.5px; }
  .code { font-size: 12px; }
  .code .ln::before { width: 38px; padding-right: 10px; }

  .toasts { left: 10px; right: 10px; top: 10px; bottom: auto; }
  .toast { max-width: none; }
}

/* Сенсорные устройства: подсказки клавиатурных сокращений не нужны */
@media (hover: none) and (pointer: coarse) {
  .btn .kbd { display: none; }
}
