:root {
  --bg: #f6f7f9;
  --card: #fff;
  --ink: #14181f;
  --muted: #6b7480;
  --line: #e3e6ea;
  --brand: #0f9d58;
  --brand-dark: #0b7c45;
  --good: #0f9d58;
  --bad: #d93025;
  --warn: #c47f00;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 24px; padding-bottom: 40px; }
footer.wrap { padding-bottom: 32px; font-size: 13px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
a { color: var(--brand-dark); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

/* ---------------------------------------------------------------- topbar */
.topbar { background: #101418; color: #fff; }
.topbar .wrap { display: flex; align-items: center; gap: 22px; height: 56px; }
.brand { font-weight: 700; font-size: 17px; color: #fff; text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--brand); }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { color: #aab3bd; text-decoration: none; font-size: 14px; padding: 4px 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover { color: #fff; }
.topbar nav a.on { color: #fff; border-color: var(--brand); }
.topbar nav em { font-style: normal; background: #262d35; border-radius: 20px; padding: 1px 7px; font-size: 12px; margin-left: 4px; }
.logout { color: #8b949e; text-decoration: none; font-size: 13px; }
.logout:hover { color: #fff; }

.env { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.env-sandbox { background: #4a3c00; color: #ffd54a; }
.env-live { background: #0b3d24; color: #58d68d; }

/* ------------------------------------------------------------------ bits */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; border: 1px solid; }
.flash.ok { background: #e8f6ee; border-color: #b7e1c6; color: #12603a; }
.flash.warn { background: #fdf5e2; border-color: #f0dfb0; color: #7a5a06; }
.flash.err { background: #fdecea; border-color: #f5c4bf; color: #9c1c11; }

.btn, button.primary {
  display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 7px; font-size: 14px; cursor: pointer; text-decoration: none;
  line-height: 1.3; font-family: inherit;
}
.btn:hover { border-color: #c3c9d0; background: #fafbfc; }
.btn.primary, button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover, button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #f0c8c4; }
.btn.danger:hover { background: #fdecea; }
.btn.tiny { padding: 4px 9px; font-size: 12.5px; }
.btn.block { display: block; text-align: center; margin-top: 10px; }

input[type=text], input[type=search], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px;
  font: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cfe9db; border-color: var(--brand); }
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { margin-top: 5px; color: var(--ink); }

/* ------------------------------------------------------------- dashboard */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; color: var(--ink); display: block;
}
.stat:hover { border-color: #c3c9d0; }
.stat.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.good b { color: var(--good); }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar .search { display: flex; gap: 8px; flex: 1 1 320px; max-width: 460px; }
.toolbar .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .actions form { margin: 0; }

/* ----------------------------------------------------------------- table */
.table-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 11px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: #fbfcfd;
}
.grid td { padding: 7px 12px; border-bottom: 1px solid #f0f2f4; vertical-align: middle; }
.grid tbody tr:hover { background: #fbfcfd; }
.grid tr.flagged { background: #fffaf9; }
.grid tr.flagged:hover { background: #fdf3f1; }
.grid tr.out { opacity: .55; }
.grid .empty { text-align: center; color: var(--muted); padding: 34px; }
.grid .snippet { max-width: 420px; }
.row-actions { white-space: nowrap; display: flex; gap: 5px; }
input.cell { padding: 5px 8px; border: 1px solid transparent; background: transparent; min-width: 130px; }
input.cell:hover { border-color: var(--line); background: #fff; }
input.cell.bad { color: var(--bad); }

.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.tag.good { background: #e8f6ee; color: #12603a; }
.tag.bad { background: #fdecea; color: #9c1c11; }
.tag.out { background: #eef0f2; color: var(--muted); }

.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager a { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; font-size: 13px; }
.pager a.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* --------------------------------------------------------------- compose */
.compose { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.counter { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.counter.warn { color: var(--warn); font-weight: 600; }
.chip {
  border: 1px dashed #c3c9d0; background: #fff; border-radius: 20px; padding: 2px 9px;
  font-size: 12px; font-family: ui-monospace, Consolas, monospace; cursor: pointer; color: var(--brand-dark);
}
.chip:hover { border-style: solid; border-color: var(--brand); }
.audience { border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 16px; }
.audience .radio { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; color: var(--ink); }
.audience .radio input { width: auto; margin: 0; }
.audience .radio em { font-style: normal; color: var(--muted); background: #eef0f2; border-radius: 20px; padding: 1px 8px; font-size: 12px; margin-left: 4px; }
.audience select, .audience textarea { margin: 0 0 14px 24px; width: calc(100% - 24px); }
.send-row { display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; }

.side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13.5px; }
.side dt { color: var(--muted); }
.side dd { margin: 0; text-align: right; }

dl.inline { display: flex; flex-wrap: wrap; gap: 4px 22px; margin: 0 0 14px; font-size: 13.5px; }
dl.inline dt { color: var(--muted); }
dl.inline dd { margin: 0 14px 0 0; font-weight: 600; }
pre.template { background: #f6f7f9; border: 1px solid var(--line); border-radius: 8px; padding: 14px; white-space: pre-wrap; font-size: 13.5px; margin: 0 0 14px; }

.bubble { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: #fbfcfd; }
.bubble .to { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.bubble p { margin: 0 0 8px; white-space: pre-wrap; }
.back { text-decoration: none; font-size: 13.5px; }

/* --------------------------------------------------------------- dialogs */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; max-width: 560px; width: 92%; }
dialog::backdrop { background: rgba(16, 20, 24, .5); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ----------------------------------------------------------------- login */
body.centered { display: grid; place-items: center; min-height: 100vh; }
.login { width: 340px; }
.login h1 { font-size: 24px; margin: 0; }
.login h1 span { color: var(--brand); }
.login p { margin: 4px 0 18px; font-size: 13.5px; }
.login button { width: 100%; }

@media (max-width: 880px) {
  .compose { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar .wrap { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; gap: 12px; }
}

/* ------------------------------------------------------------- templates */
.message-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.message-head h2 { margin: 0; }
.template-picker { display: flex; gap: 8px; align-items: center; }
.template-picker select { width: auto; min-width: 190px; padding: 6px 10px; font-size: 13.5px; }
.send-row .spacer { flex: 1; }
.template-card { padding: 16px 18px; }
.template-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.template-head h3 { margin: 0; font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 600; }
.template-card pre.template { margin-bottom: 10px; max-height: 260px; overflow: auto; }

/* --------------------------------------------------------------- estimate */
.est-total { font-weight: 700; }
.estimate-bar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px;
  background: #fbfcfd;
}
.estimate-bar div b { display: block; font-size: 19px; line-height: 1.2; }
.estimate-bar div span { font-size: 12px; color: var(--muted); }
.estimate-bar .total b { color: var(--brand-dark); }
@media (max-width: 700px) { .estimate-bar { grid-template-columns: repeat(2, 1fr); } }

/* ------------------------------------------------------------------ events */
.event-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.event-bar a {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff;
  text-decoration: none; font-size: 13.5px; color: var(--ink);
}
.event-bar a:hover { border-color: #c3c9d0; }
.event-bar a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.event-bar a em { font-style: normal; opacity: .65; margin-left: 4px; font-size: 12px; }
.event-bar .manage { border: none; background: none; color: var(--brand-dark); padding: 5px 4px; }
.tag.list { background: #eef2f7; color: #3b4a5a; margin: 1px 2px 1px 0; }
.tag.list.multi { background: #fdf5e2; color: #7a5a06; }
.tag.warn-tag { background: #fdf5e2; color: #7a5a06; }
.overlap { margin: 0; padding-left: 18px; font-size: 14px; }
.overlap li { margin-bottom: 5px; }
.overlap em { font-style: normal; font-weight: 600; }

/* ------------------------------------------------------------ suppression */
.suppression { background: #fbfcfd; }
.suppression .check { display: flex; align-items: flex-start; gap: 9px; margin: 0 0 9px; font-size: 14px; color: var(--ink); }
.suppression .check input { width: auto; margin: 3px 0 0; flex: none; }
.suppression .check em { font-style: normal; font-size: 13px; }
.campaign-skips { max-height: 168px; overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; background: #fff; }
.campaign-skips .check { font-size: 13px; margin-bottom: 7px; }
.campaign-skips .check:last-child { margin-bottom: 0; }
