:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #027a48;
  --ok-soft: #ecfdf3;
  --bad: #b42318;
  --bad-soft: #fef3f2;
  --idle: #475467;
  --idle-soft: #f2f4f7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af); }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--idle-soft); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 2px 0 0; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.stack > * + * { margin-top: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--idle-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.disabled { opacity: .5; pointer-events: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* forms */
label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=password], textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }

/* badges & chips */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.on { color: var(--ok); background: var(--ok-soft); }
.badge.off { color: var(--idle); background: var(--idle-soft); }
.badge.err { color: var(--bad); background: var(--bad-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 2px 9px; border-radius: 6px; font-size: 12.5px; font-weight: 500; }

/* campaigns */
.campaign { display: grid; grid-template-columns: 72px 1fr auto; gap: 16px; align-items: start; }
.thumb {
  width: 72px; height: 72px; border-radius: 8px; object-fit: cover;
  background: var(--idle-soft); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px;
}
.campaign-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.meta { color: var(--muted); font-size: 12.5px; margin: 2px 0 8px; word-break: break-all; }
.messages { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.msg { background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; white-space: pre-wrap; }
.msg b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 2px; }
.campaign-actions { display: flex; flex-direction: column; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* switch */
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #d0d5dd; border-radius: 999px; cursor: pointer; transition: .15s; }
.slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* preview */
.preview { display: flex; gap: 12px; align-items: center; background: var(--bg); border-radius: 8px; padding: 10px; margin-top: 8px; }
.preview img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; }
.preview p { margin: 0; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.preview.error { color: var(--bad); background: var(--bad-soft); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: none; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; z-index: 10;
}
.modal-backdrop.open { display: flex; }
.modal { width: 100%; max-width: 620px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.icon-btn { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 8px; max-height: 260px; overflow-y: auto; }
.picker button { border: 2px solid transparent; padding: 0; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--idle-soft); aspect-ratio: 1; }
.picker button:hover { border-color: var(--accent); }
.picker img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* DM flow steps */
.dm-step { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.step-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; flex-wrap: wrap; }
.step-head .hint { margin: 0; }
.step-num {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px;
}
.sub-label { font-weight: 500; font-size: 13px; margin: 10px 0 4px; }

/* posts grid with automation marks */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.post-grid > .status-line { grid-column: 1 / -1; }
.post-tile {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; padding: 0;
  border: 2px solid transparent; background: var(--idle-soft); cursor: pointer;
}
.post-tile:hover { border-color: var(--accent); }
.post-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-tile.none img { filter: grayscale(.6) brightness(.8); }
.post-tile .mark {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: rgba(16, 24, 40, .82); color: #fff;
}
.post-tile .mark.active { background: var(--ok); }
.post-tile .mark.paused { background: var(--idle); }
.post-tile .mark.none { background: #f79009; }
.picker button { position: relative; }
.picker .mark { position: absolute; left: 4px; bottom: 4px; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: #f79009; color: #fff; font-weight: 700; }
.picker .mark.active { background: var(--ok); }
.picker .mark.paused { background: var(--idle); }
.filter { display: flex; align-items: center; gap: 6px; font-weight: 500; margin: 0; white-space: nowrap; }

/* table */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.err-text { color: var(--bad); font-size: 12px; max-width: 260px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #101828; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); }

.status-line { font-size: 13px; color: var(--muted); }
code { background: var(--idle-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

@media (max-width: 720px) {
  .row, .messages { grid-template-columns: 1fr; }
  .campaign { grid-template-columns: 56px 1fr; }
  .campaign-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .thumb { width: 56px; height: 56px; }
  .topbar { gap: 12px; padding: 0 16px; }
  main { padding: 20px 16px 48px; }
}

/* ---------- SaaS chrome ---------- */
.admin-only { display: none; }
body.is-admin .admin-only { display: block; }
a.brand { color: var(--text); text-decoration: none; }
.topbar { position: sticky; top: 0; z-index: 10; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ws-name { color: var(--muted); font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.badge { text-decoration: none; }
.nav { overflow-x: auto; }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .ws-name { display: none; }
}
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat { font-size: 28px; font-weight: 700; margin: 4px 0 0; }
.meter { height: 8px; border-radius: 99px; background: var(--idle-soft); overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.warn > span { background: var(--bad); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 8px 0; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--border); }
.checklist li:first-child { border-top: 0; }
.check { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px;
  background: var(--idle-soft); color: var(--idle); flex: none; }
.check.done { background: var(--ok-soft); color: var(--ok); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters > div { min-width: 160px; }

/* ---------- public pages ---------- */
.public main { max-width: 1080px; }
.hero { text-align: center; padding: 56px 0 32px; }
.hero h1 { font-size: 40px; line-height: 1.15; letter-spacing: -.02em; max-width: 760px; margin: 0 auto; }
.hero p { font-size: 17px; color: var(--muted); max-width: 620px; margin: 16px auto 0; }
.hero .actions { justify-content: center; margin-top: 26px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.feature h3 { margin: 0 0 6px; font-size: 15px; }
.feature p { margin: 0; color: var(--muted); }
.steps { counter-reset: step; }
.steps .feature h3::before { counter-increment: step; content: counter(step) ". "; color: var(--accent); }
.plan-card { display: flex; flex-direction: column; gap: 10px; }
.plan-card.featured { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan-price { font-size: 30px; font-weight: 700; }
.plan-card ul { padding-left: 18px; margin: 0; color: var(--muted); }
.plan-card .btn { justify-content: center; margin-top: auto; }
.footer { text-align: center; color: var(--muted); padding: 32px 0 8px; font-size: 13px; }
.footer a { color: var(--muted); margin: 0 8px; }
.auth-card { max-width: 420px; margin: 48px auto; }
.auth-card h1 { margin-bottom: 4px; }
.check-row { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check-row input { width: auto; margin-top: 3px; }
[hidden] { display: none !important; }
a.btn { text-decoration: none; }
.btn { white-space: nowrap; }
.filters select, .filters input { width: 100%; }

/* legal pages */
.legal { max-width: 820px; margin: 24px auto; padding: 32px 36px; line-height: 1.65; }
.legal h2 { font-size: 17px; margin: 26px 0 8px; }
.legal ul, .legal ol { padding-left: 20px; }
.legal li { margin: 4px 0; }
.pay-note { margin-top: 8px; font-size: 12px; }
.plain-list { margin: 0; padding-left: 18px; color: var(--muted); }
.plain-list li { margin: 4px 0; }
