:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #6b7280;
  --line: #d7dde5;
  --green: #70ad47;
  --orange: #e9521b;
  --dark: #2f3642;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

html,
body {
  height: 100%;
}

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

button,
.buttonLink {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.buttonLink:hover {
  border-color: #aab4c2;
}

.app {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(760px, 1fr);
  overflow: hidden;
}

.library {
  border-right: 1px solid var(--line);
  background: #f8fafc;
  padding: 18px;
  overflow: auto;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brandActions {
  display: flex;
  gap: 8px;
}

.brand strong {
  display: block;
  font-size: 22px;
  line-height: 28px;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

#createBtn,
#settingsBtn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 38px;
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

#settingsBtn {
  background: #3b4452;
  border-color: #3b4452;
}

.userBox,
.filters {
  margin-top: 18px;
  display: grid;
  gap: 8px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
}

input[type="checkbox"] {
  width: auto;
  margin: 0 8px 0 0;
}

.campaignList {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.campaignCard {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}

.campaignCard.active {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(112, 173, 71, 0.18);
}

.campaignCard strong {
  display: block;
  font-size: 15px;
  line-height: 20px;
}

.campaignCard span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
  margin-top: 4px;
}

.campaignActions {
  display: flex;
  gap: 5px;
}

.campaignActions button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  font-size: 16px;
  line-height: 28px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

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

.meta {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px minmax(220px, 360px);
  gap: 10px;
}

.titleInput {
  font-weight: bold;
}

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

#saveState {
  min-width: 100px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.presence {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

#presenceList {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.person {
  padding: 5px 9px;
  border-radius: 999px;
  background: #e9f4e3;
  color: #365f22;
}

.editorShell {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(420px, 1fr) 320px;
  overflow: hidden;
}

.blocks,
.inspector {
  background: var(--dark);
  color: #ffffff;
  padding: 16px;
  overflow: auto;
  min-height: 0;
}

.blocks h2,
.inspector h2 {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 22px;
}

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

.blocks button {
  color: #ffffff;
  background: #3b4452;
  border-color: #4d5868;
  text-align: left;
}

.canvasWrap {
  overflow: auto;
  padding: 18px;
  background: #dfe3e8;
  min-height: 0;
  scroll-behavior: smooth;
}

.viewSwitch {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}

.viewSwitch button.active {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.canvas {
  width: 600px;
  min-height: 720px;
  margin: 0 auto;
  background: #f5f5f5;
  box-shadow: 0 8px 28px rgba(20, 28, 38, 0.18);
  transition: width 0.15s ease;
}

.canvas img,
.previewImage {
  max-width: 100%;
}

.emailBlock {
  position: relative;
  border: 2px solid transparent;
}

.emailBlock.selected {
  border-color: #1d7dd7;
}

.emailBlock:hover {
  border-color: rgba(29, 125, 215, 0.5);
}

.emailBlock.imageBlock,
.emailBlock.imageBlock.selected,
.emailBlock.imageBlock:hover {
  border: 0;
}

.blockList {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.blockListItem {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #ffffff;
  background: #3b4452;
  border: 1px solid #4d5868;
  border-radius: 6px;
  padding: 9px 10px;
  cursor: pointer;
}

.blockListItem.active {
  border-color: #ffffff;
}

.blockListItem.dragging {
  opacity: 0.5;
}

.blockListItem.dragOver {
  border-color: #22c7b8;
  box-shadow: 0 0 0 2px rgba(34, 199, 184, 0.22);
}

.dragHandle {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: #252c36;
  color: #d7dde5;
  cursor: grab;
  font-size: 18px;
  line-height: 18px;
}

.blockArrow {
  color: #aeb7c4;
}

.settings {
  display: grid;
  gap: 10px;
}

.settings.empty {
  color: #aeb7c4;
}

.settings label {
  color: #d7dde5;
}

.settings input,
.settings textarea,
.settings select {
  background: #252c36;
  color: #ffffff;
  border-color: #4d5868;
}

.settings textarea {
  min-height: 150px;
  resize: vertical;
}

.richTextEditor {
  width: 100%;
  min-height: 150px;
  border: 1px solid #4d5868;
  border-radius: 6px;
  padding: 10px 12px;
  background: #252c36;
  color: #ffffff;
  line-height: 22px;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.richTextEditor.singleLine {
  min-height: 40px;
  white-space: normal;
}

.richTextEditor:focus {
  border-color: #22c7b8;
  box-shadow: 0 0 0 2px rgba(34, 199, 184, 0.16);
}

.richTextEditor a,
.emailBlock a {
  color: inherit;
  text-decoration: underline;
}

.richTextToolbar {
  position: fixed;
  z-index: 20;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid #4d5868;
  border-radius: 6px;
  background: #20242a;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.richTextToolbar.visible {
  display: flex;
}

.richTextToolbar button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-color: #4d5868;
  background: #252c36;
  color: #ffffff;
  line-height: 28px;
}

.richTextToolbar.editingLink {
  gap: 6px;
  max-width: calc(100vw - 16px);
}

.richLinkForm {
  display: none;
  align-items: center;
  gap: 4px;
}

.richTextToolbar.editingLink .richLinkForm {
  display: flex;
}

.richTextToolbar.editingLink > button {
  display: none;
}

.richLinkForm input {
  width: min(230px, calc(100vw - 96px));
  height: 30px;
  min-width: 0;
  border-color: #4d5868;
  border-radius: 5px;
  padding: 5px 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
}

.richLinkForm button {
  flex: 0 0 30px;
}

.settingRow {
  display: grid;
  gap: 5px;
}

.dropZone {
  display: grid;
  gap: 8px;
  border: 1px dashed #7d899a;
  border-radius: 8px;
  padding: 12px;
  background: #252c36;
  color: #d7dde5;
}

.dropZone strong {
  font-size: 13px;
  line-height: 18px;
}

.dropZone span {
  color: #aeb7c4;
  font-size: 12px;
  line-height: 16px;
  overflow-wrap: anywhere;
}

.dropZone.dragActive {
  border-color: #22c7b8;
  background: #21343b;
}

.fileInput {
  display: none;
}

.buttonSettings {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #4d5868;
  border-radius: 8px;
  background: #252c36;
}

.buttonSettings strong {
  font-size: 13px;
  line-height: 18px;
}

.inlineButtons {
  display: flex;
  gap: 8px;
}

.inlineButtons button {
  flex: 1;
}

dialog {
  width: min(980px, calc(100vw - 48px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

dialog::backdrop {
  background: rgba(16, 22, 31, 0.62);
}

dialog form {
  padding: 18px;
}

dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

dialog header button {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 30px;
}

#exportCode {
  height: 420px;
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 17px;
  white-space: pre;
}

.dialogActions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.settingsSection {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.settingsSection h3 {
  margin: 0;
  font-size: 16px;
  line-height: 22px;
}

.settingsSection p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.templateSettings {
  display: grid;
  gap: 10px;
}

.presetPreviewList {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.presetPreview {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.presetPreview.active {
  border-color: #1d7dd7;
  box-shadow: 0 0 0 2px rgba(29, 125, 215, 0.14);
}

.presetPreview strong {
  color: var(--text);
  font-size: 13px;
  line-height: 18px;
}

.presetPreview span {
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.presetSwatches {
  display: flex;
  gap: 6px;
}

.presetSwatches i {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.colorControl {
  display: grid;
  grid-template-columns: 42px minmax(82px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.colorControl input[type="color"] {
  width: 42px;
  height: 38px;
  padding: 2px;
}

.colorControl input[type="text"] {
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  text-transform: uppercase;
}

.colorControl button {
  white-space: nowrap;
}

.typographyRules {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.typographyRulesHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.typographyRule {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 220px) 34px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}

.typographyRule input,
.typographyRule select {
  min-width: 0;
}

.typographyRule button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.emptyRules {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.logoLibrary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.logoItem {
  display: grid;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.logoItem img {
  max-width: 100%;
  max-height: 56px;
  object-fit: contain;
}

.logoItem span {
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
  .app {
    grid-template-columns: 280px minmax(700px, 1fr);
  }

  .editorShell {
    grid-template-columns: 190px minmax(390px, 1fr) 280px;
  }
}
