*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #25d366;
  --primary-dark: #128c7e;
  --primary-light: rgba(37,211,102,.15);
  --accent: #6366f1;
  --accent-light: rgba(99,102,241,.15);
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #2d333b;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --border: #30363d;
  --border2: #21262d;
  --danger: #f85149;
  --warning: #f0883e;
  --info: #58a6ff;
  --success: #3fb950;
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ─── LAYOUT ─── */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.main-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ─── SIDEBAR ─── */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.brand-icon svg { width: 20px; height: 20px; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--text); }
.brand-sub { font-size: 11px; color: var(--text2); }

.sidebar-nav { padding: 8px 8px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all .15s;
  position: relative;
  margin-bottom: 2px;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 12px;
  border-top: 1px solid var(--border);
}

.notif-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
}
.notif-btn:hover { background: var(--bg4); }
.notif-btn svg { width: 18px; height: 18px; color: var(--text2); }
.notif-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg2);
}

/* ─── PAGES ─── */
.page { display: none; height: 100%; overflow-y: auto; padding: 24px; flex-direction: column; }
.page.active { display: flex; }

/* ─── PAGE HEADER ─── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #4f46e5; }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: rgba(248,81,73,.15); color: var(--danger); border: 1px solid rgba(248,81,73,.3); }
.btn-danger:hover { background: rgba(248,81,73,.25); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: var(--radius); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── CARDS ─── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .05em; }

/* ─── STATS GRID ─── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.green { background: rgba(63,185,80,.15); color: var(--success); }
.stat-icon.blue { background: rgba(88,166,255,.15); color: var(--info); }
.stat-icon.orange { background: rgba(240,136,62,.15); color: var(--warning); }
.stat-icon.purple { background: rgba(99,102,241,.15); color: var(--accent); }
.stat-icon.red { background: rgba(248,81,73,.15); color: var(--danger); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ─── TABLE ─── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border2); font-size: 13px; }
th { color: var(--text2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--bg2); }
tr:hover td { background: rgba(255,255,255,.02); }
td { color: var(--text); }

/* ─── BADGES/STATUS ─── */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-connected { background: rgba(63,185,80,.15); color: var(--success); }
.status-connected::before { background: var(--success); }
.status-disconnected, .status-logged_out { background: rgba(110,118,129,.15); color: var(--text2); }
.status-disconnected::before, .status-logged_out::before { background: var(--text3); }
.status-qr { background: rgba(240,136,62,.15); color: var(--warning); }
.status-qr::before { background: var(--warning); box-shadow: 0 0 6px var(--warning); animation: pulse 1s infinite; }
.status-connecting { background: rgba(88,166,255,.15); color: var(--info); }
.status-connecting::before { background: var(--info); }
.status-running { background: rgba(63,185,80,.15); color: var(--success); }
.status-running::before { background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse 1s infinite; }
.status-draft { background: var(--bg4); color: var(--text2); }
.status-draft::before { background: var(--text3); }
.status-paused { background: rgba(240,136,62,.15); color: var(--warning); }
.status-paused::before { background: var(--warning); }
.status-finished { background: rgba(88,166,255,.1); color: var(--info); }
.status-finished::before { background: var(--info); }
.status-cancelled { background: rgba(248,81,73,.1); color: var(--danger); }
.status-cancelled::before { background: var(--danger); }
.status-recovered { background: rgba(63,185,80,.15); color: var(--success); }
.status-recovered::before { background: var(--success); }
.status-pending { background: var(--bg4); color: var(--text2); }
.status-pending::before { background: var(--text3); }
.status-approached { background: rgba(88,166,255,.1); color: var(--info); }
.status-approached::before { background: var(--info); }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }

