:root {
  --ink: #232323;
  --ink-soft: #5c5c58;
  --paper: #f7f5f0;
  --paper-raised: #ffffff;
  --indigo: #22304f;
  --indigo-soft: #364872;
  --mustard: #d9a441;
  --line: #dedad0;
  --danger: #b84c3a;
  --success: #4c7a5a;
  --radius: 3px;
  
  /* Fallbacks needed if missing in some places */
  --bg: var(--paper);
  --text: var(--ink);
  --text-muted: var(--ink-soft);
}

body.dark-theme {
  --paper: #121212;
  --paper-raised: #1e1e1e;
  --ink: #e0e0e0;
  --ink-soft: #9e9e9e;
  --indigo: #81a1c1;
  --indigo-soft: #4c566a;
  --mustard: #ebcb8b;
  --line: #3b4252;
  --danger: #bf616a;
  --success: #a3be8c;
  
  --bg: var(--paper);
  --text: var(--ink);
  --text-muted: var(--ink-soft);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

.mono { font-family: 'IBM Plex Mono', monospace; }
.hidden { display: none !important; }

h1, h2, h3, .brand-name, .nav-item {
  font-family: 'Space Grotesk', sans-serif;
}

/* ---- LOGIN ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--indigo);
  background-image: radial-gradient(circle at 20% 20%, rgba(217,164,65,0.08), transparent 40%);
}
.login-card {
  background: var(--paper-raised);
  padding: 44px 36px;
  border-radius: 12px;
  width: 380px;
  max-width: 92vw;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-mark {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--mustard);
  border: 2px solid var(--mustard);
  width: 56px; height: 56px;
  line-height: 52px;
  border-radius: 50%;
  margin: 0 auto 16px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; color: var(--indigo); }
.login-sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 24px; }
#passwordInput {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; margin-bottom: 12px;
  font-family: 'IBM Plex Mono', monospace;
}
#loginBtn {
  width: 100%; padding: 12px; background: var(--indigo); color: white;
  border: none; border-radius: var(--radius); font-weight: 600; cursor: pointer;
  font-family: 'Space Grotesk', sans-serif; letter-spacing: 0.02em;
}
#loginBtn:hover { background: var(--indigo-soft); }
.login-error { color: var(--danger); font-size: 12px; margin-top: 10px; min-height: 14px; }

/* ---- APP LAYOUT ---- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--indigo);
  color: #e8e6de;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 16px;
}
.brand-mark {
  color: var(--mustard); font-weight: 700; font-size: 20px;
  border: 1.5px solid var(--mustard); border-radius: 50%;
  width: 30px; height: 30px; text-align: center; line-height: 27px;
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: 0.01em; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: #c8c6ba;
  text-align: left; padding: 11px 12px; border-radius: var(--radius);
  cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.nav-num {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--mustard); opacity: 0.8;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(217,164,65,0.15); color: #fff; }
.nav-item.active .nav-num { opacity: 1; }

.sidebar-foot {
  margin-top: auto; padding: 16px 24px 0; font-size: 10.5px;
  color: #7a8199; border-top: 1px solid rgba(255,255,255,0.08); padding-top: 16px;
}

.main { flex: 1; padding: 40px 48px; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 28px; position: relative; }
.view-header h2 { font-size: 24px; margin: 0 0 4px; color: var(--indigo); }
.view-sub { color: var(--ink-soft); font-size: 13.5px; margin: 0; }

/* ---- STAT CARDS ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.stat-label { font-size: 12px; color: var(--ink-soft); margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 600; color: var(--indigo); }
.stat-value.accent { color: var(--mustard); }

/* ---- TABLE ---- */
.table-wrap {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}
td {
  padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fbfaf7; }

.btn-primary {
  background: var(--indigo); color: white; border: none; padding: 9px 16px;
  border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: 'Space Grotesk', sans-serif;
}
.btn-primary:hover { background: var(--indigo-soft); }
.view-header .btn-primary { position: absolute; top: 0; right: 0; }

.btn-ghost {
  background: none; border: 1px solid var(--line); padding: 9px 16px;
  border-radius: var(--radius); font-size: 13px; cursor: pointer; color: var(--ink-soft);
}

.btn-icon {
  background: none; border: none; cursor: pointer; font-size: 13px; color: var(--indigo-soft);
  padding: 4px 8px;
}
.btn-icon.danger { color: var(--danger); }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px;
  font-weight: 600; font-family: 'IBM Plex Mono', monospace;
}
.badge-pending { background: #fbeed4; color: #8a6416; }
.badge-confirmed { background: #dbe6de; color: var(--success); }
.badge-delivered { background: #dde4f0; color: var(--indigo); }
.badge-cancelled { background: #f2ddd8; color: var(--danger); }

/* ---- CONVERSATIONS ---- */
.conv-layout { display: flex; gap: 20px; height: calc(100vh - 80px); }
.conv-list-wrap { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; }
.conv-list {
  flex: 1; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper-raised);
}
.conv-list-item {
  padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.conv-list-item:hover { background: #fbfaf7; }
.conv-list-item.active { background: rgba(217,164,65,0.1); border-left: 3px solid var(--mustard); }
.conv-list-item:last-child { border-bottom: none; }
.conv-name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.conv-phone { font-size: 11.5px; color: var(--ink-soft); font-family: 'IBM Plex Mono', monospace; }

.conv-thread-wrap { flex: 1; display: flex; flex-direction: column; }
.conv-thread-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--paper-raised); border: 1px solid var(--line);
  border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; font-weight: 600; font-size: 13.5px;
}
.conv-thread { flex: 1; overflow-y: auto; border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
  background: var(--paper-raised); padding: 20px; display: flex; flex-direction: column; gap: 10px;
}
.conv-empty { color: var(--ink-soft); text-align: center; margin-top: 40px; font-size: 13.5px; }

.chat-bubble {
  max-width: 65%; padding: 10px 14px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.5;
}
.chat-bubble.customer { align-self: flex-start; background: #f0efe9; }
.chat-bubble.ai { align-self: flex-end; background: var(--indigo); color: white; }

/* ---- AI INSIGHTS ---- */
.insights-section {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.insights-section h3 { margin: 0 0 4px; font-size: 16px; color: var(--indigo); }

.lead-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.lead-card:last-child { margin-bottom: 0; }
.lead-name { font-weight: 600; font-size: 13.5px; }
.lead-phone { font-size: 11.5px; color: var(--ink-soft); font-family: 'IBM Plex Mono', monospace; margin-bottom: 6px; }
.lead-reason { font-size: 12.5px; color: var(--ink-soft); max-width: 480px; }
.lead-badge {
  flex-shrink: 0; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  font-family: 'IBM Plex Mono', monospace; white-space: nowrap;
}
.lead-badge.juu { background: #dbe6de; color: var(--success); }
.lead-badge.wastani { background: #fbeed4; color: #8a6416; }
.lead-badge.chini { background: #f2ddd8; color: var(--danger); }

.advice-box {
  background: #fbfaf7; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; font-size: 13.5px; line-height: 1.6;
}

.ask-box { display: flex; gap: 10px; margin-bottom: 16px; }
.ask-box input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 13.5px;
}
.ask-qa {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  background: #fbfaf7;
}
.ask-question { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; color: var(--indigo); }
.ask-answer { font-size: 13px; line-height: 1.6; }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(34,48,79,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--paper-raised); padding: 28px; border-radius: var(--radius);
  width: 420px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 18px; color: var(--indigo); }
.modal label { display: block; font-size: 12px; font-weight: 600; margin: 12px 0 5px; color: var(--ink-soft); }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 13.5px;
  font-family: 'Inter', sans-serif;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---- WHATSAPP STATUS CARD ---- */
.whatsapp-status-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}
.ws-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 12px;
}
.ws-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--indigo);
}
.ws-icon {
  font-size: 18px;
}
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge.connected {
  background-color: rgba(76, 122, 90, 0.15);
  color: var(--success);
}
.badge.connecting {
  background-color: rgba(217, 164, 65, 0.15);
  color: var(--mustard);
}
.badge.qr {
  background-color: rgba(217, 164, 65, 0.15);
  color: var(--mustard);
}
.badge.disconnected {
  background-color: rgba(184, 76, 58, 0.15);
  color: var(--danger);
}
.ws-body {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 15px;
  padding: 20px;
  background: #fdfdfd;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.qr-container p {
  margin: 0 0 14px 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}
#qrcode img {
  border: 8px solid white;
  box-shadow: 0 4px 15px rgba(0,0,0,0.06);
}
.ws-btn-retry {
  padding: 8px 16px;
  background: var(--indigo);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  margin-top: 12px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  letter-spacing: 0.02em;
  transition: background 0.2s ease;
}
.ws-btn-retry:hover {
  background: var(--indigo-soft);
}

/* ---- BOT TOGGLE ---- */
.ws-divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0 0 0;
}
.ws-footer {
  padding-top: 14px;
}
.bot-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.bot-toggle-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bot-toggle-icon {
  font-size: 22px;
  line-height: 1;
}
.bot-toggle-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.bot-toggle-sublabel {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
/* The toggle button itself */
.bot-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px 7px 10px;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: background 0.25s ease, transform 0.1s ease;
  flex-shrink: 0;
}
.bot-toggle-btn:active {
  transform: scale(0.96);
}
/* Pill indicator (the circle) */
.bot-toggle-pill {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: white;
  flex-shrink: 0;
  transition: background 0.2s;
}
/* ACTIVE state — green */
.bot-toggle-btn.bot-toggle-active {
  background: var(--success);
  color: white;
}
/* PAUSED state — red/danger */
.bot-toggle-btn.bot-toggle-paused {
  background: var(--danger);
  color: white;
}
/* sublabel colour shift */
.bot-sublabel-paused {
  color: var(--danger) !important;
}

