/* ── Variables ────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 240px;
  --sidebar-collapsed: 64px;
  --topbar-h: 60px;

  /* Brand */
  --brand-1: #00C389;
  --brand-2: #00956A;
  --brand-dark: #00744F;
  --brand-glow: rgba(0,195,137,.18);
  --gold: #F5C518;
  --gold-light: rgba(245,197,24,.14);

  /* Sidebar */
  --sb-bg: #0B1120;
  --sb-surface: #111827;
  --sb-border: rgba(255,255,255,.07);
  --sb-text: #94A3B8;
  --sb-active-bg: rgba(0,195,137,.12);
  --sb-active-text: #00C389;

  /* Content */
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --text-1: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;

  /* Channels */
  --wa:   #25D366;
  --ig:   #E1306C;
  --fb:   #1877F2;
  --tg:   #229ED9;
  --sms:  #7C3AED;
  --em:   #F59E0B;

  /* Status */
  --green: #22C55E;
  --red:   #EF4444;
  --amber: #F59E0B;
  --blue:  #3B82F6;

  font-size: 14px;
}

[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #111827;
  --surface-2: #1A2438;
  --border: rgba(255,255,255,.08);
  --text-1: #F1F5F9;
  --text-2: #94A3B8;
  --text-3: #475569;
}

/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background .3s, color .3s;
}
[lang="ar"] body, body.rtl {
  font-family: 'IBM Plex Sans Arabic', 'Plus Jakarta Sans', system-ui, sans-serif;
}
a { text-decoration: none; color: inherit; }
button { font: inherit; cursor: pointer; border: none; background: none; }
svg { display: block; }

/* App shell */
#app-shell { display: flex; min-height: 100vh; }
#app-shell[hidden] { display: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s;
  border-right: 1px solid var(--sb-border);
  overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-collapsed); }
body.rtl #sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--sb-border); }

.sb-logo {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 10px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}
.logo-mark { width: 34px; height: 34px; flex-shrink: 0; position: relative; }
.logo-text {
  display: flex; flex-direction: column; gap: 1px;
  transition: opacity .2s;
}
.logo-en {
  font-size: 17px; font-weight: 700; letter-spacing: -.4px;
  color: #fff; line-height: 1; white-space: nowrap;
}
.logo-en span { color: var(--brand-1); }
.logo-ar {
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  font-size: 10px; color: var(--brand-1);
  direction: rtl; line-height: 1;
}
#sidebar.collapsed .logo-text { opacity: 0; pointer-events: none; }

.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--sb-border) transparent;
}
.sb-section { padding: 0 10px; margin-bottom: 4px; }
.sb-section-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--sb-text); opacity: .5;
  padding: 8px 8px 4px; white-space: nowrap;
  transition: opacity .2s;
}
#sidebar.collapsed .sb-section-label { opacity: 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sb-text);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
  position: relative;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-text);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--brand-1);
  border-radius: 0 2px 2px 0;
}
body.rtl .nav-item.active::before { left: auto; right: 0; border-radius: 2px 0 0 2px; }

.nav-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  transition: background .15s;
}
.nav-item.active .nav-icon { background: var(--brand-glow); }
.nav-label {
  font-size: 13px; font-weight: 500;
  transition: opacity .2s, width .2s;
}
#sidebar.collapsed .nav-label { opacity: 0; width: 0; overflow: hidden; }
.nav-badge {
  margin-left: auto;
  background: var(--brand-1);
  color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  transition: opacity .2s;
}
#sidebar.collapsed .nav-badge { opacity: 0; }
body.rtl .nav-badge { margin-left: 0; margin-right: auto; }