/* ─── FORMS ─── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); }
.form-textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-select { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg4);
  border-radius: 22px;
  transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
input:checked + .toggle-slider { background: var(--primary); }
input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── CHAT LAYOUT ─── */
.chat-layout { display: flex; height: 100%; gap: 0; overflow: hidden; }
.chat-list {
  width: 300px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-list-header { padding: 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-list-header h2 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.chat-search {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 12px; color: var(--text);
  font-size: 13px; outline: none;
}
.chat-search:focus { border-color: var(--primary); }
.chat-list-items { overflow-y: auto; flex: 1; min-height: 0; }
.chat-item {
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border2);
  display: flex; gap: 10px; align-items: flex-start;
  transition: background .1s; position: relative;
}
.chat-item:hover, .chat-item.active { background: var(--bg3); }
.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-preview { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-item-time { font-size: 11px; color: var(--text3); }
.chat-unread { background: var(--primary); color: #000; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 10px; }
.ai-badge { font-size: 10px; background: var(--accent-light); color: var(--accent); padding: 1px 5px; border-radius: 4px; }

/* Chat tabs */
.chat-tabs { display: flex; gap: 0; }
.chat-tab-btn {
  flex: 1; padding: 6px 6px; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text2); cursor: pointer; transition: all .15s;
  white-space: nowrap; text-align: center;
}
.chat-tab-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.chat-tab-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.chat-tab-btn:not(:first-child) { border-left: 0; }
.chat-tab-btn.active { background: var(--primary); color: #000; border-color: var(--primary); }
.chat-tab-btn:hover:not(.active) { background: var(--bg4); color: var(--text); }
.chat-tab-count { font-size: 10px; font-weight: 700; }

.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name { font-weight: 700; font-size: 15px; }
.chat-header-sub { font-size: 12px; color: var(--text2); }
.chat-header-actions { display: flex; gap: 6px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text2); flex-direction: column; gap: 12px; }
.chat-empty svg { width: 48px; height: 48px; opacity: .3; }

.message {
  max-width: 70%; display: flex; flex-direction: column; gap: 3px;
}
.message.incoming { align-self: flex-start; }
.message.outgoing { align-self: flex-end; }
.message-bubble {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}
.message.incoming .message-bubble { background: var(--bg3); color: var(--text); border-bottom-left-radius: 3px; }
.message.outgoing .message-bubble { background: var(--primary-dark); color: #fff; border-bottom-right-radius: 3px; }
.message.outgoing.ai .message-bubble { background: var(--accent); }
.message-meta { font-size: 11px; color: var(--text3); display: flex; gap: 6px; align-items: center; }
.message.outgoing .message-meta { justify-content: flex-end; }
.msg-check { font-size: 14px; color: rgba(255,255,255,0.8); margin-left: 2px; }
.msg-check-double { color: #34b7f1; }
.ai-indicator { font-size: 10px; background: var(--accent-light); color: var(--accent); padding: 1px 5px; border-radius: 4px; }
.msg-agent-sig { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.75); padding: 0 12px; }
.message-media { margin-bottom: 4px; }
.message-media img { max-width: 100%; max-height: 280px; border-radius: 8px; display: block; cursor: pointer; }
.message-media audio { max-width: 100%; min-width: 200px; height: 36px; }
.message-sticker { margin-bottom: 4px; }
.message-sticker img { max-width: 150px; max-height: 150px; display: block; }

.chat-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end; flex-shrink: 0;
}
.chat-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 9px 16px;
  color: var(--text); font-size: 13.5px; outline: none;
  resize: none; max-height: 120px; font-family: inherit;
  transition: border-color .15s; line-height: 1.4;
}
.chat-input:focus { border-color: var(--primary); }
.chat-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #000; transition: background .15s; flex-shrink: 0;
}
.chat-send:hover { background: var(--primary-dark); color: #fff; }
.chat-send svg { width: 16px; height: 16px; }

/* ─── NUMBER CARDS ─── */
.numbers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.number-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px;
}
.number-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.number-card-label { font-weight: 700; font-size: 15px; }
.number-phone { font-size: 12px; color: var(--text2); margin-top: 2px; font-family: monospace; }
.number-card-actions { display: flex; gap: 6px; }
.number-qr { margin: 12px 0; text-align: center; }
.number-qr img { width: 160px; height: 160px; border-radius: var(--radius); border: 2px solid var(--border); }
.number-stats { display: flex; gap: 16px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border2); }
.number-stat-item { text-align: center; }
.number-stat-val { font-size: 18px; font-weight: 700; color: var(--text); }
.number-stat-label { font-size: 11px; color: var(--text2); }

/* ─── TRAINING ─── */
.training-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; height: 100%; overflow: hidden; }
.training-sidebar { overflow-y: auto; }
.training-type-item {
  padding: 10px 14px; border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
  color: var(--text2); font-size: 13.5px; transition: all .15s;
}
.training-type-item:hover { background: var(--bg3); color: var(--text); }
.training-type-item.active { background: var(--primary-light); color: var(--primary); }
.training-type-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.training-main { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.training-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.training-item-header { display: flex; justify-content: space-between; align-items: center; }
.training-item-title { font-weight: 600; font-size: 13.5px; }
.training-item-content { color: var(--text2); font-size: 13px; line-height: 1.6; }
.training-item-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.training-type-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
}
.badge-context { background: rgba(88,166,255,.15); color: var(--info); }
.badge-script { background: rgba(63,185,80,.15); color: var(--success); }
.badge-objection { background: rgba(240,136,62,.15); color: var(--warning); }
.badge-faq { background: rgba(99,102,241,.15); color: var(--accent); }
.badge-rule { background: rgba(248,81,73,.15); color: var(--danger); }

