* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
}

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.rail {
  background: var(--rail);
  color: #e8eef2;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--steel-2), var(--steel));
  color: #fff;
  flex-shrink: 0;
}
.brand-plane {
  width: 22px;
  height: 22px;
  display: block;
}
.brand-title { font-family: var(--font-display); font-size: 22px; line-height: 1; }
.brand-sub { color: #9db3bf; font-size: 12px; margin-top: 4px; }

.steps { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.step-btn {
  border: 0; background: transparent; color: #d5e2ea;
  text-align: left; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; font: inherit;
}
.step-btn:hover { background: rgba(255,255,255,0.06); }
.step-btn.active { background: var(--steel); color: #fff; }
.step-btn span { opacity: 0.55; margin-right: 8px; font-variant-numeric: tabular-nums; }

.rail-foot { display: grid; gap: 8px; }
.workspace { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  padding: 22px 28px 10px;
}
.topbar h1 {
  margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 600;
}
.muted { color: var(--muted); margin: 6px 0 0; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge {
  background: var(--choice-bg, #fff);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--steel);
}

.panel {
  margin: 8px 28px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
  min-height: calc(100vh - 140px);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: #b9b3a5; }
.btn.primary {
  background: var(--steel);
  border-color: var(--steel);
  color: #fff;
}
.btn.primary:hover { background: var(--steel-2); }
.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.18);
  color: #e8eef2;
}
.btn.ghost:hover { background: rgba(255,255,255,0.06); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.icon-btn {
  border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--muted);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 13px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; background: #fff; color: var(--ink);
}
.field textarea { min-height: 90px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  background: var(--choice-bg, var(--panel));
  color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.choice:hover { border-color: var(--steel-2); }
.choice.active {
  border-color: var(--steel);
  background: var(--choice-active-bg, var(--accent-soft));
  box-shadow: inset 0 0 0 1px var(--steel), 0 0 0 1px color-mix(in srgb, var(--steel) 35%, transparent);
  color: var(--ink);
}
.choice strong { display: block; margin-bottom: 4px; color: var(--ink); }
.choice span { color: var(--muted); font-size: 13px; }
.choice.active span { color: var(--choice-active-muted, var(--muted)); }

/* Structure editor */
.struct-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  min-height: 560px;
}
.struct-tree, .struct-editor {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: auto;
}
.struct-tree { padding: 10px; }
.struct-editor { padding: 14px; }
.tree-toolbar, .editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.tree-item {
  border: 0; width: 100%; text-align: left; background: transparent;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit;
  display: flex; gap: 8px; align-items: flex-start;
}
.tree-item:hover { background: var(--accent-soft); }
.tree-item.selected { background: var(--accent-soft); color: var(--ink); }
.tree-item .lvl {
  font-size: 11px; color: var(--steel); background: #e7f1f3;
  border-radius: 6px; padding: 2px 6px; white-space: nowrap;
}
.tree-children { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 6px; }

.block-list { display: flex; flex-direction: column; gap: 10px; }
.block-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--choice-bg, #fbfaf6);
  color: var(--ink);
}
.block-card header {
  display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px;
}
.block-card .kind {
  font-size: 12px; font-weight: 700; color: var(--steel);
  background: #e7f1f3; border-radius: 999px; padding: 4px 8px;
}
.block-preview {
  font-size: 13px; color: var(--muted); white-space: pre-wrap;
}
.table-preview {
  width: 100%; border-collapse: collapse; font-size: 13px; background: #fff;
}
.table-preview th, .table-preview td {
  border: 1px solid var(--line); padding: 6px 8px; text-align: left;
}
.img-preview {
  max-width: 100%; max-height: 180px; border-radius: 8px; border: 1px solid var(--line);
}

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 28px;
  text-align: center; color: var(--muted); background: #fff;
}
.dropzone.drag { border-color: var(--steel); background: #eef6f7; }

/* Table editor modal */
.te-grid-wrap { overflow: auto; max-height: 360px; border: 1px solid var(--line); border-radius: 10px; }
.te-grid { border-collapse: collapse; width: 100%; min-width: 480px; }
.te-grid th, .te-grid td { border: 1px solid var(--line); padding: 0; }
.te-grid input {
  width: 100%; border: 0; padding: 8px; font: inherit; background: transparent;
}
.te-grid th { background: #eef3f4; }
.te-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

/* Flow editor (VS-like) */
.modal.modal-flow {
  width: min(1180px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
}
.modal.modal-flow .modal-body { padding: 12px 14px 8px; }
.fe-root { display: grid; gap: 10px; }
.fe-top {
  display: flex; gap: 12px; align-items: end; justify-content: space-between; flex-wrap: wrap;
}
.fe-title-field { flex: 1; min-width: 220px; margin: 0; }
.fe-toolbar { display: flex; gap: 6px; flex-wrap: wrap; }
.fe-layout {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) 200px;
  gap: 10px;
  min-height: 520px;
}
.fe-toolbox, .fe-props {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 92%, #dfe7ee);
  padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
  overflow: auto;
  max-height: 560px;
}
.fe-props h3 { margin: 4px 4px 8px; font-size: 14px; }
.fe-tool {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; padding: 7px 8px; cursor: grab; text-align: left;
  font: inherit; color: inherit;
}
.fe-tool:hover { border-color: var(--steel); }
.fe-tool strong { display: block; font-size: 12px; }
.fe-tool small { color: var(--muted); font-size: 11px; }
.fe-tool-shape {
  width: 28px; height: 20px; flex-shrink: 0;
  border: 2px solid #1f4b5e; background: #fff; border-radius: 3px;
}
.fe-tool-shape.decision {
  width: 22px; height: 22px; background: #fff3d6;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border: 0; background:
    linear-gradient(#fff3d6, #fff3d6) padding-box;
  box-shadow: inset 0 0 0 2px #1f4b5e;
}
.fe-tool-shape.start, .fe-tool-shape.end {
  border-radius: 12px; background: #d7e8e4;
}
.fe-tool-shape.io {
  clip-path: polygon(18% 0, 100% 0, 82% 100%, 0 100%);
  background: #e3ecf7; border: 0; box-shadow: inset 0 0 0 2px #1f4b5e;
}
.fe-tool-shape.document { background: #f4f0e8; border-radius: 2px 2px 8px 8px; }
.fe-tool-shape.prepare {
  clip-path: polygon(18% 0, 82% 0, 100% 50%, 82% 100%, 18% 100%, 0 50%);
  background: #efe8f7; border: 0; box-shadow: inset 0 0 0 2px #1f4b5e;
}
.fe-tool-shape.connector {
  width: 20px; height: 20px; border-radius: 50%; background: #eef3f4;
}
.fe-canvas-outer { display: grid; grid-template-rows: 1fr auto; gap: 6px; min-width: 0; }
.fe-hint { font-size: 12px; }
.flow-canvas-wrap, .fe-canvas {
  border: 1px solid var(--line); border-radius: 12px;
  background-color: #f7f5ef;
  background-image:
    linear-gradient(#e8e4d8 1px, transparent 1px),
    linear-gradient(90deg, #e8e4d8 1px, transparent 1px);
  background-size: 20px 20px;
  height: 520px; position: relative; overflow: hidden;
  outline: none;
}
.fe-world { position: absolute; inset: 0; width: 2400px; height: 1800px; }
.fe-svg { display: block; }
.flow-node {
  position: absolute; min-width: 120px; max-width: 180px;
  border: 2px solid var(--steel); background: #fff; border-radius: 8px;
  padding: 10px; cursor: move; text-align: center; font-size: 13px;
  box-shadow: var(--shadow); user-select: none;
}
.flow-side { display: grid; gap: 8px; margin-top: 10px; }

@media (max-width: 980px) {
  .fe-layout { grid-template-columns: 1fr; }
  .fe-toolbox, .fe-props { max-height: 180px; }
  .flow-canvas-wrap, .fe-canvas { height: 420px; }
}

.findings { display: flex; flex-direction: column; gap: 8px; }
.finding {
  border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); background: #fff;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  text-align: left; width: 100%; font: inherit; color: inherit;
}
.finding.error { border-color: #e3b4b4; background: #fbf1f1; }
.finding.warning { border-color: #e4c69a; background: #fff8ee; }
.finding.info { border-color: #b9d0d7; background: #f3f8f9; }
.finding.clickable {
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.finding.clickable:hover {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--steel) 35%, transparent);
  border-color: var(--steel);
}
.finding.clickable:focus-visible {
  outline: 2px solid var(--steel);
  outline-offset: 2px;
}
.finding-main { flex: 1; min-width: 0; }
.finding-go {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--steel);
  white-space: nowrap;
  margin-top: 2px;
}
.focus-target {
  position: relative;
  border-radius: 10px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--steel) 45%, transparent) !important;
  animation: focusPulse 1.4s ease 2;
}
@keyframes focusPulse {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--steel) 35%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--steel) 18%, transparent); }
}

.modal-root {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
}
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(21,32,43,0.45); }
.modal {
  position: relative; width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); overflow: auto;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.modal-head, .modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-foot { border-bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; gap: 8px; }
.modal-body { padding: 16px; }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 22px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow); max-width: 360px;
}
.toast.hidden { display: none; }

