/* ─────────────────────────────────────────────────────────────────────────────
   Balesno Premium CSS v5.0 - Full UI/UX Consistency Overhaul
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0b0c10;
  --bg-sidebar:  #14151a;
  --bg-card:     rgba(30, 32, 40, 0.7);
  --bg-card-raw: #1e2028;
  --bg-card-alt: rgba(34, 36, 46, 0.8);
  --border:      rgba(255, 255, 255, 0.08);
  --border-sm:   rgba(255, 255, 255, 0.04);

  --primary:     #00f5a0;
  --primary-2:   #00d9e1;
  --primary-grad: linear-gradient(135deg, #00f5a0 0%, #00d9e1 100%);
  --primary-dim: rgba(0, 245, 160, 0.12);
  --primary-glow: rgba(0, 245, 160, 0.35);

  --danger:  #ff4d4d;
  --warning: #ffb700;
  --info:    #22d3ee;

  --text:   #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;

  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 260px;
}

/* ── Custom Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }


/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; background: var(--bg); overflow-x: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
img, svg { display: block; max-width: 100%; }

/* ── Dashboard Layout ─────────────────────────────────────────────────────── */
.dashboard-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width 0.25s ease;
  z-index: 50;
}
.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.logo-img-sidebar {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 6px;
}
/* Logo in connection card - blends with dark bg */
.logo-img-conn {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 14px;
  filter: drop-shadow(0 0 16px var(--primary-glow));
}

.tenant-badge {
  margin: 0.75rem 1rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-2);
  overflow: hidden;
  flex-shrink: 0;
}
.tenant-badge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%; flex-shrink: 0;
  background: var(--text-3);
}
.pulse-dot.active { background: var(--primary); box-shadow: 0 0 6px var(--primary); }
.pulse-dot.warning { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.pulse-dot.error { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.88rem; font-weight: 500;
  transition: all var(--transition);
  position: relative;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}
.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: var(--primary-dim);
  color: var(--primary);
}
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 10%; bottom: 10%;
  width: 2.5px; border-radius: 0 4px 4px 0;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary-glow);
}
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white; font-size: 0.7rem; font-weight: 700;
  padding: 0.1rem 0.4rem; border-radius: 10px;
  min-width: 18px; text-align: center;
  flex-shrink: 0;
}
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  background: var(--bg);
  min-width: 0;
}
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.page-header .text-muted { font-size: 0.85rem; margin-top: 0.2rem; color: var(--text-2); }
.flex-between {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap;
}
.flex-between > div { flex: 1; min-width: 0; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.main-content .tab-pane { display: none !important; margin: 0; padding: 0; }
.main-content .tab-pane.active {
  display: block !important;
  animation: fadeInUp 0.2s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  transition: all var(--transition);
  cursor: pointer; border: none; outline: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-primary { background: var(--primary-grad); color: #000; font-weight: 700; border: none; }
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 0 20px var(--primary-glow); transform: translateY(-2px); }
.btn-danger  { background: rgba(255, 77, 77, 0.1); color: var(--danger); border: 1px solid rgba(255, 77, 77, 0.2); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn-outline:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-ghost  { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-sm     { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-block  { width: 100%; }
.danger-btn { color: var(--danger) !important; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: inherit; padding: 0; font-family: inherit; }
.btn-link:hover { text-decoration: underline; }

/* Glass Panel (card base) */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Overview Dashboard Grid ──────────────────────────────────────────────── */
.overview-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 1.25rem;
}
.overview-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

/* Connection Card (tall, spans 2 rows) */
.connection-card {
  grid-column: 1;
  grid-row: 1 / 3;
  background: linear-gradient(160deg, rgba(37,211,102,0.08) 0%, var(--bg-card) 60%);
  border: 1px solid rgba(37,211,102,0.18);
  min-height: 280px;
}
.conn-header {
  display: flex; align-items: center;
  gap: 0.6rem; margin-bottom: 1rem;
}
.conn-header h2 { font-size: 0.95rem; font-weight: 600; }
.conn-body {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.25rem; padding: 1rem 0;
}
.wa-large-icon {
  color: var(--primary);
}
.glow-green {
  filter: drop-shadow(0 0 14px rgba(37,211,102,0.6));
  animation: glowPulse 2.5s ease-in-out infinite alternate;
}
@keyframes glowPulse {
  from { filter: drop-shadow(0 0 8px rgba(37,211,102,0.3)); }
  to   { filter: drop-shadow(0 0 22px rgba(37,211,102,0.75)); }
}
.conn-info { text-align: center; }
.status-badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  border-radius: 20px;
  font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--primary-dim);
  color: var(--primary);
  margin-bottom: 0.35rem;
}
.business-number { font-size: 0.85rem; color: var(--text-2); font-family: monospace; }

/* Active Rules Card */
.rules-card { grid-column: 2; grid-row: 1; }
.activity-card { grid-column: 3; grid-row: 1; }
.rules-card, .activity-card { min-height: 140px; }

.card-header-flex {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.85rem;
}
.card-header-flex h2 { font-size: 0.9rem; font-weight: 600; }
.muted-value { font-size: 0.85rem; color: var(--text-2); font-weight: 600; }
.link-sm { font-size: 0.8rem; color: var(--primary); font-weight: 500; }

.rules-mini-list { display: flex; flex-direction: column; gap: 0.5rem; }
.rule-mini-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-sm);
  border-radius: var(--radius-sm);
}
.rule-mini-icon {
  background: var(--primary-dim);
  color: var(--primary);
  padding: 0.3rem; border-radius: 6px;
}
.rule-mini-info { flex: 1; min-width: 0; }
.rule-mini-title { font-size: 0.83rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-mini-desc { font-size: 0.72rem; color: var(--text-2); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0.75rem; }
.tl-item { position: relative; padding-left: 1.1rem; }
.tl-item::before {
  content: ''; position: absolute;
  left: 0.2rem; top: 0.35rem;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
}
.tl-item.primary-tl::before { background: var(--primary); box-shadow: 0 0 5px var(--primary); }
.tl-dot.primary { background: var(--primary); }
.tl-time { font-size: 0.7rem; color: var(--text-2); }
.tl-desc { font-size: 0.83rem; color: var(--text); line-height: 1.35; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-2); }
.py-1 { padding: 0.3rem 0; }