/* ─── WEBHOOK ─── */
.webhook-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 12px;
}
.webhook-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.webhook-name { font-weight: 700; font-size: 14px; }
.webhook-url { font-size: 12px; color: var(--text2); font-family: monospace; margin-top: 4px; word-break: break-all; }
.webhook-events { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.event-tag {
  font-size: 11px; background: var(--bg4);
  color: var(--text2); padding: 2px 8px;
  border-radius: 4px; font-family: monospace;
}

/* ─── CAMPAIGN ─── */
.campaign-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; margin-bottom: 12px;
}
.campaign-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.campaign-name { font-weight: 700; font-size: 15px; }
.campaign-template { color: var(--text2); font-size: 13px; background: var(--bg3); padding: 8px 12px; border-radius: var(--radius); border-left: 3px solid var(--border); margin: 10px 0; }
.campaign-progress { height: 6px; background: var(--bg4); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.campaign-progress-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }
.campaign-stats { display: flex; gap: 16px; font-size: 12px; color: var(--text2); }
.campaign-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ─── NOTIFICATION PANEL ─── */
.notif-panel {
  position: fixed; bottom: 0; left: 0; width: 340px;
  max-height: 60vh; background: var(--bg2);
  border-top: 1px solid var(--border); border-right: 1px solid var(--border);
  border-top-right-radius: var(--radius-lg);
  z-index: 1000; display: none; flex-direction: column;
  overflow: hidden; box-shadow: 4px -4px 24px rgba(0,0,0,.4);
}
.notif-panel.open { display: flex; }
.notif-overlay { position: fixed; inset: 0; z-index: 999; display: none; }
.notif-overlay.open { display: block; }
.notif-header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 14px;
}
.notif-header button { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 12px; }
.notif-header button:hover { color: var(--primary); }
#notif-list { overflow-y: auto; flex: 1; }
.notif-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border2);
  cursor: pointer; transition: background .1s;
}
.notif-item:hover { background: var(--bg3); }
.notif-item.unread { border-left: 3px solid var(--primary); }
.notif-item-title { font-weight: 600; font-size: 13px; color: var(--text); }
.notif-item-msg { font-size: 12px; color: var(--text2); margin-top: 3px; }
.notif-item-time { font-size: 11px; color: var(--text3); margin-top: 4px; }
.notif-recovery { border-left-color: var(--success) !important; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 2000; display: none;
}
.modal-overlay.open { display: block; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); z-index: 2001;
  width: 520px; max-width: calc(100vw - 32px);
  max-height: 90vh; display: none; flex-direction: column;
  overflow: hidden;
}
.modal.open { display: flex; }
.modal-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 22px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--bg3); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ─── TOAST ─── */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
  min-width: 240px; max-width: 360px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ─── MISC ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.flex-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.text-muted { color: var(--text2); }
