/* ════════════════════════════════════════
   Meta Leads Manager — Main Stylesheet
════════════════════════════════════════ */

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

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #0f1629;
  --sidebar-active: rgba(99,139,255,0.15);
  --sidebar-hover: rgba(255,255,255,0.05);
  --sidebar-text: rgba(255,255,255,0.65);
  --sidebar-text-active: #ffffff;
  --accent: #4f7ef8;
  --accent-dark: #3563d4;
  --accent-glow: rgba(79,126,248,0.25);
  --success: #22c55e;
  --success-dark: #16a34a;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --bg: #f0f2f8;
  --card: #ffffff;
  --border: #e2e7f0;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

body { display: flex; min-height: 100vh; }

/* ════════════════════════════════
   SIDEBAR
════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 0 0 20px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 12px;
}

.brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #4f7ef8, #7c3aed);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.brand-name { font-weight: 800; font-size: 1rem; color: #fff; line-height: 1.2; }
.brand-sub  { font-size: 0.74rem; color: rgba(255,255,255,0.4); font-weight: 500; }

.sidebar-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0 12px; flex: 1;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  border: none; background: transparent;
  color: var(--sidebar-text); font-size: 0.88rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: all 0.15s ease; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover); color: rgba(255,255,255,0.85); }
.nav-item.active {
  background: var(--sidebar-active); color: var(--sidebar-text-active);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }

.nav-badge {
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 0.7rem; font-weight: 800; padding: 1px 7px; margin-left: auto;
}

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  margin-top: 12px;
}

.live-dot-wrap { display: flex; align-items: center; gap: 8px; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.25);
  animation: pulse-dot 2s infinite; flex-shrink: 0;
}

.live-label { font-size: 0.75rem; color: rgba(255,255,255,0.4); font-weight: 500; }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34,197,94,0.25); }
  50%       { box-shadow: 0 0 0 6px rgba(34,197,94,0.08); }
}

/* ════════════════════════════════
   MAIN CONTENT
════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w); flex: 1;
  min-height: 100vh; padding: 32px 36px;
  max-width: calc(100vw - var(--sidebar-w));
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 16px;
  margin-bottom: 28px; flex-wrap: wrap;
}

.page-title {
  font-size: 1.6rem; font-weight: 800; color: var(--text);
  line-height: 1.2; display: flex; align-items: center;
  gap: 12px; flex-wrap: wrap;
}

.page-desc { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }

/* Connected page pill */
.page-info-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: #f0fdf4; border: 1.5px solid #bbf7d0;
  border-radius: 999px; padding: 6px 14px;
  font-size: 0.82rem; font-weight: 700; color: #15803d;
  white-space: nowrap;
}
.pill-dot {
  width: 8px; height: 8px; background: var(--success);
  border-radius: 50%; animation: pulse-dot 2s infinite; flex-shrink: 0;
}

.live-pill {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white; font-size: 0.7rem; font-weight: 800;
  padding: 3px 10px; border-radius: 999px; letter-spacing: 0.06em;
  animation: blink-pill 1.5s infinite;
}
@keyframes blink-pill { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.two-col {
  display: grid; grid-template-columns: 300px 1fr;
  gap: 24px; align-items: start;
}

/* ════════════════════════════════
   CARDS
════════════════════════════════ */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-title {
  font-size: 0.92rem; font-weight: 700; color: var(--text);
  padding: 16px 20px 12px; border-bottom: 1px solid var(--border);
}
.controls-card { overflow: hidden; }

/* Form section */
.form-section { padding: 16px 20px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field:last-of-type { margin-bottom: 0; }

label { font-size: 0.82rem; font-weight: 700; color: #374151; }

input, select {
  font: inherit; background: #f9fafb;
  border: 1.5px solid #e5e7eb; border-radius: 8px;
  color: var(--text); min-height: 40px; outline: none;
  padding: 0 12px; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent); background: #fff;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.action-buttons {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 16px;
}

/* Env info panel */
.env-info {
  background: #f8faff;
  border-top: 1.5px solid var(--border);
  padding: 14px 20px;
}
.env-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 12px;
  padding: 5px 0; border-bottom: 1px solid #eef0f6;
}
.env-row:last-of-type { border-bottom: none; }
.env-label {
  font-size: 0.75rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0;
}
.env-value {
  font-size: 0.8rem; font-weight: 600; color: var(--text);
  font-family: 'Courier New', monospace;
  text-align: right; overflow: hidden;
  text-overflow: ellipsis; max-width: 155px; white-space: nowrap;
}
.token-masked { color: var(--success); letter-spacing: 0.06em; }
.env-note {
  font-size: 0.75rem; color: var(--text-light);
  margin-top: 10px; line-height: 1.45;
}
.env-note code {
  background: #e8f0fe; color: #1d4ed8;
  border-radius: 4px; font-size: 0.85em; padding: 1px 5px;
}

/* Results card */
.results-card { overflow: hidden; }
.results-header {
  align-items: center; border-bottom: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: space-between;
  padding: 14px 18px;
}
.stats-row { display: flex; gap: 8px; flex-wrap: wrap; }

.leads-wrap { max-height: 70vh; overflow-y: auto; padding: 16px; }
.webhook-leads-wrap { max-height: none; min-height: 300px; }

/* ════════════════════════════════
   BUTTONS
════════════════════════════════ */
button, .btn {
  align-items: center; border: none; border-radius: 8px;
  cursor: pointer; display: inline-flex; font: inherit;
  font-weight: 700; gap: 6px; justify-content: center;
  min-height: 38px; padding: 0 16px; text-decoration: none;
  transition: all 0.15s ease; white-space: nowrap; font-size: 0.85rem;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); box-shadow: 0 4px 12px var(--accent-glow); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }

.btn-ghost { background: #fff; border: 1.5px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: #f3f4f6; }

.btn-danger { background: var(--danger-bg); border: 1px solid #fecaca; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fecaca; }

.btn-sm { min-height: 32px; padding: 0 12px; font-size: 0.8rem; }
.wide { grid-column: 1 / -1; }

/* ════════════════════════════════
   BADGES
════════════════════════════════ */
.badge {
  background: #f1f5f9; border-radius: 999px;
  color: #334155; font-size: 0.8rem; font-weight: 700; padding: 4px 12px;
}
.badge-blue { background: #eff6ff; color: #1d4ed8; }

/* ════════════════════════════════
   STATUS BARS
════════════════════════════════ */
.status-bar {
  display: none; font-size: 0.85rem; font-weight: 600;
  margin: 10px 18px 0; padding: 10px 14px; border-radius: 8px;
}
.status-bar.show { display: block; }
.status-bar.info    { background: #eff6ff; color: #1d4ed8; }
.status-bar.success { background: #f0fdf4; color: #15803d; }
.status-bar.error   { background: #fef2f2; color: var(--danger); }

.webhook-status-bar {
  display: none; font-size: 0.85rem; font-weight: 600;
  margin: 0 0 14px; padding: 10px 14px; border-radius: 8px;
}
.webhook-status-bar.show { display: block; }
.webhook-status-bar.info    { background: #eff6ff; color: #1d4ed8; }
.webhook-status-bar.success { background: #f0fdf4; color: #15803d; }
.webhook-status-bar.error   { background: #fef2f2; color: var(--danger); }

/* ════════════════════════════════
   LEAD CARDS
════════════════════════════════ */
/* ════════════════════════════════
   LEAD CARDS
════════════════════════════════ */
.lead-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-items: stretch;
}
.lead-card {
  background: #fff; border: 1.5px solid #e5e9f2;
  border-radius: var(--radius-sm); padding: 18px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: box-shadow 0.2s, border-color 0.2s;
  min-height: 220px;
}
.lead-card:hover { box-shadow: var(--shadow); border-color: #cbd5e1; }
.lead-card.new-lead {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  animation: card-pop 0.4s ease;
}
@keyframes card-pop {
  0%   { transform: scale(0.97); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

.lead-card-head { border-bottom: 1px solid #f1f5f9; padding-bottom: 10px; margin-bottom: 10px; display: grid; gap: 4px; }
.lead-new-badge {
  display: inline-flex; align-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-size: 0.68rem; font-weight: 800;
  border-radius: 999px; padding: 2px 8px; letter-spacing: 0.05em;
  width: fit-content; margin-bottom: 4px;
}
.lead-title { color: var(--text); font-size: 0.98rem; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.lead-subtitle { color: var(--text-muted); font-size: 0.78rem; line-height: 1.4; overflow-wrap: anywhere; }
.lead-fields { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.lead-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lead-label { color: var(--text-light); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.lead-value { color: #1e293b; font-size: 0.88rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; white-space: pre-wrap; }

.lead-card-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.btn-send-wa-card {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #166534;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0 14px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-send-wa-card:hover {
  background: #25D366;
  color: #ffffff;
  border-color: #25D366;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* ════════════════════════════════
   EMPTY STATES
════════════════════════════════ */
.empty-state { text-align: center; padding: 56px 24px; }
.empty-icon  { font-size: 2.5rem; margin-bottom: 12px; }
.empty-text  { color: var(--text-muted); font-weight: 600; font-size: 0.95rem; }
.empty-sub   { color: var(--text-light); font-size: 0.85rem; margin-top: 6px; }

/* ════════════════════════════════
   WEBHOOK SETUP GUIDE
════════════════════════════════ */
.setup-guide {
  background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 20px; overflow: hidden;
}
.setup-guide summary {
  cursor: pointer; font-weight: 700; font-size: 0.88rem;
  padding: 14px 18px; list-style: none; color: var(--accent);
  user-select: none;
}
.setup-guide summary::-webkit-details-marker { display: none; }
.setup-guide[open] summary { border-bottom: 1.5px solid var(--border); }
.guide-body  { padding: 18px; background: #f9fafb; }
.guide-steps { display: grid; gap: 14px; }
.guide-step  { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  width: 28px; height: 28px; background: var(--accent); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 800; flex-shrink: 0;
}
.step-text { font-size: 0.88rem; color: var(--text); line-height: 1.6; }
.step-text code {
  background: #e8f0fe; color: #1d4ed8; border-radius: 4px;
  font-family: 'Courier New', monospace; font-size: 0.82em; padding: 1px 6px;
}
.hint-text { background: #f8faff; color: var(--text-muted); font-size: 0.8rem; line-height: 1.45; padding: 12px; border-radius: 6px; }

/* ════════════════════════════════
   REFRESH INDICATOR
════════════════════════════════ */
.refresh-indicator {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.78rem; color: var(--text-muted); margin-bottom: 16px;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  animation: pulse-dot 2s infinite; flex-shrink: 0;
}
.refresh-sep { color: var(--text-light); }

/* ════════════════════════════════
   RESPONSIVE
════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-w: 64px; }
  .brand-name, .brand-sub, .nav-item span:not(.nav-icon), .nav-badge, .live-label { display: none; }
  .sidebar-brand { justify-content: center; padding: 18px 0; }
  .sidebar-nav   { padding: 0 8px; }
  .nav-item      { justify-content: center; padding: 10px; }
  .main-content  { padding: 24px 20px; }
  .two-col       { grid-template-columns: 1fr; }
  .page-header   { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
}

@media (max-width: 600px) {
  .action-buttons { grid-template-columns: 1fr; }
  .lead-grid      { grid-template-columns: 1fr; }
}

/* ════════════════════════════════
   WHATSAPP CARD STYLES
════════════════════════════════ */
.whatsapp-card {
  background: #ffffff;
  border: 1.5px solid #dcfce7;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.08);
  margin-bottom: 24px;
  overflow: hidden;
}

.whatsapp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
  border-bottom: 1.5px solid #dcfce7;
  flex-wrap: wrap;
}

.whatsapp-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.whatsapp-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #25D366, #128C7E);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.25);
  flex-shrink: 0;
}

.whatsapp-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #065f46;
  line-height: 1.2;
}

.whatsapp-sub {
  font-size: 0.83rem;
  color: #047857;
  margin-top: 2px;
  font-weight: 500;
}

.whatsapp-body {
  padding: 20px 24px;
  display: grid;
  gap: 16px;
}

.wa-form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.wa-phone-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.wa-phone-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(130px, 1fr) minmax(160px, 1.1fr) minmax(200px, 1.4fr) 38px;
  gap: 12px;
  align-items: center;
  width: 100%;
  animation: fadeIn 0.25s ease;
}

.wa-input-wrap {
  position: relative;
}

.wa-input-wrap.phone-wrap {
  flex: 1.2;
  min-width: 200px;
}

.wa-input-wrap.label-wrap {
  flex: 1;
  min-width: 150px;
}

.wa-input-wrap.filter-type-wrap {
  flex: 1.1;
  min-width: 170px;
}

.wa-input-wrap.filter-val-wrap {
  flex: 1.2;
  min-width: 190px;
}

.wa-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #1e293b;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.wa-select:focus {
  border-color: #25D366;
  background: #ffffff;
  box-shadow: 0 0 0 3.5px rgba(37, 211, 102, 0.2);
}

.wa-input-wrap.label-wrap .wa-input,
.wa-input-wrap.filter-val-wrap .wa-input {
  padding-left: 14px;
}

.wa-input {
  width: 100%;
  padding: 10px 14px 10px 42px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #111827;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.wa-input:focus {
  border-color: #25D366;
  background: #ffffff;
  box-shadow: 0 0 0 3.5px rgba(37, 211, 102, 0.2);
}

.wa-phone-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  pointer-events: none;
}

.btn-whatsapp {
  background: #25D366;
  color: #ffffff;
  font-weight: 800;
  padding: 0 20px;
  min-height: 42px;
  border-radius: 10px;
  border: none;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
}

.btn-whatsapp:hover:not(:disabled) {
  background: #1eb956;
  box-shadow: 0 6px 18px rgba(37, 211, 102, 0.4);
}

.btn-wa-test {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  color: #15803d;
  font-weight: 700;
  padding: 0 16px;
  min-height: 42px;
  border-radius: 10px;
}

.btn-wa-test:hover:not(:disabled) {
  background: #dcfce7;
  border-color: #4ade80;
}

.wa-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #047857;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
}

.wa-toast {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  display: none;
  animation: fadeIn 0.3s ease;
}
.wa-toast.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.wa-toast.error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}