:root {
  --bg: #0e1117;
  --surface: #161c26;
  --surface2: #1c2333;
  --border: #2d3748;
  --green: #38ef7d;
  --green-bg: #0d2218;
  --accent: #4facfe;
  --gold: #f6a623;
  --red: #ff5f6d;
  --text: #e2e8f0;
  --muted: #718096;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'DM Sans', Arial, sans-serif; }

body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--green), var(--accent));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.topbar-title { font-weight: 700; font-size: 15px; flex: 1; }
.topbar-sub { font-size: 11px; color: var(--muted); }

.topnav { display: flex; gap: 4px; }
.topnav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 6px;
}
.topnav-link:hover { color: var(--text); background: var(--surface2); }
.topnav-link.active { color: var(--text); background: var(--surface2); }

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.logout-btn:hover { color: var(--text); border-color: var(--muted); }

.container { padding: 24px; max-width: 1200px; margin: 0 auto; }

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.card.total .card-value { color: var(--accent); }
.card.pendiente .card-value { color: var(--gold); }
.card.hola_enviado .card-value { color: var(--accent); }
.card.respondio .card-value { color: var(--green); }
.card.interesado .card-value { color: var(--green); }
.card.no_interesado .card-value { color: var(--red); }
.card.sin_whatsapp .card-value { color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.panel-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; color: var(--muted); }
.field input, .field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  min-width: 140px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }

.btn {
  background: var(--accent);
  color: #0e1117;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { opacity: .9; }
.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.green { background: var(--green); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert.success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(56,239,125,.25); }
.alert.error { background: #2a1418; color: var(--red); border: 1px solid rgba(255,95,109,.25); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}
.badge.pendiente { background: rgba(246,166,35,.15); color: var(--gold); }
.badge.hola_enviado { background: rgba(79,172,254,.15); color: var(--accent); }
.badge.respondio, .badge.interesado { background: var(--green-bg); color: var(--green); }
.badge.no_interesado { background: rgba(255,95,109,.15); color: var(--red); }
.badge.sin_whatsapp { background: rgba(113,128,150,.15); color: var(--muted); }

.estado-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
}

.muted { color: var(--muted); font-size: 12px; }

/* ── LOGIN ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 340px;
}
.login-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--green), var(--accent));
  border-radius: 10px;
  margin: 0 auto 16px;
}
.login-title { text-align: center; font-size: 16px; font-weight: 700; margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* ── CONVERSACIONES ── */
.conv-shell {
  display: flex;
  height: calc(100vh - 67px);
}

.conv-list {
  width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.conv-list-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 13px; }

.conv-item {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: var(--surface2); border-left: 3px solid var(--accent); }

.conv-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.conv-item-name { font-weight: 600; font-size: 13px; }
.conv-item-time { font-size: 11px; color: var(--muted); }
.conv-item-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.unread-badge {
  background: var(--green);
  color: #0e1117;
  font-size: 10px;
  font-weight: 700;
  border-radius: 100px;
  padding: 1px 6px;
  margin-left: 6px;
}

.conv-empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.conv-main { flex: 1; display: flex; flex-direction: column; }

.conv-chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.conv-chat-name { font-weight: 700; font-size: 14px; }
.conv-chat-phone { font-size: 12px; color: var(--muted); }

.conv-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-bubble {
  max-width: 60%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
}
.msg-bubble.prospecto { align-self: flex-start; background: var(--surface2); border: 1px solid var(--border); }
.msg-bubble.agente { align-self: flex-end; background: var(--accent); color: #0e1117; }
.msg-time { font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }

.conv-input-row {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.conv-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 13px;
}
.conv-input-row input:focus { outline: none; border-color: var(--accent); }

@media (max-width: 768px) {
  .conv-shell { flex-direction: column; height: auto; }
  .conv-list { width: 100%; border-right: none; }
  .conv-main.hidden-mobile, .conv-list.hidden-mobile { display: none; }
}

@media (max-width: 640px) {
  .container { padding: 14px; }
  .form-row { flex-direction: column; align-items: stretch; }
  .field input, .field select { min-width: 0; width: 100%; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--border); padding: 10px 0; }
  td { border: none; padding: 4px 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 11px; display: block; }
}
