:root {
  /* Palette sampled from the HappyDM logo.
     Orange #F5821F is the speech-bubble fill (brand accent, logo, yellow
     highlights). Cyan #00A5C1 to blue #008BC7 are the "y". Primary buttons
     use a slightly darkened aqua gradient #007DA8 → #00779F with white text
     so both ends meet WCAG AA (4.67:1 and 5.07:1). Exact logo aqua with
     white is too light (2.94–3.81:1). --blue is #0077B0 for AA links. */
  --orange: #F5821F;
  --orange-deep: #F26322;
  --yellow: #FAA919;
  --yellow-bright: #FCBE12;
  --cyan: #00A5C1;
  --blue-logo: #008BC7;
  --blue: #0077B0;
  --blue-deep: #006A9A;
  --aqua-btn-start: #007DA8;
  --aqua-btn-end: #00779F;
  --aqua-btn-hover: #006F94;
  --bg: #FBF6F0;
  --bg-deep: #F3EBE1;
  --surface: #FFFCF8;
  --surface-2: #FFF6EC;
  --ink: #2A211A;
  --ink-soft: #6D5E52;
  --ink-faint: #8E7F72;
  --line: #E8D9C8;
  --line-strong: #D9C4AE;
  --accent: var(--blue-logo);
  --accent-deep: var(--blue-deep);
  --accent-soft: #D8F1F6;
  --gold: #8A5A12;
  --gold-soft: #FFE9C2;
  --green: #276849;
  --green-soft: #D7F0E2;
  --rose: #8F2E2E;
  --rose-soft: #F9E3E0;
  --paused: #5C534C;
  --info: var(--blue-deep);
  --info-soft: #E5F4FA;
  --shadow: 0 12px 32px rgba(245, 130, 31, 0.12);
  --shadow-soft: 0 4px 14px rgba(42, 33, 26, 0.06);
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --display: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 8% -10%, rgba(250, 169, 25, 0.14) 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(0, 165, 193, 0.18) 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible {
  outline: 3px solid rgba(0, 139, 199, 0.70);
  outline-offset: 2px;
}
a:not(.btn) { color: var(--blue); }
[hidden] { display: none !important; }
::placeholder { color: #b3a396; font-weight: 500; opacity: 1; }

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
  min-height: 60px; padding: 10px 28px;
  background: rgba(255, 252, 248, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; flex-shrink: 0; }
.brand-wordmark { display: block; height: 40px; width: auto; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--gold-soft); color: var(--ink);
  padding: 3px 8px; border-radius: 999px;
}
.account {
  margin-left: auto;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 650;
}
.account small { display: block; font-weight: 500; color: var(--ink-faint); font-size: 11px; }
.account .handle { display: block; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(160deg, #efc39a, #c98452);
  color: #5a3418; display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  border: 2px solid #fff;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2f8a57; box-shadow: 0 0 0 4px rgba(47, 138, 87, 0.16);
}
.dot.off { background: #b9a99a; box-shadow: 0 0 0 4px rgba(185, 169, 154, 0.2); }

main { max-width: 1120px; margin: 0 auto; padding: 14px 24px 40px; }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 14px; border-radius: 14px; margin-bottom: 12px;
  font-size: 14px; font-weight: 650;
}
.banner .spacer { flex: 1; }
.banner .pulse {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: #d23a3a;
  box-shadow: 0 0 0 5px rgba(210, 58, 58, 0.16);
}
.banner.off { background: var(--info-soft); color: var(--info); border: 1px solid #b7dbe8; }
.banner.on { background: var(--rose-soft); color: var(--rose); border: 1px solid #f0c7c2; }

.flash { margin: 0 0 16px; font-size: 14px; font-weight: 650; }
.flash.ok { color: #176b2c; } .flash.bad { color: var(--rose); }
.panel.bad {
  background: var(--rose-soft); color: var(--rose);
  border: 1px solid #f0c7c2; border-radius: 14px;
  padding: 12px 16px; margin-bottom: 16px; font-weight: 650;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 20px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-soft);
}
.card > h2, .page-head h2 {
  font-family: var(--display);
  font-size: 24px; font-weight: 600; letter-spacing: -0.03em;
  margin: 0 0 8px;
}
.note { color: var(--ink-soft); font-size: 14px; margin: 0; }
.connect-row { margin: 12px 0; }
#connection { font-size: 14px; }
#connection strong { font-weight: 700; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: nowrap; margin-bottom: 10px;
}
.page-head .btn { flex-shrink: 0; margin-top: 2px; }
.page-head h2 { margin: 0 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 0; border-radius: 10px;
  font-weight: 700; font-size: 13px; text-decoration: none;
  background: var(--ink); color: #fff; cursor: pointer;
}
.btn.primary {
  background: linear-gradient(180deg, var(--aqua-btn-start) 0%, var(--aqua-btn-end) 100%);
  color: #fff;
  box-shadow: 0 4px 10px rgba(0, 125, 168, 0.28);
}
.btn.primary:hover { background: var(--aqua-btn-hover); }
.btn.secondary { background: #fff; color: var(--rose); border: 1px solid #e8b8b2; }
.btn.danger { background: #fff; color: var(--rose); border: 1px solid #e8b8b2; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line-strong); }
.btn.disabled, .btn:disabled { background: #cbbfb4; color: #fff; pointer-events: none; box-shadow: none; }

.empty { color: var(--ink-soft); font-size: 14px; padding: 8px 0 12px; }

.inbox {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #fff;
}
.rules-head, .rule-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1.3fr) minmax(7rem, 1fr) 118px 0.7fr 0.85fr minmax(8rem, 1.2fr);
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
}
.rules-head {
  text-align: left; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.rule-row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 0;
}
.rule-row:last-child { border-bottom: 0; }
.rule-row:hover { background: #fbf6f0; }
.rule-row.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--blue-logo); }
.rule-row:focus-visible { outline-offset: -3px; }
.kw {
  font-weight: 750; letter-spacing: -0.02em;
  display: inline-flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.matchpill {
  font-size: 11px; font-weight: 650; color: var(--ink-soft);
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px;
  justify-self: start;
}
.rule-row.selected .matchpill { border-color: #e0b089; }
.status-cell { display: flex; align-items: center; gap: 8px; }
.nums { color: var(--ink-soft); font-size: 13px; }
.nums strong { color: var(--ink); }
.linkcell { color: var(--ink-soft); font-size: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn-chip {
  display: inline-block; font-size: 11px; font-weight: 750;
  border: 1px solid var(--line-strong); background: #fff;
  border-radius: 7px; padding: 1px 6px; color: var(--ink);
}

.status {
  font-size: 11px; font-weight: 800; letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 999px; border: 0;
  min-width: 5.8em; text-align: center; box-sizing: border-box;
}
.status.on { background: var(--green-soft); color: var(--green); }
.status.off { background: #eee8e2; color: var(--paused); }

.toggle {
  position: relative; width: 42px; height: 24px; border-radius: 999px; border: 0;
  background: #d8cfc6; flex-shrink: 0; padding: 0;
}
.toggle.on { background: var(--green); }
.toggle i {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  transition: left 0.15s ease;
}
.toggle.on i { left: 21px; }
.toggle:disabled { cursor: default; opacity: 0.7; }
@media (prefers-reduced-motion: reduce) {
  .toggle i { transition: none; }
}

.tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--gold-soft); color: var(--gold);
  padding: 2px 7px; border-radius: 6px;
}

.flow {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 16px 12px;
}
.flow-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.flow-head h3 {
  font-family: var(--display);
  font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
  margin: 0;
}
.flow-head p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.dirty { font-size: 12px; font-weight: 700; color: var(--gold); }

.steps {
  display: grid;
  grid-template-columns: 1fr 28px 1fr 28px 1fr;
  gap: 0;
  align-items: stretch;
}
.step {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.step h4 {
  margin: 0; display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 750;
}
.num {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(180deg, var(--aqua-btn-start) 0%, var(--aqua-btn-end) 100%); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; flex-shrink: 0;
}
.blurb { font-size: 12px; color: var(--ink-soft); margin: 0; line-height: 1.4; }
.arrow {
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 20px; font-weight: 800;
}

label.field, label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; font-weight: 650; color: var(--ink-soft);
}
.field input, .field select, .field textarea,
label input, label select, label textarea {
  width: 100%; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 10px; padding: 9px 11px; font-weight: 500; color: var(--ink);
  outline: none;
}
.field textarea, label textarea { resize: vertical; line-height: 1.45; min-height: 3.6em; }
.field-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.step .field-top { flex-direction: column; align-items: stretch; gap: 2px; }
.count { font-size: 11px; font-weight: 500; color: var(--ink-faint); margin-left: auto; }
.step .count { margin-left: 0; line-height: 1.35; }
.count.over { color: var(--rose); font-weight: 700; }
.field-err { color: var(--rose); font-size: 12px; font-weight: 650; }

.flow-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-top: 10px;
}
.flow-actions .btn.primary, .flow-actions #save-rule { margin-left: auto; }
.tiny { font-size: 12px; color: var(--ink-faint); }
.msg { font-size: 13px; font-weight: 650; }
.msg.ok { color: #176b2c; } .msg.bad { color: var(--rose); }

#events { padding: 0; margin: 8px 0 0; list-style: none; font-size: 14px; }
#events li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}
#events li:last-child { border-bottom: 0; }

@media (max-width: 840px) {
  .steps { grid-template-columns: 1fr; gap: 6px; }
  .arrow { transform: rotate(90deg); height: 20px; }
  .rules-head { display: none; }
  .rule-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "kw status"
      "match status"
      "dms week"
      "link link";
    padding: 12px 14px;
    gap: 6px 10px;
  }
  .rule-row .kw { grid-area: kw; }
  .rule-row .matchpill { grid-area: match; }
  .rule-row .status-cell { grid-area: status; justify-self: end; }
  .rule-row .nums.total { grid-area: dms; }
  .rule-row .nums.week { grid-area: week; }
  .rule-row .linkcell { grid-area: link; }
  .rule-row .nums.total::before { content: "DMs sent "; }
  .rule-row .nums.week::before { content: "Last 7 days "; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .brand-wordmark { height: 32px; }
  main { padding: 12px 14px 32px; }
  .card { padding: 14px 14px 16px; }
  .flow { padding: 12px; }
  .page-head { flex-wrap: wrap; }
  .flow-actions .btn.primary, .flow-actions #save-rule { margin-left: 0; width: 100%; }
  .flow-actions #delete-rule { width: 100%; }
}

/* ---- sign-in ---- */
.header-actions { display: flex; align-items: center; margin-left: 12px; }
.header-actions:empty { display: none; }
.btn.signout { padding: 6px 12px; font-size: 13px; }
.signin-card { max-width: 460px; margin: 6vh auto 0; text-align: center; padding: 36px 32px 28px; }
.signin-card h2 { font-family: var(--display); font-size: 26px; margin: 16px 0 6px; }
.signin-logo { display: block; width: min(320px, 100%); height: auto; margin: 0 auto 8px; }
.signin-lead { color: var(--ink-soft); margin: 0 0 18px; }
.signin-note { background: var(--gold-soft); color: var(--ink); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.btn.signin-btn { display: inline-block; font-size: 16px; padding: 12px 22px; margin: 6px 0 16px; }
.signin-card .note { font-size: 13px; color: var(--ink-faint); text-align: left; }
#auth-msg .btn { margin-left: 8px; }
.account:empty + .header-actions { margin-left: auto; }

/* ---- billing: plan picker + banner ---- */
.banner.billing.info { background: var(--accent-soft); color: var(--blue-deep); border: 1px solid #a9dce7; }
.banner.billing.warn { background: var(--gold-soft); color: var(--gold); border: 1px solid #f1cf8c; }
.banner.billing.bad { background: var(--rose-soft); color: var(--rose); border: 1px solid #f0c7c2; }
.banner.billing .btn { padding: 6px 12px; font-size: 13px; }
.plans-card { max-width: 620px; margin: 4vh auto 0; text-align: center; padding: 32px 28px 24px; }
.plans-card h2 { font-family: var(--display); font-size: 26px; margin: 0 0 6px; }
.plans-lead { color: var(--ink-soft); margin: 0 0 20px; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.plan {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px 14px 18px; border-radius: 16px; cursor: pointer; font: inherit; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.plan:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.plan:focus-visible { outline: 3px solid rgba(0, 139, 199, .55); outline-offset: 2px; }
.plan.selected { border-color: var(--aqua-btn-start); box-shadow: 0 6px 18px rgba(0, 125, 168, .18); background: #fff; }
.plan-name { font-weight: 750; font-size: 15px; }
.plan-price { font-family: var(--display); font-size: 34px; font-weight: 800; line-height: 1.1; }
.plan-price small { font-size: 15px; font-weight: 650; color: var(--ink-soft); margin-left: 2px; }
.plan-note { font-size: 13px; color: var(--ink-faint); }
.plan-badge {
  position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
  background: var(--orange); color: #2A211A; font-size: 11px; font-weight: 800; letter-spacing: .02em;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.plans-trial { font-size: 14px; color: var(--ink-soft); min-height: 1em; margin: 4px 0 14px; }
.btn.plans-cta { font-size: 16px; padding: 12px 26px; }
.plans-card .msg { margin-top: 10px; }
.plans-card .note { font-size: 12.5px; color: var(--ink-faint); margin-top: 14px; }
@media (max-width: 520px) { .plans { grid-template-columns: 1fr; gap: 18px; } }
