:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-border: #e6edf7;
  --text: #142033;
  --muted: #6f7d95;
  --accent: #2667ff;
  --accent-soft: #eef4ff;
  --accent-soft-2: #f6f9ff;
  --danger: #d84d4d;
  --danger-soft: #fff1f1;
  --success: #0f9d58;
  --success-soft: #eefbf4;
  --shadow: 0 18px 40px rgba(23, 45, 84, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(38, 103, 255, 0.08), transparent 34%),
    linear-gradient(180deg, #f5f8fc 0%, #edf2f9 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(340px, 0.95fr);
  gap: 20px;
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.topbar h1,
.panel-header h2,
.sidebar-footer h3,
.editor-section-title,
.entry-type-label {
  margin: 0;
}

.subtitle,
.panel-header p,
.sidebar-footer p,
.field-label,
.helper-text,
.entry-note,
.section-subtitle,
.meta-chip,
.status-line {
  color: var(--muted);
}

.subtitle {
  margin: 12px 0 0;
  max-width: 820px;
  line-height: 1.6;
}

.toolbar-block {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toolbar-actions,
.preview-actions,
.entry-toolbar,
.editor-controls,
.entry-action-row,
.quick-add-row,
.section-header-actions,
.stats-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.wide-field,
.grow-field {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 0.9fr) minmax(560px, 1.35fr) minmax(360px, 0.95fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.sidebar-panel,
.editor-panel,
.preview-panel {
  min-height: calc(100vh - 180px);
}

.sidebar-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.panel-header p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.text-input,
.select-input,
.raw-textarea,
.entry-textarea,
.entry-input {
  width: 100%;
  border: 1px solid #dbe4f0;
  border-radius: var(--radius-md);
  background: var(--accent-soft-2);
  color: var(--text);
  padding: 12px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.text-input:focus,
.select-input:focus,
.raw-textarea:focus,
.entry-textarea:focus,
.entry-input:focus {
  outline: none;
  border-color: rgba(38, 103, 255, 0.45);
  box-shadow: 0 0 0 4px rgba(38, 103, 255, 0.1);
}

.raw-textarea,
.entry-textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.55;
}

.entry-textarea.compact {
  min-height: 78px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.mini-button {
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  font-weight: 600;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #4a86ff);
  color: #fff;
  box-shadow: 0 10px 24px rgba(38, 103, 255, 0.22);
}

.secondary-button,
.mini-button {
  background: #edf3fa;
  color: #334155;
}

.ghost-button {
  background: var(--accent-soft);
  color: var(--accent);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
}

.mini-button {
  padding: 7px 11px;
  font-size: 12px;
}

.section-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.section-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: #f7faff;
  color: inherit;
  text-align: left;
}

.section-item:hover {
  border-color: #dbe7fb;
}

.section-item.active {
  background: var(--accent-soft);
  border-color: #d5e2ff;
}

.section-title {
  font-weight: 700;
}

.section-subtitle {
  margin-top: 5px;
  font-size: 12px;
}

.section-count,
.meta-chip,
.stat-value,
.entry-index-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  white-space: nowrap;
}

.section-count {
  min-width: 34px;
  padding: 6px 10px;
  background: rgba(38, 103, 255, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 4px;
}

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

.editor-header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}

.editor-header-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.editor-title-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-section-title {
  font-size: 22px;
  font-weight: 800;
}

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

.meta-chip {
  padding: 7px 12px;
  background: #f1f6fd;
  font-size: 12px;
  font-weight: 700;
}

.entry-toolbar {
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 14px 0 4px;
}

.quick-add-box {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: #f8fbff;
  border: 1px dashed #d8e5fb;
}

.quick-add-row {
  align-items: end;
}

.quick-add-row > .field-label {
  flex: 1;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}

.entry-card {
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: #fcfdff;
}

.entry-card.empty-state,
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  text-align: center;
  border-style: dashed;
  color: var(--muted);
}

.entry-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.entry-type-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.entry-type-label {
  font-size: 13px;
  font-weight: 700;
}

.entry-index-chip {
  padding: 5px 9px;
  background: #eef4fb;
  color: #52637a;
  font-size: 12px;
  font-weight: 700;
}

.entry-action-row {
  justify-content: flex-end;
}

.entry-fields {
  display: grid;
  gap: 12px;
}

.entry-note {
  font-size: 13px;
  line-height: 1.55;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: #f7faff;
  border: 1px solid #e3ecfb;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin-top: 10px;
  justify-content: flex-start;
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.stat-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.status-line {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #f6f9fd;
  border: 1px solid #e1e9f5;
  font-size: 13px;
  line-height: 1.5;
}

.status-line.success {
  background: var(--success-soft);
  border-color: #ccefdc;
  color: var(--success);
}

.status-line.error {
  background: var(--danger-soft);
  border-color: #ffd6d6;
  color: var(--danger);
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar-panel,
  .editor-panel,
  .preview-panel {
    min-height: auto;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .quick-add-row,
  .editor-controls,
  .toolbar-actions,
  .preview-actions,
  .section-header-actions {
    flex-direction: column;
  }
}
