@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600;700;800&display=swap');

/* ==========================================================================
   TOKENS — Identidad "sala de control de flota"
   ========================================================================== */
:root {
    /* Superficies */
    --fondo: #f2f0ea;
    --superficie: #ffffff;
    --superficie-suave: #faf8f4;
    --borde: #e3ddd0;

    /* Tinta */
    --texto: #14181f;
    --texto-secundario: #626b78;
    --texto-tenue: #9199a5;

    /* Marca — navy de cabina + teal de ruta/GPS */
    --navy: #10151d;
    --navy-2: #1b2330;
    --acento: #0e7490;
    --acento-claro: #14a5c7;
    --acento-oscuro: #0a5468;

    /* Semáforo operativo — colores sólidos y saturados, no pasteles */
    --ambar: #c2650a;
    --rojo: #dc2626;
    --verde: #15803d;

    /* Tipografía */
    --fuente-display: 'Manrope', sans-serif;
    --fuente-cuerpo: 'Manrope', sans-serif;
    --fuente-dato: 'JetBrains Mono', 'SFMono-Regular', monospace;

    --radio: 14px;
    --radio-sm: 8px;
    --sombra: 0 10px 30px -12px rgba(16, 21, 29, 0.18);
    --sombra-sm: 0 2px 8px rgba(16, 21, 29, 0.06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--fuente-cuerpo);
    font-weight: 500;
    background-color: var(--fondo);
    background-image:
        radial-gradient(circle at 1px 1px, rgba(16,21,29,0.05) 1px, transparent 0);
    background-size: 22px 22px;
    color: var(--texto);
    margin: 0;
    padding: 0 0 60px;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

:focus-visible {
    outline: 2px solid var(--acento);
    outline-offset: 2px;
    border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

img, svg { max-width: 100%; }

.contenedor {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 clamp(16px, 4vw, 24px);
}

/* ==========================================================================
   CABECERA — franja de cabina oscura, estilo "panel de mando"
   ========================================================================== */
header {
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
    padding: clamp(16px, 3vw, 22px) 0 26px;
    margin-bottom: -18px;
}

.header-fila {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 clamp(16px, 4vw, 24px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.logo-titulo {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.logo-titulo .icono-marca {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(14, 116, 144, 0.18);
    border: 1px solid rgba(20, 165, 199, 0.35);
    color: var(--acento-claro);
    font-size: 1.2rem;
}

h1 {
    margin: 0;
    font-family: var(--fuente-display);
    font-size: clamp(1.1rem, 3.4vw, 1.4rem);
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

header p.subtitulo {
    margin: 2px 0 0;
    color: #8b96a6;
    font-weight: 600;
    font-size: clamp(0.7rem, 2vw, 0.82rem);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #c7cedb;
    padding: 10px 16px;
    border-radius: var(--radio-sm);
    font-family: var(--fuente-cuerpo);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
    min-height: 44px;
    white-space: nowrap;
}

.btn-logout:hover {
    background: rgba(220, 38, 38, 0.25);
    border-color: rgba(220, 38, 38, 0.5);
    color: #ffd9d0;
}

/* --- Tira de resumen de flota (elemento de firma) --- */
.resumen-flota {
    max-width: 1240px;
    margin: 18px auto 0;
    padding: 0 clamp(16px, 4vw, 24px);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radio);
    overflow: hidden;
    box-shadow: var(--sombra);
}

.resumen-chip {
    background: var(--navy-2);
    padding: clamp(12px, 2.5vw, 16px) clamp(14px, 3vw, 20px);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.resumen-chip .resumen-label {
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #8b96a6;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resumen-chip .resumen-valor {
    font-family: var(--fuente-dato);
    font-size: clamp(1.25rem, 4vw, 1.6rem);
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.resumen-chip .resumen-valor small {
    font-family: var(--fuente-cuerpo);
    font-size: 0.7rem;
    color: #8b96a6;
    font-weight: 600;
}

.resumen-chip.chip-alerta .resumen-valor { color: #ff8a5c; }
.resumen-chip.chip-ok .resumen-valor { color: #4ade80; }

/* ==========================================================================
   PANEL DE CONTROLES
   ========================================================================== */
.panel-controles {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    background: var(--superficie);
    padding: clamp(14px, 3vw, 18px) clamp(14px, 3vw, 20px);
    border-radius: var(--radio);
    box-shadow: var(--sombra-sm);
    border: 1px solid var(--borde);
    margin: clamp(20px, 4vw, 30px) 0;
}

.filtros {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.selector-grupo {
    display: flex;
    align-items: center;
    gap: 9px;
    background: var(--superficie-suave);
    padding: 0 14px;
    border-radius: var(--radio-sm);
    border: 1px solid transparent;
    min-height: 46px;
    flex: 1;
    min-width: 130px;
    transition: border-color 0.15s, background 0.15s;
}

.selector-grupo:hover {
    border-color: var(--borde);
}

.selector-grupo:focus-within {
    background: var(--superficie);
    border-color: var(--acento);
}

.selector-grupo i {
    color: var(--texto-tenue);
    font-size: 0.85rem;
    flex-shrink: 0;
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: none;
    background: transparent;
    font-family: var(--fuente-cuerpo);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--texto);
    outline: none;
    cursor: pointer;
    width: 100%;
    min-width: 0;
    padding: 0 22px 0 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'><path d='M1 1L5 5L9 1' stroke='%239199a5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right center;
}

select::-ms-expand { display: none; }

.btn-sync {
    background-color: var(--acento);
    color: #ffffff;
    border: none;
    padding: 12px 22px;
    border-radius: var(--radio-sm);
    font-family: var(--fuente-cuerpo);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    box-shadow: 0 6px 16px -6px rgba(14, 116, 144, 0.55);
    min-height: 44px;
    white-space: nowrap;
}

.btn-sync:hover {
    background-color: var(--acento-oscuro);
    transform: translateY(-1px);
}

.btn-sync:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
}

/* ==========================================================================
   GRID DE VEHÍCULOS
   ========================================================================== */
.grid-camiones {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: clamp(16px, 3vw, 22px);
}

.tarjeta-camion {
    background: var(--superficie);
    border-radius: var(--radio);
    padding: clamp(18px, 4vw, 24px);
    box-shadow: var(--sombra-sm);
    border: 1px solid var(--borde);
    border-top: 4px solid var(--acento);
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 0;
}

.tarjeta-camion:hover {
    transform: translateY(-3px);
    box-shadow: var(--sombra);
}

.tarjeta-camion.alerta {
    border-top: 4px solid var(--rojo);
}

.cabecera-tarjeta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--borde);
    flex-wrap: wrap;
}

.matricula-badge {
    font-family: var(--fuente-dato);
    font-size: clamp(0.85rem, 2.6vw, 0.95rem);
    font-weight: 600;
    background: var(--navy);
    color: #ffffff;
    padding: 6px 11px;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

.dias-trabajo {
    font-size: 0.8rem;
    color: var(--texto-tenue);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.dias-trabajo i { color: var(--texto-tenue); }

/* Estadísticas */
.grid-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    background: var(--superficie-suave);
    padding: 14px 16px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border: none;
    min-width: 0;
}

.stat-label {
    font-size: 0.68rem;
    color: var(--texto-tenue);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-valor {
    font-family: var(--fuente-cuerpo);
    font-variant-numeric: tabular-nums;
    font-size: clamp(0.98rem, 3vw, 1.1rem);
    font-weight: 700;
    color: var(--texto);
    overflow-wrap: break-word;
    letter-spacing: -0.01em;
}

.stat-valor i {
    margin-right: 6px;
    font-size: 0.85rem;
    color: var(--texto-tenue);
}

/* Colores condicionales (usados directamente por app.js) */
.texto-rojo { color: var(--rojo) !important; }
.texto-verde { color: var(--verde) !important; }

.mensaje-carga {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 1.05rem;
    color: var(--texto-secundario);
    padding: 60px 20px;
}

/* ==========================================================================
   CALENDARIO DESPLEGABLE — colores sólidos y de alto contraste
   ========================================================================== */
.btn-toggle-cal {
    width: 100%;
    margin-top: 20px;
    background: transparent;
    border: 1px dashed var(--borde);
    padding: 12px;
    color: var(--texto-secundario);
    cursor: pointer;
    border-radius: var(--radio-sm);
    transition: 0.2s;
    font-family: var(--fuente-cuerpo);
    font-weight: 700;
    font-size: 0.88rem;
    min-height: 44px;
}

.btn-toggle-cal:hover {
    background: var(--superficie-suave);
    color: var(--texto);
    border-color: var(--acento);
}

.calendario-container {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--borde);
    animation: fadeIn 0.25s ease;
}

.leyenda-calendario {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    font-size: 0.75rem;
    color: var(--texto-secundario);
    font-weight: 600;
}

.leyenda-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.leyenda-punto {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.calendario-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
}

.cal-header {
    font-size: 0.68rem;
    color: var(--texto-tenue);
    font-weight: 800;
    margin-bottom: 4px;
    letter-spacing: 0.04em;
}

.cal-dia {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-family: var(--fuente-dato);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: default;
    position: relative;
}

.cal-dia.vacio { background: transparent; }

.cal-dia.inactivo {
    background: var(--superficie-suave);
    color: var(--texto-tenue);
}

/* Días activos: verde sólido y saturado, no pastel */
.cal-dia.activo {
    background: var(--verde);
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 2px 5px -1px rgba(21, 128, 61, 0.5);
}

.cal-dia.activo:hover {
    background: #166534;
    transform: scale(1.08);
}

/* Fin de semana: navy sólido */
.cal-dia.fin-semana {
    background: var(--navy) !important;
    color: #ffffff !important;
    cursor: default;
}

/* Alerta de km: rojo sólido y saturado */
.cal-dia.alerta-km {
    background: var(--rojo) !important;
    color: #ffffff !important;
    cursor: pointer;
    box-shadow: 0 2px 5px -1px rgba(220, 38, 38, 0.5);
}

.cal-dia.alerta-km:hover {
    background: #b91c1c !important;
    transform: scale(1.08);
}

.cal-dia[data-info]:hover::after {
    content: attr(data-info);
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--navy);
    color: #ffffff;
    padding: 6px 9px;
    border-radius: 6px;
    white-space: nowrap;
    font-family: var(--fuente-dato);
    font-size: 0.72rem;
    z-index: 10;
    box-shadow: var(--sombra-sm);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   MODAL DE NOTAS
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: rgba(16, 21, 29, 0.65);
    backdrop-filter: blur(2px);
    padding: 16px;
    overflow-y: auto;
}

.modal-contenido {
    background-color: var(--superficie);
    margin: 8% auto;
    padding: clamp(20px, 5vw, 26px);
    border-radius: var(--radio);
    width: 100%;
    max-width: 480px;
    box-shadow: 0 25px 60px -15px rgba(16, 21, 29, 0.45);
    animation: fadeIn 0.2s ease;
}

.modal-contenido h2 {
    font-family: var(--fuente-display);
    font-weight: 800;
    margin-top: 0;
    font-size: clamp(1.05rem, 3.5vw, 1.2rem);
}

.cerrar-modal {
    float: right;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    color: var(--texto-tenue);
    transition: 0.2s;
    padding: 6px;
    margin: -6px -6px 0 0;
}

.cerrar-modal:hover { color: var(--rojo); }

#nota-texto {
    width: 100%;
    margin: 15px 0;
    padding: 12px;
    border: 1px solid var(--borde);
    border-radius: var(--radio-sm);
    font-family: var(--fuente-cuerpo);
    font-size: 1rem;
    resize: vertical;
    box-sizing: border-box;
    background: var(--superficie-suave);
}

#nota-texto:focus {
    background: var(--superficie);
    border-color: var(--acento);
}

.modal-acciones {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-primario, .btn-secundario {
    font-family: var(--fuente-cuerpo);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 12px 20px;
    border-radius: var(--radio-sm);
    cursor: pointer;
    border: none;
    transition: 0.2s;
    min-height: 44px;
}

.btn-primario {
    background: var(--acento);
    color: #ffffff;
}

.btn-primario:hover { background: var(--acento-oscuro); }

.btn-secundario {
    background: var(--superficie-suave);
    color: var(--texto-secundario);
    border: 1px solid var(--borde);
}

.btn-secundario:hover { background: var(--borde); color: var(--texto); }

/* ==========================================================================
   NOTAS EN TARJETA
   ========================================================================== */
.seccion-notas {
    margin-top: 16px;
    border-top: 1px dashed var(--borde);
    padding-top: 16px;
}

.titulo-notas {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--texto-secundario);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nota-item {
    background: var(--superficie-suave);
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.88rem;
    border-left: 3px solid var(--acento);
}

.nota-texto {
    flex-grow: 1;
    padding-right: 4px;
    white-space: pre-wrap;
    line-height: 1.4;
    word-break: break-word;
    min-width: 0;
}

.nota-acciones {
    display: flex;
    gap: 14px;
    color: var(--texto-tenue);
    flex-shrink: 0;
}

.nota-acciones i {
    cursor: pointer;
    transition: 0.2s;
    padding: 4px;
}
.nota-acciones .fa-pen:hover { color: var(--acento); }
.nota-acciones .fa-trash:hover { color: var(--rojo); }

/* ==========================================================================
   PANTALLA DE LOGIN
   ========================================================================== */
.pantalla-login {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(14, 116, 144, 0.25), transparent 45%),
        radial-gradient(circle at 80% 80%, rgba(20, 165, 199, 0.15), transparent 45%),
        var(--navy);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.caja-login {
    background: var(--superficie);
    padding: clamp(30px, 6vw, 44px) clamp(24px, 5vw, 38px);
    border-radius: 18px;
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.caja-login .icono-marca {
    width: 56px;
    height: 56px;
    margin: 0 auto 18px;
    border-radius: 14px;
    background: var(--acento);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.caja-login h2 {
    font-family: var(--fuente-display);
    font-weight: 800;
    color: var(--texto);
    margin: 0 0 8px;
    font-size: clamp(1.15rem, 5vw, 1.35rem);
}

.caja-login p {
    color: var(--texto-secundario);
    margin-bottom: 22px;
    font-size: 0.9rem;
}

.caja-login input {
    width: 100%;
    padding: 13px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--borde);
    border-radius: var(--radio-sm);
    font-family: var(--fuente-cuerpo);
    font-size: 1rem;
    box-sizing: border-box;
    text-align: center;
    background: var(--superficie-suave);
    transition: 0.2s;
    min-height: 48px;
}

.caja-login input:focus {
    border-color: var(--acento);
    background: var(--superficie);
}

.caja-login button { width: 100%; padding: 13px; font-size: 0.95rem; min-height: 48px; }

/* ==========================================================================
   RESPONSIVE — tablet y escritorio intermedio
   ========================================================================== */
@media (max-width: 1024px) {
    .grid-camiones { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* --- Tablets / móviles grandes --- */
@media (max-width: 768px) {
    .resumen-flota { grid-template-columns: repeat(3, 1fr); gap: 1px; }
    .resumen-chip .resumen-label { font-size: 0.62rem; }
    .grid-camiones { grid-template-columns: 1fr; }
    .modal-contenido { margin: 20% auto; }
}

/* --- Móviles --- */
@media (max-width: 480px) {
    body { padding-bottom: 40px; }
    .header-fila { justify-content: center; text-align: center; }
    .logo-titulo { justify-content: center; }
    .btn-logout { width: 100%; justify-content: center; }
    .resumen-flota { grid-template-columns: 1fr; }
    .resumen-chip { flex-direction: row; align-items: center; justify-content: space-between; }
    .panel-controles { flex-direction: column; align-items: stretch; }
    .filtros { flex-direction: column; }
    .selector-grupo { width: 100%; }
    .btn-sync { width: 100%; }
    .grid-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
    .cabecera-tarjeta { flex-direction: row; }
    .matricula-badge { font-size: 0.9rem; }
    .calendario-grid { gap: 3px; }
    .cal-dia { font-size: 0.7rem; }
    .modal-contenido { margin: 12% auto; padding: 20px; }
    .modal-acciones { flex-direction: column-reverse; }
    .modal-acciones button { width: 100%; }
}

/* --- Móviles muy pequeños --- */
@media (max-width: 360px) {
    .grid-stats { grid-template-columns: 1fr; }
}