:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #22d3ee;
  --danger: #f87171;
  --ok: #34d399;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(120deg, #1e293b, #0f172a);
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.bundle-info {
  margin: 10px 0 0;
  color: var(--accent);
  font-size: 14px;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 32px;
  width: 100%;
  box-sizing: border-box;
}

.top-panels {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  width: 100%;
}

.panel-docs,
.panel-placeholders {
  min-height: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.upload {
  margin-bottom: 14px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--primary);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(220px, 30vh);
  overflow-y: auto;
}

.doc-list li {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  word-break: break-all;
  border: 1px solid transparent;
}

.doc-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: default;
}

.doc-list-name {
  flex: 1;
  cursor: pointer;
}

.doc-list-item--unnamed {
  align-items: center;
}

.doc-list-name-row {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.doc-list-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.doc-list-name-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.doc-list-name-input:focus {
  outline: none;
  border-color: var(--primary);
}

.doc-list-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  word-break: normal;
}

.btn-save {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--accent);
  border-color: transparent;
  background: transparent;
  white-space: nowrap;
}

.doc-list-empty {
  cursor: default;
  color: var(--muted);
}

.btn-delete {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  white-space: nowrap;
}

.generate-layout {
  padding: 20px 32px;
  max-width: 720px;
}

.generate-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.generate-doc-list {
  max-height: none;
}

.btn-download {
  text-decoration: none;
  display: inline-block;
  flex-shrink: 0;
}

.doc-list li:hover {
  border-color: var(--primary);
}

.doc-list li.active {
  border-color: var(--accent);
  background: #14323c;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

.placeholder-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: min(220px, 30vh);
  overflow-y: auto;
}

.placeholder-section-label {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.btn-custom {
  border-color: #7c6cff;
  color: #5b4fd6;
}

.placeholder-btn {
  text-align: left;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
}

.editor-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.toolbar-doc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-undo {
  font-size: 13px;
  padding: 6px 12px;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mode-btn {
  border: none;
  border-radius: 0;
  padding: 7px 14px;
  background: transparent;
}

.mode-btn.active {
  background: var(--primary);
  color: white;
}

.current-doc {
  font-size: 14px;
  color: var(--muted);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.format-select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  height: 36px;
  cursor: pointer;
}

.format-select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview-mode {
  background: #f8fafc;
  color: #0f172a;
  border-radius: 0 0 12px 12px;
}

.preview-part {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px 22px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.preview-part-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 8px;
}

.preview-content {
  line-height: 1.6;
  font-size: 15px;
  -webkit-user-select: text;
  user-select: text;
}

.ooxml-p {
  margin: 0 0 8px;
  min-height: 1em;
}

.frag {
  white-space: pre-wrap;
}

.preview-content ::selection {
  background: #c7d2fe;
}

.mammoth-content h1,
.mammoth-content h2,
.mammoth-content h3 {
  margin: 0.6em 0 0.3em;
}

.mammoth-content p {
  margin: 0 0 8px;
}

.mammoth-content table {
  border-collapse: collapse;
  margin: 8px 0;
}

.mammoth-content td,
.mammoth-content th {
  border: 1px solid #cbd5e1;
  padding: 4px 8px;
}

.editor {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.paragraph {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #0b1220;
  outline: none;
  font-size: 15px;
  line-height: 1.5;
  min-height: 22px;
  white-space: pre-wrap;
}

.paragraph:focus {
  border-color: var(--primary);
}

.paragraph.empty::before {
  content: "(пустой абзац)";
  color: #475569;
  font-style: italic;
}

.placeholder-token,
.field-tag {
  border-radius: 4px;
  padding: 0 4px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.92em;
  white-space: nowrap;
}

.status {
  padding: 10px 20px;
  font-size: 13px;
  min-height: 20px;
}

.status.ok {
  color: var(--ok);
}

.status.error {
  color: var(--danger);
}

.empty-state {
  color: var(--muted);
  font-style: italic;
  padding: 20px;
}

@media (max-width: 900px) {
  .top-panels {
    grid-template-columns: 1fr;
  }
}
