/* ============================================================
   Keystone CRM — Design System
   Paleta: navy #0B1E3D | gris #F4F6FA | ambar #D97706
   Tipografia: Sora (headings) | Manrope (body) | Spline Sans Mono (datos)
   Tailwind CSS standalone + utilidades custom
   ============================================================ */

/* Variables CSS */
:root {
  --navy: #0B1E3D;
  --navy-700: rgba(255,255,255,0.08);
  --amber: #D97706;
  --gray-bg: #F4F6FA;
  --success: #15803D;
  --error: #B91C1C;
  --info: #0369A1;
}

/* Reset base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Manrope', system-ui, sans-serif; background-color: var(--gray-bg); color: #111827; }

/* Fuentes */
.font-sora { font-family: 'Sora', system-ui, sans-serif; }
.font-manrope { font-family: 'Manrope', system-ui, sans-serif; }
.font-mono { font-family: 'Spline Sans Mono', 'JetBrains Mono', monospace; }

/* Colores */
.bg-navy { background-color: var(--navy) !important; }
.text-navy { color: var(--navy) !important; }
.text-amber-500 { color: #f59e0b; }
.text-amber-600 { color: var(--amber); }
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.text-gray-600 { color: #4b5563; }
.text-gray-700 { color: #374151; }
.text-gray-800 { color: #1f2937; }
.text-gray-900 { color: #111827; }
.text-white { color: #ffffff; }
.text-red-600 { color: #dc2626; }
.text-red-700 { color: #b91c1c; }
.text-red-800 { color: #991b1b; }
.text-green-700 { color: #15803d; }
.text-green-800 { color: #166534; }
.text-blue-500 { color: #3b82f6; }
.bg-gray-50 { background-color: #f9fafb; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-white { background-color: #ffffff; }
.bg-red-50 { background-color: #fef2f2; }
.bg-green-50 { background-color: #f0fdf4; }
.bg-amber-50 { background-color: #fffbeb; }

/* Layout */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1 1 0%; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.h-screen { height: 100vh; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.overflow-x-auto { overflow-x: auto; }
.min-h-screen { min-height: 100vh; }
.w-full { width: 100%; }
.w-64 { width: 16rem; }
.w-36 { width: 9rem; }
.w-24 { width: 6rem; }
.w-20 { width: 5rem; }
.w-8 { width: 2rem; }
.w-4 { width: 1rem; }
.h-4 { height: 1rem; }
.h-2 { height: 0.5rem; }
.max-w-sm { max-width: 24rem; }
.max-w-md { max-width: 28rem; }
.max-w-xl { max-width: 36rem; }
.max-w-2xl { max-width: 42rem; }

/* Grid */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2; }

@media (min-width: 640px) {
  .sm\:col-span-2 { grid-column: span 2; }
  .sm\:flex-row { flex-direction: row; }
  .sm\:items-center { align-items: center; }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .lg\:col-span-2 { grid-column: span 2; }
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Spacing */
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.space-y-1 > * + * { margin-top: 0.25rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.space-x-1 > * + * { margin-left: 0.25rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-2\.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-5 { padding-top: 1.25rem; padding-bottom: 1.25rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.pl-3 { padding-left: 0.75rem; }
.pt-3 { padding-top: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.ml-1 { margin-left: 0.25rem; }
.ml-2 { margin-left: 0.5rem; }
.ml-3 { margin-left: 0.75rem; }
.mr-1 { margin-right: 0.25rem; }
.mx-4 { margin-left: 1rem; margin-right: 1rem; }
.mx-6 { margin-left: 1.5rem; margin-right: 1.5rem; }

/* Texto */
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }
.text-6xl { font-size: 3.75rem; line-height: 1; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.tracking-tight { letter-spacing: -0.025em; }
.tracking-wider { letter-spacing: 0.05em; }
.uppercase { text-transform: uppercase; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.antialiased { -webkit-font-smoothing: antialiased; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }

/* Borders */
.rounded { border-radius: 0.25rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-2xl { border-radius: 1rem; }
.rounded-full { border-radius: 9999px; }
.border { border-width: 1px; border-style: solid; }
.border-t { border-top-width: 1px; border-top-style: solid; }
.border-b { border-bottom-width: 1px; border-bottom-style: solid; }
.border-l-2 { border-left-width: 2px; border-left-style: solid; }
.border-gray-100 { border-color: #f3f4f6; }
.border-gray-200 { border-color: #e5e7eb; }
.border-red-200 { border-color: #fecaca; }
.border-green-200 { border-color: #bbf7d0; }
.border-amber-200 { border-color: #fde68a; }
.border-navy-700 { border-color: rgba(255,255,255,0.08); }

/* Shadows */
.shadow-xl { box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04); }

/* Transitions */
.transition-colors { transition: color 0.2s, background-color 0.2s; }
.transition-all { transition: all 0.3s; }
.duration-300 { transition-duration: 300ms; }

/* ============================================================
   Componentes del Design System
   ============================================================ */

/* Card */
.card {
  background: #ffffff;
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

/* Input */
.input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: #ffffff;
  color: #111827;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(11,30,61,0.12);
}
.input[readonly] { background: #f9fafb; color: #6b7280; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; }

/* Label */
.label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.25rem;
}

/* Error */
.error-msg {
  display: block;
  font-size: 0.75rem;
  color: var(--error);
  margin-top: 0.25rem;
}

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background-color: var(--navy);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s;
}
.btn-primary:hover { background-color: rgba(11,30,61,0.85); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background-color: #ffffff;
  color: #374151;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  border: 1px solid #d1d5db;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn-secondary:hover { background-color: #f9fafb; border-color: #9ca3af; }

/* Nav links */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}
.nav-link:hover { background-color: rgba(255,255,255,0.08); color: #ffffff; }
.nav-link-active { background-color: rgba(255,255,255,0.12); color: #ffffff; font-weight: 600; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table thead th {
  padding: 0.625rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
.table thead th.text-right { text-align: right; }
.table tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background-color: #fafafa; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  white-space: nowrap;
}
.badge-activo { background: #dcfce7; color: #166534; }
.badge-prospecto { background: #fef3c7; color: #92400e; }
.badge-inactivo { background: #f3f4f6; color: #4b5563; }
.badge-suspendido { background: #fee2e2; color: #991b1b; }

/* Prioridad */
.badge-prioridad-urgente { background: #fee2e2; color: #991b1b; }
.badge-prioridad-alta { background: #fef3c7; color: #92400e; }
.badge-prioridad-media { background: #dbeafe; color: #1e40af; }
.badge-prioridad-baja { background: #f3f4f6; color: #4b5563; }

/* Estado de tarea */
.badge-estado-pendiente { background: #fef3c7; color: #92400e; }
.badge-estado-enprogreso { background: #dbeafe; color: #1e40af; }
.badge-estado-completada { background: #dcfce7; color: #166534; }
.badge-estado-cancelada { background: #f3f4f6; color: #6b7280; }

/* Links de accion */
.link-action { font-size: 0.8125rem; color: var(--navy); text-decoration: none; font-weight: 500; }
.link-action:hover { text-decoration: underline; }
.link-danger { font-size: 0.8125rem; color: var(--error); background: none; border: none; cursor: pointer; font-weight: 500; font-family: inherit; }
.link-danger:hover { text-decoration: underline; }

/* Background util para filas vencidas */
.bg-red-50\/50 { background-color: rgba(254,242,242,0.5); }

/* Focus visible — accesibilidad AA (teclado) */
a:focus-visible,
button:focus-visible,
.link-action:focus-visible,
.link-danger:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: 0.25rem;
}
.nav-link:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
}

/* Toasts animados */
[role="alert"] {
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Sidebar mobile */
@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 30;
  }
  #sidebar-backdrop.open { display: block; }
  #sidebar-toggle { display: inline-flex; }
}
@media (min-width: 768px) {
  #sidebar-toggle { display: none; }
}

/* Estado de carga en botones (submit) */
.btn-primary[disabled], .btn-secondary[disabled] { opacity: 0.6; cursor: wait; }
