:root {
  --bg: #edf2f7;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: rgba(23, 32, 51, 0.12);
  --orange: #ff7d1a;
  --purple: #7c3aed;
  --green: #16442d;
  --shadow: 0 24px 70px rgba(24, 36, 60, 0.16);
  --radius: 8px;
}

body.dark {
  --bg: #111827;
  --panel: rgba(22, 30, 47, 0.82);
  --panel-strong: #182235;
  --text: #f7fafc;
  --muted: #aab4c4;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 125, 26, 0.18), transparent 28rem),
    radial-gradient(circle at 85% 8%, rgba(124, 58, 237, 0.16), transparent 28rem),
    linear-gradient(135deg, var(--bg), #f8fbff);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  min-height: 100vh;
}

.content-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.54);
  backdrop-filter: blur(22px);
  z-index: 30;
  transition: transform 220ms ease;
}

body.dark .content-panel {
  background: rgba(17, 24, 39, 0.7);
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-badge {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  color: white;
  font-weight: 900;
  background: linear-gradient(135deg, var(--orange), var(--purple));
  box-shadow: var(--shadow);
}

.brand-row strong,
.brand-row span {
  display: block;
}

.brand-row span,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.toolbar-group {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.field-search {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.field-search span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field-search input,
.master-form input,
.master-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-strong);
  outline: none;
}

.field-search input,
.master-form input {
  min-height: 42px;
  padding: 0 12px;
}

.master-form textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
}

.history-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.master-form {
  display: grid;
  gap: 14px;
}

.field-card {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.field-card label {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar,
.topbar-actions,
.selected-actions,
.preview-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 4vw, 42px);
}

.topbar-actions {
  flex-wrap: wrap;
}

.btn,
.icon-btn {
  border: 0;
  cursor: pointer;
  transition: transform 170ms ease, box-shadow 170ms ease, opacity 170ms ease;
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  color: white;
  background: linear-gradient(135deg, var(--orange), #ff9d2d 48%, var(--purple));
  box-shadow: 0 14px 26px rgba(255, 125, 26, 0.22);
}

.btn-secondary {
  color: white;
  background: linear-gradient(135deg, #17a673, #228be6);
}

.btn-ghost,
.btn-small {
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.btn-small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.icon-btn {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.file-btn input {
  display: none;
}

.glass-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.preview-controls {
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.segmented button.active,
.view-switch button.active {
  color: white;
  background: var(--text);
}

.view-switch {
  display: flex;
  gap: 8px;
}

.selected-actions {
  margin-bottom: 18px;
  padding: 14px 16px;
}

.selected-actions > div:last-child {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 22px;
}

.preview-grid.single {
  grid-template-columns: minmax(0, 900px);
  justify-content: center;
}

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

.preview-card.is-hidden {
  display: none;
}

.preview-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.preview-card-header strong {
  font-size: 14px;
}

.email-frame {
  max-height: 760px;
  overflow: auto;
  padding: 0;
  background:
    linear-gradient(45deg, rgba(124, 58, 237, 0.07) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 125, 26, 0.07) 25%, transparent 25%),
    rgba(255, 255, 255, 0.5);
}

.email-iframe {
  display: block;
  width: 100%;
  height: 740px;
  border: 0;
  background: #fff;
  animation: renderPulse 260ms ease;
}

@keyframes renderPulse {
  from {
    opacity: 0.58;
    transform: translateY(5px) scale(0.995);
  }
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 10px;
  z-index: 80;
}

.toast {
  min-width: 240px;
  padding: 13px 15px;
  border-radius: var(--radius);
  color: white;
  font-weight: 800;
  background: #172033;
  box-shadow: var(--shadow);
  animation: toastIn 220ms ease both;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  border: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  z-index: 20;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .content-panel {
    position: fixed;
    width: min(90vw, 390px);
    transform: translateX(-105%);
  }

  .content-panel.open {
    transform: translateX(0);
  }

  .panel-backdrop.open {
    display: block;
  }

  body.panel-open {
    overflow: hidden;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .selected-actions {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .email-frame {
    max-height: 700px;
  }

  .email-iframe {
    height: 680px;
  }
}
