:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e5e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --green: #15803d;
  --green-soft: #e4f6ea;
  --red: #b91c1c;
  --red-soft: #fde8e8;
  --amber: #b45309;
  --amber-soft: #fdf1dc;
  --gray-soft: #eceef1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 4px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
p { margin: 0 0 8px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--gray-soft); padding: 1px 5px; border-radius: 4px; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex: none; background: #0f172a; color: #cbd5e1; padding: 18px 14px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cbd5e1; padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,0.12); color: #fff; }
.sidebar nav .nav-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #64748b; padding: 12px 10px 4px; }
.sidebar nav .nav-label:first-child { padding-top: 2px; }
.sidebar nav .nav-group { display: flex; flex-direction: column; gap: 2px; }
.sidebar-status { margin-top: auto; font-size: 12px; display: flex; flex-direction: column; gap: 6px; padding: 0 6px; }
.sidebar-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #64748b; vertical-align: middle; }
.sidebar-status .dot.on { background: #22c55e; }
.sidebar-status .dot.off { background: #f59e0b; }
.sidebar-status a { color: #cbd5e1; }
.sidebar-foot { font-size: 11px; color: #64748b; padding: 0 6px; }

main { flex: 1; min-width: 0; padding: 28px 36px 60px; max-width: 1180px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.error { border-color: #fecaca; background: var(--red-soft); color: var(--red); }
.card .card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card .hint { color: var(--muted); font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } main { padding: 18px; } }

label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; color: #374151; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=tel], select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; color: var(--text);
}
input[type=file] { width: 100%; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 120px; resize: vertical; font-family: inherit; }
textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.field { margin-bottom: 14px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.row > .btn, .row > .fixed { flex: none; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13.5px; }
.check input { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid #d1d5db; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #fca5a5; }
.btn.danger:hover { background: var(--red-soft); }
.btn.warn { color: var(--amber); border-color: #fcd34d; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 10px 18px; font-size: 14.5px; }

.seg { display: inline-flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; cursor: pointer; }
.seg input { display: none; }
.seg span { display: block; padding: 7px 14px; font-weight: 600; font-size: 13px; color: var(--muted); border-right: 1px solid #d1d5db; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--primary-soft); color: var(--primary); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: #374151; white-space: nowrap; }
.pill.draft { background: var(--gray-soft); }
.pill.running { background: var(--primary-soft); color: var(--primary); }
.pill.running::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); margin-right: 6px; animation: pulse 1.2s infinite; }
.pill.paused { background: var(--amber-soft); color: var(--amber); }
.pill.completed { background: var(--green-soft); color: var(--green); }
.pill.stopped { background: var(--gray-soft); color: #374151; }
.pill.failed { background: var(--red-soft); color: var(--red); }
.pill.channel { background: #f1f5f9; color: #334155; font-weight: 500; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--mono); font-size: 12px; background: var(--primary-soft); color: var(--primary); border: 1px solid #c7d7fe; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.chip:hover { background: #dbe6ff; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
table.compact td, table.compact th { padding: 6px 8px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
td.status-SENT { color: var(--green); font-weight: 600; }
td.status-FAILED { color: var(--red); }
td.status-SKIPPED, td.status-ALREADY { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fafbfc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.stat .n { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.good .n { color: var(--green); }
.stat.bad .n { color: var(--red); }
.stat .s { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 600; font-size: 13.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.meter { height: 6px; min-width: 90px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; }
.meter > div { height: 100%; background: var(--primary); }
.meter.warn { background: var(--amber-soft); } .meter.warn > div { background: var(--amber); }
.meter.danger { background: var(--red-soft); } .meter.danger > div { background: var(--red); }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row .meter { flex: 1; }
.meter-row .v { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; }
.send-results { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.send-results li { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.send-results li:last-child { border-bottom: 0; }
.progress { height: 8px; background: var(--gray-soft); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress > div { height: 100%; background: var(--primary); transition: width 0.4s; }

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; border: 1px solid; }
.notice.warn { background: var(--amber-soft); border-color: #fcd34d; color: var(--amber); }
.notice.err { background: var(--red-soft); border-color: #fecaca; color: var(--red); }
.notice.info { background: var(--primary-soft); border-color: #c7d7fe; color: #1e3a8a; }
.notice.ok { background: var(--green-soft); border-color: #bbf7d0; color: var(--green); }

.preview-box { border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; padding: 12px 14px; font-size: 13px; }
.preview-box .subj { font-weight: 600; margin-bottom: 6px; }
.preview-box iframe { width: 100%; border: 0; background: #fff; border-radius: 6px; min-height: 160px; }
.wa-bubble { background: #dcf8c6; border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; max-width: 520px; font-size: 13.5px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 12px; }
.mb0 { margin-bottom: 0; }
.right { text-align: right; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.steps li { margin-bottom: 4px; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; color: #374151; }
details .inner { margin-top: 10px; }
.copy { font-family: var(--mono); font-size: 12px; background: var(--gray-soft); padding: 6px 10px; border-radius: 6px; display: inline-flex; gap: 10px; align-items: center; word-break: break-all; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 420px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); animation: slide 0.2s ease-out; }
.toast.err { background: #991b1b; }
.toast.ok { background: #166534; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.hidden { display: none !important; }

/* auth + user block */
.sidebar-user { display: flex; flex-direction: column; gap: 8px; padding: 10px 6px 0; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12px; }
.sidebar-user .who { display: flex; flex-direction: column; }
.sidebar-user .who b { color: #fff; font-size: 13px; }
.sidebar-user .who span { color: #94a3b8; word-break: break-all; }
.sidebar-user .btn { background: transparent; color: #cbd5e1; border-color: #334155; }
.sidebar-user .btn:hover { background: rgba(255,255,255,0.06); }
body.logged-out .sidebar { display: none; }
body.logged-out main { max-width: none; padding: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap { width: 100%; max-width: 420px; padding: 20px; }
.auth-card { padding: 28px 28px 22px; }
.auth-card .brand { color: var(--text); padding: 0 0 14px; font-size: 18px; }
.auth-card h2 { font-size: 18px; margin-bottom: 14px; }
.pill.admin { background: var(--primary-soft); color: var(--primary); }

/* ---- WhatsApp inbox */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: #22c55e; color: #052e16; font-size: 11px; font-weight: 700; text-align: center; margin-left: 6px; line-height: 18px; vertical-align: middle; }
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.convo-pane { padding: 10px; }
.convo-pane input[type=search] { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; margin-bottom: 8px; font-size: 13px; }
.convo-list { max-height: calc(100vh - 230px); overflow: auto; }
.convo { display: flex; gap: 10px; padding: 10px; border-radius: 8px; cursor: pointer; align-items: flex-start; }
.convo:hover { background: var(--gray-soft); }
.convo.active { background: var(--primary-soft); }
.convo .avatar { width: 36px; height: 36px; border-radius: 50%; background: #cbd5e1; color: #0f172a; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; font-size: 14px; }
.convo .body { flex: 1; min-width: 0; }
.convo .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.convo .top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo .snippet { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-pane { padding: 0; display: flex; flex-direction: column; min-height: 60vh; overflow: hidden; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.msgs { flex: 1; overflow: auto; padding: 16px; background: #efeae2; max-height: calc(100vh - 330px); min-height: 280px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 8px 10px; border-radius: 10px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,0.08); }
.msg.in { align-self: flex-start; background: #fff; }
.msg.out { align-self: flex-end; background: #dcf8c6; }
.msg .meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; white-space: normal; }
.msg .ticks.read { color: #2563eb; }
.msg .ticks.failed { color: var(--red); }
.msg .err { color: var(--red); font-size: 11.5px; white-space: normal; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg video, .msg audio { max-width: 100%; display: block; margin-bottom: 4px; }
.msg .tpl { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.day-sep { align-self: center; background: #fff; border-radius: 999px; padding: 2px 10px; font-size: 11px; color: var(--muted); box-shadow: 0 1px 1px rgba(0,0,0,0.06); }
.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); align-items: flex-end; flex-wrap: wrap; }
.composer textarea { flex: 1; min-width: 200px; resize: vertical; }
.tpl-box { padding: 12px 16px; border-top: 1px solid var(--border); background: #fafafa; }
@media (max-width: 900px) { .inbox { grid-template-columns: 1fr; } .convo-list { max-height: 40vh; } }
