:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #5e6a7e;
  --line: #d8dee8;
  --blue: #2346a0;
  --blue-soft: #e4eaf8;
  --red: #b42318;
  --red-soft: #fbe9e7;
  --green: #157347;
  --green-soft: #e3f3ea;
  --amber: #a15c07;
  --amber-soft: #fdf0dc;
  --radius-s: 4px;
  --radius-m: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151f; --surface: #182030; --ink: #e6eaf2; --muted: #9aa5b8; --line: #2a3446;
    --blue: #7d9bf0; --blue-soft: #1f2b4a; --red: #f08a7e; --red-soft: #3a1f1f;
    --green: #6fcf9b; --green-soft: #173327; --amber: #f0b45e; --amber-soft: #36290f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif; line-height: 1.5; }
a { color: var(--blue); text-underline-offset: 2px; }
code { background: var(--blue-soft); padding: 1px 5px; border-radius: var(--radius-s); font-size: .9em; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand strong { display: block; font-size: .95rem; line-height: 1.2; }
.brand small { color: var(--muted); }
/* airmail stamp: the one decorative element */
.stamp { width: 30px; height: 36px; flex: none; border-radius: 3px; background:
  repeating-linear-gradient(135deg, var(--red) 0 6px, var(--surface) 6px 12px, var(--blue) 12px 18px, var(--surface) 18px 24px); box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 1px var(--line); }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: var(--radius-s); display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: var(--bg); }
.side nav a.on { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.count { background: var(--red); color: #fff; border-radius: 10px; font-size: .75rem; padding: 0 7px; font-weight: 600; }
.logout { margin-top: auto; color: var(--muted); font-size: .9rem; }

main { padding: 0 32px 60px; min-width: 0; max-width: 1240px; }
h1 { font-size: 1.75rem; letter-spacing: -.01em; margin: 22px 0 14px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h2.section { margin: 28px 0 10px; }
.lede { color: var(--muted); max-width: 72ch; margin: 0 0 18px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .88rem; margin: 4px 0; max-width: 72ch; }
.err-text { color: var(--red); }
.empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius-m); }
.mt { margin-top: 12px; }

/* status strip */
.statusbar { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .92rem; flex-wrap: wrap; }
.statusbar > span:nth-child(2) { flex: 1; min-width: 200px; }
.statusbar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.statusbar.is-warn .dot { background: var(--amber); }
.statusbar.is-paused .dot { background: var(--red); }
.statusbar.is-paused { color: var(--red); font-weight: 600; }
@media (prefers-reduced-motion: no-preference) { .statusbar.is-live .dot { animation: pulse 2.4s ease-in-out infinite; } }
@keyframes pulse { 50% { opacity: .35; } }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px 20px; margin-bottom: 18px; }
.card.narrow { max-width: 760px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 18px; }
.headline-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* stats: plain ledger row */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 18px; }
.stats div { padding: 14px 18px; border-right: 1px solid var(--line); }
.stats div:last-child { border-right: 0; }
.stats b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stats span { color: var(--muted); font-size: .85rem; }
.stats .warn b { color: var(--amber); }
.stats .bad b { color: var(--red); }

.todo { margin: 0; padding-left: 18px; }
.todo li { margin: 6px 0; }
.meter { margin-bottom: 12px; }
.meter-head { display: flex; justify-content: space-between; font-size: .9rem; gap: 8px; }
.meter-head span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--blue); }

