/* CSS Reset & Variable Definitions */
:root {
  --bg-primary: #020617;
  --bg-secondary: #0b1329;
  --card-glass: rgba(15, 23, 42, 0.45);
  --border-glass: rgba(255, 255, 255, 0.06);
  --border-glass-active: rgba(16, 185, 129, 0.3);
  
  /* Brand Colors */
  --emerald: #10b981;
  --emerald-dark: #064e3b;
  --emerald-glow: rgba(16, 185, 129, 0.15);
  --amber: #fbbf24;
  --amber-dark: #78350f;
  --amber-glow: rgba(251, 191, 36, 0.15);
  --red: #ef4444;
  --red-dark: #7f1d1d;
  
  /* Text Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Card Icons */
  --color-blue: #3b82f6;
  --color-red: #f43f5e;
  --color-yellow: #eab308;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
}

/* App Container Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* Sidebar Styling */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 40px;
  padding-left: 8px;
}

.logo-icon {
  font-size: 26px;
  background: linear-gradient(135deg, var(--emerald) 0%, #3b82f6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.3));
}

.accent-text {
  color: var(--emerald);
  text-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 12px;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.menu-item i {
  font-size: 18px;
}

.menu-item:hover {
  background-color: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
}

.menu-item.active {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--emerald);
  border: 1px solid var(--border-glass-active);
}

.menu-item.active i {
  color: var(--emerald);
}

.badge {
  position: absolute;
  right: 16px;
  background-color: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 8px 0;
  border-top: 1px solid var(--border-glass);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background-color: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.footer-user {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Main Content area */
.main-content {
  flex-grow: 1;
  padding: 32px;
  overflow-y: auto;
  background: radial-gradient(circle at 80% 10%, rgba(16, 185, 129, 0.05) 0%, transparent 60%);
  display: flex;
  flex-direction: column;
}

.tab-pane {
  display: none;
  flex-grow: 1;
  flex-direction: column;
}

.tab-pane.active {
  display: flex;
}

.content-header {
  margin-bottom: 32px;
}

.content-header h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 16px;
  margin-top: 4px;
}

/* Stats Cards styling */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.stat-card {
  background-color: var(--card-glass);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.12);
}

.stat-icon-wrapper {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-icon-wrapper.blue {
  background-color: rgba(59, 130, 246, 0.12);
  color: var(--color-blue);
}

.stat-icon-wrapper.red {
  background-color: rgba(244, 63, 94, 0.12);
  color: var(--color-red);
}

.stat-icon-wrapper.yellow {
  background-color: rgba(234, 179, 8, 0.12);
  color: var(--color-yellow);
}

.stat-icon-wrapper.green {
  background-color: rgba(16, 185, 129, 0.12);
  color: var(--emerald);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 2px;
}

/* Glass Card Global Styles */
.card-glass {
  background-color: var(--card-glass);
  border: 1px solid var(--border-glass);
  border-radius: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 24px;
}

/* Charts Grid */
.charts-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.chart-box h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.chart-wrapper {
  height: 240px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Leads Table Styling */
.table-section {
  display: flex;
  flex-direction: column;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.table-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.table-badge {
  background-color: rgba(244, 63, 94, 0.1);
  color: var(--color-red);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(244, 63, 94, 0.15);
}

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

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

th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-glass);
}

td {
  padding: 16px;
  font-size: 15px;
  border-bottom: 1px solid var(--border-glass);
}

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

.table-btn {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.table-btn:hover {
  background-color: var(--emerald);
  border-color: var(--emerald);
  color: black;
  font-weight: 600;
}

/* Chat Tab Layout Container */
.inbox-container {
  display: flex;
  gap: 20px;
  flex-grow: 1;
  height: calc(100vh - 140px);
}

/* Contacts Sub-sidebar */
.contacts-sidebar {
  width: 300px;
  display: flex;
  flex-direction: column;
  padding: 16px;
  flex-shrink: 0;
}

.search-box {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.search-box i {
  color: var(--text-muted);
}

.search-box input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  outline: none;
}

.contacts-list {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.contact-item:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.contact-item.active {
  background-color: rgba(16, 185, 129, 0.05);
  border-color: var(--border-glass-active);
}

.contact-main-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0; /* allows text truncation */
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  border: 1px solid var(--border-glass);
}

.contact-meta {
  min-width: 0;
}

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

.contact-phone-small {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

.contact-status-indicator {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

/* Temperature Tag styles */
.temp-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}

.temp-tag.caliente {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.temp-tag.tibio {
  background-color: rgba(234, 179, 8, 0.15);
  color: var(--color-yellow);
  border: 1px solid rgba(234, 179, 8, 0.2);
}

.temp-tag.frio {
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--color-blue);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.bot-tag-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.bot-tag-status.active {
  background-color: var(--emerald);
  box-shadow: 0 0 6px var(--emerald);
}

.bot-tag-status.inactive {
  background-color: var(--text-muted);
}

/* Chat Panel Area */
.chat-panel {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.chat-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

.placeholder-icon {
  font-size: 64px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--emerald) 0%, #3b82f6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  opacity: 0.7;
}

.chat-placeholder h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.chat-placeholder p {
  max-width: 320px;
  font-size: 14px;
}

/* Chat Screen */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(15, 23, 42, 0.2);
}

.chat-contact-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chat-contact-info h3 {
  font-size: 16px;
  font-weight: 600;
}

.contact-phone {
  font-size: 13px;
  color: var(--text-secondary);
}

/* AI Toggle Switch styling */
.ai-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-toggle-label {
  font-size: 13px;
  font-weight: 600;
  transition: color 0.3s ease;
}

.ai-toggle-label.active {
  color: var(--emerald);
}

.ai-toggle-label.inactive {
  color: var(--red);
}

/* Switch Slider */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--red);
  transition: .4s;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--emerald);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--emerald);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Messages container */
.chat-messages {
  flex-grow: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: radial-gradient(circle at 50% 50%, rgba(15, 23, 42, 0.4) 0%, rgba(2, 6, 23, 0.4) 100%);
}

/* Chat bubble styling */
.message-bubble {
  max-width: 65%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: messageIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.message-bubble.incoming {
  align-self: flex-start;
}

.message-bubble.outgoing {
  align-self: flex-end;
}

.message-bubble-content {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.message-bubble.incoming .message-bubble-content {
  background-color: #1e293b;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-glass);
}

/* Outgoing AI Bot (Emerald) */
.message-bubble.outgoing.bot .message-bubble-content {
  background: linear-gradient(135deg, var(--emerald-dark) 0%, rgba(16, 185, 129, 0.2) 100%);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border-glass-active);
  box-shadow: 0 4px 14px var(--emerald-glow);
}

/* Outgoing Human Agent (Amber/Gold) */
.message-bubble.outgoing.human .message-bubble-content {
  background: linear-gradient(135deg, var(--amber-dark) 0%, rgba(251, 191, 36, 0.2) 100%);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(251, 191, 36, 0.3);
  box-shadow: 0 4px 14px var(--amber-glow);
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.message-bubble.outgoing .message-meta {
  justify-content: flex-end;
}

.sender-tag {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 9px;
}

.message-bubble.outgoing.bot .sender-tag {
  color: var(--emerald);
}

.message-bubble.outgoing.human .sender-tag {
  color: var(--amber);
}

/* Input Area */
.chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border-glass);
  display: flex;
  gap: 12px;
  background-color: rgba(15, 23, 42, 0.2);
}

.chat-input-area input {
  flex-grow: 1;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 14px 20px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input-area input:focus {
  border-color: var(--emerald);
}

.send-btn {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background-color: var(--emerald);
  color: black;
  border: none;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

/* Lead CRM Sidebar Panel */
.lead-crm-sidebar {
  width: 280px;
  padding: 24px 20px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.lead-crm-sidebar h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border-glass);
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-input {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  width: 100%;
}

.form-input:focus {
  border-color: var(--emerald);
}

select.form-input option {
  background-color: #0f172a;
  color: var(--text-primary);
}

.save-attributes-btn {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.save-attributes-btn:hover {
  background-color: var(--emerald);
  border-color: var(--emerald);
  color: black;
}

/* Custom Thin Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Light Mode Variables Override */
body.light-mode {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --card-glass: rgba(255, 255, 255, 0.7);
  --border-glass: rgba(15, 23, 42, 0.08);
  --border-glass-active: rgba(16, 185, 129, 0.55);
  
  /* Text Colors */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  /* Card Icons */
  --color-blue: #1d4ed8;
  --color-red: #e11d48;
  --color-yellow: #d97706;
}

body.light-mode .main-content {
  background: radial-gradient(circle at 80% 10%, rgba(16, 185, 129, 0.08) 0%, transparent 60%);
}

body.light-mode .form-input,
body.light-mode .chat-input-area input,
body.light-mode .contacts-list .contact-card {
  background-color: rgba(15, 23, 42, 0.04);
}

body.light-mode .menu-item:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

body.light-mode select.form-input option {
  background-color: #ffffff;
  color: var(--text-primary);
}

body.light-mode .table-btn,
body.light-mode .save-attributes-btn {
  background-color: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border-glass);
}

body.light-mode .table-btn:hover,
body.light-mode .save-attributes-btn:hover {
  background-color: var(--emerald);
  color: white;
}

body.light-mode .chat-input-area {
  background-color: rgba(255, 255, 255, 0.8);
}

body.light-mode ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
}

body.light-mode ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.theme-toggle-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

body.light-mode .theme-toggle-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
}
