/* ============================================================
   GM CRM — Design System
   Variables CSS, reset, tipografía, componentes base
   Light + Dark Mode
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Variables: Light Mode ─────────────────────────────────── */
:root {
  /* Paleta principal — Azul corporativo GM */
  --primary:        #1a3a5c;
  --primary-light:  #1e4976;
  --primary-dark:   #112540;
  --accent:         #0d8fcb;
  --accent-light:   #1aa8e8;
  --accent-glow:    rgba(13, 143, 203, 0.15);

  /* Éxito / Advertencia / Error */
  --success:        #16a34a;
  --success-light:  #dcfce7;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --info:           #0891b2;
  --info-light:     #cffafe;

  /* Superficie — Light */
  --bg-base:        #f0f4f8;
  --bg-surface:     #ffffff;
  --bg-surface-2:   #f8fafc;
  --bg-hover:       #f1f5f9;
  --sidebar-bg:     #1a3a5c;
  --sidebar-text:   rgba(255,255,255,0.85);
  --sidebar-active: rgba(255,255,255,0.12);

  /* Texto */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --text-inverse:   #ffffff;

  /* Bordes */
  --border:         #e2e8f0;
  --border-focus:   #0d8fcb;

  /* Sombras */
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:      0 10px 40px rgba(0,0,0,0.12);

  /* Tipografía */
  --font:           'Inter', -apple-system, sans-serif;
  --font-mono:      'Courier New', monospace;

  /* Radios */
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      16px;
  --radius-full:    9999px;

  /* Transiciones */
  --transition:     0.2s ease;
  --transition-slow: 0.35s ease;

  /* Layout */
  --sidebar-w:      240px;
  --sidebar-w-collapsed: 64px;
  --header-h:       60px;
}

/* ── Variables: Dark Mode ──────────────────────────────────── */
[data-theme="dark"] {
  --bg-base:        #0b1120;
  --bg-surface:     #111827;
  --bg-surface-2:   #1a2236;
  --bg-hover:       #1e2d42;
  --sidebar-bg:     #0d1b2e;
  --sidebar-active: rgba(255,255,255,0.10);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --border:         #1e2d42;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:      0 10px 40px rgba(0,0,0,0.5);

  --success-light:  rgba(22,163,74,0.15);
  --warning-light:  rgba(217,119,6,0.15);
  --danger-light:   rgba(220,38,38,0.15);
  --info-light:     rgba(8,145,178,0.15);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family:      var(--font);
  background-color: var(--bg-base);
  color:            var(--text-primary);
  line-height:      1.6;
  transition:       background-color var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-light); }

img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font); }

/* ── Layout Principal ──────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width:            var(--sidebar-w);
  background:       var(--sidebar-bg);
  height:           100vh;
  display:          flex;
  flex-direction:   column;
  position:         fixed;
  top:              0;
  left:             0;
  z-index:          100;
  transition:       width var(--transition-slow);
  overflow:         hidden;
  box-shadow:       4px 0 24px rgba(0,0,0,0.25);
}

.sidebar-brand {
  padding:          20px 16px 16px;
  border-bottom:    1px solid rgba(255,255,255,0.08);
  display:          flex;
  align-items:      center;
  gap:              10px;
  min-height:       var(--header-h);
}

.sidebar-brand img {
  height:     36px;
  width:      auto;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.nav-section-label {
  font-size:    0.65rem;
  font-weight:  600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color:        rgba(255,255,255,0.35);
  padding:      12px 12px 4px;
  white-space:  nowrap;
}

.nav-item {
  display:        flex;
  align-items:    center;
  gap:            10px;
  padding:        9px 12px;
  border-radius:  var(--radius-sm);
  color:          var(--sidebar-text);
  font-size:      0.875rem;
  font-weight:    500;
  white-space:    nowrap;
  transition:     all var(--transition);
  margin-bottom:  2px;
  position:       relative;
}

.nav-item:hover {
  background: var(--sidebar-active);
  color:      #ffffff;
}

.nav-item.active {
  background:   var(--sidebar-active);
  color:        #ffffff;
  font-weight:  600;
}

.nav-item.active::before {
  content:      '';
  position:     absolute;
  left:         0;
  top:          6px;
  bottom:       6px;
  width:        3px;
  background:   var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
  width:        20px;
  height:       20px;
  flex-shrink:  0;
  opacity:      0.8;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.nav-divider {
  height:     1px;
  background: rgba(255,255,255,0.06);
  margin:     8px 12px;
}

.sidebar-footer {
  padding:      12px 8px;
  border-top:   1px solid rgba(255,255,255,0.08);
}

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

/* ── Header / Topbar ───────────────────────────────────────── */
.topbar {
  height:           var(--header-h);
  background:       var(--bg-surface);
  border-bottom:    1px solid var(--border);
  display:          flex;
  align-items:      center;
  justify-content:  space-between;
  padding:          0 24px;
  position:         sticky;
  top:              0;
  z-index:          50;
  box-shadow:       var(--shadow-sm);
}