/* Quick Connect Banner */
.quick-connect-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.quick-connect-card h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.2rem; }
.quick-connect-card p { font-size: 0.82rem; color: var(--text-2); }
.quick-connect-card .btn { margin-left: auto; flex-shrink: 0; }
.qc-iconglow { font-size: 1.5rem; filter: drop-shadow(0 0 6px rgba(37,211,102,0.5)); }

/* ── Forms & Inputs ───────────────────────────────────────────────────────── */
.input-field {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
  outline: none;
  appearance: none;
}
.input-field:focus { border-color: var(--primary); background: rgba(255,255,255,0.06); }
.input-field option { background: var(--bg-card); color: var(--text); }
select.input-field { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b919e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }
label { display: block; font-size: 0.85rem; color: var(--text-2); margin-bottom: 0.35rem; }
.form-group { margin-bottom: 1rem; }

/* ── Cards, Tables ────────────────────────────────────────────────────────── */
.content-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.content-card.no-padding { padding: 0; }

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-2); font-size: 0.8rem;
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
}
.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-sm);
  font-size: 0.9rem;
}
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.keyword-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: var(--primary-dim);
  color: var(--primary);
  border-radius: 6px; font-size: 0.82rem; font-weight: 600;
}
.actions-cell { display: flex; gap: 0.4rem; align-items: center; }
.empty-state {
  text-align: center; padding: 3.5rem 1rem;
  color: var(--text-2);
}
.empty-icon { margin-bottom: 1rem; opacity: 0.35; }
.empty-icon svg { margin: 0 auto; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }
.empty-state p { font-size: 0.85rem; }