.sb-bottom {
  padding: 12px 10px;
  border-top: 1px solid var(--sb-border);
}
.sb-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: 8px;
  transition: background .15s;
}
.sb-user:hover { background: rgba(255,255,255,.05); }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  color: #fff; flex-shrink: 0;
}
.user-info { transition: opacity .2s; min-width: 0; overflow: hidden; }
.user-name { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan {
  font-size: 10px; color: var(--gold);
  display: flex; align-items: center; gap: 3px;
}
#sidebar.collapsed .user-info { opacity: 0; }
.sb-logout {
  background: none; border: none;
  color: var(--sb-text);
  padding: 4px 6px; border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sb-logout:hover { background: rgba(255,255,255,.06); color: #fff; }
#sidebar.collapsed .sb-logout { opacity: 0; pointer-events: none; }

/* ── Main layout ──────────────────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  transition: margin .25s cubic-bezier(.4,0,.2,1);
}
#main.collapsed { margin-left: var(--sidebar-collapsed); }
body.rtl #main { margin-left: 0; margin-right: var(--sidebar-w); }
body.rtl #main.collapsed { margin-right: var(--sidebar-collapsed); }

/* ── Topbar ───────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background .3s, border-color .3s;
}
.tb-toggle {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.tb-toggle:hover { background: var(--surface-2); color: var(--text-1); }

.tb-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-2);
  font-size: 13px;
}
.tb-breadcrumb .current { color: var(--text-1); font-weight: 600; }

.tb-actions { display: flex; align-items: center; gap: 8px; }
.tb-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  position: relative;
  transition: background .15s;
}
.tb-btn:hover { background: var(--surface-2); color: var(--text-1); }
.stream-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background .2s, box-shadow .2s;
}
.stream-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.18);
}
.stream-dot.off { background: var(--red); }

.lang-toggle {
  display: flex; align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.lang-btn {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px; font-weight: 600;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.lang-btn.active {
  background: var(--surface);
  color: var(--text-1);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background .15s;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ── Content ──────────────────────────────────────────────────────────── */
#content {
  flex: 1;
  padding: 28px 28px 40px;
  overflow-y: auto;
  min-width: 0;
}

.page-header { margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--text-1); line-height: 1.2; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.meta-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gold-light);
  border: 1px solid rgba(245,197,24,.3);
  color: #92660A;
  font-size: 11px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-top: 8px;
}
[data-theme="dark"] .meta-badge { color: var(--gold); }

/* Buttons */
.btn-primary {
  background: var(--brand-1); color: #fff;
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 10px 18px;
  border: none; border-radius: 10px;
  cursor: pointer;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface); color: var(--text-1);
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--brand-1); }

/* ── Stat Cards ───────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex; flex-direction: column;
  gap: 8px;
  transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(0,0,0,.07); }
.stat-header { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-1); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-2); }

/* ── Section title ────────────────────────────────────────────────────── */
.section-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 15px; font-weight: 700; color: var(--text-1); }
.section-action {
  font-size: 12px; font-weight: 600;
  color: var(--brand-1);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background .15s;
}
.section-action:hover { background: var(--brand-glow); }

/* ── Cards / Conversation list ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.card-head-title { font-size: 14px; font-weight: 700; color: var(--text-1); }

.conv-list { }
.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item:last-child { border-bottom: none; }
.conv-item.is-active { background: var(--brand-glow); }
.conv-item.is-active::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--brand-1);
}
body.rtl .conv-item.is-active::after { left: auto; right: 0; }

.conv-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  color: #fff; flex-shrink: 0;
  position: relative;
}
.conv-ch-badge {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px;
}
.conv-body { flex: 1; min-width: 0; }
.conv-name {
  font-size: 13px; font-weight: 600; color: var(--text-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-msg {
  font-size: 12px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}
.conv-meta { text-align: right; flex-shrink: 0; }
body.rtl .conv-meta { text-align: left; }
.conv-time { font-size: 10px; color: var(--text-3); }
.conv-unread {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--brand-1);
  color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 4px; margin-left: auto;
}
body.rtl .conv-unread { margin-left: 0; margin-right: auto; }

/* ── Empty / Loading states ───────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.empty-state .emoji { font-size: 40px; margin-bottom: 12px; display: block; }
.loading {
  padding: 32px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.loading::after {
  content: '…';
  display: inline-block;
  animation: loadingDots 1.4s infinite;
}
@keyframes loadingDots {
  0%,20% { content: '.'; }
  40% { content: '..'; }
  60%,100% { content: '...'; }
}

/* ── Mobile sidebar ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.mobile-open { transform: translateX(0); }
  body.rtl #sidebar { transform: translateX(100%); }
  body.rtl #sidebar.mobile-open { transform: translateX(0); }
  #main { margin-left: 0 !important; margin-right: 0 !important; }
  #overlay { display: block; }
  #content { padding: 20px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
#overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 90;
}

/* ── Logo dot animation ───────────────────────────────────────────────── */
@keyframes bobDot { 0%,100% { opacity:.2; transform:translateY(0) } 50% { opacity:1; transform:translateY(-4px) } }
.d1{animation:bobDot 1.4s ease-in-out infinite 0s}
.d2{animation:bobDot 1.4s ease-in-out infinite .2s}
.d3{animation:bobDot 1.4s ease-in-out infinite .4s}
.d4{animation:bobDot 1.4s ease-in-out infinite .2s}
.d5{animation:bobDot 1.4s ease-in-out infinite 0s}

