:root {
  --brand:      #E8500A;   /* naranja logístico */
  --brand-dark: #B83D06;
  --brand-soft: #FDF0EA;
  --ink:        #1A1A1A;
  --muted:      #6B7280;
  --border:     #E5E7EB;
  --surface:    #FFFFFF;
  --bg:         #F5F5F0;
  --success:    #16A34A;
  --warning:    #D97706;
  --danger:     #DC2626;
  --info:       #2563EB;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(232,80,10,.15);
}

/* ── Views ──────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }
#appView.active { display: flex; flex-direction: column; }

/* ── Login ──────────────────────────────────────────────────── */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1A1A1A 0%, #2D2D2D 60%, #B83D06 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--brand);
  margin-bottom: .25rem;
}
.login-sub {
  color: var(--muted);
  font-size: .875rem;
  margin-bottom: 2rem;
}
.demo-users {
  background: var(--brand-soft);
  border: 1px solid #F3C9B8;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1.5rem;
  font-size: .8rem;
  color: #7A3010;
}
.demo-users strong { display: block; margin-bottom: .4rem; }
.demo-pill {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border-radius: 20px;
  padding: .15rem .6rem;
  font-size: .75rem;
  cursor: pointer;
  margin: .15rem .1rem;
}
.demo-pill:hover { background: var(--brand-dark); }

/* ── App Shell ──────────────────────────────────────────────── */
#appView { min-height: 100vh; }

