/* ==========================================================================
   CM Desk / Chatdesk - Modern Colorful Design System
   Mobile-first, Ultra-Responsive, High-Performance CSS
   ========================================================================== */

:root {
  --font-main: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Theme Canvas */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-line: #e2e8f0;
  --border-line-subtle: #edf2f7;

  /* Typography Colors */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Brand Emerald (WhatsApp / Success) */
  --emerald: #10b981;
  --emerald-d: #059669;
  --emerald-darker: #047857;
  --emerald-light: #d1fae5;
  --emerald-subtle: #ecfdf5;
  --emerald-glow: rgba(16, 185, 129, 0.25);

  /* AI Violet / Indigo (Google Studio AI) */
  --ai-purple: #8b5cf6;
  --ai-indigo: #6366f1;
  --ai-pink: #ec4899;
  --ai-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  --ai-light: #ede9fe;
  --ai-glow: rgba(139, 92, 246, 0.25);

  /* Cyan / Blue (Campaigns / General) */
  --cyan: #06b6d4;
  --cyan-d: #0891b2;
  --cyan-light: #cffafe;
  --blue: #3b82f6;

  /* Status Colors */
  --amber: #f59e0b;
  --amber-d: #d97706;
  --amber-light: #fef3c7;
  --red: #ef4444;
  --red-d: #dc2626;
  --red-light: #fee2e2;

  /* Sidebar Dark Mesh */
  --nav-bg: #090d16;
  --nav-surface: #111827;
  --nav-active: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --nav-border: #1e293b;
  --nav-text: #cbd5e1;

  /* Modern Radius & Shadows */
  --r-sm: 8px;
  --r: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(226, 232, 240, 0.8);
  --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(203, 213, 225, 0.9);
  --shadow-float: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

/* Base Reset & Core Typography */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg-page);
  color: var(--text-main);
  font: 14.5px/1.55 var(--font-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; font-family: var(--font-main); color: var(--text-main); font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 26px; line-height: 1.25; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 700; }
h3 { font-size: 15.5px; line-height: 1.35; font-weight: 650; }
p { margin: 0; }
a { color: var(--emerald-d); text-decoration: none; transition: color .15s ease; font-weight: 500; }
a:hover { color: var(--emerald-darker); text-decoration: underline; }
.muted { color: var(--text-muted); font-size: 13.5px; }
.err { color: var(--red); font-size: 13px; font-weight: 500; min-height: 1.4em; }
code, pre { font-family: var(--font-mono); font-size: 13px; }

/* ---------- Form Controls & Inputs ---------- */
input, select, textarea {
  width: 100%; font: inherit; color: var(--text-main);
  background: #ffffff;
  border: 1px solid var(--border-line);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
}
input::placeholder, textarea::placeholder { color: var(--text-light); }
textarea { resize: vertical; min-height: 80px; }
input:hover, select:hover, textarea:hover { border-color: #cbd5e1; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px var(--emerald-glow), var(--shadow-sm);
}
label {
  display: block; font-weight: 600; font-size: 13.5px; color: #334155;
  margin-bottom: 4px;
}
label > input, label > select, label > textarea { margin-top: 6px; font-weight: 400; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: var(--r-sm); padding: 10px 18px;
  border: 1px solid var(--border-line);
  background: #ffffff; color: #1e293b;
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  user-select: none;
}
.btn:hover {
  background: #f8fafc; border-color: #cbd5e1;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
}
.btn:active { transform: translateY(0); box-shadow: none; }
.btn.primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: #059669; color: #ffffff;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.btn.primary:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border-color: #047857;
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.4);
}
.btn.danger {
  color: var(--red); border-color: #fecaca; background: #fff;
}
.btn.danger:hover {
  background: var(--red); color: #fff; border-color: var(--red);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn.small { padding: 6px 12px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }

/* ---------- Login Page ---------- */
#login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at top, #10b98115 0%, transparent 60%), linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--r-lg);
  padding: 36px 32px;
  display: grid; gap: 18px;
  box-shadow: var(--shadow-float);
  animation: fadeIn .3s ease-out;
}
.login-card h1 { font-size: 28px; background: linear-gradient(135deg, #0f172a 0%, #10b981 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* ---------- Application Shell Layout ---------- */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar Navigation */
#nav {
  background: var(--nav-bg);
  border-right: 1px solid var(--nav-border);
  color: var(--nav-text);
  padding: 24px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
#nav .brand {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0 10px 22px;
  border-bottom: 1px solid var(--nav-border);
  margin-bottom: 12px;
}
#nav .brand-title {
  font-weight: 800; font-size: 20px; color: #ffffff;
  display: flex; align-items: center; gap: 8px;
  letter-spacing: -0.02em;
}
#nav .brand-title .logo-dot {
  width: 10px; height: 10px; border-radius: 99px;
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
  display: inline-block;
}
#nav .brand-sub {
  font-size: 11.5px; font-weight: 600; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.08em;
}
#nav .nav-section-title {
  font-size: 11px; font-weight: 700; color: #475569;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 10px 12px 4px;
}
#nav a {
  display: flex; align-items: center; gap: 11px;
  color: #94a3b8; text-decoration: none;
  padding: 10px 14px; border-radius: var(--r-sm);
  font-weight: 500; font-size: 14px;
  transition: all .15s ease;
}
#nav a .nav-icon { font-size: 16px; opacity: .85; }
#nav a:hover {
  background: rgba(255, 255, 255, 0.06); color: #ffffff;
  transform: translateX(2px);
}
#nav a.on {
  background: var(--nav-active); color: #ffffff; font-weight: 600;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}
