:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-muted: #f8f9fa;
  --border: #e0e0e0;
  --border-light: #e0e0e0;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --accent: #0054a6;
  --accent-hover: #004690;
  --btn-bg: #ffffff;
  --btn-bg-hover: #f0f7ff;
  --btn-bg-active: #0054a6;
  --preview-bg: #f0f2f5;
  --sidebar-width: 400px;
  --scrollbar-track: #e8e8e8;
  --scrollbar-thumb: #0054a6;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.app {
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 5px 10px;
  flex-shrink: 0;
}

.btn-help {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--btn-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-help:hover {
  background: var(--btn-bg-hover);
}

.btn-help-icon {
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.workspace {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
  padding: 5px 24px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.sidebar::-webkit-scrollbar {
  width: 10px;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
}

.preview-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.section-title {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.block {
  margin-bottom: 28px;
}

.block-actions {
  margin-bottom: 0;
}

.visually-hidden,
.anchors-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 10px;
  border: 2px dashed var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--surface-muted);
}

.files-control {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.is-hidden {
  display: none !important;
}

.upload-zone-wrap {
  display: block;
}

.btn-reset {
  width: 100%;
  min-height: 96px;
  background: var(--btn-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-reset:hover:not(:disabled) {
  background: var(--btn-bg-hover);
}

.files-info {
  margin-top: 10px;
  padding: 0px 0px;
  font-size: 13px;
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 4px;
}

.upload-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.preview-file-wrap {
  margin-top: 12px;
}

.fields-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: block;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field-label-long {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 8px;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.offset-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-compact .field-label {
  margin-bottom: 4px;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-action {
  width: 100%;
  background: var(--btn-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-action:hover:not(:disabled) {
  background: var(--btn-bg-hover);
}

.btn-action-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-action-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.messages-panel {
  flex-shrink: 0;
  margin-top: 10px;
  border: 1px solid var(--border-light);
  background: var(--surface-muted);
  overflow: hidden;
}

.messages-panel-title {
  margin: 0;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
}

.messages-panel-body {
  max-height: 88px;
  overflow-y: auto;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-line;
  color: var(--text-secondary);
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.messages-panel-body::-webkit-scrollbar {
  width: 8px;
}

.messages-panel-body::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.messages-panel-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

.messages-panel-body.is-empty::before {
  content: "Нет сообщений";
  color: var(--text-muted);
  font-style: italic;
}

.messages-panel-body.is-error {
  color: #c0392b;
}

.preview-stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.preview-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: scroll;
  background: var(--preview-bg);
  border: 1px solid var(--border-light);
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.preview-wrap::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.preview-wrap::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.preview-wrap::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
}

#previewCanvas {
  position: relative;
  z-index: 1;
  display: block;
  max-width: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

#previewCanvas.preview-interactive {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  pointer-events: none;
  padding: 32px;
  text-align: center;
  z-index: 0;
}

.preview-placeholder svg {
  opacity: 0.35;
  margin-bottom: 8px;
}

.placeholder-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.placeholder-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.5;
}

.app-footer {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: auto;
}

@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }
}
