/* =========================================================
   CRM — Componentes UI
   ========================================================= */

/* ---------- BOTONES ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.btn:disabled,
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  color: #fff;
  box-shadow: 0 2px 6px rgb(37 99 235 / 0.28), inset 0 1px 0 rgb(255 255 255 / 0.15);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  box-shadow: 0 6px 14px rgb(37 99 235 / 0.35);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg-alt); border-color: var(--border-2); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg-alt); color: var(--text); }

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 2px 6px rgb(16 185 129 / 0.3);
}
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgb(16 185 129 / 0.4); }

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 2px 6px rgb(239 68 68 / 0.28);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgb(239 68 68 / 0.4); }

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
}
.btn-warning:hover { transform: translateY(-1px); }

.btn-sm { padding: 7px 12px; font-size: .82rem; }
.btn-lg { padding: 13px 24px; font-size: 1rem; }
.btn-icon { padding: 10px; }
.btn-icon.btn-sm { padding: 7px; }
.btn-block { width: 100%; }


/* ---------- TARJETAS ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  transition: all var(--t);
}
.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.card-body { padding: 22px; }
.card-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  border-radius: 0 0 var(--r-md) var(--r-md);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: all var(--t);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-700));
}
.stat-card.stat-success::before  { background: linear-gradient(90deg, #34d399, #059669); }
.stat-card.stat-warning::before  { background: linear-gradient(90deg, #fbbf24, #d97706); }
.stat-card.stat-danger::before   { background: linear-gradient(90deg, #f87171, #dc2626); }
.stat-card.stat-info::before     { background: linear-gradient(90deg, #38bdf8, #0284c7); }

.stat-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--r-full);
  margin-top: 10px;
}
.stat-trend.up   { background: #d1fae5; color: #065f46; }
.stat-trend.down { background: #fee2e2; color: #991b1b; }

.stat-icon {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: var(--r);
  display: grid;
  place-items: center;
  background: var(--brand-50);
  color: var(--brand-600);
  font-size: 1.2rem;
}


/* ---------- BADGES ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: .74rem;
  font-weight: 600;
  border-radius: var(--r-full);
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.phase-nuevo          { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.phase-pendiente      { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.phase-pendiente-contacto { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.phase-contactado     { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.phase-interesado     { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.phase-seguimiento    { background: #fae8ff; color: #86198f; border-color: #f5d0fe; }
.phase-venta          { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.phase-no-contesta    { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.phase-no-interesado  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: var(--bg-alt); color: var(--text-soft); border-color: var(--border); }


/* ---------- FORMULARIOS ---------- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: inherit;
  font-size: .92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  transition: all var(--t-fast);
  outline: none;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-mute); }

.form-input:hover,
.form-select:hover,
.form-textarea:hover { border-color: var(--border-2); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.15);
}

.form-textarea { resize: vertical; min-height: 90px; }
.form-hint { font-size: .78rem; color: var(--text-mute); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 4px; font-weight: 500; }

.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgb(239 68 68 / 0.12);
}

.input-group { position: relative; }
.input-group .form-input { padding-left: 40px; }
.input-group .input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-mute);
  pointer-events: none;
}

.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .9rem; color: var(--text); }
.form-check input[type="checkbox"],
.form-check input[type="radio"] { width: 18px; height: 18px; accent-color: var(--brand-600); cursor: pointer; }


/* ---------- TABLAS ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-mute);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg-alt); }
.table tbody tr:last-child td { border-bottom: none; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
@media (max-width: 768px) { .table { min-width: 720px; } }

.empty-state { text-align: center; padding: 60px 24px; color: var(--text-soft); }
.empty-state img { max-width: 180px; opacity: .85; margin-bottom: 16px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state p  { color: var(--text-mute); margin-bottom: 20px; }


/* ---------- MODALES ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn var(--t) both;
}
.modal-backdrop.is-open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn var(--t) cubic-bezier(0.16, 1, 0.3, 1) both;
}
.modal-lg { max-width: 780px; }
.modal-sm { max-width: 400px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1.05rem; font-weight: 700; margin: 0; }
.modal-close {
  background: transparent;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-mute);
  transition: all var(--t-fast);
}
.modal-close:hover { background: var(--bg-alt); color: var(--text); }

.modal-body { padding: 22px 24px; overflow-y: auto; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-alt);
}


/* ---------- SIDEBAR ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 22px;
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.sidebar-brand img { height: 32px; }

.sidebar-nav { padding: 16px 12px; flex: 1; }
.sidebar-section {
  padding: 14px 12px 8px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #64748b;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #cbd5e1;
  border-radius: var(--r);
  font-size: .9rem;
  font-weight: 500;
  transition: all var(--t-fast);
  margin-bottom: 2px;
}
.sidebar-link:hover { background: rgb(255 255 255 / 0.06); color: #fff; }
.sidebar-link.active {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  color: #fff;
  box-shadow: 0 4px 12px rgb(37 99 235 / 0.35);
}
.sidebar-link .icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgb(255 255 255 / 0.06);
  font-size: .8rem;
  color: #94a3b8;
}


/* ---------- LOGIN ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at -10% -20%, #1e3a8a 0%, transparent 55%),
    radial-gradient(900px 500px at 110% 120%, #1e40af 0%, transparent 55%),
    #0f172a;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  padding: 40px 36px;
  animation: fadeIn var(--t-slow) both;
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.auth-logo img { height: 46px; }
.auth-title { text-align: center; font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.auth-subtitle { text-align: center; color: var(--text-mute); font-size: .9rem; margin-bottom: 28px; }


/* ---------- ALERTAS Y TOASTS ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--r);
  border: 1px solid;
  font-size: .88rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-600);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--t) cubic-bezier(0.16, 1, 0.3, 1) both;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.toast-success { border-left-color: var(--success); }
.toast-danger  { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}


/* ---------- AVATARES ---------- */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  font-weight: 700;
  font-size: .8rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgb(37 99 235 / 0.25);
}
.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.05rem; }


/* ---------- SKELETON ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-alt) 25%, var(--border) 50%, var(--bg-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
    transition: transform var(--t);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.is-open { transform: translateX(0); }
}