:root {
  color-scheme: light;
  --bg: #f9f8f9;
  --surface: #ffffff;
  --surface-soft: #fbfaff;
  --text: #231d33;
  --muted: #6b6679;
  --border: #e6e5e8;
  --accent: #6239c6;
  --accent-dark: #5130a3;
  --danger: #b42318;
  --danger-soft: #ffebe9;
  --ok-bg: #e8f6f0;
  --ok-text: #155f45;
  --warn-bg: #fff7de;
  --warn-text: #7a5800;
  --err-bg: #ffeaea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #efe9ff 0%, var(--bg) 48%);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

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

.link {
  text-decoration: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.header-links {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 13px;
}

.status.success {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: #b8e3d0;
}

.status.warning {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: #efd687;
}

.status.error {
  background: var(--err-bg);
  color: var(--danger);
  border-color: #ffcfc9;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tab-btn.active {
  border-color: #cec0f2;
  background: #f4f0ff;
  color: #4a3792;
}

.tab-unsaved {
  font-size: 10px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  background: #fff4d6;
  color: #7b5600;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(35, 29, 51, 0.08);
  overflow: hidden;
}

.panel-head {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}

.panel-title {
  margin: 0;
  font-size: 16px;
}

.meta-row {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid #d9d0f3;
  background: #f2eeff;
  color: #4d3994;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.chip.muted {
  border-color: var(--border);
  background: #f7f9f9;
  color: var(--muted);
}

.panel-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.editor-pane {
  border-right: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
}

.section-title {
  margin: 0;
  font-size: 13px;
  color: #3a3550;
}

.text-editor {
  width: 100%;
  min-height: 250px;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  resize: vertical;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: #fbfaff;
}

input,
select,
textarea {
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #8160d1;
  border-color: #8160d1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-soft {
  background: #ebe7f7;
  color: #413a53;
}

.btn-danger {
  background: var(--danger-soft);
  color: #8f1d15;
}

.history-pane {
  padding: 12px 14px;
  background: #f8f6ff;
}

.history-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.history-block summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
}

.history-list {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-id {
  font-size: 12px;
  font-weight: 700;
}

.history-date {
  font-size: 12px;
  color: var(--muted);
}

.history-preview {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: #3a3550;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.history-empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.field-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 500px;
  overflow: auto;
}

.field-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfaff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 150px auto;
  gap: 8px;
  align-items: end;
}

.field-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.field-input,
.field-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 9px;
  font-size: 13px;
  background: #fff;
}

.field-required {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.field-row-actions {
  display: inline-flex;
  gap: 6px;
}

.field-row-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.field-advanced {
  border: 1px dashed var(--border);
  border-radius: 9px;
  padding: 6px 8px;
}

.field-advanced summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.field-advanced-body {
  margin-top: 8px;
}

.empty-panel {
  padding: 24px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 29, 51, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(920px, 100%);
  max-height: 88dvh;
  border: 1px solid #d8d2ea;
  border-radius: 14px;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.modal-head {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-title {
  margin: 0;
  font-size: 14px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.modal-body {
  padding: 12px;
  overflow: auto;
}

.modal-body pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.45;
  color: #24333a;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

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

  .editor-pane {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 860px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .field-main {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
}

