/* =========================================================
   Agile AI University — Leads Surface (Premium SaaS)
   Version: v2.6.0 (Experience Upgrade — SAFE)
   Date: 2026-04-02

   CHANGE TYPE:
   - SAFE UX ENHANCEMENT
   - NO STRUCTURAL CHANGE
   - FULL BACKWARD COMPATIBILITY

   ADDITIONS:
   ✅ Chat-style message UI
   ✅ Improved spacing & readability
   ✅ Non-intrusive edit UX
========================================================= */


/* =========================================================
   🧠 HEADER
========================================================= */

.leads-header {
  margin-bottom: 12px;
}

.leads-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 2px;
}

.leads-header p {
  font-size: 12px;
  color: var(--text-muted);
}


/* =========================================================
   📊 METRICS
========================================================= */

.leads-metrics {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.leads-metric {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.leads-metric .value {
  font-size: 15px;
  font-weight: 600;
}

.leads-metric .label {
  font-size: 10px;
  color: var(--text-muted);
}


/* =========================================================
   🧾 FORM CARD
========================================================= */

.leads-form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.leads-form-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}


/* =========================================================
   📐 FORM GRID
========================================================= */

.leads-form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 10px;
}

.leads-form-grid input,
.leads-form-grid select {
  height: 30px;
  font-size: 12px;
  padding: 5px 8px;
}

.leads-form-grid .full-width {
  grid-column: span 3;
}


/* =========================================================
   🔘 ACTIONS
========================================================= */

.leads-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.leads-actions .btn-primary {
  padding: 6px 14px;
  font-size: 12px;
}

.leads-actions .btn-secondary {
  padding: 6px 12px;
  font-size: 12px;
  opacity: 0.8;
}


/* =========================================================
   📊 TABLE
========================================================= */

.table-wrapper {
  border-radius: 12px;
  overflow-x: hidden;
}

.table {
  min-width: 100%;
  font-size: 12.5px;
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}

.table tbody td {
  padding: 7px 9px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover {
  background: rgba(37, 99, 235, 0.05);
}


/* =========================================================
   💬 ACTION COLUMN
========================================================= */

.table tbody td:first-child {
  width: 48px;
  text-align: center;
}

.lead-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 14px;
}

.lead-action-btn:hover {
  background: rgba(255,255,255,0.08);
  transform: scale(1.08);
}


/* =========================================================
   🔥 EXPANDED VIEW
========================================================= */

.lead-expand td {
  background: var(--bg-main);
  padding: 0;
}

.lead-expanded-card {
  padding: 16px 18px;
  border-top: 1px solid var(--border);

  /* 🔥 FIX: keep theme but restore structure */
  background: var(--bg-main);

  border-radius: 0 0 12px 12px;
}

/* Ensure expanded area has proper spacing */
.lead-expanded-row td {
  padding: 0 !important;
}

.lead-expanded-card {
  display: block;
  width: 100%;
}

.msg {
  opacity: 1 !important;
}

/* =========================================================
   💬 MESSAGE TIMELINE (UPGRADED)
========================================================= */