/* ── предпросмотр документа ───────────────────────────── */
.preview-root {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
}
.preview-root.hidden { display: none; }
.preview-backdrop {
  position: absolute; inset: 0;
  background: rgba(16, 24, 32, 0.55);
  backdrop-filter: blur(2px);
}
.preview-shell {
  position: relative;
  width: min(980px, calc(100vw - 24px));
  height: min(92vh, 980px);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.preview-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.preview-head h2 { margin: 0; font-family: var(--font-display); font-size: 22px; }
.preview-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview-banner {
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: #fff8ee; color: var(--ink); font-size: 14px;
}
.preview-banner.error { background: #fbf1f1; }
.preview-banner.hidden { display: none; }
.preview-body {
  flex: 1; overflow: auto;
  padding: 20px 16px 32px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 88%, #9aa7b5), var(--bg));
}
.doc-preview { max-width: 820px; margin: 0 auto; }
.doc-preview-meta {
  margin: 0 0 14px; color: var(--muted); font-size: 13px;
}
.doc-page {
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #d7dde3;
  border-radius: 2px;
  box-shadow: 0 10px 28px rgba(20, 40, 70, 0.12);
  padding: 48px 56px 56px;
  margin: 0 auto 22px;
  min-height: 980px;
  font-family: "Times New Roman", Times, serif;
  font-size: 14px;
  line-height: 1.45;
}
.doc-page-title { display: flex; flex-direction: column; }
.doc-center { text-align: center; margin: 0 0 10px; }
.doc-h-center { text-align: center; font-size: 16px; margin: 0 0 18px; text-transform: uppercase; }
.doc-bold { font-weight: 700; }
.doc-italic { font-style: italic; }
.doc-org { font-size: 18px; font-weight: 700; margin-top: 24px; }
.doc-type { font-size: 18px; font-weight: 700; }
.doc-desig { font-size: 28px; font-weight: 700; margin: 18px 0 12px; letter-spacing: 0.02em; }
.doc-title { font-size: 18px; font-weight: 700; margin: 8px 0 14px; }
.doc-rule {
  border: 0; border-top: 3px solid #222; width: 78%; margin: 4px auto 14px;
}
.doc-issue {
  display: flex; justify-content: space-between;
  padding: 8px 12px 8px 24px; font-size: 16px; font-weight: 700;
}
.doc-meta-line { margin: 6px 0; padding-left: 24px; }
.doc-stamp { margin-top: auto; padding-top: 48px; }
.doc-ni {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 18px; font-size: 12px; white-space: pre-wrap;
}
.doc-h1, .doc-h2 { font-size: 15px; margin: 18px 0 10px; }
.doc-h3 { font-size: 14px; margin: 14px 0 8px; }
.doc-h4 { font-size: 14px; margin: 12px 0 6px; font-weight: 600; }
.doc-page p { margin: 0 0 10px; text-align: justify; text-indent: 1.25cm; }
.doc-page .doc-center,
.doc-page .doc-meta-line,
.doc-page .doc-issue,
.doc-page .doc-caption,
.doc-page .doc-muted { text-indent: 0; text-align: left; }
.doc-page .doc-center { text-align: center; }
.doc-toc { padding-left: 22px; }
.doc-toc li { margin: 6px 0; }
.doc-list { padding-left: 22px; margin: 0 0 12px; }
.doc-list li { margin: 4px 0; }
.doc-table {
  width: 100%; border-collapse: collapse; margin: 8px 0 16px;
  font-size: 13px;
}
.doc-table th, .doc-table td {
  border: 1px solid #333; padding: 6px 8px; vertical-align: top;
}
.doc-table th { background: #f3f5f7; }
.doc-caption { font-weight: 600; margin: 10px 0 6px; text-align: center; }
.doc-img { display: block; max-width: 100%; margin: 0 auto 12px; }
.doc-flow {
  background: #f7f8fa; border: 1px dashed #b8c0c8; padding: 10px 12px;
  font-family: Consolas, "Courier New", monospace; font-size: 12px;
  white-space: pre-wrap; overflow: auto;
}
.doc-appendix { margin-bottom: 28px; padding-bottom: 12px; border-bottom: 1px dashed #cfd6dd; }
.doc-appendix:last-child { border-bottom: 0; }
.doc-muted { color: #6a747c; font-size: 13px; }

@media (max-width: 720px) {
  .doc-page { padding: 28px 20px 36px; min-height: 0; }
  .preview-shell { height: calc(100vh - 16px); width: calc(100vw - 12px); }
  .preview-actions .btn { padding: 6px 10px; font-size: 13px; }
}

.empty {
  color: var(--muted); padding: 28px; text-align: center;
  border: 1px dashed var(--line); border-radius: 12px;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; }
  .steps { flex-direction: row; flex-wrap: wrap; }
  .struct-layout, .grid-2, .grid-3, .choice-grid { grid-template-columns: 1fr; }
}
