/* ===================== TOKENS ===================== */
:root {
  --bg: #0d1117;
  --card: #1e2538;
  --card-2: #252d44;
  --accent: #f5a623;
  --accent-dim: #c8851a;
  --red: #7a2020;
  --green: #2f8f5b;
  --text: #e7ebf3;
  --text-dim: #9aa3b8;
  --border: #2c3550;
  --radius: 14px;
  --radius-sm: 10px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-weight: 400;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Syne', sans-serif; }

.hidden { display: none !important; }
.mono { font-family: ui-monospace, 'Courier New', monospace; letter-spacing: .5px; }

/* ===================== BUTTONS ===================== */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
  color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #1a1209; font-weight: 600; }
.btn-secondary { background: var(--card-2); border: 1px solid var(--border); color: var(--text); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-danger { background: var(--red); }

/* ===================== LOGIN ===================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #161d2e 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 30px;
  animation: fadeUp .4s ease;
}
.login-brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 30px;
  letter-spacing: -.5px;
}
.login-brand span { color: var(--accent); }
.login-sub { color: var(--text-dim); margin: 4px 0 26px; font-size: 14px; }
.login-error { color: #ff7a7a; font-size: 13px; margin-top: 14px; min-height: 18px; text-align: center; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field select, .search, .inline-form input, .rec-inputs input,
.add-block textarea, .add-block input, input[type="date"], input[type="time"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color .12s ease;
}
.field input:focus, .field select:focus, .search:focus, textarea:focus,
input:focus, select:focus { border-color: var(--accent); }

/* ===================== APP / TOPBAR ===================== */
.app { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 26px;
  background: #111827;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 20px;
}
.topbar-brand span { color: var(--accent); }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .12s, background .12s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); background: rgba(245,166,35,.08); }

.tab-panel { padding: 26px; max-width: 1200px; margin: 0 auto; animation: fadeUp .3s ease; }

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.panel-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.search { flex: 1; min-width: 220px; max-width: 460px; }

/* ===================== SUMMARY CARDS ===================== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.sum-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.sum-card .sum-num {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
}
.sum-card .sum-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  margin-top: 6px;
}
.sum-card.accent .sum-num { color: var(--accent); }
.sum-card.green .sum-num { color: #6fdca0; }

/* ===================== FILTER BAR ===================== */
.filter-bar { margin-bottom: 16px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
  user-select: none;
}
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.toggle:hover { color: var(--text); }

/* ===================== TABLE ===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); }
.data-table thead th {
  text-align: left;
  padding: 13px 16px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  background: #18203a;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table thead th[data-col] { cursor: pointer; user-select: none; transition: color .12s; }
.data-table thead th[data-col]:hover { color: var(--text); }
.data-table thead th[data-col]::after { content: ' \2195'; opacity: .25; }
.data-table thead th.sorted[data-dir="asc"]::after { content: ' \25B2'; opacity: 1; color: var(--accent); }
.data-table thead th.sorted[data-dir="desc"]::after { content: ' \25BC'; opacity: 1; color: var(--accent); }

.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr { cursor: pointer; transition: background .1s; }
.data-table tbody tr:hover { background: var(--card-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.row-mov { box-shadow: inset 3px 0 0 var(--green); }
.td-negocio { font-weight: 500; }
.td-muted { color: var(--text-dim); }
.dot-mov {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6fdca0;
  margin-right: 7px;
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-activo { background: rgba(47,143,91,.18); color: #6fdca0; }
.badge-vencido { background: rgba(122,32,32,.28); color: #ff9b9b; }

/* ===================== CRM ===================== */
.crm-grid { display: grid; grid-template-columns: 320px 1fr; gap: 22px; }
.crm-col { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.col-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; }

.hoy-list { display: flex; flex-direction: column; gap: 10px; }
.hoy-card {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.hoy-card .hora { font-family: 'Syne', sans-serif; font-weight: 700; color: var(--accent); font-size: 16px; }
.hoy-card .lead { font-size: 14px; margin: 2px 0; }
.hoy-card .lead small { color: var(--text-dim); }
.hoy-card .nota { font-size: 13px; color: var(--text-dim); margin: 6px 0 10px; }

.leads-list { display: flex; flex-direction: column; gap: 8px; }
.lead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .12s;
}
.lead-row:hover { border-color: var(--accent); }
.lead-row .lr-main { font-weight: 500; }
.lead-row .lr-sub { font-size: 13px; color: var(--text-dim); }
.lead-row .lr-tel { font-size: 13px; color: var(--text-dim); font-family: ui-monospace, monospace; }

.status-pill {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.status-pill.nuevo { color: #f5a623; border-color: rgba(245,166,35,.4); }
.status-pill.contactado { color: #6db3ff; border-color: rgba(109,179,255,.4); }
.status-pill.cliente { color: #6fdca0; border-color: rgba(111,220,160,.4); }
.status-pill.perdido { color: #ff9b9b; border-color: rgba(255,155,155,.4); }

/* ===================== MODALS ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,8,15,.72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  position: relative;
  animation: fadeUp .25s ease;
}
.modal-lg { max-width: 860px; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-size: 22px; font-weight: 800; margin-bottom: 18px; padding-right: 30px; }

.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-bottom: 8px; }
.info-row { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; }
.info-row span { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }
.info-row strong { font-weight: 500; font-size: 15px; word-break: break-word; }

.modal-section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.modal-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; }

.modal-msg { margin-top: 14px; font-size: 13px; min-height: 18px; }
.modal-msg.ok { color: #6fdca0; }
.modal-msg.err { color: #ff9b9b; }

/* confirmacion */
#confirmModal { z-index: 200; align-items: center; }
.modal-confirm { max-width: 380px; }
.confirm-msg { font-size: 15px; line-height: 1.5; color: var(--text); margin-bottom: 6px; }
.confirm-actions { justify-content: flex-end; margin-top: 22px; }

/* lead modal */
.lead-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.modal-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 18px; border-top: 1px solid var(--border); padding-top: 18px; }
.modal-col h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.add-block { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.rec-inputs { display: flex; gap: 8px; }
.rec-inputs input { flex: 1; }

.conv-list, .rec-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.conv-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.conv-item .conv-fecha { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.conv-item .conv-texto { font-size: 13px; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }

.rec-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.rec-item.done { opacity: .5; }
.rec-item .rec-when { font-family: 'Syne', sans-serif; font-weight: 600; font-size: 13px; color: var(--accent); }
.rec-item .rec-nota { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* ===================== STATES ===================== */
.loading { color: var(--text-dim); padding: 30px; text-align: center; font-size: 14px; }
.loading.sm { padding: 14px; }
.empty { color: var(--text-dim); padding: 30px; text-align: center; font-size: 14px; }
.empty.sm { padding: 14px; }

/* ===================== ANIMATIONS ===================== */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 820px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .crm-grid { grid-template-columns: 1fr; }
  .modal-cols { grid-template-columns: 1fr; }
  .lead-fields { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
  .topbar { gap: 14px; padding: 12px 16px; }
  .tab-panel { padding: 18px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
