:root {
  --primary: #25D366;
  --primary-dark: #1EBE5B;
  --sidebar-bg: #111827;
  --sidebar-text: #9CA3AF;
  --sidebar-text-active: #FFFFFF;
  --bg: #F5F6FA;
  --card-bg: #FFFFFF;
  --text: #1F2430;
  --muted: #6B7280;
  --border: #E5E7EB;
  --radius: 10px;
  --danger: #DC2626;
  --warning: #F59E0B;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary-dark); }

/* ---------- App shell (sidebar layout) ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 20px 0; flex-shrink: 0;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0 20px 20px; display: flex; align-items: center; gap: 8px; }
.sidebar nav { flex: 1; }
.sidebar nav a {
  display: block; padding: 10px 20px; color: var(--sidebar-text); text-decoration: none; font-size: 0.92rem; border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: #fff; }
.sidebar nav a.active { color: #fff; border-left-color: var(--primary); background: rgba(255,255,255,0.04); }
.sidebar .user-box { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.82rem; }
.sidebar .user-box .email { color: #fff; display: block; margin-bottom: 6px; word-break: break-all; }
.sidebar .badge-role { display: inline-block; background: var(--primary); color: #062; font-size: 0.65rem; padding: 2px 8px; border-radius: 20px; font-weight: 700; }
.sidebar .link-btn { color: #EF9A9A; background: none; border: none; cursor: pointer; padding: 0; font-size: 0.8rem; text-decoration: underline; margin-top: 8px; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--card-bg); border-bottom: 1px solid var(--border); padding: 18px 32px;
  display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.25rem; margin: 0; }
.content { padding: 28px 32px; max-width: 1000px; }

/* ---------- Cards & basics ---------- */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; }
.card h3 { margin-top: 0; }
label { display: block; margin-bottom: 14px; font-size: 0.88rem; color: var(--muted); }
input, textarea, select { width: 100%; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit; color: var(--text); }
textarea { min-height: 70px; }
.btn, .btn-small { display: inline-block; background: var(--primary); color: #06280F; font-weight: 600; padding: 9px 18px; border-radius: var(--radius); text-decoration: none; border: none; cursor: pointer; font-size: 0.92rem; }
.btn:hover, .btn-small:hover { background: var(--primary-dark); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 9px 18px; border-radius: var(--radius); text-decoration: none; }
.link-btn { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; text-decoration: underline; font-size: 0.85rem; }
.stacked-form { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.stacked-form:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table td, .table th { padding: 9px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.error { color: var(--danger); margin-bottom: 12px; }
.success { color: var(--primary-dark); font-weight: 600; }
.muted { color: var(--muted); font-size: 0.85rem; }
code { background: #F1F1F6; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }
.code-block { background: #1F2430; color: #E5E7EB; padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 0.8rem; white-space: pre-wrap; word-break: break-word; }

/* ---------- Badges & pills ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; }
.badge-connected { background: #DCFCE7; color: #166534; }
.badge-connecting, .badge-pending { background: #FEF3C7; color: #92400E; }
.badge-disconnected, .badge-not_started { background: #F3F4F6; color: #6B7280; }
.badge-active { background: #DCFCE7; color: #166534; }
.badge-suspended { background: #FEE2E2; color: #991B1B; }

/* ---------- Stats & usage bars ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-box strong { display: block; font-size: 1.6rem; }
.stat-box span { color: var(--muted); font-size: 0.8rem; }
.usage-bar-wrap { margin-bottom: 18px; }
.usage-bar-label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 6px; }
.usage-bar-track { background: #EEF0F5; border-radius: 20px; height: 8px; overflow: hidden; }
.usage-bar-fill { height: 100%; background: var(--primary); border-radius: 20px; }
.usage-bar-fill.warn { background: var(--warning); }
.usage-bar-fill.danger { background: var(--danger); }

/* ---------- Auth pages (no sidebar) ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { max-width: 380px; width: 100%; }

/* ---------- Plan pricing cards ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; }
.plan-card .price { font-size: 1.6rem; font-weight: 700; margin: 8px 0; }
.plan-card ul { list-style: none; padding: 0; margin: 12px 0; font-size: 0.85rem; color: var(--muted); text-align: left; }
.plan-card ul li { padding: 3px 0; }

/* ---------- Connection sub-nav ---------- */
.conn-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.back-link { font-size: 0.85rem; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--text); }
.conn-title { margin: 4px 0 0; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; flex-wrap: wrap; }
.subtabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-size: 0.88rem; border-bottom: 2px solid transparent; }
.subtabs a:hover { color: var(--text); }
.subtabs a.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Inbox / message list ---------- */
.msg-list { display: flex; flex-direction: column; gap: 14px; }
.msg-row { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.msg-row.msg-in { background: #F8FAFC; }
.msg-row.msg-out { background: #F0FDF4; }
.msg-meta { display: flex; justify-content: space-between; font-size: 0.78rem; margin-bottom: 8px; }
.msg-body { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; }
.msg-media-img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-top: 4px; object-fit: cover; }
.msg-media-video { max-width: 320px; border-radius: 8px; display: block; margin-top: 4px; }
.msg-row audio { margin-top: 4px; width: 100%; max-width: 320px; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .sidebar .brand { padding: 0 14px 0 0; }
  .sidebar nav { display: flex; flex: none; }
  .sidebar nav a { padding: 8px 12px; white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; }
  .sidebar nav a.active { border-left: none; border-bottom-color: var(--primary); }
  .sidebar .user-box { display: none; }
  .content { padding: 20px 16px; }
  .topbar { padding: 14px 16px; }
}