/* ── WhatsApp Tab ─────────────────────────────────────────────────────────── */
.wa-status-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.wa-status-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.wa-status-info {
  display: flex; align-items: center; gap: 0.85rem;
}
.wa-status-label { font-size: 0.82rem; color: var(--text-2); font-weight: 500; margin-bottom: 0.15rem; }
.wa-status-value { font-size: 1rem; font-weight: 600; color: var(--text); }
.wa-action-buttons { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.wa-control-btns { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.pulse-dot-lg {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.pulse-dot-lg.active {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulseLg 1.5s ease-in-out infinite;
}
.pulse-dot-lg.warning { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.pulse-dot-lg.error { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
@keyframes pulseLg {
  0%, 100% { box-shadow: 0 0 4px var(--primary); }
  50% { box-shadow: 0 0 12px var(--primary), 0 0 20px rgba(37,211,102,0.4); }
}

.qr-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}
.qr-area { display: flex; gap: 2rem; align-items: flex-start; flex-wrap: wrap; }
.qr-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex; flex-direction: column; align-items: center;
  gap: 1rem; min-width: 240px;
}
#qrCodeCanvas { background: white; padding: 8px; border-radius: 8px; }
#qrPlaceholder {
  width: 200px; height: 200px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; color: var(--text-2); font-size: 0.85rem;
  background: rgba(255,255,255,0.03); border-radius: 8px;
}
.qr-spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.qr-instructions { flex: 1; min-width: 220px; }
.qr-instructions h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.qr-instructions ol { padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.qr-instructions li { font-size: 0.9rem; color: var(--text-2); }
.qr-box-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.qr-refresh-hint { font-size: 0.8rem; color: var(--text-2); text-align: center; }

/* Connected State */
.connected-info {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(37,211,102,0.06);
  border: 1px solid rgba(37,211,102,0.15);
  border-radius: var(--radius-lg);
}
.connected-check {
  font-size: 1.75rem;
  line-height: 1;
  flex-shrink: 0;
}
.connected-info h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; color: var(--text); }
.connected-info p { font-size: 0.85rem; color: var(--text-2); }
.connected-item { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; }
.connected-item strong { color: var(--text-2); }

/* ── Chat Logs ────────────────────────────────────────────────────────────── */
.logs-outer {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.logs-container { max-height: 65vh; overflow-y: auto; }
.log-item {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-sm);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.log-item:last-child { border-bottom: none; }
.log-header { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--text-2); }
.log-sender { display: flex; align-items: center; gap: 0.35rem; }
.log-time { font-size: 0.78rem; color: var(--text-3); }
.log-bubble {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  max-width: 75%;
  position: relative;
}
.log-in { background: rgba(255,255,255,0.05); align-self: flex-start; border-top-left-radius: 2px; }
.log-out {
  background: rgba(37,211,102,0.12);
  border: 1px solid rgba(37,211,102,0.2);
  align-self: flex-end; border-top-right-radius: 2px;
}
.log-meta { font-size: 0.72rem; margin-top: 0.2rem; opacity: 0.65; }
.icon-inline { display: inline-block; vertical-align: middle; }

/* Logs empty state */
.logs-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  gap: 1rem;
  text-align: center;
}
.logs-empty-icon {
  width: 60px; height: 60px;
  background: rgba(37,211,102,0.08);
  border: 1px solid rgba(37,211,102,0.15);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  opacity: 0.7;
}
.logs-empty h3 { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.logs-empty p { font-size: 0.83rem; color: var(--text-2); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  padding: 1rem;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-content {
  width: 100%; max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  transform: translateY(16px);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.btn-close { background: transparent; color: var(--text-2); font-size: 1.4rem; line-height: 1; }
.btn-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.settings-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; }
.settings-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.settings-card-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.settings-desc { font-size: 0.82rem; color: var(--text-2); line-height: 1.5; margin-bottom: 0.75rem; }
.settings-desc code { background: rgba(255,255,255,0.07); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.78rem; font-family: monospace; }

/* Toggle */
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: rgba(255,255,255,0.1); border-radius: 22px; transition: 0.3s; }
.toggle-slider:before { position: absolute; content: ''; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* API Keys */
.api-keys-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.api-key-row { display: flex; gap: 0.5rem; align-items: center; }
.api-key-input { flex: 1; font-family: monospace; font-size: 0.82rem; }
.api-key-row .btn-sm { flex-shrink: 0; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 200; max-width: calc(100vw - 3rem); }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 220px;
  font-size: 0.9rem;
  animation: toastIn 0.25s ease;
  word-break: break-word;
}
.toast.success { border-left-color: var(--primary); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
.toast.hide { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateX(110%); opacity: 0; } }

/* Skeleton */
.skeleton-row {
  height: 1rem;
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-body {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}
/* Animated background */
.login-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.blob {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.12;
  animation: blobFloat 10s ease-in-out infinite alternate;
}
.blob-1 {
  width: 400px; height: 400px;
  background: var(--primary);
  top: -100px; left: -100px;
  animation-delay: 0s;
}
.blob-2 {
  width: 300px; height: 300px;
  background: #3b82f6;
  bottom: -80px; right: -80px;
  animation-delay: -3s;
}
.blob-3 {
  width: 200px; height: 200px;
  background: #a855f7;
  top: 50%; left: 60%;
  animation-delay: -6s;
}
@keyframes blobFloat {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(30px, 20px) scale(1.08); }
}

.login-container { width: 100%; max-width: 400px; position: relative; z-index: 1; }
.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2.25rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.logo-area { text-align: center; margin-bottom: 1.75rem; }
.logo-icon-wrap { display: flex; align-items: center; justify-content: center; margin-bottom: 0.85rem; }
/* login logo - use mix-blend for transparency on dark bg */
.logo-img-login {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 16px;
  filter: drop-shadow(0 0 18px rgba(37,211,102,0.5));
}
.logo-area h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.2rem; }
.login-card p { font-size: 0.85rem; color: var(--text-2); text-align: center; }

.login-form { margin-top: 1.5rem; }
.input-wrap {
  position: relative; display: flex; align-items: center;
}
.input-wrap input {
  width: 100%;
  padding: 0.65rem 0.85rem 0.65rem 2.5rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
  outline: none;
}
.input-wrap input:focus { border-color: var(--primary); background: rgba(255,255,255,0.06); }
.input-icon {
  position: absolute; left: 0.75rem;
  color: var(--text-3); pointer-events: none;
}
.btn-toggle-pw {
  position: absolute; right: 0.75rem;
  background: none; border: none; color: var(--text-3);
  cursor: pointer; padding: 0;
  display: flex; align-items: center;
}
.btn-toggle-pw:hover { color: var(--text-2); }

.btn-login {
  width: 100%; padding: 0.75rem;
  font-size: 0.95rem; font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(0,0,0,0.3);
  border-top-color: #000;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.error-text { color: var(--danger); font-size: 0.83rem; margin-top: 0.75rem; padding: 0.5rem 0.75rem; background: rgba(239,68,68,0.08); border-radius: var(--radius-sm); }
.login-footer { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1.5rem; font-size: 0.78rem; color: var(--text-3); flex-wrap: wrap; }
/* ── Inbox (Live Chat) ────────────────────────────────────────────────────── */
.inbox-container {
  display: flex;
  height: calc(100vh - 180px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}
.inbox-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.inbox-item {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.inbox-item:hover { background: rgba(255,255,255,0.05); }
.inbox-item.active { background: rgba(37, 211, 102, 0.1); border-left: 3px solid var(--primary); }
.inbox-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; }
.inbox-item-name { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.inbox-item-time { font-size: 0.75rem; color: var(--text-3); }
.inbox-item-preview { font-size: 0.82rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item-badges { display: flex; gap: 0.25rem; margin-top: 0.4rem; }
.badge-takeover { font-size: 0.65rem; background: var(--warning); color: #000; padding: 0.1rem 0.4rem; border-radius: 4px; font-weight: 600; }

.inbox-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
}
.inbox-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  background: var(--bg-body);
}
.inbox-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.inbox-contact-name { font-weight: 600; font-size: 1.1rem; color: var(--text); }
.inbox-contact-number { font-size: 0.8rem; color: var(--text-3); margin-top: 0.2rem; }
.inbox-takeover-toggle { display: flex; align-items: center; gap: 0.75rem; }
.takeover-label { font-size: 0.85rem; font-weight: 500; color: var(--text-2); transition: color 0.3s; }
.takeover-label.active { color: var(--warning); font-weight: 600; }

.inbox-messages {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}
.msg-bubble { 
  max-width: 75%; 
  padding: 0.75rem 1rem; 
  border-radius: 12px; 
  font-size: 0.9rem; 
  line-height: 1.4; 
  position: relative;
}
.msg-contact { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.msg-bot { align-self: flex-end; background: rgba(37, 211, 102, 0.15); border: 1px solid rgba(37, 211, 102, 0.3); color: var(--text); border-bottom-right-radius: 2px; }
.msg-human { align-self: flex-end; background: rgba(255, 171, 0, 0.15); border: 1px solid rgba(255, 171, 0, 0.3); color: var(--text); border-bottom-right-radius: 2px; }
.msg-time { display: block; font-size: 0.65rem; color: var(--text-3); margin-top: 0.35rem; text-align: right; }
.msg-sender-badge { font-size: 0.65rem; font-weight: 600; margin-bottom: 0.25rem; display: block; opacity: 0.7; }
.sender-bot { color: var(--primary); }
.sender-human { color: var(--warning); }

.inbox-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

/* ── Analytics Dashboard ──────────────────────────────────────────────────── */
.analytics-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 0;
}
@media (max-width: 1024px) { .analytics-stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px)  { .analytics-stats-grid { grid-template-columns: 1fr; } }

.analytics-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
}
.analytics-card-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.analytics-card-body { flex: 1; min-width: 0; }
.analytics-card-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.analytics-card-label {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 0.2rem;
}

/* top rules table */
.analytics-rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.analytics-rule-row:last-child { border-bottom: none; }
.analytics-rule-bar-wrap {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.analytics-rule-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.analytics-rule-keyword { font-size: 0.9rem; font-weight: 500; color: var(--text); min-width: 80px; }
.analytics-rule-count { font-size: 0.82rem; color: var(--text-3); min-width: 50px; text-align: right; }

/* recent convs table */
.analytics-conv-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.analytics-conv-row:last-child { border-bottom: none; }
.analytics-conv-name { flex: 1; font-size: 0.88rem; font-weight: 500; color: var(--text); }
.analytics-conv-meta { font-size: 0.78rem; color: var(--text-3); }
.badge-takeover-sm { background: rgba(239,68,68,0.15); color: #ef4444; font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; font-weight: 600; }

/* ── Broadcast ──────────────────────────────────────────────────────────────── */
.broadcast-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 900px) { .broadcast-layout { grid-template-columns: 1fr; } }

.broadcast-form-panel, .broadcast-history-panel { padding: 1.25rem; }
.broadcast-section-title {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.95rem; font-weight: 600; color: var(--text);
  margin: 0 0 1.1rem;
}

.broadcast-contact-actions { display: flex; gap: .5rem; margin-bottom: .6rem; }

.broadcast-contact-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem 0;
}
.broadcast-contact-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1rem;
  cursor: pointer;
  transition: background .15s;
  font-size: .88rem;
  color: var(--text);
}
.broadcast-contact-item:hover { background: rgba(255,255,255,0.04); }
.broadcast-contact-item input[type=checkbox] { accent-color: var(--primary); width:14px; height:14px; }
.broadcast-contact-name { flex: 1; font-weight: 500; }
.broadcast-contact-number { font-size: .75rem; color: var(--text-3); }

/* campaign history card */
.bc-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  margin-bottom: .65rem;
  background: rgba(255,255,255,0.02);
}
.bc-card:last-child { margin-bottom: 0; }
.bc-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.bc-card-msg { font-size: .88rem; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: .5rem; }
.bc-card-meta { font-size: .78rem; color: var(--text-3); }
.bc-progress { height: 5px; background: rgba(255,255,255,0.07); border-radius: 3px; overflow: hidden; margin: .4rem 0; }
.bc-progress-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .5s; }
.badge-running { background: rgba(251,191,36,0.15); color: #fbbf24; font-size: .7rem; padding: 2px 7px; border-radius: 5px; font-weight: 600; }
.badge-done { background: rgba(37,211,102,0.15); color: var(--primary); font-size: .7rem; padding: 2px 7px; border-radius: 5px; font-weight: 600; }
.badge-failed { background: rgba(239,68,68,0.15); color: #ef4444; font-size: .7rem; padding: 2px 7px; border-radius: 5px; font-weight: 600; }



@media (max-width: 900px) {
  .inbox-container { flex-direction: column; height: calc(100vh - 120px); }
  .inbox-sidebar { width: 100%; height: 35%; border-right: none; border-bottom: 1px solid var(--border); }
  .inbox-main { height: 65%; }
}

/* ── Responsive (Tablet) ──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .overview-grid { grid-template-columns: 240px minmax(0, 1fr) minmax(0, 1fr); }
  .main-content { padding: 1.5rem; }
}
@media (max-width: 900px) {
  .overview-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .connection-card { grid-column: 1 / 3; grid-row: 1; min-height: 200px; }
  .conn-body { flex-direction: row; padding: 0.5rem 0; }
  .rules-card { grid-column: 1; grid-row: 2; }
  .activity-card { grid-column: 2; grid-row: 2; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sidebar-width: 100%; }
  .dashboard-layout {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    overflow: visible;
  }
  .sidebar-header { padding: 1rem; }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 0.4rem 1rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex-shrink: 0;
    padding: 0.55rem 0.85rem;
    font-size: 0.82rem;
    white-space: nowrap;
  }
  .nav-item.active::before { display: none; }
  .nav-item.active {
    border-bottom: 2px solid var(--primary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }
  .tenant-badge { margin: 0.5rem 0.75rem; }
  .sidebar-footer { display: none; }

  .main-content {
    padding: 1rem;
    overflow-y: visible;
    flex: none;
    width: 100%;
  }
  .overview-grid { grid-template-columns: minmax(0, 1fr); gap: 0.85rem; }
  .connection-card, .rules-card, .activity-card { grid-column: 1; grid-row: auto; }
  .connection-card { min-height: 180px; }
  .conn-body { flex-direction: row; padding: 0.25rem 0; }

  .qr-area { flex-direction: column; }
  .qr-box { min-width: 0; width: 100%; }
  #qrPlaceholder { width: 100%; min-height: 180px; }

  .settings-grid { grid-template-columns: 1fr; }
  .wa-status-header { flex-direction: column; align-items: flex-start; }
  .wa-action-buttons { width: 100%; }
  .wa-action-buttons .btn { flex: 1; justify-content: center; }

  .flex-between { flex-direction: column; align-items: flex-start; }
  .flex-between .btn, .flex-between button { align-self: flex-start; }

  .logs-container { max-height: none; }
  .log-bubble { max-width: 90%; }

  .modal-overlay { padding: 0.75rem; align-items: flex-end; }
  .modal-content { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 85vh; }

  .toast-container { bottom: 0.75rem; right: 0.75rem; left: 0.75rem; }
  .toast { min-width: 0; }

  .page-header h1 { font-size: 1.25rem; }
  .quick-connect-card { flex-direction: column; align-items: flex-start; }
  .quick-connect-card .btn { margin-left: 0; width: 100%; justify-content: center; }

  .data-table th:nth-child(2), .data-table td:nth-child(2) { display: none; }
}

/* Extra small screens */
@media (max-width: 380px) {
  .main-content { padding: 0.75rem; }
  .overview-grid { gap: 0.65rem; }
}
