/* estilos.css v2 - Dashboard estilo Excel con agrupación por camión */
:root {
  --azul:        #1565c0;
  --azul-oscuro: #0d47a1;
  --azul-header: #1a237e;
  --azul-claro:  #e3f2fd;
  --retrasada-bg:   #ffcdd2;
  --retrasada-borde:#e53935;
  --retrasada-txt:  #b71c1c;
  --entregando-bg:  #fff9c4;
  --entregando-borde:#f9a825;
  --entregando-txt: #e65100;
  --entregado-bg:   #c8e6c9;
  --entregado-borde:#43a047;
  --entregado-txt:  #1b5e20;
  --border: #90caf9;
  --fondo: #f0f4f8;
  --radio: 6px;
  --sombra: 0 2px 8px rgba(0,0,0,.15);
}

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

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--fondo);
  color: #1a1a2e;
  font-size: 13px;
  font-weight: 600;
}

/* ── LOGIN ───────────────────────────────────────────────── */
#pantalla-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--azul-oscuro), var(--azul));
  padding: 1rem;
}
.login-card {
  background: white;
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--sombra);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .icono { font-size: 3rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 800; color: var(--azul); margin-top: .4rem; }
.login-logo p { color: #666; font-size: .85rem; font-weight: 400; }

.campo { margin-bottom: 1rem; }
.campo label {
  display: block; font-weight: 700; margin-bottom: .35rem;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: #333;
}
.campo input, .campo select, .campo textarea {
  width: 100%; padding: .6rem .85rem;
  border: 2px solid #d0d0d0; border-radius: var(--radio);
  font-size: .95rem; transition: border-color .2s; background: white;
  font-weight: 500;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none; border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(21,101,192,.15);
}

/* ── BOTONES ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem; border: none; border-radius: var(--radio);
  font-size: .85rem; font-weight: 700; cursor: pointer;
  transition: all .2s; text-decoration: none; white-space: nowrap;
}
.btn-primario { background: var(--azul); color: white; width: 100%; justify-content: center; padding: .75rem; }
.btn-primario:hover { background: var(--azul-oscuro); transform: translateY(-1px); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }
.btn-gris { background: #e8eaf6; color: #333; }
.btn-gris:hover { background: #c5cae9; }
.btn-verde { background: #e8f5e9; color: #2e7d32; border: 1px solid #81c784; }
.btn-verde:hover { background: #c8e6c9; }
.btn-naranja { background: #fff3e0; color: #e65100; border: 1px solid #ffb74d; }
.btn-naranja:hover { background: #ffe0b2; }
.btn-rojo { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }
.btn-azul-claro { background: var(--azul-claro); color: var(--azul-oscuro); border: 1px solid var(--border); }
.btn-azul-claro:hover { background: #bbdefb; }

/* ── LAYOUT ──────────────────────────────────────────────── */
#pantalla-dashboard { min-height: 100vh; display: flex; flex-direction: column; }

.header {
  background: var(--azul-header);
  color: white; padding: .7rem 1.2rem;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--sombra); flex-shrink: 0; gap: 1rem;
}
.header-titulo { font-size: 1rem; font-weight: 800; display: flex; align-items: center; gap: .5rem; letter-spacing: .02em; }
.header-usuario { display: flex; align-items: center; gap: .6rem; font-size: .82rem; }
.badge-sector {
  background: rgba(255,255,255,.2); padding: .2rem .6rem;
  border-radius: 20px; font-weight: 800; font-size: .78rem; letter-spacing: .05em;
}
.badge-admin   { background: #fdd835; color: #1a1a1a; }
.badge-general { background: #ab47bc; color: white; }

/* ── FILTROS ─────────────────────────────────────────────── */
.filtros-bar {
  background: white; padding: .7rem 1.2rem;
  border-bottom: 2px solid var(--border);
  display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
}
.filtros-bar .campo { margin-bottom: 0; flex: 1; min-width: 150px; max-width: 240px; }
.filtros-bar .campo label { font-size: .75rem; }
.filtros-acciones { display: flex; align-items: flex-end; gap: .5rem; flex-wrap: wrap; }

/* ── RESUMEN (estilo imagen referencia) ──────────────────── */
.resumen-bar {
  background: var(--azul);
  padding: .6rem 1.2rem;
  display: flex; flex-wrap: wrap; gap: 0;
  border-bottom: 3px solid var(--azul-oscuro);
}
.tarjeta-stat {
  flex: 1; min-width: 100px;
  text-align: center;
  padding: .5rem .8rem;
  border-right: 1px solid rgba(255,255,255,.25);
  color: white;
}
.tarjeta-stat:last-child { border-right: none; }
.tarjeta-stat .numero {
  font-size: 1.6rem; font-weight: 900; line-height: 1; color: white;
}
.tarjeta-stat .etiqueta {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; margin-top: .15rem;
  color: rgba(255,255,255,.85);
}
.stat-retrasada .numero { color: #ff8a80; }
.stat-entregando .numero { color: #ffff8d; }
.stat-entregado .numero { color: #b9f6ca; }
.stat-beneficiarios .numero { color: #e1f5fe; font-size: 1.3rem; }

/* ── TABLA ESTILO EXCEL ──────────────────────────────────── */
.contenedor-tabla { flex: 1; overflow: auto; padding: .8rem 1.2rem; }

.tabla-entregas {
  width: 100%; border-collapse: collapse;
  background: white;
  box-shadow: var(--sombra);
  font-size: .82rem;
  border: 2px solid var(--azul);
}

/* Header de tabla */
.tabla-entregas thead th {
  background: var(--azul);
  color: white; padding: .55rem .6rem;
  text-align: center; font-weight: 800;
  font-size: .75rem; text-transform: uppercase;
  letter-spacing: .04em; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.3);
  position: sticky; top: 0; z-index: 10;
}
/* Sub-header para columnas de estado (rotado) */
.tabla-entregas thead th.th-estado {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  padding: .4rem .3rem;
  min-width: 32px; max-width: 36px;
}

/* Celdas */
.tabla-entregas tbody td {
  padding: .4rem .6rem;
  border: 1px solid #bbdefb;
  vertical-align: middle;
  font-weight: 700;
}

/* Filas normales */
.tabla-entregas tbody tr.sin-estado { background: white; }
.tabla-entregas tbody tr.sin-estado:hover { background: #f5f5f5; }

/* Separador de camión (primera fila del grupo) */
tr.grupo-inicio td:first-child {
  border-top: 2px solid var(--azul) !important;
}

/* ── COLORES DE ESTADO — solo desde columna "hora" en adelante ── */
/* La fila completa cambia pero las primeras cols (fecha, ruta) van separadas */
tr.estado-RETRASADA  td.col-color { background: var(--retrasada-bg); }
tr.estado-ENTREGANDO td.col-color { background: var(--entregando-bg); }
tr.estado-ENTREGADO  td.col-color { background: var(--entregado-bg); }

tr.estado-RETRASADA  td.col-color:first-child { border-left: 4px solid var(--retrasada-borde); }
tr.estado-ENTREGANDO td.col-color:first-child { border-left: 4px solid var(--entregando-borde); }
tr.estado-ENTREGADO  td.col-color:first-child { border-left: 4px solid var(--entregado-borde); }

/* Celda de ruta (camión) agrupada */
td.celda-ruta {
  background: var(--azul-claro) !important;
  font-weight: 900; font-size: .9rem;
  color: var(--azul-oscuro);
  text-align: center; vertical-align: middle;
  border-right: 2px solid var(--border) !important;
  border-left: 2px solid var(--azul) !important;
}
td.celda-fecha {
  background: #fafafa !important;
  font-weight: 700; text-align: center;
  border-right: 1px solid #90caf9 !important;
  color: #333;
  white-space: nowrap;
}
td.col-sector {
  text-align: center;
}
td.col-cant  { text-align: right; font-variant-numeric: tabular-nums; }
td.col-dia   { text-align: center; }
td.col-hora  { text-align: center; font-weight: 800; white-space: nowrap; }

/* ── BOTONES DE ESTADO ───────────────────────────────────── */
.estado-btns { display: flex; gap: .25rem; justify-content: center; }
.btn-estado {
  padding: .2rem .35rem; border-radius: 4px;
  font-size: .68rem; font-weight: 800; cursor: pointer;
  border: 2px solid transparent; transition: all .15s;
  background: #eeeeee; color: #555;
  line-height: 1.3;
}
.btn-estado:hover { transform: scale(1.08); }
.btn-estado.activo-RETRASADA  { background: var(--retrasada-borde);  color: white; border-color: var(--retrasada-txt); }
.btn-estado.activo-ENTREGANDO { background: var(--entregando-borde); color: white; border-color: var(--entregando-txt); }
.btn-estado.activo-ENTREGADO  { background: var(--entregado-borde);  color: white; border-color: var(--entregado-txt); }

/* ── OBSERVACIONES ───────────────────────────────────────── */
.obs-input {
  width: 100%; min-width: 100px; padding: .25rem .4rem;
  border: 1.5px solid transparent; border-radius: 4px;
  background: transparent; font-size: .8rem; font-weight: 600;
  color: #333; resize: none; overflow: hidden; font-family: inherit;
  transition: border-color .2s, background .2s;
}
.obs-input:hover  { border-color: #90caf9; background: rgba(255,255,255,.8); }
.obs-input:focus  { outline: none; border-color: var(--azul); background: white; }

/* ── GUARDANDO ───────────────────────────────────────────── */
.guardando { font-size: .68rem; color: var(--azul); font-style: italic; display: none; align-items: center; gap: .2rem; }
.guardando.visible { display: flex; }

/* ── TOAST ───────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast { padding: .7rem 1.1rem; border-radius: var(--radio); color: white; font-weight: 700; font-size: .85rem; box-shadow: var(--sombra); animation: slideIn .3s ease; max-width: 300px; }
.toast-ok    { background: #2e7d32; }
.toast-error { background: #c62828; }
.toast-info  { background: var(--azul); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── SPINNER ─────────────────────────────────────────────── */
.spinner { display: inline-block; width: 1.1rem; height: 1.1rem; border: 2px solid rgba(21,101,192,.2); border-top-color: var(--azul); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cargando-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 9998; }
.cargando-card { background: white; padding: 2rem; border-radius: 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; font-weight: 700; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 9000; padding: 1rem; }
.modal { background: white; border-radius: 10px; padding: 2rem; width: 100%; max-width: 480px; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal h2 { font-size: 1.1rem; font-weight: 800; color: var(--azul-oscuro); margin-bottom: 1.2rem; display: flex; align-items: center; gap: .5rem; }
.modal-acciones { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ── UTILIDADES ──────────────────────────────────────────── */
.oculto { display: none !important; }
.txt-centro { text-align: center; }
.txt-gris { color: #888; }
.badge-estado { display: inline-block; padding: .15rem .5rem; border-radius: 20px; font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.error-login { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; border-radius: var(--radio); padding: .6rem .9rem; font-size: .85rem; margin-bottom: 1rem; display: none; }
.error-login.visible { display: block; }
.mensaje-vacio { text-align: center; padding: 3rem; color: #999; font-weight: 600; }
.mensaje-vacio .icono { font-size: 3rem; margin-bottom: 1rem; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .resumen-bar { flex-wrap: wrap; }
  .tarjeta-stat { min-width: 80px; }
  .col-dia, .col-sector { display: none; }
  .filtros-bar .campo { min-width: 130px; }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE MÓVIL — VERTICAL (max 600px)
   Elimina rowspan visual y convierte cada fila en tarjeta
══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Ocultar tabla tradicional */
  .tabla-entregas { display: none !important; }

  /* Mostrar vista de tarjetas */
  #vista-movil { display: block !important; }

  .filtros-bar .campo { min-width: 100%; max-width: 100%; }
  .filtros-acciones { width: 100%; justify-content: stretch; }
  .filtros-acciones .btn { flex: 1; justify-content: center; }

  .resumen-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
  }
  .tarjeta-stat { border-right: 1px solid rgba(255,255,255,.25); }
  .tarjeta-stat .numero { font-size: 1.3rem; }
}

/* Vista móvil: oculto por defecto, solo en móvil */
#vista-movil { display: none; padding: .6rem; }

/* Tarjeta de camión en móvil */
.camion-card {
  background: white;
  border-radius: 8px;
  margin-bottom: .75rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
  overflow: hidden;
  border: 2px solid var(--azul);
}
.camion-header {
  background: var(--azul);
  color: white;
  padding: .4rem .75rem;
  font-weight: 800;
  font-size: .85rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.entrega-row {
  border-top: 1px solid #bbdefb;
  padding: .5rem .75rem;
  transition: background .15s;
}
.entrega-row.estado-RETRASADA  { background: var(--retrasada-bg);  border-left: 4px solid var(--retrasada-borde); }
.entrega-row.estado-ENTREGANDO { background: var(--entregando-bg); border-left: 4px solid var(--entregando-borde); }
.entrega-row.estado-ENTREGADO  { background: var(--entregado-bg);  border-left: 4px solid var(--entregado-borde); }
.entrega-row.sin-estado        { border-left: 4px solid transparent; }

.entrega-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .35rem;
}
.entrega-zona {
  font-weight: 800;
  font-size: .88rem;
  flex: 1;
  line-height: 1.3;
}
.entrega-meta {
  font-size: .75rem;
  color: #555;
  font-weight: 600;
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .35rem;
}
.entrega-meta span { background: #e8eaf6; padding: .1rem .4rem; border-radius: 4px; }
.entrega-acciones {
  display: flex;
  gap: .4rem;
  align-items: center;
  flex-wrap: wrap;
}
.btn-estado-movil {
  padding: .25rem .6rem;
  border-radius: 5px;
  font-size: .75rem;
  font-weight: 800;
  cursor: pointer;
  border: 2px solid transparent;
  background: #eeeeee;
  color: #555;
  transition: all .15s;
}
.btn-estado-movil.activo-RETRASADA  { background: var(--retrasada-borde);  color: white; }
.btn-estado-movil.activo-ENTREGANDO { background: var(--entregando-borde); color: white; }
.btn-estado-movil.activo-ENTREGADO  { background: var(--entregado-borde);  color: white; }
.obs-movil {
  width: 100%;
  margin-top: .3rem;
  padding: .3rem .5rem;
  border: 1.5px solid #c5cae9;
  border-radius: 5px;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  resize: none;
  background: rgba(255,255,255,.7);
}
.obs-movil:focus { outline: none; border-color: var(--azul); background: white; }
