/* ============================================================
   ECO MÁQUINAS — Estilos globales
   Colores: Morado #6B21A8 · Amarillo #EAB308 · Azul #1D4ED8
   ============================================================ */

:root {
  /* Paleta principal */
  --purple-900: #3B0764;
  --purple-800: #6B21A8;
  --purple-700: #7C3AED;
  --purple-100: #EDE9FE;
  --purple-50:  #F5F3FF;

  --yellow-500: #EAB308;
  --yellow-400: #FACC15;
  --yellow-100: #FEF9C3;

  --blue-800:   #1E3A8A;
  --blue-700:   #1D4ED8;
  --blue-500:   #3B82F6;
  --blue-100:   #DBEAFE;
  --blue-50:    #EFF6FF;

  /* Neutros */
  --gray-900:   #111827;
  --gray-700:   #374151;
  --gray-500:   #6B7280;
  --gray-300:   #D1D5DB;
  --gray-100:   #F3F4F6;
  --gray-50:    #F9FAFB;
  --white:      #FFFFFF;

  /* Semánticos */
  --primary:        var(--purple-800);
  --primary-dark:   var(--purple-900);
  --primary-light:  var(--purple-100);
  --accent:         var(--yellow-500);
  --secondary:      var(--blue-700);
  --text-main:      var(--gray-900);
  --text-muted:     var(--gray-500);
  --border:         var(--gray-300);
  --bg:             var(--gray-50);
  --surface:        var(--white);

  /* Éxito / Advertencia / Error */
  --success:  #16A34A;
  --warning:  #D97706;
  --danger:   #DC2626;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius:        0.5rem;
  --radius-lg:     0.75rem;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
  --shadow:        0 2px 8px rgba(0,0,0,.10);
  --shadow-lg:     0 8px 24px rgba(0,0,0,.14);

  --transition: 0.2s ease;
}

/* ── Reset base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--secondary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Tipografía ─────────────────────────────── */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem;   font-weight: 700; line-height: 1.25; }
h3 { font-size: 1.25rem;  font-weight: 600; }
h4 { font-size: 1.125rem; font-weight: 600; }
h5 { font-size: 1rem;     font-weight: 600; }
p  { margin-bottom: .5rem; }

/* ── Botones ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .625rem 1.25rem;
  border-radius: var(--radius);
  font-size: .9375rem;
  font-weight: 600;
  border: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: var(--primary);
  color: var(--white);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-secondary {
  background: var(--secondary);
  color: var(--white);
}
.btn-secondary:hover { background: var(--blue-800); }
.btn-accent {
  background: var(--accent);
  color: var(--gray-900);
}
.btn-accent:hover { background: var(--yellow-400); }
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-danger {
  background: var(--danger);
  color: var(--white);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: .4rem .9rem; font-size: .875rem; }
.btn-lg { padding: .875rem 1.75rem; font-size: 1.0625rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ── Formularios ────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: .375rem;
}
.form-label .req { color: var(--danger); margin-left: .15rem; }
.form-control {
  width: 100%;
  padding: .6875rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--text-main);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(107,33,168,.15);
}
.form-control.error { border-color: var(--danger); }
.form-error { font-size: .8125rem; color: var(--danger); margin-top: .3rem; }
.form-hint  { font-size: .8125rem; color: var(--text-muted); margin-top: .3rem; }

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card-header {
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.card-body  { padding: 1.5rem; }
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Tabla ──────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9375rem;
}
.table th {
  background: var(--primary);
  color: var(--white);
  font-weight: 600;
  padding: .75rem 1rem;
  text-align: left;
  font-size: .875rem;
  white-space: nowrap;
}
.table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--purple-50); }
.table tbody tr:nth-child(even) { background: var(--gray-50); }
.table tbody tr:nth-child(even):hover { background: var(--purple-50); }

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-purple  { background: var(--purple-100); color: var(--primary); }
.badge-yellow  { background: var(--yellow-100); color: #92400E; }
.badge-blue    { background: var(--blue-100);   color: var(--blue-700); }
.badge-green   { background: #DCFCE7; color: #166534; }
.badge-red     { background: #FEE2E2; color: #991B1B; }
.badge-gray    { background: var(--gray-100); color: var(--gray-700); }

/* ── Alertas ────────────────────────────────── */
.alert {
  padding: .875rem 1.125rem;
  border-radius: var(--radius);
  border-left: 4px solid;
  font-size: .9375rem;
  margin-bottom: 1rem;
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}
.alert-info    { background: var(--blue-50);   border-color: var(--blue-500);  color: var(--blue-800);  }
.alert-success { background: #F0FDF4;           border-color: var(--success);   color: #14532D; }
.alert-warning { background: #FFFBEB;           border-color: var(--warning);   color: #78350F; }
.alert-danger  { background: #FFF1F2;           border-color: var(--danger);    color: #881337; }

/* ── Offline banner ─────────────────────────── */
#offline-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--accent);
  color: var(--gray-900);
  text-align: center;
  padding: .5rem 1rem;
  font-size: .875rem;
  font-weight: 700;
  z-index: 9999;
  box-shadow: var(--shadow);
}
#offline-banner.visible { display: block; }

/* ── Spinner ─────────────────────────────────── */
.spinner {
  width: 2rem; height: 2rem;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilidades ─────────────────────────────── */
.text-primary  { color: var(--primary); }
.text-accent   { color: var(--accent); }
.text-secondary{ color: var(--secondary); }
.text-muted    { color: var(--text-muted); }
.text-danger   { color: var(--danger); }
.text-success  { color: var(--success); }
.text-center   { text-align: center; }
.text-right    { text-align: right; }
.font-bold     { font-weight: 700; }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: .25rem; }  .mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; } .mt-8 { margin-top: 2rem; }
.mb-1 { margin-bottom: .25rem; } .mb-2 { margin-bottom: .5rem; }
.mb-4 { margin-bottom: 1rem; }   .mb-6 { margin-bottom: 1.5rem; }
.flex  { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; } .gap-4 { gap: 1rem; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Indicador de conectividad ───────────────── */
.offline-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--success);
  transition: background .3s;
  flex-shrink: 0;
}
.offline-dot.offline  { background: var(--danger); }
.offline-dot.syncing  {
  background: var(--accent);
  animation: pulse-dot 1s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(1.4); }
}