@keyframes fadeInScale { from { opacity:0; transform:scale(.97) } to { opacity:1; transform:scale(1) } }
.page-section { animation: fadeInScale .25s ease both; }

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

/* ── AUTH SCREEN ──────────────────────────────────────────────────────── */
#auth-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0B1120 0%, #0D2030 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
#auth-screen[hidden] { display: none; }
.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px 32px;
  width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  text-align: center;
}
.auth-logo { margin: 0 auto 16px; width: 56px; height: 36px; }
.auth-title { font-size: 24px; font-weight: 700; color: var(--text-1); }
.auth-title span { color: var(--brand-1); }
.auth-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  font: inherit; font-size: 14px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-1);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.auth-form input:focus { border-color: var(--brand-1); box-shadow: 0 0 0 3px var(--brand-glow); }
.auth-form .btn-primary { padding: 12px 16px; font-size: 14px; }
.auth-error {
  font-size: 12px; color: var(--red);
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
  text-align: left;
}
.auth-error[hidden] { display: none; }

/* ── INBOX split layout ───────────────────────────────────────────────── */
.inbox-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  height: calc(100vh - var(--topbar-h) - 90px);
  min-height: 480px;
}
@media (max-width: 900px) {
  .inbox-shell { grid-template-columns: 1fr; height: auto; }
  .inbox-pane-thread { min-height: 520px; }
}
.inbox-pane-list, .inbox-pane-thread {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.inbox-pane-list .card-head { padding: 12px 14px; gap: 8px; }
.inbox-search {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit; font-size: 13px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.inbox-search:focus { border-color: var(--brand-1); }
.inbox-pane-list .conv-list { flex: 1; overflow-y: auto; min-height: 0; }

/* Thread */
.thread-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.thread-head-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.thread-name { font-size: 14px; font-weight: 700; color: var(--text-1); }
.thread-sub { font-size: 11px; color: var(--text-3); margin-top: 1px; }

.thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--surface-2);
  display: flex; flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.msg-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.msg-row.in .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}
