:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8f0;
  --border-strong: #d3d9e6;
  --text: #1a2233;
  --text-soft: #5b6678;
  --text-faint: #8a93a6;
  --primary: #2563eb;
  --primary-soft: #eef3ff;
  --primary-strong: #1d4ed8;
  --wa-teal: #075e54;
  --wa-green: #25d366;
  --wa-bg: #e6ddd4;
  --wa-bubble: #d9fdd3;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --warn: #d97706;
  --warn-soft: #fdf2e2;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --info: #0ea5e9;
  --info-soft: #e6f6fd;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 40px rgba(16, 24, 40, .14);
  font-family: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), #4f46e5); display: grid; place-items: center; color: #fff; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: var(--text-soft); font-weight: 500; font-size: 14px;
  padding: 8px 14px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 8px;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.topbar .spacer { flex: 1; }
.chan-pill { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; }
.chan-pill .live { width: 8px; height: 8px; border-radius: 50%; background: var(--wa-green); box-shadow: 0 0 0 3px rgba(37,211,102,.18); }

.main { flex: 1; padding: 28px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--text-soft); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; gap: 8px; transition: .15s; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.tpl-card { padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; transition: .15s; }
.tpl-card:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.tpl-card .name { font-weight: 700; font-size: 14.5px; word-break: break-word; }
.tpl-card .snippet { font-size: 13px; color: var(--text-soft); line-height: 1.5; max-height: 60px; overflow: hidden; }
.tpl-card .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: auto; }
.tpl-card .row { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Badges ---------- */
.badge { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; text-transform: capitalize; letter-spacing: .01em; }
.badge.approved, .badge.read, .badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.pending, .badge.draft { background: var(--surface-2); color: var(--text-soft); }
.badge.rejected, .badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.running, .badge.sent, .badge.scheduled { background: var(--info-soft); color: var(--info); }
.badge.paused, .badge.delivered { background: var(--warn-soft); color: var(--warn); }
.badge.cat { background: #eef0fe; color: #4f46e5; text-transform: uppercase; font-size: 10.5px; }
.badge.lang { background: var(--surface-2); color: var(--text-soft); }

/* ---------- Empty / loading ---------- */
.empty { text-align: center; padding: 64px 24px; color: var(--text-faint); }
.empty svg { opacity: .35; margin-bottom: 14px; }
.empty h3 { color: var(--text-soft); margin: 0 0 6px; font-size: 16px; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { display: grid; place-items: center; padding: 80px; }

/* ---------- Drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.5); backdrop-filter: blur(2px); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { width: min(960px, 100%); background: var(--bg); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slidein .22s ease; }
@keyframes slidein { from { transform: translateX(40px); opacity: .6; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { flex: 1; overflow: auto; display: grid; grid-template-columns: 1fr 380px; gap: 0; }
.drawer-form { padding: 22px; overflow: auto; }
.drawer-preview { background: var(--wa-bg); border-left: 1px solid var(--border); padding: 22px; position: sticky; top: 0; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; background: var(--surface); border-top: 1px solid var(--border); }
.iconbtn { border: 0; background: transparent; color: var(--text-soft); padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.iconbtn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Forms ---------- */
.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; line-height: 1.4; }
.input, .select, .textarea { width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; background: var(--surface); color: var(--text); transition: .15s; }
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 110px; line-height: 1.55; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
.seg button.on { background: var(--surface); color: var(--primary-strong); font-weight: 600; box-shadow: var(--shadow); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; margin: 22px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-soft); color: var(--primary-strong); border: 1px solid #d6e2ff; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.var-insert { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.var-insert button { background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--text-soft); padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.var-insert button:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Button-builder rows ---------- */
.btn-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.btn-row .select { width: 130px; }

/* ---------- WhatsApp preview ---------- */
.wa-phone { background: var(--wa-bg); border-radius: 18px; padding: 0; box-shadow: var(--shadow-lg); overflow: hidden; max-width: 320px; margin: 0 auto; }
.wa-top { background: var(--wa-teal); color: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.wa-top .av { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.25); display: grid; place-items: center; font-weight: 700; }
.wa-top .nm { font-weight: 600; font-size: 14px; }
.wa-top .st { font-size: 11px; opacity: .8; }
.wa-chat { padding: 16px 12px; min-height: 260px; background-image: linear-gradient(rgba(229,221,212,.6),rgba(229,221,212,.6)), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 0h40v40H0z' fill='%23e6ddd4'/%3E%3Ccircle cx='20' cy='20' r='1' fill='%23d4c9bd'/%3E%3C/svg%3E"); }
.wa-bubble { background: var(--wa-bubble); border-radius: 8px; padding: 8px 10px 6px; max-width: 88%; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 13.5px; line-height: 1.5; color: #111b21; position: relative; }
.wa-bubble .hdr { font-weight: 700; margin-bottom: 4px; }
.wa-bubble .hdr-media { background: rgba(0,0,0,.06); border-radius: 6px; height: 120px; display: grid; place-items: center; color: #667; margin-bottom: 6px; font-size: 12px; }
.wa-bubble .body { white-space: pre-wrap; word-break: break-word; }
.wa-bubble .ftr { color: #667781; font-size: 11.5px; margin-top: 5px; }
.wa-bubble .time { color: #667781; font-size: 10.5px; text-align: right; margin-top: 2px; }
.wa-bubble .var { background: #fff4c2; border-radius: 3px; padding: 0 2px; font-weight: 600; }
.wa-buttons { margin-top: 6px; display: flex; flex-direction: column; gap: 1px; }
.wa-btn { background: var(--surface); color: #027eb5; text-align: center; padding: 9px; font-size: 13.5px; font-weight: 500; border-radius: 8px; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }

/* ---------- Wizard (campanha) ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 24px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-faint); font-weight: 600; }
.step .n { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border-strong); display: grid; place-items: center; font-size: 12px; }
.step.on { color: var(--primary-strong); }
.step.on .n { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.done .n { background: var(--ok); border-color: var(--ok); color: #fff; }
.step .bar { width: 28px; height: 2px; background: var(--border-strong); }
.pick-list { display: grid; gap: 10px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: .15s; }
.pick:hover { border-color: var(--border-strong); }
.pick.sel { border-color: var(--primary); background: var(--primary-soft); }
.pick .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; }
.pick.sel .radio { border-color: var(--primary); background: radial-gradient(circle, var(--primary) 40%, transparent 45%); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Progress ---------- */
.prog { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.prog .seg-read { background: var(--ok); }
.prog .seg-deliv { background: var(--warn); }
.prog .seg-sent { background: var(--info); }
.prog .seg-fail { background: var(--danger); }
.statgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 18px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; max-width: 380px; animation: slidein .2s; }
.toast.ok { background: #16341f; border-left: 3px solid var(--wa-green); }
.toast.err { background: #3a1414; border-left: 3px solid var(--danger); }

.banner { background: var(--warn-soft); border: 1px solid #f3d9a8; color: #92500e; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 18px; display: flex; gap: 10px; align-items: flex-start; }

@media (max-width: 840px) { .drawer-body { grid-template-columns: 1fr; } .drawer-preview { border-left: 0; border-top: 1px solid var(--border); } .statgrid { grid-template-columns: repeat(2,1fr); } }
