/* ============================================
   WhatsApp Monitor — Minimal Dark UI
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:          #1c1f2e;
  --bg-1:        #232637;
  --bg-2:        #2a2d42;
  --bg-3:        #32364d;
  --border:      rgba(255,255,255,0.07);
  --border-hover:rgba(255,255,255,0.14);

  --text-1: #dde1f5;
  --text-2: #8b91b5;
  --text-3: #555a7a;

  --green:  #4ade80;
  --green-dim: rgba(74,222,128,0.10);
  --green-glow: rgba(74,222,128,0.22);

  --blue:   #818cf8;
  --blue-dim: rgba(129,140,248,0.12);

  --amber:  #fbbf24;
  --amber-dim: rgba(251,191,36,0.12);

  --red:    #f87171;
  --red-dim: rgba(248,113,113,0.12);

  --purple: #c084fc;
  --purple-dim: rgba(192,132,252,0.12);

  --radius:    14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', -apple-system, sans-serif;

  --sidebar-w: 220px;
  --header-h:  64px;

  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============================================
   Layout
   ============================================ */
.app { display: flex; min-height: 100vh; }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  background: #181b29;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon { font-size: 22px; }

.logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-2);
  text-decoration: none;
  border-radius: var(--radius-xs);
  transition: all 0.15s;
  font-size: 13.5px;
  font-weight: 500;
}

.nav-item:hover {
  background: var(--bg-2);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--blue-dim);
  color: var(--blue);
  font-weight: 600;
}

.nav-icon { font-size: 16px; line-height: 1; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.user-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.user-avatar {
  font-size: 16px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  color: var(--red);
  border-color: var(--red);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green-glow);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%,100% { box-shadow: 0 0 6px var(--green-glow); }
  50%      { box-shadow: 0 0 14px var(--green-glow); }
}

/* ============================================
   Main
   ============================================ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  height: var(--header-h);
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(28,31,46,0.90);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-1);
}

.header-actions { display: flex; gap: 10px; }

.content {
  flex: 1;
  padding: 28px 32px;
  background: var(--bg);
}

/* ============================================
   Stats Grid
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: default;
  box-shadow: 0 2px 12px rgba(99,102,241,0.06);
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 28px rgba(99,102,241,0.14);
}

.stat-card:nth-child(1) .stat-icon { background: rgba(99,102,241,0.12); }
.stat-card:nth-child(2) .stat-icon { background: rgba(16,185,129,0.12); }
.stat-card:nth-child(3) .stat-icon { background: rgba(245,158,11,0.12); }
.stat-card:nth-child(4) .stat-icon { background: rgba(239,68,68,0.12); }
.stat-card:nth-child(5) .stat-icon { background: rgba(139,92,246,0.12); }

.stat-icon {
  font-size: 24px;
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text-1);
  letter-spacing: -1px;
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 4px;
  font-weight: 500;
}

/* ============================================
   Section / Table
   ============================================ */
.section {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(99,102,241,0.06);
}

.section h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 18px;
}

.table-container { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
}

.table tr:last-child td { border-bottom: none; }

.table tbody tr:hover td {
  background: var(--bg-2);
}

.table .loading {
  text-align: center;
  color: var(--text-3);
  padding: 48px;
  font-size: 13px;
}

/* ============================================
   Badges
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-success { background: var(--green-dim); color: var(--green); }
.badge-warning { background: var(--amber-dim); color: var(--amber); }
.badge-danger  { background: var(--red-dim);   color: var(--red); }
.badge-info    { background: var(--blue-dim);  color: var(--blue); }
.badge-muted   { background: var(--bg-3);      color: var(--text-3); }

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--sans);
}

.btn-primary {
  background: var(--blue);
  color: #0f1020;
}
.btn-primary:hover {
  opacity: 0.88;
  box-shadow: 0 4px 16px rgba(129,140,248,0.3);
}

.btn-secondary {
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-3);
  border-color: var(--border-hover);
}

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 16px;
}
.btn-icon:hover { background: var(--bg-3); border-color: var(--border-hover); }

.btn-lg { padding: 12px 24px; font-size: 15px; width: 100%; }

.btn-sync {
  background: var(--green-dim);
  border-color: var(--green-glow);
  color: var(--green);
  font-size: 13px;
  padding: 0 14px;
  height: 36px;
}
.btn-sync:hover { background: rgba(74,222,128,0.18); }

.sync-status-text {
  font-size: 12px;
  color: var(--text-2);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ============================================
   Forms
   ============================================ */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}

