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

:root {
  --bg-primary: #0b0f19;
  --bg-card: rgba(255, 255, 255, 0.03);
  --border-card: rgba(255, 255, 255, 0.06);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent-color: #6366f1;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --success-color: #25d366; /* Verde WhatsApp */
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --font-main: 'Outfit', sans-serif;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 10% 20%, rgba(99, 102, 241, 0.08) 0px, transparent 50%),
    radial-gradient(at 90% 80%, rgba(168, 85, 247, 0.08) 0px, transparent 50%);
}

/* --- SIDEBAR --- */
.sidebar {
  width: 260px;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--border-card);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 3rem;
}

.logo-icon {
  background: var(--accent-gradient);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, #f3f4f6, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-grow: 1;
}

.nav-item {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.nav-item:hover, .nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  border-left: 3px solid #a855f7;
  padding-left: calc(1rem - 3px);
}

.nav-item i {
  font-size: 1.1rem;
}

.sidebar-footer {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  border-top: 1px solid var(--border-card);
  padding-top: 1.5rem;
}

/* --- MAIN CONTENT --- */
.main-content {
  margin-left: 260px;
  flex-grow: 1;
  padding: 2.5rem;
  max-width: 1400px;
  width: calc(100% - 260px);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
}

.page-title h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.page-title p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.api-status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  padding: 0.5rem 1rem;
  border-radius: 30px;
  border: 1px solid var(--border-card);
  font-size: 0.85rem;
  font-weight: 500;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.badge-dot.active { background: var(--success-color); box-shadow: 0 0 8px var(--success-color); }
.badge-dot.inactive { background: var(--danger-color); box-shadow: 0 0 8px var(--danger-color); }

/* --- TABS --- */
.tab-content {
  display: none;
  animation: fadeIn 0.4s ease forwards;
}

.tab-content.active {
  display: block;
}

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

/* --- CARDS & GRID --- */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-info h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  letter-spacing: 0.5px;
}

.stat-info p {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-card:nth-child(2) .stat-icon {
  background: rgba(37, 211, 102, 0.15);
  color: var(--success-color);
}

.stat-card:nth-child(3) .stat-icon {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning-color);
}

/* --- GLASS CARD FORM & TABLES --- */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(10px);
  margin-bottom: 2rem;
}

.card-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.card-header p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* --- FORMS --- */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.25);
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  border: none;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-card);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-success {
  background: var(--success-color);
  color: white;
  box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.5);
}

/* --- QR SCANNER VIEW --- */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.qr-box {
  background: white;
  padding: 1.5rem;
  border-radius: 20px;
  margin: 1.5rem 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 250px;
  min-width: 250px;
}

.qr-box img {
  max-width: 100%;
}

.qr-status-indicator {
  padding: 0.5rem 1.5rem;
  border-radius: 30px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 1rem;
}

/* --- LEADS TABLE --- */
.table-container {
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  padding: 1rem;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-card);
}

.custom-table td {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border-card);
  font-size: 0.95rem;
}

.custom-table tr:hover {
  background: rgba(255, 255, 255, 0.01);
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge.interesado { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.status-badge.listo { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.status-badge.compro { background: rgba(37, 211, 102, 0.15); color: #34d399; }
.status-badge.no-interesado { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* --- WHATSAPP SIMULATOR --- */
.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 600px;
  background: #0f172a;
  border-radius: 20px;
  border: 1px solid var(--border-card);
  overflow: hidden;
  box-shadow: var(--glass-shadow);
}

/* Chat Sidebar (Contacts) */
.chat-sidebar {
  border-right: 1px solid var(--border-card);
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 25, 0.6);
  min-height: 0;
}

.chat-sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-card);
}

.chat-search {
  position: relative;
}

.chat-search input {
  padding-left: 2rem;
}

.chat-search i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.contact-list {
  overflow-y: auto;
  flex-grow: 1;
  min-height: 0;
}

.contact-item {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: background 0.3s;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.contact-item:hover, .contact-item.active {
  background: rgba(255, 255, 255, 0.04);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  color: white;
}

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

.contact-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.contact-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.contact-last-msg {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat Main Area */
.chat-area {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  padding: 0.75rem 1.5rem;
  background: #0b0f19;
  border-bottom: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-active-contact {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.active-contact-name {
  font-weight: 600;
  font-size: 1rem;
}

.active-contact-status {
  font-size: 0.75rem;
  color: var(--success-color);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.chat-body {
  flex-grow: 1;
  padding: 1.5rem;
  overflow-y: auto;
  min-height: 0;
  background: #0f172a;
  background-image: radial-gradient(rgba(255,255,255,0.015) 1px, transparent 0);
  background-size: 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message-bubble {
  max-width: 65%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
}

.message-bubble.received {
  background: #1e293b;
  color: var(--text-primary);
  align-self: flex-start;
  border-top-left-radius: 0;
}

.message-bubble.sent {
  background: #056162; /* Color clásico WhatsApp Web */
  color: var(--text-primary);
  align-self: flex-end;
  border-top-right-radius: 0;
}

.message-time {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: right;
  margin-top: 0.25rem;
}

.chat-footer {
  padding: 1rem 1.5rem;
  background: #0b0f19;
  border-top: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.chat-input-wrapper {
  flex-grow: 1;
  position: relative;
}

.chat-input-wrapper textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  border-radius: 24px;
  padding: 0.75rem 1.5rem;
  padding-right: 3rem;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  resize: none;
  height: 45px;
  outline: none;
}

.chat-input-wrapper textarea:focus {
  border-color: var(--accent-color);
}

.chat-btn-send {
  background: var(--accent-gradient);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
  transition: transform 0.2s;
}

.chat-btn-send:hover {
  transform: scale(1.05);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.5rem 1rem;
  background: #1e293b;
  border-radius: 12px;
  width: fit-content;
  border-top-left-radius: 0;
  align-self: flex-start;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.alert-gemini-warning {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: #f87171;
}

.alert-gemini-warning i {
  font-size: 1.5rem;
}
