/* ================================================================
   ARIA Panel — Puerto Escondido Inversiones  v15
   Apple-inspired design system
   ================================================================ */

/* ─── Variables ─── */
:root {
  --bg:          #f5f5f7;
  --surface:     #ffffff;
  --surface-2:   #f2f2f7;
  --nav-bg:      #ececf0;
  --text-1:      #1d1d1f;
  --text-2:      #6e6e73;
  --text-3:      #aeaeb2;
  --border:      rgba(0,0,0,0.09);
  --border-2:    rgba(0,0,0,0.16);
  --accent:      #2d6a4f;
  --accent-2:    #52b788;
  --accent-bg:   rgba(45,106,79,0.1);
  --accent-bg-s: rgba(45,106,79,0.17);
  --red:         #ff3b30;
  --orange:      #ff9500;
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  20px;
  --sh-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --sh-md: 0 4px 20px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --sh-lg: 0 20px 60px rgba(0,0,0,0.14), 0 8px 24px rgba(0,0,0,0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
               'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ─── LOGIN ─── */
#login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(155deg, #0d2318 0%, #1a4030 45%, #2d6a4f 100%);
}

.login-box {
  background: var(--surface);
  padding: 48px 40px;
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo { font-size: 48px; margin-bottom: 12px; }

.login-box h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.login-subtitle {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-box form input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text-1);
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  outline: none;
}

.login-box form input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.login-box form button {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s;
  margin-top: 4px;
  letter-spacing: -0.1px;
}

.login-box form button:hover  { background: #215a3f; }
.login-box form button:active { transform: scale(0.98); }

.error {
  color: var(--red);
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
}

/* ─── HEADER ─── */
header {
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--text-1);
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 52px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  display: flex;
  align-items: center;
  color: var(--accent);
  line-height: 0;
}

header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-2);
  margin-left: 8px;
}

.header-controls { display: flex; gap: 12px; align-items: center; }

.status {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status.connected {
  background: rgba(52,199,89,0.14);
  color: #1a7a2a;
  border: 1px solid rgba(52,199,89,0.35);
}

.status.disconnected {
  background: rgba(142,142,147,0.12);
  color: var(--text-2);
  border: 1px solid rgba(142,142,147,0.22);
}

#logout-btn {
  padding: 6px 14px;
  background: transparent;
  color: var(--text-2);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.18s;
}

#logout-btn:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

/* ─── LAYOUT ─── */
#dashboard-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: 52px;
}

.tab-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-content.hidden { display: none !important; }

.dashboard { display: flex; flex: 1; overflow: hidden; }

