:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #d6dae1;
  --accent: #2f6fed;
  --accent-hover: #2458c4;
  --warn-bg: #fff4e5;
  --warn-border: #f5b54a;
  --ok-bg: #eaf6ee;
  --ok-border: #5bb57a;
  --visited: #7a8599;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { margin: 0 0 4px; font-size: 1.7rem; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
.hint { color: var(--muted); margin: 0 0 16px; font-size: 0.9rem; }
.hint code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 0.85rem; color: var(--text); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  min-width: 200px;
}
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field.grow { flex: 1; }

input[type="text"], select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
fieldset:disabled { opacity: 0.5; }

.btn {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  margin-bottom: 12px;
}
.btn:hover:not(:disabled) { background: #eef1f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn.small { padding: 3px 10px; font-size: 0.85rem; margin: 0; }

.toolbar {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #f0f2f5;
}
.toolbar button {
  font: inherit;
  min-width: 34px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
.toolbar button:hover:not(:disabled) { background: #fff; border-color: var(--border); }
.toolbar button.active { background: #dce6fb; border-color: #a9c1f5; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

.editor {
  min-height: 300px;
  max-height: 70vh;
  overflow: auto;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  background: #fff;
  outline: none;
}
.editor:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #2f6fed22; }
.editor:empty::before { content: "Write your email here. Use + Insert to add column tags like {{Name}}."; color: var(--muted); }
.editor p, .editor div { margin: 0; }

.notice {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--ok-border);
  background: var(--ok-bg);
  margin-bottom: 12px;
  font-size: 0.92rem;
}
.notice.warn { border-color: var(--warn-border); background: var(--warn-bg); }

.actions { align-items: center; }
.actions .btn { margin-bottom: 0; }
.dirty { color: #b25e00; font-size: 0.9rem; }

details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.table-wrap { overflow: auto; max-height: 320px; margin-top: 8px; border: 1px solid var(--border); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { padding: 4px 8px; border-bottom: 1px solid #eceef2; text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: #f0f2f5; }
th.email-col { background: #dce6fb; }

.results { list-style: none; margin: 0; padding: 0; }
.results li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid #eceef2;
}
.results li:last-child { border-bottom: 0; }
.results a { color: var(--accent); text-decoration: none; word-break: break-all; }
.results a:hover { text-decoration: underline; }
.results li.opened a { color: var(--visited); }
.results li.opened a::after { content: " ✓"; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: 360px;
  padding: 10px 14px;
  background: #1d2330;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 20px #0003;
  font-size: 0.9rem;
}