.text-sm { font-size: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .3; display: block; }
.empty-state p { font-size: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px; font-size: 12px; cursor: pointer;
  transition: all .15s; color: var(--text2);
}
.chip.selected { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.chip:hover { border-color: var(--primary); color: var(--text); }
.copy-btn { font-size: 11px; background: var(--bg4); border: none; color: var(--text2); padding: 3px 8px; border-radius: 4px; cursor: pointer; font-family: monospace; }
.copy-btn:hover { background: var(--bg3); color: var(--text); }
.preview-box { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; font-size: 12px; color: var(--text2); white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto; font-family: 'Courier New', monospace; }
.tabs { display: flex; gap: 4px; background: var(--bg3); padding: 4px; border-radius: var(--radius); margin-bottom: 16px; }
.tab-btn { padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; background: transparent; color: var(--text2); transition: all .15s; }
.tab-btn.active { background: var(--bg2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.recovery-alert {
  background: rgba(63,185,80,.1); border: 1px solid rgba(63,185,80,.3);
  border-radius: var(--radius-lg); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.recovery-alert svg { width: 20px; height: 20px; color: var(--success); flex-shrink: 0; }

/* ─── QUICK REPLY BUTTON & DROPDOWN ─── */
.chat-quick-reply-btn {
  background: transparent; border: none; color: var(--text2); cursor: pointer;
  padding: 6px; border-radius: var(--radius); display: flex; align-items: center;
  transition: all .15s; flex-shrink: 0;
}
.chat-quick-reply-btn:hover { color: var(--primary); background: var(--bg3); }
.quick-reply-dropdown {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  max-height: 300px; overflow-y: auto; z-index: 100;
  box-shadow: 0 -4px 24px rgba(0,0,0,.5); margin-bottom: 4px;
}
.qr-category { font-size: 11px; font-weight: 700; color: var(--text3); padding: 8px 14px 4px; text-transform: uppercase; letter-spacing: .5px; }
.qr-item { padding: 8px 14px; cursor: pointer; transition: background .1s; border-bottom: 1px solid var(--border2); }
.qr-item:hover { background: var(--bg3); }
.qr-item strong { display: block; font-size: 13px; color: var(--text); }
.qr-preview { display: block; font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-empty { padding: 16px; text-align: center; color: var(--text3); font-size: 13px; }
.chat-footer { position: relative; }

/* ─── FLOW CANVAS EDITOR ─── */
.flow-canvas-wrap { display: flex; flex-direction: column; height: 100%; }
.flow-canvas-toolbar {
  display: flex; align-items: center; padding: 8px 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.flow-canvas-hint {
  padding: 6px 16px; background: var(--bg3); font-size: 12px; color: var(--text3);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.flow-canvas {
  flex: 1; position: relative; overflow: hidden; background:
    radial-gradient(circle, var(--bg4) 1px, transparent 1px);
  background-size: 24px 24px; cursor: grab; user-select: none;
}
.flow-canvas:active { cursor: grabbing; }

.flow-node {
  position: absolute; background: var(--bg2); border: 1.5px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 2px 12px rgba(0,0,0,.3);
  z-index: 10; min-width: 180px; cursor: default;
}
.flow-node-selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

.fn-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: var(--bg3); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  cursor: move; font-size: 12px; font-weight: 700; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.fn-delete { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.fn-body { padding: 8px 10px; }
.fn-type { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.fn-start .fn-type { color: var(--success); }
.fn-message .fn-type { color: #ef4444; }
.fn-menu .fn-type { color: var(--accent); }
.fn-delay .fn-type { color: var(--warning); }

.fn-textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 12px; padding: 6px 8px; resize: vertical; font-family: inherit;
}
.fn-input-sm {
  width: 50px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 12px; padding: 3px 6px; text-align: center;
}
.fn-delay-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--text2); }
.fn-opts-label { font-size: 11px; color: var(--text3); margin: 6px 0 2px; }

.fn-port {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg4); border: 2px solid var(--primary); cursor: crosshair;
  z-index: 20; transition: background .15s;
}
.fn-port:hover, .fn-port-active { background: var(--primary); }
.fn-port-in { left: -7px; top: 24px; }
.fn-port-out { right: -7px; top: 24px; }
.fn-port-opt {
  right: -7px; font-size: 0;
}
.fn-port-label {
  position: absolute; right: 18px; top: -1px; font-size: 10px; color: var(--text3);
  white-space: nowrap; pointer-events: none;
}
.fn-start { text-align: center; padding: 12px 10px; color: var(--success); font-weight: 600; font-size: 13px; }

/* ─── TAG CHIPS & BADGES ─── */
.tag-chip {
  display: inline-block; background: var(--accent-light); color: var(--accent);
  padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.badge-pill {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.badge-success { background: rgba(63,185,80,.15); color: var(--success); }
.badge-muted { background: var(--bg4); color: var(--text3); }

/* ─── QUOTED MESSAGE ─── */
.msg-quoted {
  display: flex; align-items: stretch; gap: 8px;
  background: rgba(255,255,255,.06); border-radius: 6px;
  padding: 6px 10px; margin-bottom: 4px; font-size: 12px;
  color: var(--text2); max-width: 100%; overflow: hidden;
}
.msg-quoted-bar {
  width: 3px; min-height: 100%; border-radius: 2px;
  background: var(--primary); flex-shrink: 0;
}
.msg-quoted span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ─── ATTACH BUTTON ─── */
.chat-attach-btn {
  background: none; border: none; color: var(--text2);
  cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.chat-attach-btn:hover { color: var(--primary); background: var(--bg4); }

/* ─── REPLY BUTTON & BAR ─── */
.message { position: relative; }
.msg-reply-btn {
  position: absolute; top: 4px; right: 4px;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text2); cursor: pointer; font-size: 14px;
  width: 26px; height: 26px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  z-index: 5; transition: all .15s;
}
.message:hover .msg-reply-btn { display: flex; }
.msg-reply-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.message.incoming .msg-reply-btn { left: 4px; right: auto; }

.reply-bar {
  display: none; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg3);
  border-top: 1px solid var(--border2); border-radius: 8px 8px 0 0;
}
.reply-bar-content {
  flex: 1; display: flex; gap: 8px; align-items: stretch;
  font-size: 12px; color: var(--text2); overflow: hidden;
  min-width: 0;
}
.reply-bar-content span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reply-bar-close {
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 16px; padding: 4px;
}
.reply-bar-close:hover { color: var(--danger); }
