* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1f2933;
  background: #f6f8fb;
}
a { color: #175cd3; text-decoration: none; }
h1 { font-size: 2rem; margin: 0 0 .4rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 64px;
  padding: .75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #d9e2ec;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; color: #102a43; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #14b8a6, #0f766e); box-shadow: 0 4px 12px rgba(20, 184, 166, .35); }
.brand-mark svg { width: 17px; height: 17px; }
.brand-name { font-size: 1.15rem; letter-spacing: -.3px; }
.brand-name b { color: #0f766e; font-weight: 800; }
nav { display: flex; gap: .75rem; flex-wrap: wrap; flex: 1; }
nav a { color: #52606d; font-size: .92rem; }
.logout { margin-left: auto; }
.logout button, .button, button {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #243b53;
  padding: .55rem .8rem;
  min-height: 38px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.primary, button.primary { background: #0f766e; color: #fff; border-color: #0f766e; }
.page { width: min(1120px, calc(100% - 2rem)); margin: 2rem auto; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.muted { color: #627d98; }
.panel, .stat {
  background: #fff;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(16, 42, 67, .04);
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin: 1rem 0; }
/* Sequence wizard: keep the step list compact so the editor column gets the room. */
.grid-sequence { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .grid-sequence { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat span { color: #627d98; display: block; font-size: .85rem; }
.stat strong { font-size: 1.7rem; }
.messages { margin-bottom: 1rem; }
.message { padding: .75rem 1rem; border-radius: 6px; background: #e0f2fe; color: #075985; margin-bottom: .5rem; }
.message.error { background: #fee2e2; color: #991b1b; }
.message.warning { background: #fef3c7; color: #92400e; }
label { display: grid; gap: .35rem; margin-bottom: .9rem; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: .6rem .7rem;
  font: inherit;
  background: #fff;
}
input[type="checkbox"] { width: auto; justify-self: start; }
small, .error { color: #b42318; font-weight: 500; }
.badge { display: inline-block; padding: .2rem .45rem; border-radius: 999px; background: #e6fffa; color: #0f766e; font-size: .78rem; }
.badge.alt { background: #eef2ff; color: #3730a3; }
.filter-bar, .bulk-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filter-bar input, .filter-bar select, .bulk-bar input, .bulk-bar select { width: auto; min-width: 140px; flex: 0 1 auto; }
.filter-bar input[type="search"] { flex: 1 1 240px; }
.bulk-bar { background: #f8fafc; }
.row-actions { white-space: nowrap; }
.wizard-nav { display: flex; flex-wrap: wrap; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.5rem; counter-reset: step; }
.wizard-nav li { flex: 1 1 auto; }
.wizard-nav li a, .wizard-nav li { display: flex; align-items: center; gap: .5rem; padding: .55rem .8rem; border: 1px solid #d9e2ec; border-radius: 6px; background: #fff; color: #627d98; font-size: .9rem; font-weight: 600; }
.wizard-nav li span { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 999px; background: #e3e8ef; color: #52606d; font-size: .8rem; }
.wizard-nav li.active a, .wizard-nav li.active { border-color: #0f766e; color: #0f766e; background: #f0fdfa; }
.wizard-nav li.active span { background: #0f766e; color: #fff; }
td input[type="checkbox"], th input[type="checkbox"] { width: auto; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.item { border-bottom: 1px solid #e5e7eb; padding: .75rem 0; }
.item:last-child { border-bottom: 0; }
.template-starters {
  border-bottom: 1px solid #e5e7eb;
  margin: 0 0 1rem;
  padding: 0 0 1rem;
}
.starter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .75rem;
}
.starter-card {
  display: grid;
  gap: .25rem;
  width: 100%;
  min-height: 112px;
  padding: .85rem;
  text-align: left;
  align-content: start;
}
.starter-card strong {
  color: #102a43;
  line-height: 1.25;
}
.starter-card span {
  color: #627d98;
  font-size: .86rem;
  line-height: 1.35;
}
button.danger, .button.danger {
  color: #b42318;
  border-color: #f5b5ae;
  background: #fff7f6;
}
.template-builder {
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  background: #fff;
  margin: 0 0 1rem;
  padding: 1rem;
}
.builder-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.builder-header h2, .builder-panel h3 {
  margin: 0 0 .35rem;
}
.builder-grid {
  display: grid;
  grid-template-columns: 250px minmax(360px, 1fr) 280px;
  gap: 1rem;
  align-items: start;
}
.builder-panel {
  background: #f8fafc;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  padding: .85rem;
}
.builder-panel label {
  font-size: .86rem;
  margin-bottom: .65rem;
}
.builder-panel input,
.builder-panel select,
.builder-panel textarea {
  padding: .48rem .55rem;
  font-size: .9rem;
}
.builder-add {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem;
  margin-bottom: .8rem;
}
.builder-add .button {
  min-height: 34px;
  padding: .38rem .45rem;
}
.builder-section-list {
  display: grid;
  gap: .45rem;
}
.builder-list-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: .5rem;
  row-gap: .12rem;
  width: 100%;
  min-height: 58px;
  padding: .55rem;
  text-align: left;
  align-items: center;
  cursor: grab;
}
.builder-list-item.is-active {
  border-color: #0f766e;
  background: #f0fdfa;
}
.builder-list-item.is-dragging {
  opacity: .4;
}
.builder-list-item.drag-above {
  box-shadow: inset 0 2px 0 #0f766e;
}
.builder-list-item.drag-below {
  box-shadow: inset 0 -2px 0 #0f766e;
}
.builder-drag-handle {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
  color: #9fb0c0;
  font-size: .9rem;
  letter-spacing: -2px;
  line-height: 1;
  cursor: grab;
}
.builder-list-item strong {
  grid-column: 2;
  color: #102a43;
  font-size: .88rem;
  text-transform: capitalize;
}
.builder-list-summary {
  grid-column: 2;
  color: #627d98;
  font-size: .78rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.builder-preview-wrap {
  min-height: 520px;
  overflow: auto;
  background: #e7edf3;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  padding: 1rem;
}
.builder-preview {
  min-width: 360px;
}
.builder-preview [data-builder-section] {
  outline: 1px dashed transparent;
  outline-offset: -2px;
  cursor: pointer;
}
.builder-preview [data-builder-section]:hover {
  outline-color: rgba(15, 118, 110, .55);
}
.builder-upload {
  display: grid;
  gap: .4rem;
  margin: .25rem 0 .75rem;
  padding: .75rem;
  background: #fff;
  border: 1px dashed #b6c5d6;
  border-radius: 8px;
}
.builder-upload strong {
  color: #102a43;
  font-size: .9rem;
}
.builder-upload span {
  color: #627d98;
  font-size: .8rem;
  line-height: 1.35;
}
.builder-upload .button {
  justify-self: start;
  min-height: 34px;
  padding: .38rem .65rem;
}
.builder-upload input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}
.builder-save-note {
  margin: .8rem 0 0;
  color: #627d98;
  font-size: .9rem;
}
.template-builder + .actions + label,
.template-builder + .actions + input {
  margin-top: 1rem;
}
@media (max-width: 1080px) {
  .builder-grid { grid-template-columns: 1fr; }
  .builder-preview-wrap { min-height: 360px; }
}
.checklist { padding-left: 1.2rem; }
.checklist li { margin: .4rem 0; color: #b42318; }
.checklist li.ok { color: #0f766e; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: .65rem .5rem; text-align: left; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
th { color: #52606d; font-size: .85rem; }
.auth { width: min(440px, 100%); margin: 3rem auto; }
.var-suggest {
  position: absolute;
  z-index: 1000;
  display: none;
  width: 260px;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(16, 42, 67, .16);
  padding: .25rem;
}
.var-suggest-item {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .4rem .55rem;
  border-radius: 6px;
  cursor: pointer;
}
.var-suggest-item code {
  font-size: .85rem;
  color: #0f766e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.var-suggest-item .var-suggest-desc { font-size: .76rem; color: #627d98; }
.var-suggest-item.is-active { background: #f0fdfa; }
.var-suggest-item.is-active code { color: #0b5c55; }
@media (max-width: 760px) {
  .topbar, .heading { align-items: flex-start; flex-direction: column; }
  .logout { margin-left: 0; }
}

/* --- Rich text editor (Quill) ------------------------------------------- */
.rich-editor { margin: .35rem 0 .75rem; }
.rich-editor-vars {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  margin-bottom: .4rem;
}
.rich-editor-vars .var-chip {
  min-height: auto;
  padding: .2rem .5rem;
  font-size: .8rem;
}
.rich-editor-surface .ql-editor {
  min-height: 260px;
  font-size: .95rem;
}
/* The content_type radios read as a compact inline switch, not a tall list. */
ul#id_content_type, #id_content_type {
  list-style: none;
  display: flex;
  gap: 1rem;
  padding: 0;
  margin: .2rem 0 0;
}
#id_content_type li { display: inline-flex; }
#id_content_type label { flex-direction: row; align-items: center; gap: .35rem; }

/* Rendered HTML email preview. */
.email-preview {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem 1.1rem;
  background: #fff;
}
.email-preview img { max-width: 100%; height: auto; }

/* --- Contextual image toolbar (resize / align / shape) ------------------ */
.img-toolbar {
  position: absolute;
  z-index: 1100;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 42, 67, .18);
  padding: .55rem .65rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  min-width: 280px;
}
.img-toolbar-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.img-toolbar-label {
  font-size: .75rem;
  color: #627d98;
  width: 46px;
  flex: 0 0 auto;
}
.img-toolbar .button {
  min-height: auto;
  padding: .22rem .5rem;
  font-size: .8rem;
}
.img-toolbar .img-width { flex: 1; }
.img-toolbar .img-width-val { font-size: .78rem; color: #334e68; width: 42px; text-align: right; }
.ql-editor img.img-selected { outline: 2px solid #2f6fed; outline-offset: 2px; }

.template-link-banner {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
  padding: .6rem .8rem;
  border: 1px solid #b6e3d4;
  border-radius: 8px;
  background: #f0fdf9;
  color: #0f766e;
  font-size: .9rem;
}
.template-link-banner .button {
  margin-left: auto;
  min-height: 30px;
  padding: .25rem .6rem;
}
