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

:root {
  --navy: #1B3A6B;
  --navy-dk: #0f2244;
  --red: #B22234;
  --red-dk: #8B1A28;
  --gold: #C9A84C;
  --gold-lt: #E8C96A;
  --cream: #F8F4ED;
  --cream-dk: #EDE7DA;
  --dark: #1a1a1a;
  --maxw: 960px;
}

body {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  margin: 0;
  background: var(--cream);
  color: var(--dark);
  line-height: 1.6;
}

h1, h2, h3 { font-family: 'Playfair Display', serif; color: var(--navy); line-height: 1.2; }
h1 { font-size: 2rem; font-weight: 900; margin: 0 0 6px; }
h2 { font-size: 1.3rem; font-weight: 700; margin: 0 0 6px; }
a { color: var(--navy); }

/* ── Masthead ─────────────────────────────────────────── */
.nav {
  background: var(--navy-dk);
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 2px 16px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 64px;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
  color: #fff;
  font-weight: 700;
}
.nav-crest {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', serif;
  font-size: .8rem; font-weight: 900; color: #fff;
}
.nav-brand-text { font-family: 'Playfair Display', serif; font-size: 1.05rem; }
.nav a, .nav button {
  color: rgba(255,255,255,.82);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 8px 6px;
  transition: color .15s;
}
.nav a:hover, .nav button:hover { color: var(--gold); }
.nav-logout { display: inline; margin: 0; }

/* ── Page shell ───────────────────────────────────────── */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 40px 24px 64px; }
.gold-bar { display: block; width: 48px; height: 4px; background: var(--gold); margin: 10px 0 28px; border-radius: 2px; }

/* ── Flash messages ───────────────────────────────────── */
.flash { padding: 12px 18px; border-radius: 4px; margin-bottom: 20px; font-size: .95rem; border-left: 4px solid; }
.flash-success { background: #eaf5ec; color: #1e6b34; border-color: #2e8b46; }
.flash-error { background: #fbeceb; color: #922; border-color: var(--red); }

/* ── Buttons ──────────────────────────────────────────── */
button, .btn {
  display: inline-block;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 700;
  font-size: .92rem;
  letter-spacing: .02em;
  border: none;
  border-radius: 4px;
  padding: 10px 22px;
  cursor: pointer;
  background: var(--gold);
  color: var(--navy-dk);
  transition: transform .15s, box-shadow .15s, background .15s;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--gold-lt); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(201,168,76,.4); }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--navy); outline-offset: 2px;
}
.btn-quiet { background: none; color: var(--navy); padding: 6px 10px; font-weight: 600; box-shadow: none; }
.btn-quiet:hover { background: var(--cream-dk); transform: none; box-shadow: none; }
.btn-danger { background: none; color: var(--red); padding: 6px 10px; font-weight: 600; box-shadow: none; }
.btn-danger:hover { background: #fbeceb; transform: none; box-shadow: none; color: var(--red-dk); }

/* ── Forms ────────────────────────────────────────────── */
label { display: block; margin-bottom: 16px; font-weight: 600; font-size: .92rem; color: var(--navy); }
input[type=text], input[type=email], input[type=password], select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,168,76,.25); outline: none; }
input[type=file] { padding: 8px 0; border: none; }
.card-form {
  background: #fff; border-radius: 6px; padding: 28px 32px; max-width: 440px;
  box-shadow: 0 2px 16px rgba(0,0,0,.08); border-top: 4px solid var(--navy);
}