.lead-history {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 14px;
  max-width: 75%;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

/* OUTBOUND */
.msg.out,
.msg.outbound {
  margin-left: auto;
  background: linear-gradient(
    135deg,
    rgba(59,130,246,0.18),
    rgba(59,130,246,0.08)
  );
  border-bottom-right-radius: 6px;
}

/* INBOUND */
.msg.in,
.msg.inbound {
  background: rgba(34,197,94,0.12);
  border-bottom-left-radius: 6px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* EDIT BUTTON */
.msg-meta button {
  opacity: 0.5;
  border-radius: 6px;
  padding: 2px 6px;
}

.msg-meta button:hover {
  opacity: 1;
  transform: scale(1.15);
}

.msg-body {
  word-break: break-word;
}


/* =========================================================
   📊 META GRID (UNCHANGED + SAFE)
========================================================= */

.lead-meta-row td {
  background: rgba(255,255,255,0.02);
  padding: 6px 10px;
}

.lead-meta-inline,
.lead-meta-grid {
  display: grid;
  grid-template-columns: repeat(7, auto);
  gap: 12px 18px;
  font-size: 11.5px;
  color: var(--text-muted);
}


/* =========================================================
   📱 RESPONSIVE
========================================================= */

@media (max-width: 640px) {
  .lead-meta-inline,
  .lead-meta-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* =========================================================
   🔥 CHANNEL + DIRECTION (EXTENSION — SAFE)
   ADD-ONLY LAYER (NO OVERRIDES)
========================================================= */


/* =========================================================
   🧭 CHANNEL BADGE (INSIDE msg-meta)
========================================================= */

.msg-channel {
  display: inline-flex;
  align-items: center;
  gap: 6px;

  font-size: 10px;
  font-weight: 600;

  padding: 2px 6px;
  border-radius: 999px;

  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}


/* Channel Variants */

.msg-channel.whatsapp {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.msg-channel.email {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
}

.msg-channel.call {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
}


/* =========================================================
   🔄 DIRECTION BADGE (OPTIONAL VISUAL BOOST)
========================================================= */

.msg-direction {
  font-size: 9px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 6px;
}

.msg-direction.in {
  background: rgba(34,197,94,0.12);
  color: #16a34a;
}

.msg-direction.out {
  background: rgba(99,102,241,0.12);
  color: #4f46e5;
}


/* =========================================================
   ✨ HOVER ACTIONS (AI / DELETE READY)
========================================================= */

.msg {
  position: relative;
}

.msg-actions {
  position: absolute;
  top: 6px;
  right: 8px;

  display: flex;
  gap: 6px;

  opacity: 0;
  transition: opacity 0.2s ease;
}

.msg:hover .msg-actions {
  opacity: 1;
}

.msg-action-btn {
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
}

.msg-action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.msg-channel.manual {
  background: rgba(107, 114, 128, 0.12);
  color: #6b7280;
}

/* ============================================
   🎯 PREMIUM COMPACT LOG UI
============================================ */

.log-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  max-width: 700px;
}

/* Row containing dropdowns + textarea */
.log-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Dropdowns compact */
.log-box select {
  width: auto;
  min-width: 110px;
  max-width: 140px;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 6px;
}

/* Message box inline feel */
.log-box textarea {
  flex: 1;
  min-height: 36px;
  max-height: 60px;
  resize: none;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 6px;
}

/* Buttons aligned right */
.log-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.log-actions button {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
}

/* Small dropdowns */
.interaction-field.small {
  width: 110px;
  min-width: 100px;
}

/* Message input expands */
.interaction-field.flex {
  flex: 1;
  min-width: 200px;
}

/* Buttons */
.interaction-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: white;
  cursor: pointer;
}

.interaction-btn.primary {
  background: #2563eb;
  color: white;
  border: none;
}

/* =========================================================
   🎨 CHANNEL BADGES (Premium Visual Layer)
   SAFE ADDITION — No impact to layout
========================================================= */

.channel-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 500;
}

/* LinkedIn */
.channel-linkedin {
  background: rgba(10,102,194,0.12);
  color: #0a66c2;
}

/* WhatsApp */
.channel-whatsapp {
  background: rgba(37,211,102,0.12);
  color: #25d366;
}

/* Email */
.channel-email {
  background: rgba(239,68,68,0.12);
  color: #ef4444;
}

/* Call */
.channel-call {
  background: rgba(245,158,11,0.12);
  color: #f59e0b;
}

/* Manual */
.channel-manual {
  background: rgba(107,114,128,0.12);
  color: #6b7280;
}

/* =========================================================
   🎨 CHANNEL VISUAL ENHANCEMENT (SAFE ADDITION)
   Version: v2.8.0
   Type: NON-BREAKING (Visual only)
========================================================= */

/* Channel badge base */
.msg-channel {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 500;
  display: inline-block;
}

/* Channel colors */
.channel-linkedin {
  background: rgba(10, 102, 194, 0.12);
  color: #0a66c2;
}

.channel-whatsapp {
  background: rgba(37, 211, 102, 0.12);
  color: #25d366;
}

.channel-email {
  background: rgba(249, 115, 22, 0.12);
  color: #f97316;
}

.channel-call {
  background: rgba(168, 85, 247, 0.12);
  color: #a855f7;
}

.channel-manual {
  background: rgba(100, 116, 139, 0.12);
  color: #64748b;
}

/* =========================================================
   🎨 OTHER / OFFLINE CHANNEL
========================================================= */

.channel-other {
  background: rgba(100, 116, 139, 0.12);
  color: #64748b;
}

/* =========================================================
   ✨ INTERACTION UI (DARK MODE SAFE + PREMIUM)
========================================================= */

.interaction-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 10px;

  border-radius: 10px;
  margin-top: 10px;

  /* THEME SAFE */
  background: var(--bg-card);
  border: 1px solid var(--border);
}

