:root {
    --azul: #2563eb;
    --azul-oscuro: #1e40af;
    --verde: #16a34a;
    --rojo: #dc2626;
    --gris-fondo: #f3f4f6;
    --gris-borde: #e5e7eb;
    --texto: #111827;
    --texto-muted: #6b7280;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--gris-fondo);
    color: var(--texto);
}

.oculto { display: none !important; }

/* ---- Login ---- */
#pantalla-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 360px;
}
.login-box h1 { font-size: 20px; margin-bottom: 24px; text-align: center; }
.login-box input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    font-size: 14px;
}
.login-box button {
    width: 100%;
    padding: 12px;
    background: var(--azul);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.login-box button:hover { background: var(--azul-oscuro); }
.error { color: var(--rojo); font-size: 13px; margin-top: 8px; }

/* ---- Topbar ---- */
.topbar {
    background: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gris-borde);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar button {
    padding: 8px 16px;
    background: var(--gris-fondo);
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    cursor: pointer;
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 4px;
    padding: 0 24px;
    background: white;
    border-bottom: 1px solid var(--gris-borde);
    overflow-x: auto;
}
.tab-btn {
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--texto-muted);
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}
.tab-btn.activo {
    color: var(--azul);
    border-bottom-color: var(--azul);
    font-weight: 600;
}

main { padding: 24px; max-width: 1000px; margin: 0 auto; }
main h2 { font-size: 18px; margin-bottom: 16px; }