/* ── Topbar sync button ──────────────────────── */
#btn-sync-now {
  position: relative;
  transition: opacity .2s;
}
#btn-sync-now:hover { opacity: .75; }

/* ── Dashboard: fila de stats secundarios ────── */
.stat-card .stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ── Activity items con color dot ────────────── */
.activity-dot.green  { background: var(--success); }
.activity-dot.yellow { background: var(--accent); }
.activity-dot.blue   { background: var(--secondary); }
.activity-dot.red    { background: var(--danger); }

/* ── Map: controles y leyenda ────────────────── */
#map-loading {
  background: rgba(59,7,100,.7);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: 1rem 1.5rem;
  color: #fff;
}
.leaflet-popup-content-wrapper {
  border-radius: 10px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,.15) !important;
  font-family: 'Inter', sans-serif !important;
}
.leaflet-popup-tip-container { display: none; }

/* ── Tabla responsive: scroll horizontal ─────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Badge de estado warning ─────────────────── */
.badge-warning { background: var(--yellow-100); color: #78350F; }

/* ── Tablet (≤ 900px) ─────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-width: 240px; }

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

  #mod-dashboard > div[style*="grid-template-columns:repeat(3"] {
    grid-template-columns: 1fr 1fr !important;
  }

  #mod-dashboard > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  #mod-map .flex { flex-direction: column; }
  #map-container { height: 55vh; }
}

/* ── Móvil (≤ 640px) ──────────────────────────── */
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }

  .stat-card {
    padding: .875rem;
    gap: .625rem;
  }
  .stat-value { font-size: 1.4rem; }

  #mod-dashboard > div[style*="grid-template-columns:repeat(3"] {
    grid-template-columns: 1fr !important;
  }

  .table th, .table td { font-size: .8rem; padding: .5rem .4rem; }

  /* Ocultar columnas menos críticas en móvil */
  .table th:nth-child(3),
  .table td:nth-child(3),
  .table th:nth-child(4),
  .table td:nth-child(4) {
    display: none;
  }

  #map-container { height: 50vh; }
  #map-filter-status { width: 100% !important; }
}

/* ── Impresión ────────────────────────────────── */
@media print {
  #sidebar,
  #topbar,
  #offline-banner,
  .btn,
  .nav-item,
  #sidebar-overlay {
    display: none !important;
  }

  #app {
    display: block !important;
  }

  .module {
    display: block !important;
    padding: 0 !important;
  }

  .module:not(#mod-reports) { display: none !important; }
  #mod-reports { display: block !important; }

  body, .card { box-shadow: none !important; }

  .table th, .table td { font-size: 11px; padding: .3rem .4rem; }

  /* Mostrar todas las columnas ocultas en impresión */
  .table th, .table td { display: table-cell !important; }
}