.topbar-left {
  display:    flex;
  align-items: center;
  gap:        16px;
}

.page-title {
  font-size:   1.125rem;
  font-weight: 600;
  color:       var(--text-primary);
}

.topbar-right {
  display:    flex;
  align-items: center;
  gap:        12px;
}

/* Botón toggle dark mode */
.btn-theme {
  width:        36px;
  height:       36px;
  border-radius: var(--radius-full);
  background:   var(--bg-surface-2);
  border:       1px solid var(--border);
  display:      flex;
  align-items:  center;
  justify-content: center;
  color:        var(--text-secondary);
  transition:   all var(--transition);
}
.btn-theme:hover {
  background:   var(--accent-glow);
  color:        var(--accent);
  border-color: var(--accent);
}

/* Avatar de usuario */
.user-avatar {
  width:         36px;
  height:        36px;
  border-radius: var(--radius-full);
  background:    var(--accent);
  color:         #fff;
  font-size:     0.8rem;
  font-weight:   700;
  display:       flex;
  align-items:   center;
  justify-content: center;
  cursor:        pointer;
  transition:    transform var(--transition);
}
.user-avatar:hover { transform: scale(1.08); }

/* ── Page Container ────────────────────────────────────────── */
.page-container {
  padding:  24px;
  flex:     1;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-sm);
  overflow:      hidden;
  transition:    box-shadow var(--transition), border-color var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  padding:       16px 20px;
  border-bottom: 1px solid var(--border);
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  gap:           12px;
}

.card-title {
  font-size:   0.95rem;
  font-weight: 600;
  color:       var(--text-primary);
  display:     flex;
  align-items: center;
  gap:         8px;
}

.card-body { padding: 20px; }
.card-footer {
  padding:    14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-2);
}

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap:     16px;
  margin-bottom: 24px;
}

.kpi-card {
  background:    var(--bg-surface);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       20px;
  display:       flex;
  align-items:   flex-start;
  gap:           14px;
  box-shadow:    var(--shadow-sm);
  transition:    all var(--transition);
  position:      relative;
  overflow:      hidden;
}

.kpi-card::before {
  content:    '';
  position:   absolute;
  top:        0;
  left:       0;
  right:      0;
  height:     3px;
  background: var(--kpi-color, var(--accent));
}

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

.kpi-icon {
  width:         44px;
  height:        44px;
  border-radius: var(--radius);
  background:    var(--kpi-bg, var(--accent-glow));
  color:         var(--kpi-color, var(--accent));
  display:       flex;
  align-items:   center;
  justify-content: center;
  flex-shrink:   0;
}

.kpi-info { flex: 1; min-width: 0; }

.kpi-value {
  font-size:   1.6rem;
  font-weight: 700;
  color:       var(--text-primary);
  line-height: 1.2;
}

.kpi-label {
  font-size:  0.8rem;
  color:      var(--text-muted);
  margin-top: 2px;
}

.kpi-trend {
  font-size:  0.75rem;
  font-weight: 600;
  margin-top: 4px;
  display:    flex;
  align-items: center;
  gap:        3px;
}
.kpi-trend.up   { color: var(--success); }
.kpi-trend.down { color: var(--danger); }

/* ── Botones ────────────────────────────────────────────────── */
.btn {
  display:       inline-flex;
  align-items:   center;
  gap:           7px;
  padding:       8px 16px;
  border-radius: var(--radius);
  font-size:     0.875rem;
  font-weight:   500;
  border:        1px solid transparent;
  transition:    all var(--transition);
  white-space:   nowrap;
  line-height:   1;
}

.btn-primary {
  background:   var(--accent);
  color:        #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background:   var(--accent-light);
  color:        #fff;
  box-shadow:   0 4px 12px rgba(13,143,203,0.35);
  transform:    translateY(-1px);
}

.btn-secondary {
  background:   var(--bg-surface-2);
  color:        var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background:   var(--bg-hover);
  color:        var(--text-primary);
}

.btn-success {
  background:   var(--success);
  color:        #fff;
  border-color: var(--success);
}
.btn-success:hover {
  opacity:      0.9;
  box-shadow:   0 4px 12px rgba(22,163,74,0.35);
  transform:    translateY(-1px);
}

.btn-danger {
  background:   var(--danger);
  color:        #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  opacity:      0.9;
  transform:    translateY(-1px);
}

.btn-ghost {
  background:   transparent;
  color:        var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background:   var(--bg-hover);
  color:        var(--text-primary);
}