.input, .select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-1);
  font-size: 13.5px;
  font-family: var(--sans);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-dim);
}

.select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%2355556a' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Searchable Select */
.searchable-select { position: relative; width: 100%; }
.ss-display {
  width: 100%; padding: 10px 36px 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text-2); font-size: 13.5px; font-family: var(--sans);
  cursor: pointer; user-select: none; transition: border-color .15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%2355556a' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ss-display:hover { border-color: var(--border-hover); }
.ss-display.ss-has-value { color: var(--text-1); }
.ss-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 999;
  background: var(--bg-1); border: 1px solid var(--border-hover); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.ss-search {
  width: 100%; padding: 10px 14px; background: var(--bg); border: none;
  border-bottom: 1px solid var(--border); color: var(--text-1); font-size: 13px;
  font-family: var(--sans); outline: none;
}
.ss-search::placeholder { color: var(--text-3); }
.ss-list { max-height: 220px; overflow-y: auto; }
.ss-option {
  padding: 9px 14px; color: var(--text-2); font-size: 13px; cursor: pointer;
  transition: background .1s; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ss-option:hover { background: var(--bg-2); color: var(--text-1); }
.ss-no-match { padding: 16px 14px; color: var(--text-3); font-size: 13px; text-align: center; }

/* WA sidebar searchable override */
.wa-sidebar .searchable-select { width: 100%; }
.wa-sidebar .ss-display {
  background: #2A3942; border: none; color: #8696A0; padding: 8px 10px;
  border-radius: 8px; font-size: 13px;
}
.wa-sidebar .ss-display.ss-has-value { color: #E9EDEF; }
.wa-sidebar .ss-dropdown { background: #2A3942; border-color: #3B4A54; }
.wa-sidebar .ss-search { background: #202C33; border-bottom-color: #3B4A54; color: #E9EDEF; }
.wa-sidebar .ss-search::placeholder { color: #8696A0; }
.wa-sidebar .ss-option { color: #8696A0; }
.wa-sidebar .ss-option:hover { background: #202C33; color: #E9EDEF; }

/* ============================================
   Page Header / Filters
   ============================================ */
.page-header { margin-bottom: 20px; }

.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.filters .select,
.filters .input {
  width: auto;
  min-width: 160px;
}

/* ============================================
   Upload Page
   ============================================ */
.upload-page { max-width: 560px; margin: 0 auto; }

.upload-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
}

.upload-card h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 6px;
}

.upload-description {
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 28px;
}

.file-drop {
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}

.file-drop:hover, .file-drop.dragover {
  border-color: var(--green);
  background: var(--green-dim);
}

.file-drop-content { pointer-events: none; }

.file-icon { font-size: 40px; margin-bottom: 12px; display: block; }

.file-drop p { color: var(--text-2); font-size: 13.5px; margin-bottom: 4px; }

.file-hint { font-size: 12px; color: var(--text-3) !important; }

.file-name {
  color: var(--green) !important;
  font-weight: 600;
  margin-top: 10px !important;
  font-family: var(--mono);
  font-size: 12px !important;
}

/* Progress */
.progress-section { margin-top: 28px; }

.progress-bar {
  height: 3px;
  background: var(--bg-3);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  width: 0%;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px var(--green-glow);
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.step { font-size: 11.5px; color: var(--text-3); transition: color 0.2s; }
.step.active { color: var(--green); font-weight: 600; }
.step.done { color: var(--text-2); }

/* Result */
.result-section { margin-top: 24px; }

.result-card {
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13.5px;
  line-height: 1.6;
}

.result-card.success { background: var(--green-dim); border-color: rgba(0,230,118,0.25); }
.result-card.error   { background: var(--red-dim);   border-color: rgba(255,82,82,0.25); }

/* ============================================
   Alerts Page
   ============================================ */
.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.alert-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.alert-card.warning { border-top: 2px solid var(--amber); }
.alert-card.danger  { border-top: 2px solid var(--red); }
.alert-card.error   { border-top: 2px solid var(--red); }
.alert-card.info    { border-top: 2px solid var(--blue); }

.alert-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.alert-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.alert-icon { font-size: 18px; }

.alert-count {
  font-size: 40px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -2px;
  color: var(--text-1);
  margin-bottom: 14px;
  line-height: 1;
}

.alert-list {
  font-size: 12.5px;
  color: var(--text-2);
  max-height: 320px;
  overflow-y: auto;
}

.alert-list-item {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}

.alert-list-item:last-child { border-bottom: none; }

/* ============================================
   Messages Viewer
   ============================================ */
.messages-page {
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.messages-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-1);
}

.chats-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
}

.panel-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-header .select { width: 100%; }

.chats-list { flex: 1; overflow-y: auto; }

.chat-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.chat-item:hover { background: var(--bg-2); }
.chat-item.active { background: var(--bg-2); border-left: 2px solid var(--green); }

.chat-avatar {
  font-size: 20px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--green-dim);
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-info { flex: 1; min-width: 0; }

.chat-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-meta { text-align: right; flex-shrink: 0; }

.chat-time { font-size: 10.5px; color: var(--text-3); }

.chat-count {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
  font-family: var(--mono);
}

/* Thread */
.thread-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.thread-header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.thread-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-1);
}

.message-thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thread-empty {
  text-align: center;
  color: var(--text-3);
  padding: 60px 20px;
  font-size: 13px;
}

.thread-load-more {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.message-bubble {
  max-width: 68%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}

.message-bubble.sent {
  align-self: flex-end;
  background: var(--blue);
  color: #0f1020;
  border-bottom-right-radius: 3px;
}

.message-bubble.received {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-bottom-left-radius: 3px;
}

.message-text { word-break: break-word; }

.message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

/* ============================================
   AI Insights
   ============================================ */
.ai-status {
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  margin-bottom: 18px;
  font-size: 13px;
}

.ai-status.info    { background: var(--blue-dim);  border: 1px solid rgba(68,138,255,0.2);  color: var(--blue); }
.ai-status.success { background: var(--green-dim); border: 1px solid rgba(0,230,118,0.2);   color: var(--green); }
.ai-status.error   { background: var(--red-dim);   border: 1px solid rgba(255,82,82,0.2);   color: var(--red); }

.ai-insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.loading-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px;
  color: var(--text-3);
  font-size: 13px;
}

.insight-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.2s, transform 0.2s;
}

.insight-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.insight-card.flagged {
  border-color: rgba(255,82,82,0.3);
  border-left: 3px solid var(--red);
}

.insight-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.insight-chat { font-size: 14px; font-weight: 600; color: var(--text-1); }

.insight-phone {
  font-size: 11.5px;
  color: var(--text-3);
  margin-bottom: 8px;
  font-family: var(--mono);
}

.insight-summary {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 12px;
}

.insight-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.topic-tag {
  background: var(--blue-dim);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}

.insight-flags {
  background: var(--red-dim);
  border: 1px solid rgba(255,82,82,0.15);
  border-radius: var(--radius-xs);
  padding: 9px 12px;
  margin-bottom: 10px;
}

.flags-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.flag-item { font-size: 12px; color: var(--text-2); padding: 2px 0; }

.insight-footer {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 6px;
  font-family: var(--mono);
}

/* ============================================
   Ask AI Chat
   ============================================ */
.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  max-width: 800px;
  margin: 0 auto;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 16px;
  gap: 8px;
}

