/* ============================================================
   VIALYS — Hoja de estilos principal v1.1
   Mejorado para uso móvil — conductores
   ============================================================ */

/* --- Reset y base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --azul:        #1a56db;
    --azul-hover:  #1648c0;
    --azul-claro:  #e8f0fe;
    --verde:       #057a55;
    --verde-claro: #def7ec;
    --rojo:        #c81e1e;
    --rojo-claro:  #fde8e8;
    --amarillo:    #9f580a;
    --amarillo-claro: #fef3c7;
    --gris-50:     #f9fafb;
    --gris-100:    #f3f4f6;
    --gris-200:    #e5e7eb;
    --gris-400:    #9ca3af;
    --gris-600:    #4b5563;
    --gris-800:    #1f2937;
    --blanco:      #ffffff;
    --sombra-sm:   0 1px 3px rgba(0,0,0,.10);
    --sombra-md:   0 4px 12px rgba(0,0,0,.12);
    --radio:       8px;
    --radio-lg:    12px;
    --fuente:      'Inter', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--fuente);
    font-size: 15px;
    color: var(--gris-800);
    background: var(--gris-100);
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

/* --- LOGIN --- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a56db 0%, #0e3a8c 100%);
    padding: 1rem;
}

.login-card {
    background: var(--blanco);
    border-radius: var(--radio-lg);
    box-shadow: var(--sombra-md);
    padding: 2rem 1.5rem;
    width: 100%;
    max-width: 420px;
}

.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo img { height: 64px; margin-bottom: .5rem; }
.login-logo h1 { font-size: 1.6rem; color: var(--azul); font-weight: 700; }
.login-logo p  { color: var(--gris-400); font-size: .9rem; }
.login-pie     { text-align: center; margin-top: 1.25rem; font-size: .875rem; color: var(--gris-600); }
.login-pie a   { color: var(--azul); text-decoration: none; }

/* --- FORMULARIOS --- */
.campo        { margin-bottom: 1rem; }
.campo label  { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; color: var(--gris-600); }
.campo input,
.campo select,
.campo textarea {
    width: 100%;
    padding: .65rem .9rem;
    border: 1.5px solid var(--gris-200);
    border-radius: var(--radio);
    font-size: 1rem;
    font-family: var(--fuente);
    background: var(--blanco);
    transition: border-color .15s;
    -webkit-appearance: none;
    appearance: none;
}
.campo input:focus,
.campo select:focus,
.campo textarea:focus {
    outline: none;
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.campo textarea  { resize: vertical; min-height: 90px; }
.campo select    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2rem; }
.campo input[type=file] { padding: .5rem; font-size: .9rem; }

/* --- BOTONES --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .65rem 1.2rem;
    border: none;
    border-radius: var(--radio);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.btn-full        { width: 100%; }
.btn-primary     { background: var(--azul);   color: var(--blanco); }
.btn-primary:hover  { background: var(--azul-hover); }
.btn-primary:active { opacity: .85; }
.btn-success     { background: var(--verde);  color: var(--blanco); }
.btn-danger      { background: var(--rojo);   color: var(--blanco); }
.btn-secondary   { background: var(--gris-200); color: var(--gris-800); }
.btn-secondary:hover { background: #d1d5db; }
.btn-sm          { padding: .45rem .85rem; font-size: .825rem; }

/* Botones más grandes en móvil para fácil toque */
@media (max-width: 640px) {
    .btn { padding: .75rem 1.25rem; font-size: .95rem; }
    .btn-sm { padding: .6rem .9rem; font-size: .85rem; }
}

