:root {
  --bg: #f4f1eb;
  --surface: #fffef9;
  --ink: #1a1a1a;
  --muted: #5c5852;
  --accent: #c45c26;
  --accent-dim: #9a4720;
  --border: #dcd6cc;
  --error: #a42020;
  --radius: 8px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.masthead {
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.tab,
.mini-tab {
  font: inherit;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

.tab.is-active,
.mini-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panels,
.preview-panels {
  display: block;
}

.tab-panel,
.preview-panel,
.builder-subpanel {
  display: none;
}

.tab-panel.is-active,
.preview-panel.is-active,
.builder-subpanel.is-active {
  display: block;
}

.masthead h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font);
  font-size: clamp(1.75rem, 3vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  color: var(--muted);
  max-width: 42rem;
}

.layout {
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.layout-settings {
  grid-template-columns: 1.05fr 0.95fr;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.panel h2 {
  margin: 0 0 1rem;
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 600;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.field-note {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.req {
  color: var(--accent);
}

.hint {
  font-weight: 500;
  color: var(--muted);
}

input[type="text"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 2.5rem;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.grid-2 {
  display: grid;
  gap: 1rem;
}

@media (min-width: 520px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.seed-row .seed-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.seed-row .seed-controls input {
  flex: 1;
  min-width: 140px;
}

.seed-auto-randomize {
  margin-top: 0.5rem;
  color: var(--text-muted, #666);
  font-size: 0.85rem;
}

.checks {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
}

.checks legend {
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0 0.35rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.check:first-of-type {
  margin-top: 0.35rem;
}

.check input {
  margin-top: 0.2rem;
}

.output-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.output-head h2 {
  margin-bottom: 0;
}

.char-count {
  font-size: 0.8rem;
  color: var(--muted);
}

.form-error {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  color: var(--error);
}

.output-text {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  min-height: 320px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.actions-top {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.preview-shell {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.preview-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.preview-frame {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.preview-text {
  min-height: 520px;
}

.saved-list {
  display: grid;
  gap: 0.85rem;
}

.saved-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.7);
}

.saved-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.saved-meta,
.saved-empty {
  color: var(--muted);
  font-size: 0.875rem;
}

.saved-snippet {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.plain-list {
  margin: 0;
  padding-left: 1.1rem;
}

.plain-list li + li {
  margin-top: 0.45rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-dim);
}

.btn.secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--ink);
}

.btn.secondary:hover {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Offline banner */
.offline-banner {
  background: #7a2a00;
  color: #fff;
  text-align: center;
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
}

.offline-banner code {
  background: rgba(255, 255, 255, 0.18);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-family: ui-monospace, "Cascadia Code", monospace;
}

/* Form status messages */
.form-info {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  color: #2a6e2a;
}

/* Variation fingerprint */
.variation-fingerprint {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}
.fp-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.2rem;
}
.fp-tag {
  font-size: 0.75rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}
.fp-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.fp-tag--brand {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #065f46;
  font-weight: 600;
}
.fp-tag--ai {
  background: #fef9c3;
  border-color: #fde047;
  color: #713f12;
  font-weight: 600;
}
.fp-tag--seeded {
  color: var(--muted);
}

.brand-color-status {
  margin-top: 0.3rem;
}
.brand-color-status--ok {
  color: #065f46;
}
.brand-color-status--ai {
  color: #713f12;
}

/* Auto-save draft status */
.draft-status {
  font-size: 0.8rem;
  color: var(--muted);
  align-self: center;
  flex: 1;
}

/* Saved card layout */
.saved-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.saved-card-head h3 {
  margin: 0;
  font-size: 1rem;
}

.saved-meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0.4rem 0 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.saved-meta-grid dt {
  font-weight: 600;
  color: var(--ink);
}

/* Campaign ID row in saved cards */
.saved-id-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.saved-id-code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  color: var(--ink-muted, #666);
  background: var(--surface, #f5f5f5);
  border: 1px solid var(--border, #ddd);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  word-break: break-all;
}

.btn-copy-id {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border, #ddd);
  background: transparent;
  color: var(--ink-muted, #666);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.5;
  transition: background 0.15s, color 0.15s;
}

.btn-copy-id:hover {
  background: var(--accent, #0070f3);
  color: #fff;
  border-color: var(--accent, #0070f3);
}

/* Code block in settings */
.code-block {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.85rem;
  background: #f0ece4;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}

/* Import label acts like a button */
.import-label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

/* ── AI features ─────────────────────────────────────────────────────────── */

/* AI action buttons — distinct amber/gold tint */
.btn.ai-btn {
  background: #fff8ec;
  border-color: #d4960a;
  color: #7a5500;
}

.btn.ai-btn:hover {
  background: #fef0cc;
  border-color: #b87d00;
}

.btn.ai-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Inline AI suggest button next to field labels */
.label-with-action {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.label-with-action label {
  margin-bottom: 0;
}

.btn-ai-inline {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  border: 1px solid #d4960a;
  background: #fff8ec;
  color: #7a5500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-ai-inline:hover {
  background: #fef0cc;
}

.btn-ai-inline:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* AI Quick Brief collapsible */
.ai-brief-box {
  margin-bottom: 1.25rem;
  border: 1px solid #d4960a;
  border-radius: var(--radius);
  background: #fffdf5;
}

.ai-brief-toggle {
  padding: 0.65rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
  color: #7a5500;
  user-select: none;
}

.ai-brief-toggle::-webkit-details-marker { display: none; }

.ai-brief-toggle::before {
  content: "▶ ";
  font-size: 0.7rem;
  transition: transform 0.15s;
}

details[open] .ai-brief-toggle::before {
  content: "▼ ";
}

.ai-brief-body {
  padding: 0 0.9rem 0.9rem;
  border-top: 1px solid #f0dfa0;
}

.ai-brief-body .field {
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
}

/* AI result panels */
.ai-panel {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf8;
  overflow: hidden;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: #f0ece4;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.btn-close {
  font: inherit;
  font-size: 1rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0 0.25rem;
  line-height: 1;
}

.btn-close:hover { color: var(--ink); }

.ai-panel-text {
  margin: 0;
  padding: 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
  max-height: 340px;
  overflow-y: auto;
}

/* Variant switcher for multi-preview */
.variant-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: #f5f2ea;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.variant-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-right: 0.2rem;
}

.variant-switcher .btn {
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 2.5rem;
}

.variant-switcher .btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.variant-seed-chip {
  font-size: 0.72rem;
  font-family: monospace;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  align-self: center;
  white-space: nowrap;
}

.btn-use-variation {
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.btn-use-variation:hover {
  background: var(--accent);
  color: #fff;
}

.btn.btn-danger {
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn.btn-danger:hover {
  background: #fff5f5;
  border-color: #b91c1c;
}

/* ── Seed Checker ─────────────────────────────────────────────────────────── */

.sc-suggestion-bank {
  background: #fffbf0;
  border: 2px solid #e0c76b;
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
  margin-bottom: 1.5rem;
}

.sc-bank-title {
  font-size: 1rem;
  font-family: var(--font);
}

.sc-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-ui);
  margin-left: 0.5rem;
}

.sc-bank-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.sc-bank-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.sc-bank-item-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

.sc-bank-item-title {
  font-size: 0.9rem;
  font-weight: 600;
}

/* Email list */
.sc-email-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.sc-email-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
}

.sc-email-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.sc-email-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.sc-email-subject {
  font-size: 0.95rem;
  line-height: 1.3;
  word-break: break-word;
}

.sc-email-from {
  font-size: 0.82rem;
  color: var(--muted);
}

/* Spam score badge */
.sc-score-badge {
  flex-shrink: 0;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font-ui);
  white-space: nowrap;
}

.sc-score--green   { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.sc-score--yellow  { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.sc-score--red     { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.sc-score--unknown { background: #f1f5f9; color: var(--muted); border: 1px solid var(--border); }

/* SpamAssassin rules collapsible */
.sc-sa-details {
  margin-top: 0;
}

.sc-sa-details > summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.3rem 0;
  user-select: none;
}

.sc-sa-details > summary:hover { color: var(--ink); }

.sc-sa-rules {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
  background: #f8f7f3;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
}

.sc-sa-rule {
  display: grid;
  grid-template-columns: 10rem 4rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.82rem;
}

.sc-rule-name {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--ink);
  word-break: break-all;
}

.sc-rule-score {
  font-family: monospace;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: right;
}

.sc-rule-score--pos { color: #b91c1c; }
.sc-rule-score--neg { color: #166534; }

.sc-rule-desc {
  color: var(--muted);
  font-size: 0.8rem;
}

/* Flags */
.sc-flags {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.sc-flag {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.sc-flag--high   { border-left-color: #ef4444; }
.sc-flag--medium { border-left-color: #f59e0b; }
.sc-flag--low    { border-left-color: #6b7280; }
.sc-flag--approved { opacity: 0.7; }

.sc-flag-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.sc-flag-title {
  font-size: 0.9rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.sc-flag-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  line-height: 1.5;
}

.sc-flag-suggestion {
  background: #f0f9f4;
  border: 1px solid #86efac;
  border-radius: 5px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.6rem;
}

.sc-suggestion-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: #166534;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sc-suggestion-text {
  font-size: 0.85rem;
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}

.sc-flag-approved-note {
  font-size: 0.82rem;
  color: #166534;
  font-weight: 600;
  padding: 0.2rem 0;
}

/* Category badges */
.sc-cat-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sc-cat--spam      { background: #fee2e2; color: #991b1b; }
.sc-cat--link      { background: #fef3c7; color: #92400e; }
.sc-cat--copy      { background: #ede9fe; color: #5b21b6; }
.sc-cat--html      { background: #dbeafe; color: #1e40af; }
.sc-cat--auth      { background: #fce7f3; color: #9d174d; }
.sc-cat--creative  { background: #d1fae5; color: #065f46; }
.sc-cat--delivery  { background: #e0f2fe; color: #075985; }

/* Severity badges */
.sc-sev-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-ui);
  text-transform: uppercase;
}

.sc-sev--high   { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.sc-sev--medium { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.sc-sev--low    { background: #f8fafc; color: #475569; border: 1px solid #cbd5e1; }