.chat-welcome-icon { font-size: 44px; margin-bottom: 6px; }

.chat-welcome-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.chat-welcome-sub {
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 20px;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 580px;
}

.suggestion-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--sans);
}

.suggestion-btn:hover {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-dim);
}

.chat-bubble {
  max-width: 76%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--blue);
  color: #0f1020;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.chat-bubble.ai {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}

.chat-bubble.ai ul { padding-left: 16px; margin: 4px 0; }
.chat-bubble.ai li { margin: 2px 0; }
.chat-bubble.ai.error { border-color: rgba(255,82,82,0.3); color: var(--red); }

.chat-bubble.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
}

.chat-bubble .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: typing-dot 1.2s infinite;
}

.chat-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dot {
  0%,60%,100% { opacity: 0.3; transform: translateY(0); }
  30%          { opacity: 1;   transform: translateY(-5px); }
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 0 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-1);
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: var(--sans);
  resize: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--green);
}

.chat-send-btn {
  background: var(--blue);
  color: #0f1020;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
  height: 42px;
  font-family: var(--sans);
}

.chat-send-btn:hover { opacity: 0.85; }
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ============================================
   Mono helper
   ============================================ */
.mono { font-family: var(--mono); font-size: 13px; }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
  .upload-card { padding: 24px; }
  .messages-layout { grid-template-columns: 1fr; }
}

