:root {
  --bg: #f6f4f2;
  --surface: #ffffff;
  --surface-2: #faf8f7;
  --border: #e8e3df;
  --border-strong: #d6cfc9;
  --text: #1f1a1c;
  --text-2: #6b6266;
  --text-3: #9a9195;
  --accent: #a3294f;
  --accent-hover: #8a2142;
  --accent-soft: #fbeef2;
  --success: #1f8a5b;
  --success-soft: #e7f5ee;
  --warning: #a36a00;
  --warning-soft: #fdf3e1;
  --danger: #c0392b;
  --danger-soft: #fcebe9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 26, 28, .04), 0 4px 16px rgba(31, 26, 28, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ── Shell ─────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: #1f1a1c; color: #efe9eb; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #a99ea3; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #cfc5c9; text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; align-items: center; color: #a99ea3; font-size: 13px; }
.sidebar-foot button { background: none; border: 0; color: #cfc5c9; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.sidebar-foot button:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { padding: 28px 36px 120px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.back { color: var(--text-2); text-decoration: none; font-size: 13px; display: inline-flex; gap: 4px; margin-bottom: 6px; }
.back:hover { color: var(--text); }

/* ── Controles ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(31,26,28,.05); }
.btn-danger { color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }

.input, .textarea, .select {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface);
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 84px; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.label { font-weight: 600; font-size: 13px; }
.hint { color: var(--text-2); font-size: 12.5px; }
.counter { color: var(--text-3); font-size: 12px; text-align: right; }

.switch { position: relative; display: inline-flex; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 99px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ── Lista de fluxos ───────────────────────────────── */
.flow-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.flow-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.flow-card.paused { opacity: .72; }
.flow-top { display: flex; gap: 12px; align-items: flex-start; }
.thumbs { display: flex; flex: none; }
.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 2px solid var(--surface); display: grid; place-items: center; color: var(--text-3); }
.thumbs .thumb + .thumb { margin-left: -18px; }
.thumb.all { background: var(--accent-soft); color: var(--accent); }
.thumb svg { width: 22px; height: 22px; }
.flow-title { flex: 1; min-width: 0; }
.flow-title h3 { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-title p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.stat { padding: 10px 12px; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--text-2); font-size: 12px; }
.flow-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flow-foot label { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; color: var(--text-2); cursor: pointer; }
.flow-actions { display: flex; gap: 2px; }

.empty { text-align: center; padding: 64px 24px; }
.empty-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 16px; }
.empty h2 { font-size: 18px; margin-bottom: 6px; }
.empty p { color: var(--text-2); max-width: 420px; margin: 0 auto 20px; }

/* ── Editor ────────────────────────────────────────── */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.steps { display: flex; flex-direction: column; gap: 14px; }
.step { padding: 20px; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.step-head.toggle { margin-bottom: 0; }
.step-head.toggle + .step-body { margin-top: 16px; }
.step-num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.step-head h2 { font-size: 15px; font-weight: 600; }
.step-head p { margin: 1px 0 0; color: var(--text-2); font-size: 13px; }
.step-head > div:not(.step-num) { flex: 1; }

.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; border: 1px solid var(--border-strong); border-radius: 10px; padding: 12px 14px 12px 40px; cursor: pointer; transition: border-color .15s, background .15s; }
.choice input { position: absolute; left: 14px; top: 15px; accent-color: var(--accent); }
.choice b { display: block; font-weight: 600; }
.choice span { color: var(--text-2); font-size: 12.5px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.picked { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; align-items: center; }
.picked-item { position: relative; width: 76px; }
.picked-item img, .picked-item .ph { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; color: var(--text-3); border: 1px solid var(--border); }
.picked-item button { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--text); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 13px; line-height: 1; }
.picked-add { width: 76px; height: 76px; border-radius: 10px; border: 1.5px dashed var(--border-strong); background: none; color: var(--text-2); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; }
.picked-add:hover { border-color: var(--accent); color: var(--accent); }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--border-strong); border-radius: 9px; padding: 6px 8px; background: var(--surface); min-height: 42px; cursor: text; }
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 3px 4px 3px 9px; font-weight: 600; font-size: 13px; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; }
.tag button:hover { background: rgba(163,41,79,.12); }
.tag-input input { border: 0; outline: 0; flex: 1; min-width: 140px; padding: 4px; background: transparent; }

