/* css/styles.css */

/* --- ESTILOS ORIGINALES --- */
body { font-size: 0.9rem; }
.sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 100; padding: 48px 0 0; box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1); }
.sidebar-sticky { position: relative; top: 0; height: calc(100vh - 48px); padding-top: .5rem; overflow-x: hidden; overflow-y: auto; }
.nav-link { font-weight: 500; color: #333; cursor: pointer;}
.nav-link .bi { margin-right: 8px; font-size: 1.1rem; vertical-align: text-bottom; }
.nav-link.active { color: #0d6efd; }
.navbar-brand { padding-top: .75rem; padding-bottom: .75rem; background-color: rgba(0, 0, 0, .25); box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25); }
.navbar .navbar-toggler { top: .25rem; right: 1rem; }

/* CORRECCIÓN DE SOLAPAMIENTO */
main { padding-top: 4rem; }

#modalNuevoCliente, #modalVerCliente, #modalNuevoProducto, #modalVerProducto, #modalVerVenta { z-index: 1060; }
.preview-wrapper { position: relative; display: inline-block; margin-right: 10px; margin-top: 10px; border-radius: 5px; overflow: hidden; border: 1px solid #ddd; }
.img-preview { width: 100px; height: 100px; object-fit: cover; display: block; }
.preview-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); color: white; font-weight: bold; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s ease; font-size: 1rem; text-shadow: 1px 1px 2px rgba(0,0,0,0.5); }
.preview-wrapper.is-loading .preview-overlay { opacity: 1; }
.preview-wrapper.is-complete .preview-overlay { opacity: 1; background: rgba(25, 135, 84, 0.7); }
.detalle-fotos-wrapper { display: flex; flex-wrap: wrap; gap: 10px; }
.detalle-foto { width: 150px; height: 150px; object-fit: cover; border-radius: 5px; border: 1px solid #eee; cursor: pointer; }
.existing-photo-wrapper { position: relative; display: inline-block; margin: 5px; border: 1px solid #ccc; border-radius: 5px; overflow: hidden; width: 100px; height: 100px; }
.existing-photo-wrapper img { width: 100%; height: 100%; object-fit: cover; }
.existing-photo-wrapper .btn-delete-photo { position: absolute; top: 2px; right: 2px; padding: 2px 5px; font-size: 0.75rem; line-height: 1; z-index: 10; }
#cliente-ordenes-body tr:hover, #garantia-resultados .list-group-item:hover { background-color: #f8f9fa; cursor: pointer; }
#resultadosBusquedaPOS .list-group-item { cursor: pointer; }
#resultadosBusquedaPOS .list-group-item:hover { background-color: #e9ecef; }

/* Tacha todas las celdas EXCEPTO la última */
.venta-cancelada td:not(:last-child),
.item-baja-por-partes td:not(:last-child) { 
    color: #6c757d; 
    text-decoration: line-through; 
}
/* Evita que el badge de estado se tache */
.item-baja-por-partes .badge {
    text-decoration: none;
    font-style: normal;
    opacity: 0.7;
}

.garantia-meses-input { width: 60px; font-size: 0.8rem; padding: 0.2rem 0.4rem; }
.kpi-card .card-body { min-height: 120px; }

/* --- ESTILOS PARA ORDENAMIENTO (Escritorio) --- */
.sortable-header {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px;
}
.sortable-header:hover {
    background-color: #f8f9fa;
}
.sort-icon {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1em;
    vertical-align: -0.125em;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: contain;
    transition: transform 0.2s ease-in-out;
}
/* Icono Neutral */
.sortable-header:not(.sort-asc):not(.sort-desc) .sort-icon {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cccccc' stroke-width='1.5'%3E%3Cpath d='M20 7L4 7' stroke-linecap='round'%3E%3C/path%3E%3Cpath d='M15 12L4 12' stroke-linecap='round'%3E%3C/path%3E%3Cpath d='M9 17H4' stroke-linecap='round'%3E%3C/path%3E%3C/svg%3E");
}
/* Icono Ascendente */
.sortable-header.sort-asc .sort-icon {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' fill='%230d6efd'%3E%3Cpath d='M400.817,178.731l-128-170.667c-8.043-10.752-26.091-10.752-34.133,0l-128,170.667 c-4.843,6.464-5.611,15.104-2.005,22.336c3.627,7.232,10.987,11.797,19.072,11.797h64v85.333c0,11.776,9.536,21.333,21.333,21.333 h85.333c11.797,0,21.333-9.557,21.333-21.333v-85.333h64c8.085,0,15.467-4.565,19.093-11.797 C406.449,193.835,405.681,185.195,400.817,178.731z'%3E%3C/path%3E%3Cpath d='M298.421,340.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,340.855,298.421,340.855z'%3E%3C/path%3E%3Cpath d='M298.421,404.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,404.855,298.421,404.855z'%3E%3C/path%3E%3Cpath d='M298.421,468.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,468.855,298.421,468.855z'%3E%3C/path%3E%3C/svg%3E");
    transform: translateY(-50%) rotate(0deg); 
}
/* Icono Descendente */
.sortable-header.sort-desc .sort-icon {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' fill='%230d6efd'%3E%3Cpath d='M400.817,178.731l-128-170.667c-8.043-10.752-26.091-10.752-34.133,0l-128,170.667 c-4.843,6.464-5.611,15.104-2.005,22.336c3.627,7.232,10.987,11.797,19.072,11.797h64v85.333c0,11.776,9.536,21.333,21.333,21.333 h85.333c11.797,0,21.333-9.557,21.333-21.333v-85.333h64c8.085,0,15.467-4.565,19.093-11.797 C406.449,193.835,405.681,185.195,400.817,178.731z'%3E%3C/path%3E%3Cpath d='M298.421,340.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,340.855,298.421,340.855z'%3E%3C/path%3E%3Cpath d='M298.421,404.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,404.855,298.421,404.855z'%3E%3C/path%3E%3Cpath d='M298.421,468.855h-85.333c-11.797,0-21.333,9.536-21.333,21.333s9.536,21.333,21.333,21.333h85.333 c11.797,0,21.333-9.536,21.333-21.333S310.218,468.855,298.421,468.855z'%3E%3C/path%3E%3C/svg%3E");
    transform: translateY(-50%) rotate(180deg); 
}

/* --- ESTILOS VISUALES ADICIONALES --- */
.navbar-translucent {
    background-color: rgba(var(--bs-primary-rgb), 0.75) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.sidebar .nav-link {
    color: #333; 
    transition: all 0.2s ease-in-out;
    padding: 0.75rem 1rem; 
}
.sidebar .nav-link .bi {
    color: #333; 
    margin-right: 12px;
    transition: color 0.2s ease-in-out;
}
.sidebar .nav-link:hover, .sidebar .nav-link:hover .bi {
    color: #000; 
}
.sidebar .nav-link.active {
    color: #0d6efd; 
    background-color: rgba(var(--bs-primary-rgb), 0.1); 
    border-radius: 5px; 
}
.sidebar .nav-link.active .bi { color: #0d6efd; }
.sidebar-heading { color: #6c757d !important; }

.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1010; 
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none; 
}
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

@media (max-width: 767.98px) {
   .sidebar {
        display: block !important;
        height: 100vh !important;
        position: fixed;
        top: 0; left: 0; width: 85%; max-width: 300px;
        z-index: 1020;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 0 !important; 
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0,0,0,0.3);
    }
    .sidebar .sidebar-sticky {
        height: 100%; 
        padding-top: 1rem;
        padding-bottom: 80px; 
        overflow-y: auto;     
    }
    .mobile-user-info {
        margin-top: -1.5rem; 
        margin-bottom: 0.5rem; 
    }
}

.sidebar .nav-link.logoutButton:hover {
    color: var(--bs-danger-text-emphasis) !important; 
    background-color: var(--bs-danger-bg-subtle) !important; 
    border-radius: 5px;
}

#producto-detalle-descripcion { word-break: break-word; line-height: 1.6; }
#producto-detalle-descripcion a { font-weight: 500; }

#tabla-inventario-taller .text-muted {
    display: -webkit-box;
    -webkit-line-clamp: 2; 
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    font-size: 0.85rem;
    color: #6c757d; 
    white-space: normal;
    line-height: 1.4;
}

.problema-truncado {
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.problema-truncado[title] { cursor: help; }


/* --- NUEVOS ESTILOS MENÚ SUPERIOR (Material Chips) --- */
.top-menu-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 50px;
    margin-left: 10px;
    font-weight: 500;
    font-size: 0.9rem;
    text-decoration: none !important;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white !important;
    backdrop-filter: blur(5px);
}
.pill-web { background: rgba(255, 255, 255, 0.1); }
.pill-web:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
}
.pill-user {
    background: rgba(0, 0, 0, 0.2);
    border-color: transparent;
    cursor: default;
}
.pill-user .bi-person-circle { font-size: 1.1rem; opacity: 0.8; }
.pill-logout {
    background: rgba(220, 53, 69, 0.15);
    border-color: rgba(220, 53, 69, 0.3);
}
.pill-logout:hover {
    background: #dc3545;
    border-color: #dc3545;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}
@media (min-width: 768px) {
    .navbar-nav.d-md-flex { gap: 5px; }
}


/* --- TABLAS RESPONSIVAS (CARD VIEW + SORTING BAR) --- */
@media (max-width: 768px) {
    
    /* 1. TRANSFORMACIÓN DEL ENCABEZADO (BARRA DE ORDENAMIENTO) */
    
    #tabla-ordenes thead, 
    #tabla-inventario-equipos thead,
    #tabla-inventario-accesorios thead,
    #tabla-inventario-taller thead {
        display: block;
        margin-bottom: 15px;
        white-space: normal;
        padding-bottom: 5px;
    }

    #tabla-ordenes thead tr,
    #tabla-inventario-equipos thead tr,
    #tabla-inventario-accesorios thead tr,
    #tabla-inventario-taller thead tr {
        display: flex;
        flex-wrap: wrap; /* Permite que los botones bajen de línea */
        gap: 8px;
    }

    th:not(.sortable-header) { display: none !important; }

    .sortable-header {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #fff;
        border: 1px solid #dee2e6;
        border-radius: 50px;
        padding: 6px 16px;
        font-size: 0.8rem;
        color: #6c757d;
        text-transform: uppercase;
        font-weight: 600;
        cursor: pointer;
        flex: 0 0 auto;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        transition: all 0.2s ease;
        margin-bottom: 5px; 
    }
    .sortable-header.sort-asc,
    .sortable-header.sort-desc {
        background-color: var(--bs-primary);
        color: white !important;
        border-color: var(--bs-primary);
        box-shadow: 0 4px 6px rgba(13, 110, 253, 0.3);
    }
    
    /* --- CORRECCIÓN DEFINITIVA DE ICONOS EN MÓVIL --- */
    .sortable-header .sort-icon {
        position: static; /* Quitamos absolute (reset de escritorio) */
        transform: none;  /* Quitamos translate (reset de escritorio) */
        margin-left: 8px;
        filter: brightness(0) invert(0.6);
        
        /* Aseguramos dimensiones */
        width: 14px; 
        height: 14px;
        min-width: 14px;
        display: inline-block;
        transform-origin: center center;
    }

    /* Icono blanco cuando está activo */
    .sortable-header.sort-asc .sort-icon,
    .sortable-header.sort-desc .sort-icon {
        filter: brightness(0) invert(1);
    }
    
    /* Definimos explícitamente la rotación para móvil */
    .sortable-header.sort-asc .sort-icon { transform: rotate(0deg); }
    .sortable-header.sort-desc .sort-icon { transform: rotate(180deg); }
    
    
    #tabla-ordenes thead::before, 
    #tabla-inventario-equipos thead::before,
    #tabla-inventario-accesorios thead::before,
    #tabla-inventario-taller thead::before {
        content: "Ordenar por:";
        display: inline-flex;
        align-items: center;
        margin-right: 5px;
        font-size: 0.8rem;
        color: #999;
        font-weight: 500;
        width: 100%; 
        margin-bottom: 5px;
    }

    /* 2. TRANSFORMACIÓN DE FILAS A TARJETAS */
    #tabla-ordenes tbody tr,
    #tabla-inventario-equipos tbody tr,
    #tabla-inventario-accesorios tbody tr,
    #tabla-inventario-taller tbody tr {
        display: block;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 3px 10px rgba(0,0,0,0.06);
        margin-bottom: 1.2rem;
        padding: 0;
        border: 1px solid #f1f1f1;
        overflow: hidden;
    }
    #tabla-ordenes tbody td,
    #tabla-inventario-equipos tbody td,
    #tabla-inventario-accesorios tbody td,
    #tabla-inventario-taller tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        border-bottom: 1px solid #f8f9fa;
        text-align: right;
    }
    #tabla-ordenes tbody td > *, 
    #tabla-inventario-equipos tbody td > * {
        text-align: right;
        max-width: 65%;
    }
    #tabla-ordenes tbody td:last-child,
    #tabla-inventario-equipos tbody td:last-child,
    #tabla-inventario-accesorios tbody td:last-child,
    #tabla-inventario-taller tbody td:last-child {
        border-bottom: 0;
        background-color: #fafafa;
        justify-content: flex-end;
        gap: 10px;
        padding: 12px 15px;
    }
    #tabla-ordenes tbody td::before,
    #tabla-inventario-equipos tbody td::before,
    #tabla-inventario-accesorios tbody td::before,
    #tabla-inventario-taller tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #888;
        text-transform: uppercase;
        font-size: 0.7rem;
        letter-spacing: 0.5px;
        text-align: left;
        flex: 1;
    }

    /* HEADER DE TARJETA (Títulos y IDs): Layout Vertical */
    #tabla-ordenes tbody td[data-label="# Orden"],
    #tabla-inventario-equipos tbody td[data-label="Producto"],
    #tabla-inventario-accesorios tbody td[data-label="Producto"],
    #tabla-inventario-taller tbody td[data-label="Producto"] {
        background-color: var(--bs-primary);
        color: white;
        padding: 12px 15px;
        flex-direction: column; 
        align-items: flex-start;
        gap: 5px;
        font-size: 1rem;
        font-weight: 500;
    }

    /* Etiqueta del Header */
    #tabla-ordenes tbody td[data-label="# Orden"]::before,
    #tabla-inventario-equipos tbody td[data-label="Producto"]::before,
    #tabla-inventario-accesorios tbody td[data-label="Producto"]::before,
    #tabla-inventario-taller tbody td[data-label="Producto"]::before {
        color: rgba(255, 255, 255, 0.7);
        font-size: 0.75rem;
        margin-bottom: 2px;
    }

    /* Contenido del Header */
    #tabla-ordenes tbody td[data-label="# Orden"] > *,
    #tabla-inventario-equipos tbody td[data-label="Producto"] > *,
    #tabla-inventario-accesorios tbody td[data-label="Producto"] > *,
    #tabla-inventario-taller tbody td[data-label="Producto"] > * {
        max-width: 100% !important;
        text-align: left;
        white-space: normal;
        font-size: 1.1rem;
    }

    /* DESCRIPCIÓN DEL PROBLEMA (Órdenes) */
    #tabla-ordenes tbody td[data-label="Problema"] {
        display: block; 
        text-align: left;
    }
    #tabla-ordenes tbody td[data-label="Problema"]::before {
        display: block;
        margin-bottom: 8px;
        color: var(--bs-primary);
    }
    #tabla-ordenes tbody td[data-label="Problema"] > * {
        display: block;
        max-width: 100% !important;
        text-align: left;
        white-space: normal !important;
    }
    
    .problema-truncado {
        white-space: normal !important;
        max-height: none;
        overflow: visible;
        text-align: left;
        max-width: 100% !important;
    }

    /* --- CORRECCIÓN DEFINITIVA PARA EQUIPOS "PARA ALISTAR" --- */
    
    /* 1. Fondo del CUERPO de la tarjeta (todas las celdas, incluyendo impares y hover) */
    #tabla-inventario-equipos tbody tr.table-warning > *,
    #tabla-inventario-accesorios tbody tr.table-warning > *,
    #tabla-inventario-equipos tbody tr.table-warning:hover > *,
    #tabla-inventario-accesorios tbody tr.table-warning:hover > * {
        background-color: #fff3cd !important; /* Ganamos a striped y hover */
        border-color: #ffeeba;
        color: #664d03;
        box-shadow: none; 
    }

    /* 2. Fondo del HEADER de la tarjeta (Celda de Producto) - Ocre Oscuro */
    #tabla-inventario-equipos tbody tr.table-warning td[data-label="Producto"],
    #tabla-inventario-accesorios tbody tr.table-warning td[data-label="Producto"],
    /* Incluimos selectores hover para mantener el dorado al tocar */
    #tabla-inventario-equipos tbody tr.table-warning:hover td[data-label="Producto"],
    #tabla-inventario-accesorios tbody tr.table-warning:hover td[data-label="Producto"] {
        background-color: #d39e00 !important; 
        color: white !important;
        border-bottom-color: #c69500;
    }
    
    /* Ajuste de etiqueta dentro del header amarillo */
    #tabla-inventario-equipos tbody tr.table-warning td[data-label="Producto"]::before,
    #tabla-inventario-accesorios tbody tr.table-warning td[data-label="Producto"]::before {
        color: rgba(255, 255, 255, 0.8) !important;
    }
}