/* ── LOGO & BRAND IMAGES ──────────────────────────────────────────────────── */

/* Login screen logo */
.login-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 1.5rem auto;
  border-radius: 12px;
  object-fit: contain;
  filter: drop-shadow(0 0 18px rgba(124, 58, 237, 0.5));
  animation: logoGlow 3s ease-in-out infinite alternate;
}

@keyframes logoGlow {
  from { filter: drop-shadow(0 0 12px rgba(124, 58, 237, 0.4)); }
  to   { filter: drop-shadow(0 0 28px rgba(37, 211, 102, 0.6)); }
}

/* Sidebar brand icon */
.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.45);
  transition: box-shadow 0.3s ease;
}

.brand:hover .brand-icon {
  box-shadow: 0 0 20px rgba(37, 211, 102, 0.55);
}

/* ── CONVERSATIONS VIEW ─────────────────────────────────── */
.conv-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 80px);
  gap: 0;
  overflow: hidden;
}

.conv-list-wrap {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s;
}
.conv-item:hover { background: var(--paper); }
.conv-item.active { background: var(--indigo); color: #fff; }
.conv-item.active div { color: #fff !important; }
.conv-item.active span { opacity: 0.9; }

.conv-thread-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conv-thread-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  background: var(--paper-raised);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conv-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
}

.conv-empty {
  color: var(--text-muted);
  text-align: center;
  margin-top: 60px;
  font-size: 14px;
}

/* Chat Bubbles */
.chat-bubble {
  max-width: 72%;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  position: relative;
}

.chat-customer {
  align-self: flex-start;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}

.chat-ai {
  align-self: flex-end;
  background: var(--indigo);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-ai .bubble-time { color: rgba(255,255,255,0.65); }

.bubble-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

/* ── MODALS ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.modal-content {
  background: var(--paper);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  border: 1px solid var(--line);
  transform: scale(1);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.hidden .modal-content {
  transform: scale(0.95);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--indigo);
  font-size: 18px;
}
.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}
.close-btn:hover {
  color: var(--danger);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
}
.modal-body h4 {
  color: var(--ink);
  margin-top: 15px;
  margin-bottom: 5px;
}
.modal-body ul {
  padding-left: 20px;
  margin-bottom: 10px;
}
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

@media (max-width: 768px) {
  .conv-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 200px 1fr;
  }
  .conv-list-wrap { border-right: none; border-bottom: 1px solid var(--line); }
}
