:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #7b8794;
  --line: #e4e7eb;
  --accent: #2f6fed;
  --good: #0f9d58;
  --bad: #d64545;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ------------------------------------------------------------- sidebar -- */

.sidebar {
  width: 210px;
  flex: 0 0 210px;
  background: #1f2933;
  color: #cbd2d9;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand { font-weight: 600; color: #fff; font-size: 16px; padding-left: 10px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  background: none;
  border: 0;
  color: #cbd2d9;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.nav-item:hover { background: #323f4b; color: #fff; }
.nav-item.active { background: #3e4c59; color: #fff; }

.transport {
  margin-top: auto;
  font-size: 12px;
  line-height: 1.5;
  color: #9aa5b1;
  border-top: 1px solid #323f4b;
  padding: 14px 10px 0;
}
.transport .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--good); }
.dot.off { background: #f0b429; }
.dot.err { background: var(--bad); }

/* ---------------------------------------------------------------- main -- */

main { flex: 1; padding: 26px 30px; min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 22px; margin: 0; }
.head-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}
.btn:hover { border-color: #cbd2d9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2559c9; }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--muted); padding: 0 0 6px; }
.btn.link:hover { color: var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 13px; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c3d4fb; border-color: var(--accent); }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.two-col.contacts { grid-template-columns: 240px 1fr; }

/* ----------------------------------------------------------- campaigns -- */

.card-list { display: flex; flex-direction: column; gap: 10px; }

.campaign-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
}
.campaign-card:hover { border-color: #cbd2d9; }
.campaign-card .grow { flex: 1; min-width: 0; }
.campaign-card h3 { margin: 0 0 3px; font-size: 15px; }
.campaign-card .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: #e4e7eb;
  color: #52606d;
}
.badge.sent { background: #def7ec; color: #046c4e; }
.badge.sending { background: #fdf2d0; color: #8d6708; }

.empty { color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px; text-align: center; }

/* -------------------------------------------------------------- editor -- */

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.title-input { border: 0; padding: 0; font-size: 22px; font-weight: 600; background: none; }
.title-input:focus { outline: 0; border-bottom: 2px solid var(--accent); border-radius: 0; }
.saved { color: var(--muted); font-size: 12px; min-width: 60px; }

.body-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin: 6px 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }

#c-body { min-height: 320px; resize: vertical; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13.5px; line-height: 1.6; }
.merge-hint { margin: 8px 0 14px; }
.merge-hint code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }

.test-row { display: flex; gap: 8px; }
.test-row input { flex: 1; }

.issues { margin-top: 12px; color: var(--bad); font-size: 13px; }
.issues div { margin-top: 4px; }

.preview { display: flex; flex-direction: column; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.preview-subject { font-weight: 600; padding: 10px 12px; background: #eef1f5; border-radius: 6px; margin-bottom: 10px; min-height: 40px; }
#preview-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

/* -------------------------------------------------------------- report -- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 600; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .pct { color: var(--muted); font-size: 12px; }

.progress { background: #fdf2d0; border: 1px solid #f7e0a3; color: #8d6708; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
td { padding: 7px 8px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.scroll { max-height: 460px; overflow: auto; }
.trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: #e4e7eb; color: #52606d; }
.pill.subscribed { background: #def7ec; color: #046c4e; }
.pill.unsubscribed { background: #fce8e6; color: #8f2c2c; }
.pill.failed { background: #fce8e6; color: #8f2c2c; }

/* ------------------------------------------------------------ contacts -- */

.lists .list-btn {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  width: 100%; background: none; border: 0; border-radius: 6px;
  padding: 7px 9px; font: inherit; text-align: left; cursor: pointer; color: var(--ink);
}
.lists .list-btn:hover { background: #f0f2f5; }
.lists .list-btn.active { background: #e8effc; color: var(--accent); font-weight: 600; }
.lists .count { color: var(--muted); font-size: 12px; font-weight: 400; }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input { flex: 1; }
.filters select { width: auto; }

/* --------------------------------------------------------------- misc -- */

.prose p { margin: 0 0 12px; }
.prose code { background: #eef1f5; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.prose dl { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; margin: 0; }
.prose dt { color: var(--muted); font-size: 13px; }
.prose dd { margin: 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1f2933; color: #fff; padding: 11px 20px; border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); font-size: 14px; z-index: 50; max-width: 70vw;
}
.toast.error { background: var(--bad); }

@media (max-width: 1000px) {
  .editor, .two-col, .two-col.contacts { grid-template-columns: 1fr; }
  body { flex-direction: column; }
  .sidebar { width: auto; flex: none; flex-direction: row; align-items: center; padding: 12px; }
  .sidebar nav { flex-direction: row; }
  .transport { margin: 0 0 0 auto; border: 0; padding: 0; }
}