/* ── Login screen ─────────────────────────────────────── */
.login-shell { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 64px); }
.login-card { background: #fff; border-radius: 8px; padding: 40px 36px; width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(15,34,68,.16); border-top: 5px solid var(--gold); }
.login-crest { width: 56px; height: 56px; border-radius: 50%; background: var(--red); border: 3px solid var(--gold); display: flex; align-items: center; justify-content: center; font-family: 'Playfair Display', serif; font-size: 1.1rem; font-weight: 900; color: #fff; margin: 0 auto 16px; }
.login-card h1 { text-align: center; }
.login-sub { text-align: center; color: #777; font-size: .88rem; margin-bottom: 24px; }

/* ── Tables (contacts, history) ───────────────────────── */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 6px; overflow: hidden; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
thead th {
  background: var(--navy); color: #fff;
  font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  text-align: left; padding: 12px 16px;
}
tbody td { padding: 12px 16px; font-size: .95rem; border-bottom: 1px solid #eee; }
tbody tr:nth-child(even) { background: var(--cream); }
tbody tr:last-child td { border-bottom: none; }
tbody form { display: inline; }

/* ── Toolbar row above lists ──────────────────────────── */
.list-actions { display: flex; gap: 8px; margin-bottom: 20px; }

/* ── Template gallery ─────────────────────────────────── */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.template-card {
  display: block; background: #fff; border-radius: 6px; padding: 22px 24px;
  text-decoration: none; color: var(--dark);
  border-top: 4px solid var(--navy);
  box-shadow: 0 2px 14px rgba(0,0,0,.07);
  transition: transform .18s, box-shadow .18s;
}
.template-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(0,0,0,.12); }
.template-card h2 { margin-bottom: 8px; }
.template-card p { color: #666; font-size: .9rem; margin: 0; }

/* ── Compose editor ───────────────────────────────────── */
.editor-toolbar {
  display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px;
  background: var(--cream-dk); border: 1px solid #d8d0c2; border-bottom: none;
  border-radius: 6px 6px 0 0; padding: 8px;
}
.editor-toolbar button {
  background: #fff; color: var(--navy); border: 1px solid #d8d0c2;
  border-radius: 4px; padding: 6px 12px; font-size: .85rem; font-weight: 700;
  box-shadow: none;
}
.editor-toolbar button:hover { background: #fff; border-color: var(--gold); transform: none; box-shadow: none; }
.editor-toolbar button.is-active { background: var(--navy); border-color: var(--navy); color: #fff; }
.editor-toolbar button:disabled { opacity: .4; cursor: not-allowed; }
.editor-toolbar button:disabled:hover { border-color: #d8d0c2; }
.toolbar-sep { width: 1px; align-self: stretch; background: #d8d0c2; margin: 2px 4px; }

#editor {
  background: #fff; border: 1px solid #d8d0c2; border-radius: 0 0 6px 6px;
  padding: 24px 28px; margin-bottom: 20px; min-height: 320px;
  box-shadow: 0 2px 14px rgba(0,0,0,.05);
}
#editor .ProseMirror { outline: none; min-height: 268px; font-size: 1.02rem; }
#editor .ProseMirror:focus { box-shadow: inset 0 0 0 2px var(--gold); border-radius: 3px; }
#editor .ProseMirror h1, #editor .ProseMirror h2, #editor .ProseMirror h3 { color: var(--navy); }
#editor .ProseMirror a { color: var(--navy); text-decoration: underline; }
#editor .ProseMirror img { max-width: 100%; border-radius: 4px; margin: 8px 0; }
#editor .ProseMirror blockquote { border-left: 3px solid var(--gold); margin: 0; padding: 2px 0 2px 16px; color: #555; font-style: italic; }
#editor .ProseMirror ul, #editor .ProseMirror ol { padding-left: 24px; }
#image_input { margin: 0; }

.compose-meta { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: end; margin-bottom: 20px; }
@media (max-width: 640px) { .compose-meta { grid-template-columns: 1fr; } }

/* ── Send status ──────────────────────────────────────── */
.status-card { background: #fff; border-radius: 6px; padding: 28px 32px; box-shadow: 0 2px 14px rgba(0,0,0,.06); border-top: 4px solid var(--gold); }
.status-bar { background: var(--cream-dk); border-radius: 999px; height: 10px; overflow: hidden; margin-top: 16px; }
.status-bar-fill { background: var(--gold); height: 100%; transition: width .4s ease; }
#status-label { font-weight: 600; color: var(--navy); }

/* ── Unsubscribe (standalone page) ────────────────────── */
.center-card {
  max-width: 440px; margin: 12vh auto; background: #fff; border-radius: 8px;
  padding: 40px; text-align: center; box-shadow: 0 8px 32px rgba(15,34,68,.14);
  border-top: 5px solid var(--gold);
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 640px) {
  .nav { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 4px 16px; }
  .nav-brand { width: 100%; margin-bottom: 4px; }
  table, thead, tbody, tr { display: block; }
  thead { display: none; }
  tbody tr { border-bottom: 8px solid var(--cream); padding: 8px 0; }
  tbody td { display: flex; justify-content: space-between; gap: 12px; border-bottom: none; padding: 6px 16px; }
  tbody td::before { content: attr(data-label); font-weight: 700; color: var(--navy); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
}