.msg-row.out .msg-bubble {
  background: var(--brand-1);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-body { white-space: pre-wrap; }
.msg-body em { opacity: .85; font-style: italic; }
.msg-meta {
  font-size: 10px; margin-top: 4px; text-align: right;
}
.msg-row.in .msg-meta { color: var(--text-3); }
.msg-row.out .msg-meta { color: rgba(255,255,255,.78); }

.send-box {
  display: flex; gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.send-box input {
  flex: 1;
  font: inherit; font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.send-box input:focus { border-color: var(--brand-1); }
.send-error {
  margin: 0 14px 12px;
  font-size: 12px; color: var(--red);
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: 8px;
  padding: 7px 12px;
  flex-shrink: 0;
}
.send-error[hidden] { display: none; }

/* ── Contacts ─────────────────────────────────────────────────────────── */
.contacts-rows { padding: 4px 0; }
.contact-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.contact-row:last-child { border-bottom: none; }
.contact-name { font-size: 13px; font-weight: 600; color: var(--text-1); }
.contact-sub { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.contact-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Misc form ────────────────────────────────────────────────────────── */
.text-input {
  font: inherit; font-size: 13px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.text-input:focus { border-color: var(--brand-1); }

/* Toast (lightweight) */
#toast-root {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
body.rtl #toast-root { right: auto; left: 24px; }
.toast {
  background: var(--text-1);
  color: var(--surface);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  animation: toastIn .2s ease both;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Send-area: icon buttons, attachment menu, emoji panel ───────────── */
.send-area { display: flex; flex-direction: column; flex-shrink: 0; position: relative; }
.send-icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 18px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.send-icon-btn:hover { background: var(--surface-2); border-color: var(--brand-1); }
.send-icon-btn.active { background: var(--brand-glow); border-color: var(--brand-1); }

.attach-menu, .emoji-panel {
  position: absolute;
  bottom: 100%;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  z-index: 30;
}
.attach-menu { left: 14px; display: flex; flex-direction: column; gap: 2px; min-width: 180px; }
.attach-menu[hidden], .emoji-panel[hidden] { display: none; }
.attach-opt {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-1);
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
}
.attach-opt:hover { background: var(--surface-2); }

.emoji-panel {
  left: 60px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: 320px;
  max-height: 260px;
  overflow-y: auto;
}
.emoji-btn {
  font-size: 18px;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: none;
  transition: background .12s;
}
.emoji-btn:hover { background: var(--surface-2); }

/* Attachment preview above send box */
#attachment-preview {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 14px;
}
#attachment-preview[hidden] { display: none; }
.attach-preview-inner {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
.attach-thumb {
  width: 48px; height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.attach-icon {
  width: 48px; height: 48px;
  border-radius: 8px;
  background: var(--brand-glow);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.attach-info { flex: 1; min-width: 0; }
.attach-name {
  font-size: 13px; font-weight: 600; color: var(--text-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-size { font-size: 11px; color: var(--text-2); margin-top: 1px; text-transform: capitalize; }
.attach-cancel {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.attach-cancel:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Inline media in bubbles ──────────────────────────────────────────── */
.msg-image, .msg-sticker {
  max-width: 260px;
  max-height: 320px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
}
.msg-sticker { background: transparent; max-width: 140px; }
.msg-video, .msg-audio {
  max-width: 280px;
  border-radius: 10px;
  display: block;
}
.msg-audio { width: 260px; }
.msg-doc {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,.06);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  text-decoration: none;
  margin-bottom: 4px;
}
.msg-row.out .msg-doc { background: rgba(255,255,255,.18); }
.msg-doc:hover { text-decoration: underline; }

.msg-location {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px;
  background: rgba(0,0,0,.06);
  border-radius: 10px;
  min-width: 200px;
  font-size: 12px;
}
.msg-row.out .msg-location { background: rgba(255,255,255,.18); }
.msg-location-pin { font-size: 22px; line-height: 1; }
.msg-location-name { font-weight: 600; font-size: 13px; }
.msg-location-addr { opacity: .85; margin-top: 1px; }
.msg-location-coords {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px; opacity: .8; margin-top: 2px;
}
.msg-location-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: inherit;
  opacity: .9;
}
.msg-location-link:hover { opacity: 1; text-decoration: underline; }

/* ── Status ticks ─────────────────────────────────────────────────────── */
.tick {
  font-size: 11px;
  letter-spacing: -.5px;
  margin-left: 4px;
  display: inline-block;
}
.msg-row.out .tick.sent { color: rgba(255,255,255,.6); }
.msg-row.out .tick.delivered { color: rgba(255,255,255,.85); }
.msg-row.out .tick.read { color: #66D8FF; }
.msg-row.out .tick.failed { color: #FFE0E0; }
body.rtl .tick { margin-left: 0; margin-right: 4px; }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: modalIn .2s ease both;
}
@keyframes modalIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--text-1); }
.modal-close {
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 16px;
  color: var(--text-2);
  cursor: pointer;
  background: transparent;
  border: none;
}
.modal-close:hover { background: var(--surface-2); color: var(--text-1); }
.modal-body-inner { padding: 16px 18px; overflow-y: auto; }
.modal-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.modal-row label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.modal-row input {
  font: inherit; font-size: 14px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  outline: none;
}
.modal-row input:focus { border-color: var(--brand-1); }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-error {
  font-size: 12px; color: var(--red);
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: 8px;
  padding: 7px 10px;
  margin-top: 8px;
}
.modal-error[hidden] { display: none; }

/* Template list */
.template-list { display: flex; flex-direction: column; gap: 10px; }
.template-row {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.template-name { font-size: 13px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.template-lang {
  font-size: 10px;
  background: var(--brand-glow);
  color: var(--brand-1);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  font-weight: 600;
}
.template-body { font-size: 12px; color: var(--text-2); white-space: pre-wrap; margin-bottom: 8px; }
.template-warning { font-size: 11px; color: #B45309; margin-bottom: 6px; }
.template-send { font-size: 12px; padding: 6px 12px; }

/* ── Broadcast campaigns ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.campaigns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.campaigns-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.campaigns-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
  vertical-align: middle;
}
.campaigns-table tbody tr:last-child td { border-bottom: none; }
.campaign-row { cursor: pointer; transition: background .12s; }
.campaign-row:hover { background: var(--surface-2); }

.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: .02em;
  white-space: nowrap;
}
.status-pill.status-draft     { background: rgba(148,163,184,.18); color: #64748B; }
.status-pill.status-scheduled { background: rgba(245,158,11,.16);  color: #B45309; }
.status-pill.status-sending   { background: rgba(0,195,137,.18);   color: #00744F; }
.status-pill.status-completed { background: rgba(34,197,94,.18);   color: #15803D; }
.status-pill.status-canceled  { background: rgba(148,163,184,.20); color: #475569; }
.status-pill.status-failed    { background: rgba(239,68,68,.14);   color: #B91C1C; }

.status-pill.status-pending   { background: rgba(245,158,11,.14);  color: #B45309; }
.status-pill.status-sent      { background: rgba(0,195,137,.14);   color: #00744F; }
.status-pill.status-delivered { background: rgba(34,197,94,.18);   color: #15803D; }
.status-pill.status-read      { background: rgba(102,216,255,.22); color: #0E7490; }

.tag-chip {
  display: inline-block;
  margin-left: 6px;
  background: var(--brand-glow);
  color: var(--brand-1);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}
body.rtl .tag-chip { margin-left: 0; margin-right: 6px; }

.back-link {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-1);
  margin-bottom: 8px;
}
.back-link:hover { text-decoration: underline; }

.text-input {
  font: inherit; font-size: 14px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.text-input:focus { border-color: var(--brand-1); }

/* ── Flow tree editor ─────────────────────────────────────────────────── */
.flow-tree { padding: 4px; }
.node-list {
  display: flex; flex-direction: column;
  gap: 8px;
  padding: 6px 0;
}
.node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  position: relative;
  transition: box-shadow .15s, border-color .15s;
}
.node-card:hover { border-color: var(--brand-1); box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.node-card--condition { background: linear-gradient(180deg, var(--surface) 0%, rgba(0,195,137,.04) 100%); }
.node-head {
  display: flex; align-items: center; gap: 10px;
}
.node-icon { font-size: 18px; }
.node-type-label {
  font-size: 12px; font-weight: 700;
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.node-actions {
  margin-left: auto;
  display: flex; gap: 4px;
}
body.rtl .node-actions { margin-left: 0; margin-right: auto; }
.node-actions button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s, border-color .12s;
}
.node-actions button:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border); }

.node-summary {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.45;
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: 8px;
  word-break: break-word;
}
.node-summary strong { color: var(--text-1); font-weight: 700; }

.node-branches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
@media (max-width: 760px) { .node-branches { grid-template-columns: 1fr; } }
.node-branch {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
}
.node-branch--true  { border-color: rgba(34,197,94,.4); }
.node-branch--false { border-color: rgba(239,68,68,.35); }
.node-branch-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}
.node-branch--true  .node-branch-label { color: #15803D; }
.node-branch--false .node-branch-label { color: #B91C1C; }
.node-branch-count {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
}

.add-node-btn {
  align-self: stretch;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--brand-1);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.add-node-btn:hover { background: var(--brand-glow); border-color: var(--brand-1); }

/* Add-node picker grid */
.node-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 6px;
}
@media (max-width: 480px) { .node-picker { grid-template-columns: 1fr; } }
.node-pick {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-1);
  text-align: left;
  transition: background .12s, border-color .12s;
}
.node-pick:hover { background: var(--surface-2); border-color: var(--brand-1); }
.node-pick-icon { font-size: 20px; }
.node-pick-label { font-weight: 600; }