.btn-sm { padding: 5px 11px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

.btn-icon {
  width:         36px;
  height:        36px;
  padding:       0;
  border-radius: var(--radius);
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display:       inline-flex;
  align-items:   center;
  padding:       3px 9px;
  border-radius: var(--radius-full);
  font-size:     0.72rem;
  font-weight:   600;
  white-space:   nowrap;
}

.badge-primary { background: var(--accent-glow);    color: var(--accent); }
.badge-success { background: var(--success-light);  color: var(--success); }
.badge-warning { background: var(--warning-light);  color: var(--warning); }
.badge-danger  { background: var(--danger-light);   color: var(--danger); }
.badge-info    { background: var(--info-light);     color: var(--info); }
.badge-muted   { background: var(--bg-hover);       color: var(--text-muted); }

/* ── Tablas ─────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

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

.table th {
  background:     var(--bg-surface-2);
  color:          var(--text-muted);
  font-size:      0.75rem;
  font-weight:    600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding:        11px 14px;
  text-align:     left;
  border-bottom:  2px solid var(--border);
  white-space:    nowrap;
}

.table td {
  padding:      11px 14px;
  border-bottom: 1px solid var(--border);
  color:        var(--text-primary);
  vertical-align: middle;
}

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

.table tbody tr {
  transition: background var(--transition);
}
.table tbody tr:hover { background: var(--bg-hover); }

.table tbody tr.clickable { cursor: pointer; }

/* ── Formularios ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display:     block;
  font-size:   0.8rem;
  font-weight: 500;
  color:       var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width:         100%;
  padding:       9px 13px;
  border:        1px solid var(--border);
  border-radius: var(--radius);
  font-size:     0.875rem;
  font-family:   var(--font);
  color:         var(--text-primary);
  background:    var(--bg-surface);
  transition:    all var(--transition);
  outline:       none;
}

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

.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }

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

/* ── Alertas ────────────────────────────────────────────────── */
.alert {
  padding:       12px 16px;
  border-radius: var(--radius);
  font-size:     0.875rem;
  display:       flex;
  align-items:   center;
  gap:           10px;
  margin-bottom: 16px;
}

.alert-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid rgba(220,38,38,0.2); }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(22,163,74,0.2); }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(217,119,6,0.2); }
.alert-info    { background: var(--info-light);    color: var(--info);    border: 1px solid rgba(8,145,178,0.2); }

/* ── Grid helpers ───────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Flexbox helpers ────────────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col     { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; }  .gap-2 { gap: 8px; }  .gap-3 { gap: 12px; }
.gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }

/* ── Spacing helpers ────────────────────────────────────────── */
.mb-0 { margin-bottom: 0; }     .mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }   .mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }  .mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }     .mt-6 { margin-top: 24px; }
.ms-auto { margin-left: auto; }

/* ── Text helpers ───────────────────────────────────────────── */
.text-muted    { color: var(--text-muted); }
.text-sm       { font-size: 0.8rem; }
.text-xs       { font-size: 0.72rem; }
.text-lg       { font-size: 1.125rem; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap:           16px;
  flex-wrap:     wrap;
}

.page-header h1 {
  font-size:   1.4rem;
  font-weight: 700;
  color:       var(--text-primary);
}

.page-header p {
  font-size: 0.875rem;
  color:     var(--text-muted);
  margin-top: 2px;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding:    60px 20px;
  color:      var(--text-muted);
}
.empty-state svg {
  margin:    0 auto 16px;
  opacity:   0.3;
  width:     64px;
  height:    64px;
}
.empty-state h3 {
  font-size: 1rem;
  color:     var(--text-secondary);
  margin-bottom: 6px;
}

/* ── Scrollbar global ───────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive: tablet ─────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 64px; }
  .nav-item span, .nav-section-label, .sidebar-brand span { display: none; }
  .sidebar-brand { justify-content: center; padding: 12px; }
  .nav-item { justify-content: center; padding: 10px; }
}

/* ── Responsive: mobile ─────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.open { transform: translateX(0); width: 240px !important; }
  .sidebar.open .nav-item span,
  .sidebar.open .nav-section-label,
  .sidebar.open .sidebar-brand span { display: flex !important; }
  .sidebar.open .nav-item { justify-content: flex-start !important; }
  .main-content { margin-left: 0; }
  .page-container { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── Animaciones ────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(-10px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.fade-in   { animation: fadeIn   0.3s ease forwards; }
.slide-in  { animation: slideIn  0.3s ease forwards; }

/* Skeleton loading */
.skeleton {
  background:    linear-gradient(90deg, var(--border) 25%, var(--bg-hover) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation:     shimmer 1.5s infinite;
  border-radius: var(--radius);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