/* tables */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 18px; }
.card .tablewrap { border: 0; margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.note { color: var(--muted); max-width: 320px; }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
td.actions form { margin: 0; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.s-pending, .c-draft { background: var(--amber-soft); color: var(--amber); }
.s-approved, .s-active, .c-active { background: var(--blue-soft); color: var(--blue); }
.s-replied, .s-won { background: var(--green-soft); color: var(--green); }
.s-bounced, .s-failed, .s-unsubscribed, .c-paused, .t-send_error, .t-health, .t-bounce { background: var(--red-soft); color: var(--red); }
.t-reply { background: var(--green-soft); color: var(--green); }

/* forms */
.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .92rem; }
label small { font-weight: 400; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 10px; width: 100%; }
textarea { resize: vertical; line-height: 1.45; }
input[type=checkbox] { width: auto; }
input[readonly] { background: var(--bg); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; margin: 0; }
legend { font-weight: 500; font-size: .92rem; padding: 0 4px; }
.days { display: flex; gap: 14px; flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
details summary { cursor: pointer; color: var(--blue); margin-bottom: 10px; }
details[open] { display: flex; flex-direction: column; gap: 12px; }
.formactions { display: flex; gap: 8px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; flex-wrap: wrap; }
.inline select { width: auto; }
.search { display: flex; gap: 6px; margin: 12px 0 6px; }

/* buttons */
.btn { font: inherit; font-weight: 600; font-size: .9rem; border-radius: var(--radius-s); padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10151f; } }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn.danger-ghost:hover { border-color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: .84rem; }

/* tabs, chips, bulk bar */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-color: var(--blue); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); font-size: .85rem; }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.bulkbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 10px 0; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager a { padding: 3px 9px; border: 1px solid var(--line); border-radius: var(--radius-s); text-decoration: none; }
.pager a.on { background: var(--blue); color: #fff; border-color: var(--blue); }

/* flash */
.flash { padding: 10px 14px; border-radius: var(--radius-s); margin: 14px 0 0; border-left: 4px solid; }
.flash.ok { background: var(--green-soft); border-color: var(--green); }
.flash.err { background: var(--red-soft); border-color: var(--red); }
.flash ul { margin: 6px 0 0; padding-left: 18px; }

/* email preview: looks like a letter */
.email { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 14px; max-width: 760px; overflow: hidden; }
.email header { display: flex; justify-content: space-between; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); font-size: .88rem; }
.email .subj { padding: 12px 16px 0; font-weight: 600; }
.email pre { margin: 0; padding: 10px 16px 16px; white-space: pre-wrap; word-break: break-word; font: inherit; }
pre.code { background: var(--bg); padding: 10px; border-radius: var(--radius-s); white-space: pre-wrap; word-break: break-all; font-size: .85rem; }
.step-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.reply { border-left: 4px solid var(--green); }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 6px 0 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 12px; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .logout { margin-top: 0; margin-left: auto; }
  main { padding: 0 16px 40px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .stats div { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------- v4: guidance & polish ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; border-radius: var(--radius-s); }
.skip:focus { left: 8px; }
.ic { flex: none; }
.side nav a { justify-content: flex-start; gap: 10px; }
.side nav a .count { margin-left: auto; }
.side nav a .ic { color: var(--muted); }
.side nav a.on .ic { color: var(--blue); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.side-foot .logout { margin-top: 0; padding: 0 10px; }
.linkbtn { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s); text-align: left; }
.linkbtn:hover { background: var(--bg); color: var(--ink); }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 22px 0 18px; flex-wrap: wrap; }
.pagehead h1 { margin: 0; }
.pagehead .sub { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.helpbtn { white-space: nowrap; }

/* info bubbles */
.tip { font: 600 .72rem/1 "Public Sans", system-ui, sans-serif; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; padding: 0; display: inline-grid; place-items: center; vertical-align: 1px; margin-left: 2px; }
.tip:hover, .tip[aria-expanded="true"] { border-color: var(--blue); color: var(--blue); }
.tipbubble { position: absolute; z-index: 60; background: var(--ink); color: var(--surface); padding: 10px 12px; border-radius: var(--radius-m); font-size: .86rem; line-height: 1.45; font-weight: 400; box-shadow: 0 8px 24px rgba(15, 23, 42, .18); }
label > span { display: inline-flex; align-items: center; gap: 4px; }

/* modals */
dialog.modal { border: 0; padding: 0; border-radius: 12px; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(15, 23, 42, .28); }
dialog.modal.small { width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.modal-inner { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.modal-inner header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-inner h2 { margin: 0; font-size: 1.25rem; }
.modal-inner .lede { margin: 0; }
.modal-inner footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.modal.small footer { justify-content: flex-end; }
.x { background: none; border: 0; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: var(--radius-s); }
.x:hover { color: var(--ink); background: var(--bg); }
ol.guide { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
ol.guide li { display: flex; gap: 12px; }
ol.guide .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-weight: 700; display: grid; place-items: center; font-size: .85rem; }
ol.guide p { margin: 2px 0 0; color: var(--muted); }
.callout { margin: 0; padding: 10px 12px; background: var(--amber-soft); color: var(--ink); border-radius: var(--radius-s); border-left: 3px solid var(--amber); font-size: .92rem; }
@media (prefers-reduced-motion: no-preference) { dialog.modal[open] { animation: rise .18s ease-out; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* setup checklist */
.setup { border-color: var(--blue); }
.bar.big { height: 8px; margin: 0 0 14px; }
ol.checklist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px 20px; }
ol.checklist li { display: flex; gap: 10px; align-items: flex-start; }
ol.checklist small { display: block; color: var(--muted); }
ol.checklist .tick { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .8rem; color: #fff; margin-top: 1px; }
ol.checklist li.done .tick { background: var(--green); border-color: var(--green); }
ol.checklist li.done b { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.todo li.hot a { color: var(--green); }

/* next-step banner */
.nextstep { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--blue-soft); border-radius: var(--radius-m); padding: 12px 16px; margin-bottom: 16px; flex-wrap: wrap; }
.nextstep span { color: var(--ink); }

/* sequence timeline */
.timeline { display: flex; gap: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px 14px; margin-bottom: 16px; }
.tl-item { flex: 1 0 140px; display: flex; flex-direction: column; gap: 2px; position: relative; padding-right: 14px; }
.tl-day { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); margin: 6px 0; position: relative; }
.tl-item:not(:last-child) .tl-dot::after { content: ""; position: absolute; left: 12px; top: 5px; height: 2px; width: calc(140px - 12px); background: var(--line); }
.tl-item.end .tl-dot { background: var(--muted); }
.tl-item small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

/* toasts, empty states, buttons */
.toasts:empty { display: none; }
.flash { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; transition: opacity .4s; }
.flash.fade { opacity: 0; }
.flash .x { font-size: 1.2rem; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }
.empty p { margin: 0; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 860px) {
  .side-foot { flex-direction: row; margin-top: 0; margin-left: auto; }
  .side nav a span:not(.count) { display: none; }
  .side nav a .count { margin-left: 4px; }
  .linkbtn span { display: none; }
}
.cap-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.cap-row b { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.cap-row span { color: var(--muted); }
.ok-text { color: var(--green); font-weight: 600; }
.mb { margin-bottom: 14px; }