.variant { display: flex; gap: 8px; align-items: flex-start; }
.variant + .variant { margin-top: 8px; }
.variant .input { flex: 1; }
.icon-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid transparent; background: none; color: var(--text-3); cursor: pointer; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.var-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.var-btn { border: 1px dashed var(--border-strong); background: var(--surface-2); border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer; color: var(--text-2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.var-btn:hover { border-color: var(--accent); color: var(--accent); }
.callout { display: flex; gap: 10px; background: var(--warning-soft); color: #6e4a00; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.callout svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.savebar { position: fixed; left: 232px; right: 0; bottom: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-top: 1px solid var(--border); padding: 12px 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 20; }
.savebar label { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.savebar .right { display: flex; gap: 8px; }

/* ── Prévia (celular) ──────────────────────────────── */
.preview { position: sticky; top: 24px; }
.preview-label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; text-align: center; }
.phone { background: #111; border-radius: 38px; padding: 10px; box-shadow: 0 20px 50px rgba(31,26,28,.18); }
.phone-screen { background: #fff; border-radius: 30px; overflow: hidden; height: 620px; display: flex; flex-direction: column; }
.phone-bar { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; border-bottom: 1px solid #efefef; font-weight: 600; font-size: 13px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #f9ce34, #ee2a7b, #6228d7); padding: 2px; flex: none; }
.avatar::after { content: ""; display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent) center/cover; border: 2px solid #fff; }
.phone-body { flex: 1; overflow-y: auto; padding: 0 0 16px; font-size: 13px; }
.pv-post { width: 100%; aspect-ratio: 4/5; max-height: 210px; object-fit: cover; background: linear-gradient(135deg, #f3e6ea, #e9dde1); display: grid; place-items: center; color: var(--text-3); }
.pv-comments { padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.pv-comment b { margin-right: 4px; }
.pv-comment.reply { padding-left: 22px; color: #333; }
.pv-section { text-align: center; color: #999; font-size: 11px; margin: 10px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
.pv-dm { padding: 0 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.bot { background: #efefef; align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.user { background: #3797f0; color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.muted { opacity: .55; }

/* ── Modal ─────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(31,26,28,.45); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 16px; width: min(860px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.modal.small { width: min(420px, 100%); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
@keyframes fade { from { opacity: 0; } }

.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.post { position: relative; border-radius: 10px; overflow: hidden; cursor: pointer; border: 2px solid transparent; background: var(--surface-2); aspect-ratio: 4/5; padding: 0; text-align: left; }
.post img, .post .ph { width: 100%; height: 100%; object-fit: cover; display: grid; place-items: center; color: var(--text-3); }
.post .meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 8px 7px; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; font-size: 11.5px; line-height: 1.3; }
.post .meta p { margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post .type { position: absolute; top: 7px; left: 7px; background: rgba(0,0,0,.55); color: #fff; font-size: 10.5px; font-weight: 600; padding: 2px 6px; border-radius: 5px; }
.post .check { position: absolute; top: 7px; right: 7px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25); display: grid; place-items: center; color: #fff; }
.post.selected { border-color: var(--accent); }
.post.selected .check { background: var(--accent); border-color: var(--accent); }
.loading { color: var(--text-2); padding: 30px; text-align: center; }

/* ── Tabelas ───────────────────────────────────────── */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .input, .filters .select { width: auto; min-width: 180px; height: 38px; padding-top: 0; padding-bottom: 0; }
.filters .input { flex: 1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.muted { color: var(--text-2); }
td .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }

/* ── Configurações ─────────────────────────────────── */
.settings { display: grid; gap: 14px; max-width: 760px; }
.setting { padding: 18px 20px; display: flex; gap: 16px; align-items: center; }
.setting > div { flex: 1; min-width: 0; }
.setting h3 { font-size: 14px; font-weight: 600; }
.setting p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.setting img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.copy { display: flex; gap: 8px; margin-top: 8px; }
.copy code { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; overflow-x: auto; white-space: nowrap; }

/* ── Login ─────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%, #fbeef2, transparent 50%), var(--bg); }
.login .card { width: min(380px, 100%); padding: 32px; }
.login .brand { color: var(--text); padding: 0 0 22px; }
.login .brand small { color: var(--text-2); }
.login .btn { width: 100%; margin-top: 18px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }

#toasts { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: fade .2s; }
.toast.error { background: var(--danger); }

@media (max-width: 1080px) {
  .editor { grid-template-columns: 1fr; }
  .preview { position: static; max-width: 340px; margin: 0 auto; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 10px 0 0; }
  .brand small, .sidebar-foot span { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 20px 16px 120px; }
  .savebar { left: 0; padding: 12px 16px; }
  .choice-row, .grid-2 { grid-template-columns: 1fr; }
  .flow-grid { grid-template-columns: 1fr; }
}
