/* ============================================================
   CRM Mascobranzas — Estilos principales
   ============================================================ */

:root {
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --brand-primary: #1a4f8a;
  --brand-accent:  #e63946;
  --bg-sidebar:    #0f1923;
  --bg-topbar:     #fff;
  --bg-page:       #f4f6f9;
  --bg-card:       #fff;
  --text-primary:  #1a2332;
  --text-muted:    #6b7280;
  --border:        #e5e7eb;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --info:          #2563eb;
  --radius:        10px;
  --shadow:        0 1px 4px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg-page); color: var(--text-primary);
       display: flex; min-height: 100vh; font-size: 14px; }

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--bg-sidebar);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  z-index: 200; transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon { font-size: 22px; color: var(--brand-accent); }
.brand-text { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: .3px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: rgba(255,255,255,.6);
  text-decoration: none; font-size: 13.5px; transition: all .15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-link.active {
  color: #fff; background: rgba(230,57,70,.15);
  border-left-color: var(--brand-accent);
}
.nav-link i { font-size: 16px; width: 20px; }
.nav-section {
  padding: 16px 20px 6px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.3);
}

.sidebar-footer {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: #fff;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-rol  { font-size: 11px; color: rgba(255,255,255,.4); }
.btn-logout {
  color: rgba(255,255,255,.4); font-size: 18px; text-decoration: none;
  transition: color .15s; flex-shrink: 0;
}
.btn-logout:hover { color: var(--brand-accent); }

/* ---- MAIN ---- */
.main-content {
  margin-left: var(--sidebar-w); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h); background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 24px; position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.sidebar-toggle {
  background: none; border: none; font-size: 20px;
  color: var(--text-muted); cursor: pointer; padding: 4px;
  display: none;
}
.page-title { font-size: 16px; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge-ext {
  background: #eff6ff; color: var(--info); border: 1px solid #bfdbfe;
  border-radius: 20px; padding: 4px 10px; font-size: 12px; font-weight: 500;
}
.badge-online { color: var(--success); font-size: 12px; }
.badge-online i { font-size: 8px; }

/* ---- CONTENIDO ---- */
.page-content { padding: 24px; flex: 1; }

/* ---- CARDS ---- */
.card-crm {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-crm .card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 14px;
}
.card-crm .card-body { padding: 20px; }

/* ---- MÉTRICAS DASHBOARD ---- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; }
.metric-card {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 18px 20px;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.metric-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.metric-icon.blue   { background: #eff6ff; color: var(--info); }
.metric-icon.green  { background: #f0fdf4; color: var(--success); }
.metric-icon.red    { background: #fef2f2; color: var(--danger); }
.metric-icon.yellow { background: #fffbeb; color: var(--warning); }
.metric-value { font-size: 26px; font-weight: 700; line-height: 1; }
.metric-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ---- TABLA CRM ---- */
.table-crm { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-crm th {
  background: #f8fafc; padding: 10px 14px; text-align: left;
  font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.table-crm td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table-crm tr:hover td { background: #f8fafc; }
.table-crm tr:last-child td { border-bottom: none; }

/* ---- BADGES DE ESTADO ---- */
.badge-estado {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.estado-activo       { background:#dbeafe; color:#1d4ed8; }
.estado-promesa_pago { background:#fef9c3; color:#854d0e; }
.estado-acuerdo      { background:#dcfce7; color:#166534; }
.estado-pagado       { background:#d1fae5; color:#065f46; }
.estado-inubicable   { background:#f3f4f6; color:#4b5563; }
.estado-juridico     { background:#fee2e2; color:#991b1b; }
.estado-inactivo     { background:#f3f4f6; color:#9ca3af; }

/* ---- BOTONES ---- */
.btn-crm {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: 13.5px;
  font-weight: 500; border: none; cursor: pointer; text-decoration: none;
  transition: all .15s;
}
.btn-primary-crm { background: var(--brand-primary); color: #fff; }
.btn-primary-crm:hover { background: #153d6e; color: #fff; }
.btn-danger-crm  { background: var(--brand-accent); color: #fff; }
.btn-danger-crm:hover  { background: #c1121f; color: #fff; }
.btn-outline-crm {
  background: transparent; color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline-crm:hover { background: #f8fafc; }
.btn-call {
  background: #16a34a; color: #fff; border-radius: 50px;
  padding: 6px 14px; font-size: 13px;
}
.btn-call:hover { background: #15803d; color: #fff; }
.btn-wa {
  background: #25d366; color: #fff; border-radius: 50px;
  padding: 6px 14px; font-size: 13px;
}
.btn-wa:hover { background: #128c7e; color: #fff; }

/* ---- CLICK-TO-CALL indicator ---- */
.calling-spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid #fff; border-top-color: transparent;
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- FORMULARIOS ---- */
.form-crm .form-label { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-crm .form-control, .form-crm .form-select {
  font-size: 13.5px; border-radius: 8px; border: 1px solid var(--border);
  padding: 8px 12px; transition: border-color .15s;
}
.form-crm .form-control:focus, .form-crm .form-select:focus {
  border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(26,79,138,.12);
}
.section-divider {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); padding-bottom: 6px;
  margin: 20px 0 14px;
}

/* ---- FICHA DEUDOR ---- */
.ficha-header {
  background: linear-gradient(135deg, var(--brand-primary), #1e3a5f);
  color: #fff; border-radius: var(--radius) var(--radius) 0 0; padding: 20px 24px;
}
.ficha-nombre { font-size: 20px; font-weight: 700; }
.ficha-doc    { font-size: 13px; opacity: .75; }
.deuda-monto  { font-size: 28px; font-weight: 800; color: var(--brand-accent); }

/* ---- TIMELINE GESTIONES ---- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-dot {
  position: absolute; left: -24px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand-primary); border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--brand-primary);
}
.timeline-dot.llamada    { background: var(--info); box-shadow: 0 0 0 2px var(--info); }
.timeline-dot.whatsapp   { background: #25d366; box-shadow: 0 0 0 2px #25d366; }
.timeline-dot.promesa    { background: var(--warning); box-shadow: 0 0 0 2px var(--warning); }
.timeline-dot.pago       { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.timeline-card {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px;
}
.timeline-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* ---- LOGIN ---- */
.login-wrap {
  min-height: 100vh; width: 100vw;
  background: var(--bg-sidebar);
  display: flex; align-items: center; justify-content: center;
  position: fixed; top: 0; left: 0; z-index: 9999;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo i { font-size: 40px; color: var(--brand-accent); }
.login-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-sub   { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 28px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}