/* ============================================
   Live / Realtime indicator
   ============================================ */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.25);
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  font-family: var(--mono);
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: livePulse 1.5s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ============================================
   Message improvements
   ============================================ */
.message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 3px;
  opacity: 0.85;
}
.msg-media-tag {
  font-size: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text-2);
  font-family: var(--mono);
  margin-right: 4px;
  vertical-align: middle;
}

/* ============================================
   WhatsApp-like Messages UI
   ============================================ */

/* Layout */
.messages-page { height: calc(100vh - 60px); overflow: hidden; }
.wa-layout { display: flex; height: 100%; background: #0B141A; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }

/* Left Sidebar */
.wa-sidebar { width: 360px; min-width: 300px; display: flex; flex-direction: column; background: #111B21; border-right: 1px solid rgba(255,255,255,0.06); }
.wa-sidebar-header { padding: 16px 16px 8px; background: #202C33; }
.wa-sidebar-title { color: #E9EDEF; font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.wa-phone-select { width: 100%; background: #2A3942; border: none; color: #E9EDEF; padding: 8px 10px; border-radius: 8px; font-size: 13px; outline: none; cursor: pointer; }
.wa-phone-select option { background: #2A3942; }

/* Search */
.wa-search-bar { padding: 8px 12px; background: #111B21; }
.wa-search-input { width: 100%; background: #202C33; border: none; color: #E9EDEF; padding: 9px 16px; border-radius: 8px; font-size: 14px; outline: none; box-sizing: border-box; }
.wa-search-input::placeholder { color: #8696A0; }

/* Chat list */
.wa-chat-list { flex: 1; overflow-y: auto; }
.wa-chat-list::-webkit-scrollbar { width: 4px; }
.wa-chat-list::-webkit-scrollbar-thumb { background: #3B4A54; border-radius: 2px; }
.wa-empty-state { color: #8696A0; text-align: center; padding: 32px 16px; font-size: 14px; line-height: 1.6; }

/* Chat list item */
.wa-chat-item { display: flex; align-items: center; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.04); transition: background 0.15s; gap: 12px; }
.wa-chat-item:hover { background: #202C33; }
.wa-chat-item.active { background: #2A3942; }
.wa-chat-avatar-circle { width: 48px; height: 48px; border-radius: 50%; background: #2A3942; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; color: #8696A0; font-weight: 600; font-size: 18px; }
.wa-chat-avatar-circle.group { background: #1F3240; }
.wa-chat-item-info { flex: 1; min-width: 0; }
.wa-chat-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.wa-chat-item-name { color: #E9EDEF; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.wa-chat-item-time { color: #8696A0; font-size: 11px; flex-shrink: 0; }
.wa-chat-item-bottom { display: flex; justify-content: space-between; align-items: center; }
.wa-chat-item-preview { color: #8696A0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.wa-chat-item-count { background: #00A884; color: #fff; border-radius: 50%; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; padding: 0 4px; flex-shrink: 0; }

/* Right chat area */
.wa-chat-area { flex: 1; display: flex; flex-direction: column; position: relative; background: #0B141A; }

/* Welcome screen */
.wa-welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #8696A0; gap: 12px; }
.wa-welcome-icon { font-size: 64px; opacity: 0.5; }
.wa-welcome-title { font-size: 22px; font-weight: 300; color: #E9EDEF; }
.wa-welcome-sub { font-size: 14px; }

/* Chat header */
.wa-chat-header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #202C33; border-bottom: 1px solid rgba(255,255,255,0.06); flex-shrink: 0; }
.wa-chat-avatar { font-size: 24px; width: 40px; height: 40px; border-radius: 50%; background: #2A3942; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.wa-chat-header-name { color: #E9EDEF; font-size: 16px; font-weight: 500; }
.wa-chat-header-sub { color: #8696A0; font-size: 12px; margin-top: 1px; }

/* Messages background — WhatsApp pattern */
.wa-messages-bg {
  flex: 1;
  overflow-y: auto;
  padding: 12px 60px;
  background-color: #0B141A;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23182229' fill-opacity='0.6'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E");
}
.wa-messages-bg::-webkit-scrollbar { width: 4px; }
.wa-messages-bg::-webkit-scrollbar-thumb { background: #3B4A54; border-radius: 2px; }

/* Date separator */
.wa-date-sep { display: flex; justify-content: center; margin: 16px 0; }
.wa-date-sep span { background: #182229; color: #8696A0; font-size: 12px; padding: 5px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.06); }

/* Message bubbles */
.wa-msg { display: flex; margin: 2px 0; }
.wa-msg.sent { justify-content: flex-end; }
.wa-msg.received { justify-content: flex-start; }
.wa-msg.system { justify-content: center; margin: 6px 0; }

.wa-bubble {
  max-width: 65%;
  min-width: 80px;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  position: relative;
  word-break: break-word;
  font-size: 14.2px;
  line-height: 1.45;
}
.wa-msg.sent .wa-bubble {
  background: #005C4B;
  color: #E9EDEF;
  border-top-right-radius: 2px;
}
.wa-msg.received .wa-bubble {
  background: #202C33;
  color: #E9EDEF;
  border-top-left-radius: 2px;
}
.wa-msg.system .wa-bubble {
  background: #182229;
  color: #8696A0;
  font-size: 12px;
  border-radius: 8px;
  padding: 4px 10px;
  max-width: 80%;
  text-align: center;
}

/* Bubble tail */
.wa-msg.sent .wa-bubble::after {
  content: '';
  position: absolute;
  top: 0; right: -8px;
  border: 8px solid transparent;
  border-top: 8px solid #005C4B;
  border-left: 8px solid #005C4B;
  border-top-right-radius: 3px;
}
.wa-msg.received .wa-bubble::after {
  content: '';
  position: absolute;
  top: 0; left: -8px;
  border: 8px solid transparent;
  border-top: 8px solid #202C33;
  border-right: 8px solid #202C33;
  border-top-left-radius: 3px;
}

/* Sender name in groups */
.wa-sender { font-size: 12.5px; font-weight: 600; color: #53BDEB; margin-bottom: 3px; }

/* Message text */
.wa-text { white-space: pre-wrap; }
.wa-text a { color: #53BDEB; text-decoration: underline; }

/* Message time */
.wa-time-row { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 3px; }
.wa-time { font-size: 11px; color: rgba(233,237,239,0.6); line-height: 1; }
.wa-tick { font-size: 12px; color: rgba(233,237,239,0.6); }

/* Media placeholder */
.wa-media-card {
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  min-width: 160px;
}
.wa-media-icon { font-size: 28px; opacity: 0.8; }
.wa-media-info { flex: 1; }
.wa-media-type { font-size: 13px; font-weight: 500; color: #E9EDEF; text-transform: capitalize; }
.wa-media-sub { font-size: 11px; color: #8696A0; margin-top: 2px; }

/* URL link preview card */
.wa-link-preview {
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
  border-left: 3px solid #00A884;
  padding: 8px 10px;
  margin-bottom: 4px;
  font-size: 13px;
  color: #53BDEB;
  word-break: break-all;
}
.wa-link-preview a { color: #53BDEB; text-decoration: none; }
.wa-link-preview a:hover { text-decoration: underline; }
.wa-link-domain { font-size: 11px; color: #8696A0; margin-top: 2px; }

/* Deleted / system */
.wa-deleted { color: #8696A0; font-style: italic; font-size: 13.5px; }
.wa-deleted::before { content: '🚫 '; }

/* Load more */
.wa-load-more { padding: 8px; display: flex; justify-content: center; background: #0B141A; }
.wa-load-more-btn { background: #202C33; color: #8696A0; border: 1px solid rgba(255,255,255,0.08); padding: 8px 20px; border-radius: 20px; cursor: pointer; font-size: 13px; }
.wa-load-more-btn:hover { background: #2A3942; color: #E9EDEF; }

@media (max-width: 768px) {
  .wa-sidebar { width: 100%; }
  .wa-chat-area { display: none; }
  .wa-messages-bg { padding: 8px 12px; }
}
