:root {
  --bg: #f7f7f5;
  --fg: #1c1c1a;
  --muted: #6b6b66;
  --rule: #e2e2dc;
  --accent: #2f5d50;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #ececea;
    --muted: #9a9a94;
    --rule: #2c2c2a;
    --accent: #8fc2b1;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 4rem 1.25rem;
}
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 0.5rem; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.5rem; }
p, li { color: var(--fg); }
.muted { color: var(--muted); }
a { color: var(--accent); }
footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--muted);
}

/* Dashboard */
:root { --danger: #a33a2c; --flash: #e7f0ec; --flash-error: #f6e4e1; --surface: #ffffff; }
@media (prefers-color-scheme: dark) {
  :root { --danger: #e08a7d; --flash: #1f2e29; --flash-error: #3a2320; --surface: #1e1e1d; }
}
main:has(.topbar) { padding-top: 1.5rem; }
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--rule);
}
.brand { font-weight: 600; color: var(--fg); text-decoration: none; }
.inline { display: flex; gap: 0.75rem; align-items: center; margin: 0; }
.small { font-size: 0.875rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.flash { padding: 0.6rem 0.9rem; border-radius: 6px; background: var(--flash); }
.flash.error { background: var(--flash-error); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form { margin: 0; }
label { font-weight: 600; display: block; }
.connect .row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
input, select, textarea {
  flex: 1 1 12rem;
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
}
button, .button {
  font: inherit;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; padding: 0.3rem 0.7rem; font-size: 0.875rem; }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* App shell: left nav */
.app { display: flex; min-height: 100vh; }
.sidebar {
  flex: 0 0 14rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--rule);
  background: var(--surface);
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { padding: 0 0.5rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar nav a {
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
}
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--flash); color: var(--accent); font-weight: 600; }
.signout { margin-top: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; padding: 0 0.5rem; }
.content { flex: 1; min-width: 0; max-width: 56rem; padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; }
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { position: static; height: auto; flex-basis: auto; border-right: 0; border-bottom: 1px solid var(--rule); gap: 0.75rem; padding: 1rem; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .signout { margin-top: 0; flex-direction: row; align-items: center; gap: 0.75rem; }
}

/* Panels, headings, forms */
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
}
.panel h2 { margin-top: 0; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; }
.page-head h1, .page-head h2 { margin: 0; }
.crumbs { margin: 0 0 0.25rem; font-size: 0.875rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row form { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field p { margin: 0; }
.field input, .field select, .field textarea { flex: none; width: 100%; }
.label { font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.1rem; }
.checks { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
label.check { font-weight: normal; display: inline-flex; align-items: center; gap: 0.5rem; }
label.check input { flex: none; width: auto; }
textarea { font: 0.9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.connect { margin-top: 1.25rem; }
.connect p { margin: 0.25rem 0 0.5rem; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid currentColor; }
.error-text { color: var(--danger); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.5rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--rule);
  color: var(--fg);
  white-space: nowrap;
}
.badge.sent { background: var(--flash); color: var(--accent); }
.badge.failed { background: var(--flash-error); color: var(--danger); }
.badge.running { background: var(--flash); }
.badge.off, .badge.skipped, .badge.previewed { background: var(--rule); color: var(--muted); }

/* Email preview */
.email-preview {
  width: 100%;
  min-height: 70vh;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: #fff;
}
.nowrap { white-space: nowrap; }