#nav a.nav-ai {
  position: relative;
  background: rgba(139, 92, 246, 0.1);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.25);
  margin: 6px 0;
}
#nav a.nav-ai:hover {
  background: rgba(139, 92, 246, 0.2);
  color: #fff;
  border-color: rgba(139, 92, 246, 0.4);
}
#nav a.nav-ai.on {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-color: #8b5cf6;
  color: #fff;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
}
.ai-badge {
  background: var(--ai-pink); color: #fff;
  font-size: 10px; font-weight: 800; padding: 2px 6px;
  border-radius: 99px; margin-left: auto; letter-spacing: 0.05em;
  box-shadow: 0 0 8px rgba(236, 72, 153, 0.5);
}
#nav #logout {
  margin-top: auto; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  color: #ef4444; font-weight: 600; font-size: 13.5px;
  border-radius: var(--r-sm);
  transition: all .15s ease;
}
#nav #logout:hover { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* Main Content Surface */
main {
  padding: 32px 40px 80px; min-width: 0;
  max-width: 1400px;
}
.pagehead {
  margin-bottom: 24px;
  display: flex; flex-direction: column; gap: 6px;
}
.pagehead h1 {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

/* ---------- Cards & Grid Containers ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-line);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow-card);
  transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover {
  box-shadow: var(--shadow-hover);
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .btn { flex: 0 0 auto; }
.grid2 {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}
.stack { display: grid; gap: 16px; }

/* Status Pills & Badges */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 99px;
  font-size: 12.5px; font-weight: 700;
  background: #f1f5f9; color: var(--text-muted);
}
.pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 99px; background: currentColor;
}
.pill.ok {
  background: var(--emerald-subtle); color: var(--emerald-darker);
  border: 1px solid #a7f3d0;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}
.pill.ok::before {
  background: var(--emerald); box-shadow: 0 0 6px var(--emerald);
  animation: pulse 2s infinite;
}
.pill.wait {
  background: var(--amber-light); color: var(--amber-d);
  border: 1px solid #fde68a;
}
.pill.bad {
  background: var(--red-light); color: var(--red-d);
  border: 1px solid #fecaca;
}
.tag {
  display: inline-flex; align-items: center;
  background: #f1f5f9; border: 1px solid #e2e8f0;
  border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600;
  margin: 0 4px 4px 0; color: #475569;
}
.empty {
  color: var(--text-muted); padding: 40px 16px; text-align: center;
  background: #f8fafc; border-radius: var(--r); border: 2px dashed #e2e8f0;
  font-size: 14px;
}

/* Modern Tables */
.tablewrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: #fff; border-radius: var(--r); border: 1px solid var(--border-line);
}
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--border-line-subtle); vertical-align: middle; }
th {
  background: #f8fafc; font-size: 12.5px; font-weight: 700;
  color: #475569; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-line);
}
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- WhatsApp Numbers Page ---------- */
.cards {
  display: grid; gap: 20px; margin-top: 20px;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
}
.num {
  display: flex; gap: 24px; justify-content: space-between; align-items: center;
}
.num-info { display: grid; gap: 10px; justify-items: start; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.scan {
  flex: none; width: 195px; height: 195px; padding: 14px;
  display: grid; place-items: center; text-align: center;
  font-size: 13px; color: var(--text-muted);
  border-radius: 12px; background: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 2px dashed var(--emerald);
  position: relative;
}
.scan img { width: 100%; height: 100%; border-radius: 8px; image-rendering: pixelated; }
.scan.done {
  background: var(--emerald-subtle); border: 2px solid var(--emerald);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.2);
}