/* ─── INNER SIDEBAR (conversaciones) ─── */
.sidebar {
  width: 272px;
  min-width: 272px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-3);
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-count {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 7px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

/* ─── CONVERSATIONS ─── */
.conversations-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.conv-search-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.conv-search-input {
  width: 100%;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: var(--surface-2);
  color: var(--text-1);
  transition: border-color 0.18s, background 0.18s;
}

.conv-search-input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.empty-state {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 24px 16px;
}

.conversation-item {
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.13s;
}

.conversation-item:hover  { background: var(--surface-2); }

.conversation-item.active {
  background: var(--accent-bg);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.conversation-item.paused { opacity: 0.72; }

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.conv-top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-delete-conv {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}

.conversation-item:hover .btn-delete-conv { opacity: 1; }
.btn-delete-conv:hover { background: #fee2e2; }

.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.conv-time { font-size: 11px; color: var(--text-3); white-space: nowrap; }

.conv-preview {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}

.conv-badges { display: flex; gap: 6px; }

.badge-active {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-bg);
  border-radius: 10px;
  padding: 1px 7px;
  font-weight: 600;
}

.badge-paused {
  font-size: 10px;
  color: #b45309;
  background: #fef3c7;
  border-radius: 10px;
  padding: 1px 7px;
  font-weight: 600;
}

/* ─── CHAT CONTROLS ─── */
.chat-controls {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.active-jid-label {
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── BUTTONS ─── */
.btn-secondary {
  padding: 8px 14px;
  background: rgba(0,0,0,0.06);
  color: var(--text-1);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.18s;
}

.btn-secondary:hover { background: rgba(0,0,0,0.1); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-warning {
  padding: 9px;
  background: rgba(255,149,0,0.12);
  color: #b45309;
  border: 1.5px solid rgba(255,149,0,0.28);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.18s;
}

.btn-warning:hover:not(:disabled) { background: rgba(255,149,0,0.2); }
.btn-warning:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-success {
  padding: 9px;
  background: rgba(52,199,89,0.12);
  color: #1a6b2a;
  border: 1.5px solid rgba(52,199,89,0.28);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.18s;
}

.btn-success:hover:not(:disabled) { background: rgba(52,199,89,0.22); }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  padding: 11px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.18s, transform 0.1s;
  letter-spacing: -0.1px;
}

.btn-primary:hover  { background: #215a3f; }
.btn-primary:active { transform: scale(0.98); }

/* ─── QR buttons row ─── */
.qr-btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.qr-btn-row button { flex: 1; }

.btn-reconnect {
  padding: 6px 12px;
  background: rgba(255,149,0,0.12);
  color: #b45309;
  border: 1.5px solid rgba(255,149,0,0.28);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.18s;
}

.btn-reconnect:hover:not(:disabled) { background: rgba(255,149,0,0.2); }
.btn-reconnect:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── CHAT SECTION ─── */
.chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface-2);
}

.chat-header {
  background: var(--surface);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
}

.chat-header-info { display: flex; align-items: center; gap: 12px; }

#chat-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.ai-badge {
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
  padding: 3px 10px;
}

.ai-badge.active  { background: rgba(52,199,89,0.14); color: #1a6b2a; }
.ai-badge.paused  { background: rgba(255,149,0,0.14); color: #b45309; }
.ai-badge.hidden  { display: none; }

.chat-jid-small { font-size: 11px; color: var(--text-3); }

.messages-container { flex: 1; overflow-y: auto; padding: 16px 20px; }

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
}

.empty-state-chat {
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.8;
  padding: 60px 20px;
}

/* ─── MESSAGES ─── */
.message { display: flex; }
.message.incoming     { justify-content: flex-start; }
.message.outgoing     { justify-content: flex-end; }
.message.system-note  { justify-content: center; }

.system-note-text {
  font-size: 12px;
  color: var(--text-2);
  background: rgba(0,0,0,0.06);
  border-radius: 12px;
  padding: 5px 14px;
  font-style: italic;
}

.message-bubble {
  max-width: 65%;
  padding: 9px 13px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message.incoming .message-bubble {
  background: var(--surface);
  border-bottom-left-radius: 4px;
  box-shadow: var(--sh-sm);
}

.message.outgoing .message-bubble {
  background: #d1f7e4;
  border-bottom-right-radius: 4px;
  box-shadow: var(--sh-sm);
}

.message-sender { font-size: 11px; font-weight: 700; color: var(--accent); }
.message.incoming .message-sender { color: var(--text-2); }

.message-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time { font-size: 11px; color: var(--text-3); align-self: flex-end; }

/* ─── MESSAGE INPUT ─── */
.message-input-section {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.send-row { display: flex; gap: 8px; align-items: center; }
.input-phone { flex: 1; }

.input-field {
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  resize: none;
  background: var(--surface-2);
  color: var(--text-1);
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  outline: none;
}

.input-field:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

/* ─── ALERT BANNER ─── */
.alert-banner {
  position: fixed;
  top: 52px; left: 0; right: 0;
  z-index: 200;
  background: var(--accent);
  color: white;
  text-align: center;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.14);
  transition: opacity 0.3s;
}

.alert-banner.hidden { display: none; }

/* ─── APP LAYOUT ─── */
.app-layout { display: flex; flex: 1; overflow: hidden; }

/* ─── NAV SIDEBAR ─── */
.app-sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--nav-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  z-index: 50;
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 17px 16px 15px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 2.5px;
  text-transform: uppercase;
}

.sidebar-nav { flex: 1; padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 8px;
  padding: 9px 12px;
  border: none;
  border-radius: var(--r-sm);
  border-left: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: calc(100% - 16px);
}

.nav-item:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--accent-bg-s);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg { width: 20px; height: 20px; }

.nav-label { font-size: 13.5px; line-height: 1; }

/* ─── APP CONTENT ─── */
.app-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── HAMBURGER (mobile) ─── */
.hamburger-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--r-sm);
  line-height: 0;
  margin-right: 4px;
  transition: background 0.18s;
}