/* ---- Dashboard stats ---- */
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
}
.stat-num { font-size: 28px; font-weight: 700; color: var(--azul); }
.stat-label { font-size: 13px; color: var(--texto-muted); margin-top: 4px; }
.stat-card-icono { font-size: 22px; margin-bottom: 6px; }
.stat-card-verde .stat-num { color: var(--verde); }
.stat-card-alerta .stat-num { color: var(--rojo); }
.stat-card-ambar .stat-num { color: #d97706; }

/* ---- Listas / cards ---- */
select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--gris-borde);
    margin-bottom: 16px;
}
.lista { display: flex; flex-direction: column; gap: 12px; }
.card {
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.card-info { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.card-info strong { font-size: 15px; }
.muted { color: var(--texto-muted); font-size: 12px; }
.card-acciones { display: flex; gap: 8px; }
.card-acciones button {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.btn-aprobar, .btn-reactivar { background: var(--verde); color: white; }
.btn-rechazar, .btn-suspender { background: var(--rojo); color: white; }
.btn-suscripcion { background: var(--azul); color: white; }
.btn-editar-ciudad { background: var(--azul); color: white; }
.btn-editar-vehiculo-chofer { background: var(--gris-fondo); color: var(--texto); border: 1px solid var(--gris-borde); }
.btn-editar-datos-chofer { background: var(--gris-fondo); color: var(--texto); border: 1px solid var(--gris-borde); }
.btn-eliminar-chofer { background: none; color: var(--rojo); border: 1px solid var(--rojo); }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: var(--gris-fondo);
    width: fit-content;
}
.badge-aprobado { background: #dcfce7; color: var(--verde); }
.badge-pendiente { background: #fef9c3; color: #a16207; }
.badge-rechazado, .badge-suspendido { background: #fee2e2; color: var(--rojo); }

/* ---- Modales ---- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-box {
    background: white;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
}
.modal-box h3 { margin-top: 0; }
.modal-box label { display: block; font-size: 13px; margin: 12px 0 4px; color: var(--texto-muted); }
.modal-box input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--gris-borde);
}
.modal-botones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-botones button {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
#modal-cancelar, #modal-ciudad-cancelar { background: var(--gris-fondo); }
#modal-confirmar, #modal-ciudad-confirmar { background: var(--azul); color: white; }

#btn-nueva-ciudad {
    padding: 10px 16px;
    background: var(--azul);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 16px;
}

/* ---- Toolbar choferes / crear chofer ---- */
.toolbar-choferes { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-choferes select { margin-bottom: 0; }
#btn-nuevo-chofer {
    padding: 10px 16px;
    background: var(--verde);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}
.modal-subtitulo { margin: 18px 0 4px; font-size: 13px; color: var(--texto-muted); border-top: 1px solid var(--gris-borde); padding-top: 14px; }

/* ---- Mapa ---- */
.mapa-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.mapa-header h2 { margin: 0; }
#filtro-ciudad-mapa { margin-bottom: 0; }
.leyenda-mapa { display: flex; gap: 16px; margin-bottom: 12px; }
.leyenda-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--texto-muted); }
.leyenda-item .punto { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.punto-libre { background: var(--azul); }
.punto-ocupado { background: #f59e0b; }
.punto-offline { background: var(--rojo); }
#mapa-admin { height: 500px; border-radius: 12px; overflow: hidden; border: 1px solid var(--gris-borde); }
.popup-chofer-admin { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 13px; }
.popup-chofer-admin strong { display: block; font-size: 14px; margin-bottom: 3px; }
.popup-chofer-admin .popup-estado { font-weight: 700; font-size: 11px; text-transform: uppercase; margin-top: 4px; }

/* ---- Pagos ---- */
.subseccion-titulo { font-size: 15px; margin: 28px 0 12px; color: var(--texto-muted); }
.badge-efectivo { background: #e0e7ff; color: #4338ca; }
.badge-pending { background: #fef9c3; color: #a16207; }
.badge-approved { background: #dcfce7; color: var(--verde); }
.badge-rejected { background: #fee2e2; color: var(--rojo); }
.chip-monto { font-size: 15px; font-weight: 700; color: var(--texto); }
.chip-monto.chico { font-size: 13px; font-weight: 600; }

/* ---- Buscador de viajes + detalle expandible ---- */
.toolbar-viajes { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
#buscar-viaje { flex: 1; min-width: 220px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--gris-borde); font-size: 14px; }
.card-viaje { flex-direction: column; align-items: stretch; cursor: pointer; }
.card-viaje-resumen { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; }
.card-viaje-detalle { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--gris-borde); font-size: 13px; display: none; }
.card-viaje-detalle.abierto { display: block; }
.detalle-fila { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--gris-borde); }
.detalle-fila:last-child { border-bottom: none; }
.detalle-seccion-titulo { font-weight: 700; margin: 14px 0 6px; color: var(--texto-muted); font-size: 12px; text-transform: uppercase; }
.detalle-seccion-titulo:first-child { margin-top: 0; }
.estrellas-detalle { color: #f59e0b; }

/* ---- Modal ancho + secciones (crear/editar chofer) ---- */
.modal-box-ancho { max-width: 560px; }
.seccion-form { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--gris-borde); }
.seccion-form:last-of-type { border-bottom: none; margin-bottom: 8px; padding-bottom: 0; }
.seccion-form-titulo { font-weight: 700; font-size: 14px; margin-bottom: 10px; color: var(--texto); }
.ayuda-form-inline { font-weight: 400; font-size: 12px; color: var(--texto-muted); }
.ayuda-form { font-size: 12px; color: var(--texto-muted); margin: 8px 0 0; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-2col label { margin: 10px 0 4px; }
.grid-2col input, .grid-2col select { margin: 0; }

/* ---- Modal tipo hoja, a pantalla completa (formularios largos) ---- */
.modal-hoja { align-items: flex-start; justify-content: center; padding: 24px 16px; }
.modal-box-hoja {
    max-width: 720px; width: 100%; max-height: calc(100vh - 48px);
    display: flex; flex-direction: column; padding: 0; overflow: hidden;
}
.modal-hoja-header { padding: 20px 28px; border-bottom: 1px solid var(--gris-borde); flex-shrink: 0; }
.modal-hoja-header h3 { margin: 0; }
.modal-hoja-contenido { padding: 20px 28px; overflow-y: auto; flex: 1; }
.modal-hoja-footer {
    padding: 16px 28px; border-top: 1px solid var(--gris-borde); flex-shrink: 0;
    display: flex; justify-content: flex-end; gap: 8px;
}
.modal-hoja .grid-2col { grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) {
    .modal-hoja { padding: 0; }
    .modal-box-hoja { max-height: 100vh; height: 100vh; border-radius: 0; }
    .modal-hoja .grid-2col { grid-template-columns: 1fr; }
}

/* ---- Badges de vencimiento de documentación ---- */
.badge-vencido { background: #fee2e2; color: var(--rojo); }
.badge-por-vencer { background: #fef9c3; color: #a16207; }
.btn-documentacion { background: var(--gris-fondo); color: var(--texto); border: 1px solid var(--gris-borde); }

/* ---- Alertas de vencimiento (dashboard) ---- */
.tarjeta-alertas {
    background: #fff7ed; border: 1px solid #fdba74; border-radius: 12px;
    padding: 16px 20px; margin-bottom: 20px;
}
.tarjeta-alertas.sin-alertas { background: #f0fdf4; border-color: #86efac; }
.tarjeta-alertas-titulo { font-weight: 700; font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.tarjeta-alertas-lista { display: flex; flex-direction: column; gap: 8px; }
.alerta-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; background: white; border-radius: 8px; padding: 8px 12px; flex-wrap: wrap; }
.alerta-item-nombre { font-weight: 600; }
.alerta-item-docs { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Analíticas ---- */
.toolbar-analiticas { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-analiticas select { margin-bottom: 0; }

.grid-analiticas { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin: 16px 0; }
.tarjeta-analitica { background: white; border-radius: 12px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.tarjeta-analitica h3 { font-size: 14px; margin: 0 0 12px; }
.tarjeta-analitica-ancha { margin-bottom: 16px; }

.lista-ranking { display: flex; flex-direction: column; gap: 10px; }
.ranking-fila { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.ranking-fila-top { display: flex; align-items: center; gap: 8px; }
.ranking-pos { width: 22px; height: 22px; border-radius: 50%; background: var(--gris-fondo); color: var(--texto-muted);
    font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ranking-pos-1 { background: #fef3c7; color: #b45309; }
.ranking-pos-2 { background: #e5e7eb; color: #4b5563; }
.ranking-pos-3 { background: #fed7aa; color: #9a3412; }
.ranking-nombre { flex: 1; font-weight: 600; }
.ranking-valor { font-weight: 700; color: var(--azul); flex-shrink: 0; }
.ranking-barra-pista { height: 8px; border-radius: 4px; background: var(--gris-fondo); overflow: hidden; margin-left: 30px; }
.ranking-barra-relleno { height: 100%; border-radius: 4px; background: var(--azul); }
.ranking-vacio { color: var(--texto-muted); font-size: 13px; }