/* Prevent wrapping */
.interaction-row * {
  white-space: nowrap;
}

/* Fields */
.interaction-field {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;

  /* THEME SAFE */
  background: var(--bg-input, var(--bg-card));
  border: 1px solid var(--border);
  color: var(--text-primary);
}

/* Dropdown width */
.interaction-field.small {
  width: 120px;
}

/* Message field */
.interaction-field.flex {
  flex: 1;
  min-width: 200px;
}

/* Buttons */
.interaction-btn {
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;

  /* THEME SAFE */
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

/* Primary button */
.interaction-btn.primary {
  background: #2563eb;
  color: white;
  border: none;
}

/* Cancel button */
.interaction-btn.cancel {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Hover states (premium feel) */
.interaction-btn:hover {
  opacity: 0.9;
}

/* =========================================================
   ✨ INTERACTION ROW POLISH (FINAL TOUCH)
========================================================= */

.interaction-row {
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: all 0.2s ease;
}

.interaction-row:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.interaction-field select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%236b7280' height='20' viewBox='0 0 20 20' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M5 7l5 5 5-5H5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 16px;
}

.msg {
  border: 1px solid rgba(0,0,0,0.04);
  backdrop-filter: blur(2px);
}

/* =========================================================
   🌙 FINAL DARK MODE FIX — HISTORY + INTERACTION LAYERS
   (PRODUCTION SAFE)
========================================================= */

/* 🔹 Fix outer history container */
.lead-history,
.lead-expanded-row td {
  background: var(--bg-card) !important;
}

/* 🔹 Remove any forced white backgrounds */
.lead-expanded-row,
.lead-expanded-row * {
  background-color: transparent;
}

/* 🔹 Fix interaction row to adapt to theme */
.interaction-row {
  background: var(--bg-card) !important;
  border: 1px solid var(--border);
}

/* 🔹 Inputs should follow theme */
.interaction-field {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* 🔹 Dropdown + input consistency */
.interaction-field select,
.interaction-field input {
  background: transparent;
  color: var(--text-primary);
}

/* 🔹 Placeholder visibility */
.interaction-field input::placeholder {
  color: var(--text-muted);
}

/* 🔹 Cancel button visibility */
.interaction-btn {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* 🔹 Primary button remains strong */
.interaction-btn.primary {
  background: #2563eb;
  color: white;
}

/* =========================================================
   🔥 FINAL STABILITY PATCH (NON-DESTRUCTIVE)
   Fixes:
   - Dark mode visibility
   - White background bug
   - Interaction row shrink issue
   - Layer conflicts
========================================================= */

/* FORCE EXPANDED AREA TO FOLLOW THEME */
.lead-expand td,
.lead-expanded-row td {
  background: var(--bg-card) !important;
}

/* REMOVE ANY HARD WHITE BACKGROUNDS */
.lead-expanded-row,
.lead-expanded-row * {
  background-color: transparent !important;
}

/* KEEP MESSAGE BUBBLES VISIBLE */
.msg {
  background: rgba(59,130,246,0.16) !important;
  color: var(--text-primary); /* 🔥 ensures visibility */
}

.msg.in,
.msg.inbound {
  background: rgba(34,197,94,0.12) !important;
}

/* INTERACTION ROW — FINAL CONTROL */
.interaction-row {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  display: flex !important;
  flex-wrap: nowrap !important;
}

/* PREVENT SHRINK BUG */
.interaction-row * {
  flex-shrink: 0;
}

/* MESSAGE FIELD SHOULD EXPAND ONLY */
.interaction-field.flex {
  flex: 1 1 auto !important;
  min-width: 200px;
}

/* INPUT VISIBILITY FIX */
.interaction-field,
.interaction-field select,
.interaction-field input {
  background: transparent !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
}

/* PLACEHOLDER FIX */
.interaction-field input::placeholder {
  color: var(--text-muted);
}

/* BUTTON VISIBILITY */
.interaction-btn {
  background: transparent !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
}

.interaction-btn.primary {
  background: #2563eb !important;
  color: #fff !important;
  border: none !important;
}

/* FINAL OVERRIDE — ENSURE NO WHITE FLASH */
.lead-expanded-row,
.lead-expanded-row td {
  background: var(--bg-card) !important;
}

.lead-row-secondary td {
  padding-top: 2px;
  color: #6b7280;
  font-size: 12.5px;
}

#leadBody td {
  vertical-align: top;
}

#leadBody tr td:nth-child(3) {
  width: 280px; /* adjust if needed */
}