/* Aesthetic direction: technical and editorial — dense working tool, not a marketing page. */

:root {
  --ink: #1d1a16;
  --ink-soft: #5a544a;
  --paper: #faf8f4;
  --panel: #ffffff;
  --line: #e5e1da;
  --line-strong: #d3cdc2;
  --brand: #4951ef;
  --brand-ink: #ffffff;
  --accent: #2c2925;
  --danger: #b2364a;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Playfair Display', 'Times New Roman', serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font-family: inherit;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.topbar-logo {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 12px;
  color: var(--ink-soft);
}

.topbar-sub code {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

.topbar-right {
  display: flex;
  gap: 8px;
}

/* Buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s ease-out, background 0.12s ease-out, border-color 0.12s ease-out;
  min-height: 40px;
}

.btn:hover {
  background: #f3f1ec;
}

.btn:active {
  transform: scale(0.96);
}

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

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

.btn-primary:hover {
  background: #3d45d1;
}

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

.btn-secondary:hover {
  background: #1f1c19;
}

.btn-add {
  font-size: 12px;
  padding: 6px 12px;
  min-height: 34px;
}

.btn-danger {
  color: var(--danger);
  border-color: #e9c9cf;
}

.btn-danger:hover {
  background: #fff5f6;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 480px);
  gap: 0;
  min-height: calc(100vh - 61px);
}

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

.editor-pane {
  padding: 24px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.section-heading {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 24px 0 4px;
}

.section-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 0 16px;
}

/* Envelope card */

.envelope-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.envelope-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 16px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.envelope-toggle .chev {
  transition: transform 0.15s ease-out;
  color: var(--ink-soft);
}

.envelope-toggle[aria-expanded='true'] .chev {
  transform: rotate(180deg);
}

.envelope-fields {
  padding: 4px 18px 18px;
  display: grid;
  gap: 12px;
}

.field-row {
  display: grid;
  gap: 4px;
}

.field-row label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-row input,
.field-row select,
.field-row textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  min-height: 40px;
}

.field-row textarea {
  min-height: 72px;
  resize: vertical;
  font-family: inherit;
}

.field-row input:focus-visible,
.field-row select:focus-visible,
.field-row textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

#footerText-row[hidden] {
  display: none;
}

/* Block list */

.block-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.block-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px 16px;
  position: relative;
}

.block-card.dragging {
  opacity: 0.4;
}

.block-card.drag-over {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(73, 81, 239, 0.15);
}

.block-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.drag-handle {
  cursor: grab;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  user-select: none;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.block-type-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
  background: #edeeff;
  border-radius: 999px;
  padding: 3px 10px;
}

.block-spacer {
  flex: 1;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  min-height: 32px;
}

.icon-btn:hover {
  background: #f3f1ec;
  color: var(--ink);
}

.icon-btn.remove:hover {
  background: #fff0f2;
  color: var(--danger);
}

.block-fields {
  display: grid;
  gap: 10px;
}

.block-fields .field-row-inline {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: start;
  gap: 10px;
}

.block-fields .field-row-inline label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding-top: 10px;
}

.block-fields input,
.block-fields select,
.block-fields textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  background: var(--paper);
  color: var(--ink);
  min-height: 40px;
  width: 100%;
}

.block-fields textarea {
  min-height: 64px;
  resize: vertical;
  font-family: inherit;
}

.block-fields input:focus-visible,
.block-fields select:focus-visible,
.block-fields textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-soft);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  font-size: 13px;
}

/* Add-block row */

.add-block-row {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.add-block-label {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-right: 4px;
}

/* Preview pane */

.preview-pane {
  background: #efece4;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-toolbar {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.preview-label {
  font-size: 13px;
  font-weight: 600;
}

.preview-status {
  font-size: 11px;
  color: var(--ink-soft);
}

.preview-frame-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 28px 20px 60px;
}

#preview-frame {
  width: 100%;
  max-width: 620px;
  min-height: 900px;
  border: none;
  border-radius: var(--radius-md);
  background: white;
  box-shadow: 0 1px 2px rgba(29, 26, 22, 0.06), 0 8px 24px rgba(29, 26, 22, 0.08);
}

/* Toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
  pointer-events: none;
  z-index: 50;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