header {
  background: #1A1A1A;
  color: #fff;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-logo { font-size: 1.1rem; font-weight: 800; color: var(--brand); display: flex; align-items: center; gap: .5rem; }
.header-logo-icon { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.user-badge {
  font-size: .8rem;
  color: #ccc;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.role-tag {
  padding: .15rem .5rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
}
.role-tag.cliente       { background: #D1FAE5; color: #065F46; }
.role-tag.admin         { background: #DBEAFE; color: #1E40AF; }
.role-tag.transportador { background: #FEF3C7; color: #92400E; }
.role-tag.asignador     { background: #EDE9FE; color: #5B21B6; }

.notif-btn {
  position: relative;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  padding: .25rem;
}
.notif-badge {
  position: absolute;
  top: -2px; right: -4px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  width: 16px; height: 16px;
  font-size: .6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notif-badge.hidden { display: none; }

.app-body {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 56px);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
nav {
  width: 220px;
  background: #242424;
  color: #ccc;
  flex-shrink: 0;
  padding: 1rem 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1.25rem;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(232,80,10,.15);
  color: var(--brand);
  border-left-color: var(--brand);
}
.nav-icon { width: 20px; text-align: center; }
.nav-section {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #555;
  padding: 1rem 1.25rem .35rem;
}

main { flex: 1; padding: 1.5rem; overflow-y: auto; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.card-title { font-size: 1rem; font-weight: 700; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 600;
  transition: .15s;
}
.btn-primary   { background: var(--brand);  color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--border); color: var(--ink); }
.btn-secondary:hover { background: #D1D5DB; }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--brand);
  color: var(--brand);
}
.btn-outline:hover { background: var(--brand-soft); }

/* El botón de push del header es btn-outline pero sobre fondo oscuro:
   evita que el :hover/:active claro de btn-outline lo deje "en blanco"
   al tocarlo en el celular */
.push-toggle-btn,
.push-toggle-btn:hover,
.push-toggle-btn:active,
.push-toggle-btn:focus {
  background: transparent !important;
  -webkit-tap-highlight-color: transparent;
}

/* ── Stat cards ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px,1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.stat-label { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-icon  { font-size: 1.4rem; float: right; opacity: .6; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left;
  padding: .6rem .75rem;
  background: var(--bg);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ── Status badges ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-registrado    { background: #F3F4F6; color: #374151; }
.badge-recibido      { background: #DBEAFE; color: #1E40AF; }
.badge-transito      { background: #FEF3C7; color: #92400E; }
.badge-entregado     { background: #D1FAE5; color: #065F46; }
.badge-devolucion    { background: #FEE2E2; color: #991B1B; }
.badge-reprogramado  { background: #F3E8FF; color: #5B21B6; }

/* ── Form grid ───────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-grid.single { grid-template-columns: 1fr; }
.form-field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: .3rem;
}
.form-field.full { grid-column: 1 / -1; }

/* ── Filtro de fechas (bandeja de envíos admin) ─────────────────
   Etiqueta "Desde"/"Hasta" para que los campos de fecha no se
   confundan entre sí ni con el resto de los filtros */
.filtro-fecha { display: flex; flex-direction: column; }
.filtro-fecha label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: .3rem;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.75rem;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  line-height: 1;
}

/* ── Timeline ────────────────────────────────────────────────── */
.timeline { padding: .5rem 0; }
.tl-item {
  display: flex;
  gap: .75rem;
  padding-bottom: 1.25rem;
  position: relative;
}
.tl-item::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 22px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .7rem;
  margin-top: 2px;
}
.tl-body { flex: 1; }
.tl-estado { font-weight: 700; font-size: .875rem; }
.tl-meta { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.tl-comment { font-size: .8rem; color: #555; margin-top: .2rem; }

/* ── Notif panel ─────────────────────────────────────────────── */
.notif-panel {
  position: fixed;
  top: 56px; right: 0;
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 150;
  display: none;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}
.notif-panel.open { display: block; }
.notif-item {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.notif-item.unread { background: var(--brand-soft); }
.notif-time { font-size: .72rem; color: var(--muted); margin-top: .2rem; }

/* ── Paquete row (multi-envío) ───────────────────────────────── */
.pkg-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .75rem;
  position: relative;
}
.pkg-row-num {
  position: absolute;
  top: -10px; left: 12px;
  background: var(--brand);
  color: #fff;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 700;
  padding: .1rem .5rem;
}

/* ── Alert ───────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
}
.alert-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #6EE7B7; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }

/* ── Loading spinner ─────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page title ──────────────────────────────────────────────── */
.page-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-icon { font-size: 3rem; margin-bottom: .75rem; }

/* ── Tracking public ─────────────────────────────────────────── */
#trackingView {
  min-height: 100vh;
  background: var(--bg);
  padding: 2rem 1rem;
}
.tracking-card {
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE 
══════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 900px) ─────────────────────────────────────────── */
@media (max-width: 900px) {
  nav { width: 180px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); }
  main { padding: 1.25rem; }
}

/* ── Móvil / tablet vertical (≤ 768px) ───────────────────────── */
@media (max-width: 768px) {
  html { font-size: 14px; }

  /* Header más compacto */
  header { padding: 0 .75rem; height: 52px; }
  .header-logo { font-size: 1rem; }
  .header-logo-icon { width: 24px; height: 24px; }
  .header-right { gap: .4rem; }
  .user-badge span:first-child { display: none; } /* oculta el nombre, deja solo el rol-tag */
  header .role-tag { padding: .12rem .4rem; font-size: .62rem; }
  header .btn-sm { padding: .3rem .55rem; min-height: 30px; } /* botones del header más compactos que el resto de la app */

  /* Botón de notificaciones push: ícono de dispositivo (no campana, para no
     confundirlo con el ícono de notificaciones) + texto "Activar"/"Desactivar" */
  .push-toggle-btn { padding: .3rem .45rem !important; gap: .2rem; }
  .push-toggle-btn .push-icon { font-size: .85rem; }
  .push-toggle-btn .push-label { font-size: .6rem; white-space: nowrap; }

  /* Sidebar → barra inferior fija */
  .app-body { flex-direction: column; padding-bottom: 64px; } /* espacio para la barra */
  nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 64px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding: 0;
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 120;
    overflow-x: auto;
  }
  .nav-section { display: none; } /* el título de sección no cabe en la barra */
  .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: .15rem;
    padding: .4rem .5rem;
    font-size: .65rem;
    text-align: center;
    border-left: none;
    border-top: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 64px;
  }
  .nav-item.active { border-left-color: transparent; border-top-color: var(--brand); }
  .nav-icon { font-size: 1.15rem; }

  main { padding: 1rem; }

  /* Stats en 2 columnas en vez de romperse en 1 sola muy angosta */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .stat-value { font-size: 1.4rem; }

  /* Formularios: siempre una columna */
  .form-grid { grid-template-columns: 1fr; }

  /* Modales: casi pantalla completa, más fáciles de usar con el teclado del celular */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    padding: 1.25rem;
  }

  /* Panel de notificaciones a pantalla completa */
  .notif-panel {
    width: 100%;
    top: 52px;
    max-height: calc(100vh - 52px - 64px);
  }

  /* Botones: área táctil más grande */
  .btn { padding: .6rem 1rem; min-height: 40px; }
  .btn-sm { min-height: 34px; padding: .4rem .8rem; }

  /* Tabla: convertir filas en tarjetas apiladas */
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  thead { display: none; }
  tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: .75rem;
    padding: .5rem .75rem;
  }
  tr:hover td { background: transparent; }
  td {
    border-bottom: none;
    padding: .4rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    text-align: right;
  }
  td::before {
    content: attr(data-label);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 700;
    text-align: left;
  }
  td:last-child { justify-content: flex-end; flex-wrap: wrap; }

  .login-card { padding: 1.75rem 1.5rem; margin: 1rem; }
  .page-title { font-size: 1.1rem; }
}

/* ── Móvil pequeño (≤ 420px) ─────────────────────────────────── */
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .demo-pill { font-size: .68rem; }
  .nav-item { min-width: 56px; font-size: .6rem; }
}

/* ── Móvil muy angosto (≤ 360px): si no alcanza el espacio en el
   header, el botón de push vuelve a mostrar solo el ícono ──────── */
@media (max-width: 360px) {
  .push-toggle-btn .push-label { display: none; }
}

#tablaEnviosAdmin{
    width:100%;
    border-collapse:collapse;
}

#tablaEnviosAsignador{
    width:100%;
    border-collapse:collapse;
}

#tablaEnviosAdmin thead th,
#tablaEnviosAsignador thead th{
    position:sticky;
    top:0;
    z-index:5;
    background:#ffffff;
    border-bottom:2px solid #E86A33;
    box-shadow:0 2px 4px rgba(0,0,0,.08);
}

#tablaEnviosAdmin tbody tr:nth-child(even),
#tablaEnviosAsignador tbody tr:nth-child(even){
    background:#fafafa;
}

#tablaEnviosAdmin tbody tr:hover,
#tablaEnviosAsignador tbody tr:hover{
    background:#FFF4EF;
    transition:.2s;
}