/* =========================================
   FIX: Columna Dirección (Tabla Clientes)
   ========================================= */
#tabla-clientes th:nth-child(2),
#tabla-clientes td:nth-child(2) {
    max-width: 250px;           /* Límite máximo */
    width: 250px;               /* Ancho preferido */
    white-space: normal !important; /* Permite saltos de línea */
    word-wrap: break-word !important; /* Rompe palabras largas */
    overflow-wrap: break-word !important; /* Estándar moderno */
    word-break: break-word; /* Asegura ruptura en todos los navegadores */
}

/* =========================================
   NUEVO: ANIMACIÓN DESTELLO EN MODALES
   ========================================= */
@keyframes destelloRojo {
    0%, 100% { box-shadow: none; transform: scale(1); }
    50% { box-shadow: 0 0 0 0.35rem rgba(220, 53, 69, 0.5); background-color: rgba(220, 53, 69, 0.2); transform: scale(1.1); }
}

.btn-close-destello {
    animation: destelloRojo 0.5s ease-in-out;
}

/* --- Estilos para menú contextual de títulos --- */
.rotate-icon {
    display: inline-block; /* <--- ¡ESTA LÍNEA ES LA CLAVE! Sin ella no gira */
    transition: transform 0.3s ease;
}

/* Cuando el botón desplegable está activo (abierto) */
[aria-expanded="true"] .rotate-icon {
    transform: rotate(180deg);
}