/* ─── Variables ─────────────────────────────────────────────────── */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-w: 220px;
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Layout: Sidebar + Main ────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--gray-900);
  color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; z-index: 100;
  transition: transform .2s;
}
.sidebar-logo { padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo h1 { font-size: .95rem; font-weight: 700; color: #fff; }
.sidebar-logo span { font-size: .75rem; color: var(--gray-400); }
.sidebar-nav { flex: 1; padding: .5rem 0; }
.nav-item {
  display: flex; align-items: center; gap: .6rem; padding: .65rem 1rem;
  color: var(--gray-300); border-left: 3px solid transparent;
  transition: all .15s; font-size: .875rem;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(59,130,246,.15); color: #fff; border-left-color: var(--primary-light); }
.nav-item .icon { width: 1.1rem; text-align: center; }
.sidebar-footer { padding: .75rem 1rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user { font-size: .8rem; color: var(--gray-400); margin-bottom: .5rem; }
.sidebar-user strong { display: block; color: var(--gray-200); }

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--gray-200); padding: .75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 600; }
.content { padding: 1.5rem; flex: 1; }

/* ─── Cards estadísticas ─────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: #fff; border-radius: .5rem; padding: 1rem;
  border-left: 4px solid var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.stat-card.green { border-color: var(--success); }
.stat-card.amber { border-color: var(--warning); }
.stat-card.red { border-color: var(--danger); }
.stat-card.cyan { border-color: var(--info); }
.stat-label { font-size: .75rem; color: var(--gray-600); margin-bottom: .25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

/* ─── Tabla ──────────────────────────────────────────────────────── */
.table-card { background: #fff; border-radius: .5rem; box-shadow: 0 1px 3px rgba(0,0,0,.05); overflow: hidden; }
.table-header { padding: .875rem 1rem; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
th { background: var(--gray-50); padding: .6rem .8rem; text-align: left; font-weight: 600; color: var(--gray-600); white-space: nowrap; border-bottom: 1px solid var(--gray-200); }
td { padding: .55rem .8rem; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.td-wrap { white-space: normal; max-width: 200px; }

/* ─── Badges estado ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: .2rem .6rem;
  border-radius: 9999px; font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-en_ruta { background: #dbeafe; color: #1e40af; }
.badge-completado { background: #dcfce7; color: #166534; }
.badge-cancelado { background: #fee2e2; color: #991b1b; }
.badge-incidencia { background: #fce7f3; color: #9d174d; }
.badge-pagada { background: #dcfce7; color: #166534; }
.badge-anulada { background: #fee2e2; color: #991b1b; }

/* ─── Formularios ────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--gray-700); margin-bottom: .3rem; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: .5rem .75rem; border: 1px solid var(--gray-300);
  border-radius: .375rem; font-size: .875rem; background: #fff;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ─── Botones ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: .375rem; font-size: .875rem; font-weight: 500;
  border: 1px solid transparent; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: .3rem .6rem; font-size: .75rem; }
.btn-xs { padding: .2rem .5rem; font-size: .7rem; }
.btn-icon { padding: .4rem; border-radius: .375rem; }

/* ─── Modal ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: #fff; border-radius: .5rem; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-lg { max-width: 800px; }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: .95rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .875rem 1.25rem; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: .5rem; }

/* ─── Filtros toolbar ────────────────────────────────────────────── */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filter-input { padding: .4rem .7rem; border: 1px solid var(--gray-300); border-radius: .375rem; font-size: .8rem; width: 180px; }
.filter-select { padding: .4rem .6rem; border: 1px solid var(--gray-300); border-radius: .375rem; font-size: .8rem; }

/* ─── Login ──────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%); display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: .75rem; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo h2 { font-size: 1.25rem; font-weight: 700; color: var(--primary-dark); }
.login-logo p { font-size: .8rem; color: var(--gray-400); }

/* ─── Utilidades ─────────────────────────────────────────────────── */
.text-muted { color: var(--gray-400); }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .72rem; }
.text-right { text-align: right; }
.text-green { color: var(--success); }
.text-red { color: var(--danger); }
.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; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.alert { padding: .75rem 1rem; border-radius: .375rem; font-size: .85rem; margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.spinner { width: 1.2rem; height: 1.2rem; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.upload-zone { border: 2px dashed var(--gray-300); border-radius: .5rem; padding: 2rem; text-align: center; cursor: pointer; transition: all .2s; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary-light); background: #eff6ff; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem; background: var(--gray-100); border-radius: 9999px; font-size: .72rem; }
.divider { height: 1px; background: var(--gray-200); margin: 1rem 0; }
.pagination { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-top: 1px solid var(--gray-200); }
.page-btn { padding: .3rem .65rem; border-radius: .25rem; border: 1px solid var(--gray-300); background: #fff; font-size: .8rem; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.section-title { font-size: .875rem; font-weight: 600; margin-bottom: .75rem; color: var(--gray-700); border-bottom: 1px solid var(--gray-200); padding-bottom: .4rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; }
.detail-item label { font-size: .72rem; color: var(--gray-500); display: block; }
.detail-item span { font-size: .82rem; font-weight: 500; }

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: .75rem 1rem; }
}
.hamburger { display: none; background: none; border: none; padding: .4rem; }
@media (max-width: 768px) { .hamburger { display: flex; } }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; display: none; }
.overlay.visible { display: block; }