/* ---------- Inbox (WhatsApp Live Web Interface) ---------- */
.inbox {
  display: grid; grid-template-columns: 350px 1fr;
  height: calc(100vh - 120px); min-height: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border-line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-float);
}
.chatlist {
  border-right: 1px solid var(--border-line);
  display: flex; flex-direction: column;
  min-height: 0; background: #ffffff;
}
.cl-head {
  display: flex; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border-line);
  background: #f8fafc;
}
.chats { overflow-y: auto; flex: 1; }
.chat {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  width: 100%; text-align: left; padding: 13px 16px;
  background: none; border: 0; border-bottom: 1px solid var(--border-line-subtle);
  cursor: pointer; font: inherit; color: inherit;
  transition: all .15s ease;
}
.chat:hover { background: #f8fafc; }
.chat.on {
  background: var(--emerald-subtle); border-left: 4px solid var(--emerald);
}
.chat .t { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #0f172a; }
.chat .time { font-size: 11.5px; color: var(--text-light); }
.chat .p { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--emerald); color: #fff; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; padding: 2px 8px; justify-self: end;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

/* Chat Conversation Canvas */
.conv {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: #f1f5f9;
}
.conv-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: #ffffff;
  border-bottom: 1px solid var(--border-line);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}
.conv-head .back { display: none; }
.msgs {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(540px, 80%); padding: 9px 14px;
  border-radius: 16px; background: #ffffff;
  border: 1px solid var(--border-line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 14px; line-height: 1.5;
}
.msg.in .bubble { border-top-left-radius: 4px; }
.msg.out .bubble {
  background: #dcfce7; border-color: #bbf7d0; border-top-right-radius: 4px;
  color: #064e3b;
}
.bubble .meta {
  font-size: 11px; color: var(--text-muted); text-align: right;
  margin-top: 4px; opacity: .85;
}
.bubble img, .bubble video {
  max-width: 100%; max-height: 320px; border-radius: 10px;
  display: block; margin-bottom: 6px;
}
.composer {
  background: #ffffff; border-top: 1px solid var(--border-line);
  padding: 12px 18px; display: grid; gap: 10px;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.02);
}
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tools select { width: auto; padding: 6px 10px; font-size: 13px; }
.send { display: flex; gap: 10px; align-items: flex-end; }
.send textarea { min-height: 46px; max-height: 140px; padding: 10px 14px; }

/* ---------- Campaigns & Progress ---------- */
.bar { height: 10px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.bar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, #10b981 0%, #06b6d4 100%);
  border-radius: 99px;
}
.camp { display: grid; gap: 12px; }
.camp-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.note {
  background: var(--amber-light); color: var(--amber-d);
  padding: 10px 14px; border-radius: var(--r-sm); font-size: 13.5px;
  border-left: 4px solid var(--amber);
}
.warn {
  background: var(--amber-light); color: #78350f;
  padding: 12px 16px; border-radius: var(--r-sm); font-size: 13.5px;
  border-left: 4px solid var(--amber-d);
}

/* ---------- API Documentation Blocks ---------- */
pre {
  background: #0f172a; color: #e2e8f0;
  padding: 16px; border-radius: var(--r-sm);
  overflow-x: auto; margin: 10px 0 0;
  white-space: pre-wrap; word-break: break-all;
  border: 1px solid #1e293b;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}
.keyrow { display: flex; gap: 8px; }
.keyrow input { font-family: var(--font-mono); font-size: 13.5px; font-weight: 500; }

/* Toast Notifications */
#toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #0f172a; color: #ffffff;
  padding: 12px 22px; border-radius: 99px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 90vw; z-index: 9999;
  font-weight: 600; font-size: 14px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); box-shadow: 0 10px 25px -5px rgba(239, 68, 68, 0.4); }

/* Animation Keyframes */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.85); } }

/* ==========================================================================
   Responsive Breakpoints & Mobile Optimization
   ========================================================================== */

@media (max-width: 960px) {
  #app {
    grid-template-columns: 1fr;
  }
  #nav {
    position: sticky; top: 0; z-index: 50; height: auto;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 10px 14px; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
  #nav .brand {
    padding: 0 12px 0 0; margin-bottom: 0;
    border-bottom: 0; border-right: 1px solid var(--nav-border);
  }
  #nav .brand-sub { display: none; }
  #nav a {
    padding: 8px 12px; font-size: 13px; gap: 6px;
    white-space: nowrap; flex-shrink: 0;
  }
  #nav a.nav-ai { margin: 0; }
  #nav #logout {
    margin: 0 0 0 auto; padding: 8px 12px;
    flex-shrink: 0;
  }
  main {
    padding: 20px 16px 60px;
  }
  .grid2 { grid-template-columns: 1fr; gap: 18px; }
  .cards { grid-template-columns: 1fr; }
  .num { flex-direction: column-reverse; align-items: flex-start; }
  .inbox {
    grid-template-columns: 1fr;
    height: calc(100vh - 135px);
  }
  .inbox .conv { display: none; }
  .inbox.open-conv .chatlist { display: none; }
  .inbox.open-conv .conv { display: flex; }
  .conv-head .back { display: inline-flex; }
}

@media (max-width: 480px) {
  h1 { font-size: 22px; }
  .card { padding: 18px 14px; }
  .btn { width: 100%; justify-content: center; }
  .actions .btn { width: auto; }
}
