/* ============================================================
   ClientCRM — Hoja de estilos global
   Mobile-first | Light theme profesional | Acento índigo
   ============================================================ */

/* ── Variables ────────────────────────────────────────────── */
:root {
  /* Fondo y superficies */
  --bg:        #f5f6fa;
  --surface:   #ffffff;
  --surface-2: #f8f9fc;

  /* Bordes y sombras */
  --border:    rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Tipografía */
  --text:       #1a1f2e;
  --text-muted: #6b7280;
  --font-display: 'Syne', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  /* Colores de acción — índigo */
  --coral:     #4f46e5;
  --coral-dim: rgba(79, 70, 229, 0.10);
  --mint:      #06b6d4;
  --purple:    #7c3aed;

  /* Colores de estado — optimizados para fondo claro */
  --caliente:    #b91c1c;
  --caliente-bg: #fee2e2;
  --tibio:       #b45309;
  --tibio-bg:    #fef3c7;
  --frio:        #1d4ed8;
  --frio-bg:     #dbeafe;
  --ganado:      #15803d;
  --ganado-bg:   #dcfce7;

  /* Misc */
  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --transition: 0.18s ease;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

a { color: var(--coral); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 60px;
  background: #ffffff;
  box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0, 0, 0, 0.04);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--coral);
  white-space: nowrap;
  text-decoration: none;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
}

.nav-links a {
  display: block;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition), background var(--transition);
}

.nav-links a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-links a.active {
  color: var(--coral);
  background: var(--coral-dim);
  font-weight: 600;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.nav-user-name {
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity var(--transition), transform var(--transition),
              background var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--coral);
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
  background: #4338ca;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: #d1d5db;
}

.btn-danger {
  background: #fee2e2;
  color: var(--caliente);
  border: 1px solid #fecaca;
}
.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 0.4rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: #d1d5db;
}

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: var(--surface);
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-dim);
}

.form-control::placeholder { color: #9ca3af; }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

textarea.form-control {
  resize: vertical;
  min-height: 90px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ============================================================
   BADGES DE ESTADO
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: capitalize;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.badge::before { content: '●'; font-size: 0.55rem; }

.badge-caliente { background: var(--caliente-bg); color: var(--caliente); }
.badge-tibio    { background: var(--tibio-bg);    color: var(--tibio);    }
.badge-frio     { background: var(--frio-bg);     color: var(--frio);     }
.badge-ganado   { background: var(--ganado-bg);   color: var(--ganado);   }

/* ============================================================
   TARJETAS DE ESTADÍSTICAS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card.total::before    { background: linear-gradient(90deg, #4f46e5, #818cf8); }
.stat-card.activas::before  { background: linear-gradient(90deg, var(--tibio), var(--caliente)); }
.stat-card.ganadas::before  { background: linear-gradient(90deg, var(--ganado), #34d399); }
.stat-card.pipeline::before { background: linear-gradient(90deg, var(--purple), #a78bfa); }

.stat-icon {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat-card.total    .stat-value { color: #4f46e5; }
.stat-card.activas  .stat-value { color: var(--tibio); }
.stat-card.ganadas  .stat-value { color: var(--ganado); }
.stat-card.pipeline .stat-value { color: var(--purple); }

/* ============================================================
   TABLAS
   ============================================================ */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.table-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  padding: 0.8rem 1.25rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

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

tbody tr {
  transition: background var(--transition);
}
tbody tr:hover { background: #fafafa; }

.td-name { font-weight: 600; }
.td-company { color: var(--text-muted); font-size: 0.8rem; }

.td-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

/* Estado "sin datos" */
.empty-state {
  padding: 3.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* ============================================================
   BARRA DE FILTROS (clientes.html)
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.filter-select { min-width: 160px; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
  transition: color var(--transition);
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  color: var(--text);
  background: var(--surface-2);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
  color: var(--text);
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ============================================================
   DASHBOARD — Layout de 2 columnas (chart + tabla reciente)
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.chart-card h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.chart-container { position: relative; height: 220px; }

/* ============================================================
   DETALLE DEL CLIENTE
   ============================================================ */
.client-detail-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
  align-items: start;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}

.client-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--coral-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin-bottom: 1rem;
}

.client-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.client-company {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.client-meta {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}

.client-meta-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.client-meta-item span:last-child { color: var(--text); }

.client-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Notas ── */
.notes-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}

.notes-section h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.add-note-form {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.add-note-form textarea {
  flex: 1;
  min-height: 70px;
}

.add-note-form .btn { align-self: flex-end; }

/* Timeline de notas */
.notes-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.note-item {
  display: flex;
  gap: 0.75rem;
  padding-bottom: 1.25rem;
  position: relative;
}

/* Línea vertical */
.note-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 22px;
  bottom: 0;
  width: 2px;
  background: #e5e7eb;
}

.note-dot {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--coral-dim);
  border: 2px solid var(--coral);
  margin-top: 2px;
}

.note-body {
  flex: 1;
  background: #f8f9fc;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}

.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.note-author {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--coral);
}

.note-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.note-content {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(79, 70, 229, 0.07) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(124, 58, 237, 0.05) 0%, transparent 60%),
    #f5f6fa;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 0.5rem;
}

.login-logo h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--coral);
}

.login-logo p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.3rem;
}

.login-form .btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem;
  font-size: 1rem;
  margin-top: 0.5rem;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--caliente);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: none;
}

.login-error.visible { display: block; }

/* ============================================================
   NOTIFICACIONES TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
  max-width: 340px;
}

@keyframes toastIn  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

.toast-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: var(--ganado);
}
.toast-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--caliente);
}
.toast-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: var(--frio);
}

/* ============================================================
   UTILIDADES
   ============================================================ */
.text-muted    { color: var(--text-muted); }
.text-right    { text-align: right; }
.fw-600        { font-weight: 600; }
.mb-1          { margin-bottom: 1rem; }
.mb-2          { margin-bottom: 2rem; }
.d-flex        { display: flex; }
.align-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1         { gap: 1rem; }

/* Spinner de carga */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   RESPONSIVE — Tablet (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ============================================================
   RESPONSIVE — Mobile (< 640px)
   ============================================================ */
@media (max-width: 639px) {
  .navbar { padding: 0 1rem; }

  .nav-links { display: none; }

  .main-content { padding: 1.25rem 1rem; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .dashboard-grid  { grid-template-columns: 1fr; }
  .client-detail-grid { grid-template-columns: 1fr; }

  .form-row { grid-template-columns: 1fr; }

  .modal { padding: 1.5rem; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input { max-width: none; }

  .add-note-form { flex-direction: column; }

  /* Ocultar columnas menos importantes en tabla */
  .col-empresa,
  .col-telefono { display: none; }
}