/* --- ALERTAS --- */
.alerta {
    padding: .75rem 1rem;
    border-radius: var(--radio);
    margin-bottom: 1rem;
    font-size: .9rem;
    line-height: 1.5;
}
.alerta-danger  { background: var(--rojo-claro);    color: var(--rojo);     border: 1px solid #f8b4b4; }
.alerta-success { background: var(--verde-claro);   color: var(--verde);    border: 1px solid #84e1bc; }
.alerta-warning { background: var(--amarillo-claro);color: var(--amarillo); border: 1px solid #fcd34d; }
.alerta-info    { background: var(--azul-claro);    color: var(--azul);     border: 1px solid #a4cafe; }

/* --- LAYOUT PANEL --- */
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR DESKTOP */
.sidebar {
    width: 240px;
    background: var(--gris-800);
    color: var(--blanco);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--blanco);
    text-decoration: none;
    display: block;
}
.sidebar-logo span { display: block; font-size: .75rem; font-weight: 400; opacity: .6; margin-top: .15rem; }

.sidebar-nav { flex: 1; padding: .5rem 0; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .7rem 1rem;
    color: rgba(255,255,255,.75);
    text-decoration: none;
    font-size: .875rem;
    transition: background .15s, color .15s;
}
.sidebar-nav a:hover,
.sidebar-nav a.activo {
    background: rgba(255,255,255,.1);
    color: var(--blanco);
}
.sidebar-nav .grupo {
    padding: .75rem 1rem .2rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    opacity: .4;
}

.sidebar-pie {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.1);
    font-size: .825rem;
}
.sidebar-pie a { color: rgba(255,255,255,.6); text-decoration: none; }
.sidebar-pie a:hover { color: var(--blanco); }

.contenido { flex: 1; padding: 1.5rem 2rem; overflow-x: hidden; min-width: 0; }
.cabecera-pagina { margin-bottom: 1.25rem; }
.cabecera-pagina h2 { font-size: 1.3rem; font-weight: 600; }
.cabecera-pagina p  { color: var(--gris-400); font-size: .875rem; margin-top: .2rem; }

/* --- TARJETAS --- */
.tarjeta {
    background: var(--blanco);
    border-radius: var(--radio-lg);
    box-shadow: var(--sombra-sm);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.tarjeta-titulo {
    font-size: .95rem;
    font-weight: 600;
    margin-bottom: .75rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--gris-200);
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

/* --- TABLAS --- */
.tabla-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; min-width: 500px; }
thead th {
    text-align: left;
    padding: .55rem .8rem;
    background: var(--gris-50);
    border-bottom: 2px solid var(--gris-200);
    font-weight: 600;
    color: var(--gris-600);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
tbody td { padding: .6rem .8rem; border-bottom: 1px solid var(--gris-200); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gris-50); }

/* --- SEMÁFORO --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-verde    { background: var(--verde-claro);    color: var(--verde); }
.badge-amarillo { background: var(--amarillo-claro); color: var(--amarillo); }
.badge-rojo     { background: var(--rojo-claro);     color: var(--rojo); }
.punto          { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.punto-verde    { background: var(--verde); }
.punto-amarillo { background: #d97706; }
.punto-rojo     { background: var(--rojo); }

/* ============================================================
   RESPONSIVE MÓVIL — Conductor usa celular
   ============================================================ */

/* Botón hamburguesa — solo móvil */
.menu-toggle {
    display: none;
    position: fixed;
    top: .75rem;
    left: .75rem;
    z-index: 200;
    background: var(--gris-800);
    color: var(--blanco);
    border: none;
    border-radius: 8px;
    padding: .5rem .7rem;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--sombra-md);
    -webkit-tap-highlight-color: transparent;
}

/* Overlay cuando el menú está abierto */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 150;
}

@media (max-width: 768px) {
    /* Mostrar botón hamburguesa */
    .menu-toggle { display: flex; align-items: center; }

    /* Sidebar se convierte en drawer lateral */
    .sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        height: 100vh;
        width: 260px;
        transition: left .25s ease;
        z-index: 160;
        overflow-y: auto;
    }
    .sidebar.abierto { left: 0; }

    /* Overlay visible cuando menú abierto */
    .sidebar-overlay.activo { display: block; }

    /* Contenido ocupa todo el ancho */
    .contenido {
        padding: 1rem;
        padding-top: 3.5rem; /* espacio para el botón hamburguesa */
        width: 100%;
    }

    /* Grids de 2 columnas → 1 columna en móvil */
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="grid-template-columns:repeat(auto-fit"],
    div[style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="grid-template-columns:1fr 2fr"],
    div[style*="grid-template-columns: 1fr 2fr"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="grid-template-columns:repeat(3"],
    div[style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }

    /* Cabecera con botón en columna */
    .cabecera-pagina {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* Tarjetas sin padding lateral excesivo */
    .tarjeta { padding: 1rem; }

    /* Formularios de filtro en columna */
    form[style*="display:flex"] {
        flex-direction: column;
    }

    /* Tablas: scroll horizontal */
    .tabla-wrapper { border-radius: var(--radio); }

    /* Métricas en 2 columnas en móvil */
    .grid-metricas {
        grid-template-columns: 1fr 1fr !important;
    }
}

@media (max-width: 400px) {
    .grid-metricas {
        grid-template-columns: 1fr !important;
    }
    .login-card { padding: 1.5rem 1rem; }
}