.hamburger-btn:hover { background: rgba(0,0,0,0.07); }

/* ─── CHAT BACK BUTTON (mobile) ─── */
.chat-back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--r-sm);
  line-height: 0;
  margin-right: 4px;
  flex-shrink: 0;
  transition: background 0.18s;
}
.chat-back-btn:hover { background: rgba(0,0,0,0.07); }
.chat-back-btn svg { width: 22px; height: 22px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* ─── CONEXIÓN TAB ─── */
.conexion-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg);
  overflow-y: auto;
}

.conexion-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--sh-md);
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.conexion-wa-icon {
  width: 72px;
  height: 72px;
  background: var(--accent-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 4px;
}

.conexion-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.4px;
}

.conexion-subtitle {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 320px;
}

.conexion-card .qr-placeholder {
  width: 220px;
  height: 220px;
  background: var(--surface-2);
  border: 2px dashed rgba(0,0,0,0.14);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.6;
  margin: 8px 0;
}

.conexion-card .qr-placeholder img {
  width: 100%;
  height: 100%;
  border-radius: calc(var(--r-lg) - 2px);
  object-fit: contain;
}

.conexion-card .connected-check {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  padding: 28px 16px;
}

.conexion-btn-row {
  width: 100%;
  display: flex;
  gap: 10px;
}

.conexion-btn-row .btn-secondary,
.conexion-btn-row .btn-reconnect {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--r-sm);
}

.conexion-hint {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
  max-width: 300px;
  margin-top: 4px;
}

/* ─── CRM ─── */
.crm-container {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.crm-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--sh-sm);
}

.stat-num {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.5px;
}

.stat-label { font-size: 12px; color: var(--text-2); }

.stat-card--alert {
  border-left: 3px solid var(--red);
  background: linear-gradient(135deg, #fff5f5 0%, var(--surface) 100%);
}

.stat-card--alert .stat-num { color: #d92b21; }

/* Hot Leads Banner */
.hot-leads-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%);
  border: 1.5px solid rgba(245,158,11,0.35);
  border-left: 4px solid #f59e0b;
  border-radius: var(--r-md);
  padding: 12px 18px;
  margin-bottom: 20px;
}

.hot-leads-banner.hidden { display: none !important; }
.hot-leads-icon { font-size: 20px; }

.hot-leads-text { flex: 1; font-size: 14px; color: #78350f; }
.hot-leads-text strong { font-size: 16px; color: #92400e; }

.hot-leads-btn {
  padding: 7px 16px;
  background: #f59e0b;
  color: white;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s;
  white-space: nowrap;
}

.hot-leads-btn:hover { background: #d97706; }

/* CRM Sub-tabs */
.crm-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1.5px solid var(--border);
}

.crm-tab-btn {
  padding: 10px 20px;
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.18s;
  margin-bottom: -1.5px;
}

.crm-tab-btn.active,
.crm-tab-btn:hover {
  color: var(--text-1);
  border-bottom-color: var(--accent);
}

.crm-tab-content.hidden { display: none !important; }

/* Toolbar */
.crm-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.crm-search {
  flex: 1;
  min-width: 200px;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-1);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.crm-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.crm-filter {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-1);
  outline: none;
  transition: border-color 0.18s;
}

.crm-filter:focus { border-color: var(--accent); }

/* Table */
.crm-table-wrap {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
  overflow: auto;
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.crm-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.crm-table td {
  padding: 11px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  vertical-align: middle;
  color: var(--text-1);
}

.crm-table tr:last-child td { border-bottom: none; }
.crm-table tr:hover td { background: var(--surface-2); }

.crm-empty {
  text-align: center;
  color: var(--text-3);
  padding: 32px !important;
}

.crm-actions { display: flex; gap: 6px; }

/* Badges */
.crm-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-green  { background: rgba(52,199,89,0.14);  color: #1a6b2a; }
.badge-yellow { background: rgba(255,149,0,0.14);  color: #b45309; }
.badge-gray   { background: rgba(142,142,147,0.14);color: var(--text-2); }
.badge-blue   { background: rgba(0,122,255,0.12);  color: #0051cc; }
.badge-purple { background: rgba(88,86,214,0.12);  color: #4a48b5; }
.badge-gold   { background: rgba(245,158,11,0.14); color: #b45309; }
.badge-alert  { background: rgba(255,59,48,0.14);  color: #c82020; font-weight: 700; }

.row-hot td { background: #fffbeb !important; }
.row-hot:hover td { background: #fef9c3 !important; }
.row-hot { border-left: 3px solid #f59e0b; }

/* Chat button */
.btn-chat {
  padding: 6px 10px;
  background: rgba(0,122,255,0.12);
  color: #0051cc;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s;
}

.btn-chat:hover { background: rgba(0,122,255,0.2); }

.btn-danger {
  padding: 6px 12px;
  background: rgba(255,59,48,0.12);
  color: #c82020;
  border: none;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s;
}

.btn-danger:hover { background: rgba(255,59,48,0.2); }

/* ─── MODAL ─── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none !important; }

.modal-box {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 32px;
  width: 600px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--sh-lg);
}

.modal-box h2 {
  margin-bottom: 20px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.form-grid label,
.modal-box > form > label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.form-grid label input,
.form-grid label select,
.modal-box > form > label textarea,
.modal-box > form > label input {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text-1);
  outline: none;
  margin-top: 2px;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.form-grid label input:focus,
.form-grid label select:focus,
.modal-box > form > label textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
  background: var(--surface);
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ─── LEAD DETAIL MODAL ─── */
.modal-wide {
  width: 90vw;
  max-width: 1140px;
  padding: 0;
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  gap: 16px;
}

.detail-header-info h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.detail-meta-row { display: flex; gap: 16px; flex-wrap: wrap; }
.detail-meta { font-size: 13px; color: var(--text-2); }

.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.detail-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.detail-left {
  width: 44%;
  min-width: 300px;
  padding: 22px 24px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.detail-right {
  flex: 1;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 10px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.detail-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.detail-form-grid label input,
.detail-form-grid label select {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text-1);
  outline: none;
}

.detail-form-grid label input:focus,
.detail-form-grid label select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
  background: var(--surface);
}

.detail-notas {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text-1);
  outline: none;
  resize: vertical;
  min-height: 90px;
  margin-bottom: 14px;
  transition: border-color 0.18s;
}

.detail-notas:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.detail-form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.detail-conv {
  flex: 1;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-chat-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  text-decoration: underline;
  text-transform: none;
  font-family: inherit;
}

.btn-chat-link:hover { color: #1a3a2a; }

/* ─── CALENDARIO ─── */
.cal-container {
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}

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

.cal-nav { display: flex; align-items: center; gap: 8px; }

.cal-month-label {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  min-width: 180px;
  text-align: center;
  letter-spacing: -0.4px;
}

.cal-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-cell {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  padding: 6px;
  cursor: pointer;
  background: var(--surface);
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: border-color 0.13s, background 0.13s;
  min-height: 56px;
}

.cal-cell:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.cal-cell--empty { background: transparent; border-color: transparent; cursor: default; }
.cal-cell--empty:hover { background: transparent; border-color: transparent; }

.cal-today { background: rgba(45,106,79,0.06); border-color: var(--accent); }

.cal-today .cal-day-num {
  background: var(--accent);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.cal-selected {
  border-color: var(--text-1) !important;
  box-shadow: 0 0 0 2px rgba(29,29,31,0.15);
}

.cal-day-num { font-size: 13px; font-weight: 500; color: var(--text-1); line-height: 24px; }

.cal-dots {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  flex-wrap: wrap;
  justify-content: center;
}

.cal-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.cal-dot--pendiente  { background: #ff9500; }
.cal-dot--confirmada { background: #34c759; }
.cal-dot--cancelada  { background: var(--text-3); }
.cal-dot--completada { background: #007aff; }

.cal-day-panel {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  padding: 20px;
  min-height: 400px;
}

.cal-day-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 16px;
  text-transform: capitalize;
  letter-spacing: -0.2px;
}

.cal-day-citas { display: flex; flex-direction: column; gap: 10px; }

/* Cita item — tarjeta vertical estructurada */
.cita-item {
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  transition: box-shadow 0.18s, transform 0.15s;
  cursor: default;
}

.cita-item:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.cita-item--confirmada { border-left-color: #34c759; background: linear-gradient(135deg, #f0fdf4 0%, var(--surface) 60%); }
.cita-item--pendiente  { border-left-color: #ff9500; }
.cita-item--cancelada  { border-left-color: var(--text-3); opacity: 0.7; }
.cita-item--completada { border-left-color: #007aff; background: linear-gradient(135deg, #f0f6ff 0%, var(--surface) 60%); }

/* Fila superior: hora + badges */
.cita-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cita-time {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-1);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.cita-badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Cuerpo: datos del cliente */
.cita-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

.cita-nombre {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.3;
}

.cita-telefono {
  font-size: 12px;
  color: var(--text-2);
}

.cita-propiedad {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.cita-asesor {
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
}

/* Fila inferior: acciones */
.cita-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}

.cita-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

.label-full { grid-column: 1 / -1; }


/* ─── SEGUIMIENTO ─── */
.seg-container {
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}

.seg-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.seg-stat-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--sh-sm);
}

.seg-stat-card--cold { border-left: 3px solid #007aff; }
.seg-stat-card--info { border-left: 3px solid var(--text-3); }

.seg-stat-num {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.5px;
}

.seg-stat-num--sm { font-size: 22px; }
.seg-stat-label   { font-size: 12px; color: var(--text-2); }

.seg-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.seg-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

/* Historial modal */
.modal-seg-hist {
  width: 660px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.seg-hist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}

.seg-hist-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-1);
  margin: 0;
  letter-spacing: -0.3px;
}

.seg-hist-list {
  overflow-y: auto;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.seg-hist-item {
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: var(--surface-2);
}

.seg-hist-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.seg-hist-date { font-size: 12px; color: var(--text-3); margin-left: auto; }

.seg-hist-msg {
  font-size: 14px;
  color: var(--text-1);
  line-height: 1.55;
  white-space: pre-wrap;
}

/* ─── EQUIPO ─── */
.equipo-container {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg);
}

.equipo-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  flex-shrink: 0;
}

.equipo-stat-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--sh-sm);
}

.equipo-stat--urgente {
  border-left: 3px solid var(--red);
  background: linear-gradient(135deg, #fff5f5 0%, var(--surface) 100%);
}

.equipo-stat--urgente .equipo-stat-num { color: #d92b21; }
.equipo-stat--citas { border-left: 3px solid #007aff; }

.equipo-stat-num {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.5px;
}

.equipo-stat-label { font-size: 12px; color: var(--text-2); }

.equipo-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.equipo-panel {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.equipo-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.equipo-panel-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.2px;
}

.eq-scroll-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eq-urgente-item {
  border: 1.5px solid rgba(255,59,48,0.2);
  border-left: 4px solid var(--red);
  border-radius: var(--r-md);
  padding: 14px;
  background: #fff9f9;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.eq-urgente-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.eq-urgente-top strong { font-size: 15px; color: var(--text-1); }

.eq-urgente-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-2);
}

.eq-urgente-tiempo {
  font-size: 12px;
  color: var(--text-3);
  margin-left: auto;
}

.eq-urgente-notas {
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  white-space: pre-wrap;
}

.eq-urgente-actions { display: flex; gap: 8px; }

.eq-cita-item {
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--text-3);
  border-radius: var(--r-md);
  padding: 12px 14px;
  background: var(--surface-2);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.eq-cita-item--confirmada { border-left-color: #34c759; background: #f0fdf4; }
.eq-cita-item--pendiente  { border-left-color: #ff9500; }
.eq-cita-item--completada { border-left-color: #007aff; }
.eq-cita-item--cancelada  { border-left-color: var(--text-3); opacity: 0.65; }

.eq-cita-hora { font-size: 16px; font-weight: 700; color: var(--text-1); min-width: 46px; }

.eq-cita-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  color: var(--text-2);
}

.eq-cita-info strong { font-size: 14px; color: var(--text-1); }
.eq-cita-prop { font-style: italic; font-size: 12px; color: var(--text-3); }
.eq-cita-badges { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

.equipo-resumen-section {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 16px 20px;
  box-shadow: var(--sh-sm);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.equipo-resumen-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.equipo-resumen-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.equipo-phone-input {
  max-width: 240px;
  flex-shrink: 0;
}

/* ─── BASE DE DATOS ─── */
.db-container {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.db-section {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sm);
  padding: 20px;
}

.db-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.db-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.2px;
}

.db-health-cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.db-health-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 20px;
  min-width: 110px;
  text-align: center;
  flex: 1;
}

.db-health-card--ok { border-color: #34c759; background: #f0fdf4; }

.db-health-icon  { font-size: 18px; }
.db-health-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.4px; }
.db-health-value { font-size: 13px; font-weight: 600; color: var(--text-1); }

.db-count-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.db-count-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.db-count-card:hover { background: var(--accent-bg); border-color: var(--accent-2); }

.db-count-num   { display: block; font-size: 26px; font-weight: 700; color: var(--text-1); letter-spacing: -0.5px; }
.db-count-label { display: block; font-size: 12px; color: var(--text-2); margin-top: 2px; }

.db-subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.db-subtab-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
}

.db-subtab-btn:hover  { background: var(--surface-2); color: var(--text-1); }
.db-subtab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.db-table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.db-table-info { font-size: 13px; color: var(--text-2); flex: 1; min-width: 80px; }
.db-pagination  { display: flex; gap: 6px; }

.db-null           { color: var(--text-3); font-style: italic; font-size: 12px; }
.db-badge          { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 4px; }
.db-badge--yes     { background: #dcfce7; color: #16a34a; }
.db-badge--no      { background: #fee2e2; color: #dc2626; }
.db-array          { font-size: 12px; color: var(--text-3); font-style: italic; }
.db-actions-cell   { white-space: nowrap; }

.db-maint-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.db-maint-log {
  background: #0d1117;
  color: #e6edf3;
  border-radius: var(--r-md);
  padding: 16px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  min-height: 90px;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

.modal-db {
  width: 720px;
  max-height: 85vh;
  overflow-y: auto;
}

.db-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.db-fields-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.db-field-input {
  font-size: 14px;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-1);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.db-field-input:focus { border-color: var(--accent-2); }

.db-field-full  { grid-column: 1 / -1; }

.db-field-checkbox {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  padding-top: 20px;
  color: var(--text-1) !important;
  font-weight: 400 !important;
}

.db-field-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ─── CHAT INFO SIDEBAR (Right) ─── */
.chat-info-sidebar {
  width: 290px;
  min-width: 290px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.info-sidebar-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-sidebar-section.border-top {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.info-sidebar-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-1);
}

.info-sidebar-subtitle {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
}

.info-context-textarea {
  min-height: 160px;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  resize: vertical;
}

.file-upload-zone {
  border: 2px dashed var(--border-2);
  border-radius: var(--r-sm);
  padding: 22px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: all 0.15s ease-in-out;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.file-upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.upload-icon {
  font-size: 26px;
}

.upload-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.file-upload-progress {
  font-size: 11.5px;
  color: var(--accent);
  text-align: center;
  font-weight: 600;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.files-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  gap: 8px;
}

.file-item-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  flex: 1;
}

.file-item-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.file-link {
  color: var(--text-1);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.file-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.file-item-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.12s;
  line-height: 1;
}

.file-item-delete:hover {
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
}

/* ─── RESPONSIVE ─── */

/* ══ Tablets y teléfonos (≤768px) ══════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header ── */
  .hamburger-btn   { display: flex; align-items: center; justify-content: center; }
  .header-subtitle { display: none; }
  .header-logo     { display: none; }

  /* ── Nav sidebar: drawer slide-in ── */
  .app-sidebar {
    position: fixed;
    top: 52px; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 50;
    width: 220px; min-width: 220px;
    box-shadow: var(--sh-lg);
  }
  .app-sidebar.open        { transform: translateX(0); }
  .sidebar-overlay.visible { display: block; }
  .nav-item                { min-height: 44px; }

  /* ── WhatsApp: un panel a la vez ── */
  #tab-whatsapp .dashboard    { flex-direction: column; overflow: hidden; }
  #tab-whatsapp .sidebar      { width: 100%; min-width: unset; flex: 1; border-right: none; }
  #tab-whatsapp .chat-section { display: none; flex: 1; }
  #tab-whatsapp .chat-info-sidebar { display: none !important; }
  #tab-whatsapp .dashboard.mobile-chat-open .sidebar      { display: none; }
  #tab-whatsapp .dashboard.mobile-chat-open .chat-section { display: flex; }

  /* Botón volver */
  .chat-back-btn { display: flex; }

  /* JID en chat header: oculto (largo y técnico) */
  .chat-jid-small { display: none; }

  /* Chat-controls: botones en fila */
  .chat-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 14px;
  }
  .chat-controls h3,
  .chat-controls .active-jid-label { grid-column: 1 / -1; }

  /* Nombre en lista de conversaciones */
  .conv-name { max-width: 200px; }

  /* Burbujas */
  .message-bubble  { max-width: 88%; }
  .messages-container { padding: 12px 14px; }

  /* Área de envío */
  .message-input-section { padding: 10px 12px; gap: 6px; }
  .send-row              { gap: 6px; }

  /* ── CRM ── */
  /* Stats: carrusel horizontal para evitar grids desbalanceados */
  .crm-stats {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    gap: 10px;
    padding-bottom: 4px;
    /* ocultar scrollbar visualmente */
    scrollbar-width: none;
  }
  .crm-stats::-webkit-scrollbar { display: none; }
  .crm-stats .stat-card {
    flex: 0 0 150px;
    min-width: 150px;
    scroll-snap-align: start;
  }

  /* Toolbar: columna */
  .crm-toolbar  { flex-direction: column; gap: 8px; }
  .crm-search   { width: 100%; min-width: unset; }
  .crm-filter   { width: 100%; }

  /* Tabs: scroll horizontal sin saltos */
  .crm-tabs     { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 0; }
  .crm-tabs::-webkit-scrollbar { display: none; }
  .crm-tab-btn  { flex-shrink: 0; }
  .crm-container { padding: 16px; }

  /* Tabla con scroll */
  .crm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Hot leads banner */
  .hot-leads-banner { flex-wrap: wrap; gap: 8px; }
  .hot-leads-btn    { width: 100%; }

  /* ── Modal CRM detalle: pantalla completa apilada ── */
  .modal-wide            { width: 100%; max-width: 100%; max-height: 100dvh; border-radius: 0; }
  .detail-header         { flex-direction: column; gap: 8px; padding: 14px 16px; }
  .detail-header-info h2 { font-size: 17px; }
  .detail-header-actions { width: 100%; justify-content: flex-end; }
  .detail-meta-row       { flex-direction: column; gap: 3px; }
  .detail-body           { flex-direction: column; overflow-y: auto; }
  .detail-left           { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); overflow-y: visible; }
  .detail-right          { overflow: visible; }
  .detail-form-grid      { grid-template-columns: 1fr; }
  .detail-form-actions   { flex-direction: column-reverse; gap: 8px; }
  .detail-form-actions button { width: 100%; padding: 11px; }

  /* ── Modal genérico ── */
  .modal-box     { width: calc(100vw - 24px); max-width: calc(100vw - 24px); padding: 20px 16px; }
  .modal-box h2  { font-size: 17px; }
  .form-grid     { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions button { width: 100%; padding: 12px; }

  /* ── Calendario ── */
  .cal-container   { padding: 16px; }
  .cal-toolbar     { flex-direction: column; gap: 8px; align-items: stretch; }
  .cal-nav         { justify-content: center; }
  .cal-month-label { min-width: unset; font-size: 17px; }
  #cal-new-btn     { width: 100%; }
  .cal-body        { grid-template-columns: 1fr; gap: 16px; }
  .cal-cell        { min-height: 48px; }

  /* ── Seguimiento ── */
  .seg-container { padding: 16px; }

  /* Stats: carrusel horizontal (3 tarjetas) */
  .seg-stats { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 10px; padding-bottom: 4px; margin-bottom: 16px; }
  .seg-stats::-webkit-scrollbar { display: none; }
  .seg-stats .seg-stat-card { flex: 0 0 160px; min-width: 160px; scroll-snap-align: start; }

  .seg-toolbar { flex-direction: row; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
  .seg-title   { font-size: 14px; }

  /* ── Equipo ── */
  .equipo-container { padding: 16px; gap: 12px; }

  /* Stats: carrusel horizontal (4 tarjetas) */
  .equipo-stats {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    gap: 10px;
    padding-bottom: 4px;
    flex-shrink: 0;
  }
  .equipo-stats::-webkit-scrollbar { display: none; }
  .equipo-stat-card { flex: 0 0 130px; min-width: 130px; scroll-snap-align: start; }

  /* Paneles: columna con altura fija para mantener scroll interno */
  .equipo-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: none;
    min-height: unset;
  }
  .equipo-panel    { height: 320px; overflow: hidden; }
  .eq-scroll-list  { overflow-y: auto; }

  /* Resumen: columna */
  .equipo-resumen-section { flex-direction: column; align-items: stretch; gap: 10px; flex-shrink: 0; }
  .equipo-resumen-label   { white-space: normal; }
  .equipo-resumen-row     { width: 100%; }
  .equipo-phone-input     { flex: 1; max-width: unset; }
  #eq-send-resumen-btn    { white-space: nowrap; flex-shrink: 0; }

  /* ── Base de Datos ── */
  .db-container      { padding: 16px; gap: 14px; }
  .db-section        { padding: 16px; }
  .db-section-header { gap: 8px; flex-wrap: wrap; }

  /* Health cards: scroll horizontal */
  .db-health-cards { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
  .db-health-cards::-webkit-scrollbar { display: none; }
  .db-health-card  { flex: 0 0 auto; min-width: 90px; padding: 10px 12px; }

  /* Count cards: carrusel horizontal (5 tarjetas — evita grid asimétrico) */
  .db-count-cards { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 8px; flex-wrap: nowrap; padding-bottom: 4px; }
  .db-count-cards::-webkit-scrollbar { display: none; }
  .db-count-cards .db-count-card { flex: 0 0 110px; min-width: 110px; }

  /* Subtabs: scroll horizontal */
  .db-subtabs    { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 8px; }
  .db-subtabs::-webkit-scrollbar { display: none; }
  .db-subtab-btn { flex-shrink: 0; }

  /* Toolbar DB: búsqueda en línea propia, paginación + add juntos */
  .db-table-toolbar { flex-wrap: wrap; gap: 8px; }
  #db-search-input  { flex: 1 1 100%; }
  .db-table-info    { flex: 1; font-size: 12px; }
  .db-pagination    { flex-shrink: 0; }
  #db-add-btn       { flex-shrink: 0; }

  /* Mantenimiento: botones a ancho completo */
  .db-maint-actions        { flex-direction: column; gap: 10px; }
  .db-maint-actions button { width: 100%; }

  /* Modal DB */
  .db-fields-grid { grid-template-columns: 1fr; }
  .modal-db       { width: 96vw; max-height: 90dvh; }

  /* Modal historial seguimiento */
  .modal-seg-hist { width: 96vw; }

  /* ── Conexión ── */
  .conexion-card { padding: 32px 24px; gap: 12px; max-width: 100%; }
}

/* ══ Teléfonos pequeños (≤480px) ════════════════════════════════ */
@media (max-width: 480px) {

  /* Header */
  #connection-status { display: none; }
  header h1          { font-size: 14px; }
  #logout-btn        { font-size: 12px; padding: 5px 10px; }

  /* Login */
  .login-box { padding: 28px 18px; margin: 12px; max-width: unset; }

  /* ── WhatsApp ── */
  .chat-controls    { padding: 8px 10px; gap: 6px; }
  .message-input-section { padding: 8px 10px; }
  .send-row         { flex-direction: column; }
  #clear-chat-btn   { width: 100%; }
  #send-btn         { padding: 10px; }

  /* ── CRM ── */
  .crm-container    { padding: 12px; }
  .crm-stats .stat-card { flex: 0 0 130px; min-width: 130px; }
  .stat-num         { font-size: 22px; }
  .stat-card        { padding: 14px 12px; }
  .crm-tab-btn      { padding: 8px 10px; font-size: 12px; }
  .crm-toolbar      { gap: 6px; }

  /* ── Conexion QR ── */
  .conexion-card              { padding: 28px 16px; gap: 10px; }
  .conexion-card .qr-placeholder { width: 176px; height: 176px; }
  .conexion-title             { font-size: 18px; }
  .conexion-subtitle          { font-size: 13px; }

  /* ── Seguimiento ── */
  .seg-container    { padding: 12px; }
  .seg-stats        { grid-template-columns: 1fr; }
  .seg-stat-num     { font-size: 22px; }
  .seg-title        { font-size: 13px; }

  /* ── Equipo ── */
  .equipo-container { padding: 12px; gap: 10px; }
  .equipo-stat-card { flex: 0 0 116px; min-width: 116px; }
  .equipo-stat-num  { font-size: 22px; }

  /* ── Base de Datos ── */
  .db-container     { padding: 12px; gap: 10px; }
  .db-section       { padding: 12px; }
  .db-count-num     { font-size: 20px; }
}
