/* css/admin.css - Diseño del Dashboard Financiero y Modal Panorámico Ampliado */

/* =========================================
   1. PERSONALIZACIÓN DEL SCROLLBAR
========================================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background-color: #333;
    border-radius: 10px;
    border: 2px solid var(--bg-color);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent-cyan);
}

* {
    scrollbar-width: thin;
    scrollbar-color: #333 var(--bg-color);
}

/* =========================================
   2. ESTILOS GENERALES
========================================= */
.admin-body {
    display: flex;
    min-height: 100vh;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    /* Evita doble scroll */
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    z-index: 100;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 2.5rem;
    text-align: center;
}

.sidebar h2 span {
    color: var(--accent-cyan);
    background: rgba(0, 180, 216, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 1.2rem;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.sidebar ul li {
    padding: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.sidebar ul li:hover,
.sidebar ul li.active {
    background: linear-gradient(90deg, rgba(0, 180, 216, 0.1) 0%, transparent 100%);
    color: var(--accent-cyan);
    border-left: 4px solid var(--accent-cyan);
}

/* Dashboard */
.dashboard {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
    height: 100vh;
    position: relative;
}

.dashboard header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard header h1 {
    font-size: 1.8rem;
    background: linear-gradient(45deg, var(--text-primary), var(--accent-cyan));
    /* Corrección de propiedad estándar */
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-export {
    background: linear-gradient(45deg, var(--accent-orange), #ff8c00);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(255, 94, 0, 0.2);
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 94, 0, 0.4);
}

/* KPI Cards Mejoradas */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.kpi-card {
    background-color: var(--surface-color);
    padding: 1.8rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(0, 180, 216, 0.1) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.kpi-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-cyan);
    box-shadow: 0 15px 35px rgba(0, 180, 216, 0.1);
}

.kpi-card h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.kpi-card h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-weight: 800;
}

.positive {
    color: #25D366;
    font-size: 0.8rem;
    font-weight: 700;
    background: rgba(37, 211, 102, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-block;
    width: fit-content;
}

/* Charts */
.charts-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    width: 100%;
}

.chart-box {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    height: 400px;
    width: 100%;
}

/* Animaciones */
.admin-section {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scanner */
.scanner-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

#reader {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--accent-cyan) !important;
}

.scanner-result {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: var(--bg-color);
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2rem;
}

.scanner-result.success {
    border-color: #25D366;
    background: rgba(37, 211, 102, 0.05);
}

.result-icon {
    font-size: 4rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.scanner-result.success .result-icon {
    color: #25D366;
}

/* Inventario Tabla */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    background: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    max-height: 70vh;
}

.inventory-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

.inventory-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-color);
    z-index: 20;
    /* Lo subimos de 5 a 20 para que tape el botón de la cámara */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.inventory-table th,
.inventory-table td {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.inventory-table th {
    background: rgba(0, 180, 216, 0.05);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
    color: var(--accent-cyan);
}

.inventory-table tr:hover {
    background: rgba(0, 180, 216, 0.02);
}

.inventory-table img {
    width: 45px;
    height: 45px;
    object-fit: contain;
    background: white;
    border-radius: 8px;
    padding: 2px;
    border: 1px solid var(--border-color);
}

.btn-action {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    margin: 0 5px;
    transition: transform 0.2s;
}

.btn-action:hover {
    transform: scale(1.2);
}

.btn-edit {
    color: var(--accent-cyan);
}

.btn-delete {
    color: #FF4444;
}

/* =========================================
   3. NUEVO MODAL PANORÁMICO (DISEÑO EXACTO)
========================================= */
.admin-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    /* Fondo oscuro traslúcido */
    backdrop-filter: blur(5px);
    z-index: 5000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.admin-modal.active {
    display: flex;
}

/* Contenedor Base para TODOS los Modales (Escáner, etc.) */
.admin-modal-content {
    background-color: var(--surface-color);
    /* Cambia entre blanco y oscuro según el tema */
    color: var(--text-primary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    position: relative;
    width: 100%;
}

/* Contenedor Específico para el Modal Grande (Formulario) */
.admin-modal-content.large-modal {
    background-color: #151A22;
    /* Se mantiene oscuro siempre */
    color: #E0E6ED;
    border: 1px solid #2A3241;
    max-width: 950px;
    max-height: 90vh;
    overflow-y: auto;
}


/* Header del Modal */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: none;
    /* Quitamos la línea divisoria del header */
}

.modal-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
    color: #FFFFFF;
    margin: 0;
}

.close-modal {
    background: none;
    border: none;
    color: #8D99AE;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}

.close-modal:hover {
    color: #FFFFFF;
}

/* Estructura Superior (Foto + Formulario) */
.top-split {
    display: grid;
    grid-template-columns: 200px 1fr;
    /* Columna foto fija, resto flexible */
    gap: 2rem;
    align-items: start;
    margin-bottom: 1rem;
}

/* Área de Foto */
.image-upload-compact {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-preview-box.small {
    width: 100%;
    height: 160px;
    background-color: #0B0E14;
    /* Fondo negro de la caja de foto */
    border: 1px dashed #2A3241;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #586270;
    margin-bottom: 10px;
    overflow: hidden;
}

.image-preview-box.small i {
    font-size: 2rem;
    margin-bottom: 5px;
}

.image-preview-box.small img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.btn-upload-mini {
    background: #21262D;
    border: 1px solid #363B42;
    color: #C9D1D9;
    padding: 6px 15px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: 0.2s;
}

.btn-upload-mini:hover {
    background: #30363D;
    border-color: #8B949E;
}

/* Grids del Formulario */
.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.main-info-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Estilos de Inputs y Labels */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #8B949E;
    /* Gris claro para textos */
}

.form-input {
    background-color: #0B0E14;
    /* Fondo muy oscuro para inputs */
    border: 1px solid #2A3241;
    /* Borde sutil */
    color: #FFFFFF;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    width: 100%;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--accent-cyan);
}

.form-input::placeholder {
    color: #444C56;
}

.form-input:disabled {
    background-color: #111418;
    color: #555;
    cursor: not-allowed;
}

/* Títulos de Secciones (Cyan) */
.section-title {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--accent-cyan);
    text-transform: uppercase;
    margin: 25px 0 10px 0;
    letter-spacing: 0.5px;
}

/* Grids Inferiores */
.grid-4-cols {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.grid-3-cols {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

/* Botones No Aplica (Badges) */
.label-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.na-toggle {
    background: transparent;
    border: 1px solid #2A3241;
    color: #8B949E;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
}

.na-toggle:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.na-toggle.active {
    background: #21262D;
    color: #555;
    border-color: transparent;
    text-decoration: line-through;
}

/* Botón Guardar */
.full-width-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border-radius: 6px;
    background: var(--accent-cyan);
    /* Cyan vibrante */
    color: white;
    font-weight: 800;
    border: none;
    cursor: pointer;
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}

.full-width-btn:hover {
    background: #0096b5;
    transform: translateY(-1px);
}

/* Responsive */
@media (max-width: 900px) {
    .top-split {
        grid-template-columns: 1fr;
    }

    .grid-4-cols,
    .grid-3-cols {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .admin-body {
        flex-direction: column;
        height: auto;
        overflow: auto;
    }

    .dashboard {
        padding: 1.5rem;
        height: auto;
        overflow: visible;
    }

    .scanner-container {
        grid-template-columns: 1fr;
    }

    /* Modal en Móvil */
    .admin-modal-content.large-modal {
        padding: 1.5rem;
        max-height: 85vh;
        width: 100%;
    }

    .top-split {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .image-preview-box.small {
        height: 200px;
    }

    .grid-4-cols,
    .grid-3-cols,
    .form-row-2 {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* =========================================
   4. MEJORAS DE DISEÑO (BOTONES Y MODALES)
========================================= */

/* Botón Nuevo Producto Premium */
.btn-new-product {
    background: linear-gradient(135deg, var(--accent-cyan), #0077b6);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 180, 216, 0.3);
    font-size: 1rem;
    margin: 0;
}

.btn-new-product:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 180, 216, 0.5);
}

/* Ventanas Emergentes (Alertas Custom) */
.custom-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-modal-overlay.active {
    display: flex;
    opacity: 1;
}

.custom-modal-box {
    background: var(--surface-color);
    padding: 2.5rem 2rem;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--border-color);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.custom-modal-overlay.active .custom-modal-box {
    transform: scale(1);
}

.custom-modal-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.custom-modal-icon.success {
    color: #25D366;
}

.custom-modal-icon.error {
    color: #FF4444;
}

.custom-modal-icon.warning {
    color: var(--accent-orange);
}

.custom-modal-box h3 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.custom-modal-box p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.custom-modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.btn-modal-primary,
.btn-modal-secondary {
    padding: 12px 25px;
    border-radius: 8px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
}

.btn-modal-primary {
    background: var(--accent-cyan);
    color: white;
}

.btn-modal-primary:hover {
    background: #0096b5;
    transform: translateY(-2px);
}

.btn-modal-primary.danger {
    background: #FF4444;
}

.btn-modal-primary.danger:hover {
    background: #cc0000;
}

.btn-modal-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-modal-secondary:hover {
    background: var(--bg-color);
}

/* =========================================
   5. ESTILOS DE TABLA TIPO EXCEL (INLINE EDIT)
========================================= */
.editable-cell {
    border: 1px solid transparent;
    transition: all 0.2s;
    outline: none;
    min-width: 100px;
}

.editable-cell:hover {
    border: 1px dashed var(--accent-cyan);
    background: rgba(0, 180, 216, 0.05);
    cursor: text;
}

.editable-cell:focus {
    border: 1px solid var(--accent-cyan);
    background: rgba(0, 180, 216, 0.1);
    box-shadow: 0 0 5px rgba(0, 180, 216, 0.5);
}

.col-filter {
    width: 100%;
    padding: 5px;
    margin-top: 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: normal;
    outline: none;
    box-sizing: border-box;
}

.col-filter:focus {
    border-color: var(--accent-cyan);
}

.inventory-table th {
    vertical-align: top;
    /* Alinea los títulos y filtros arriba */
}

/* =========================================
   6. ANCHOS FIJOS DE COLUMNAS Y WRAP TEXT CORREGIDO
========================================= */
.inventory-table {
    table-layout: fixed;
    min-width: 1700px;
}

.inventory-table th,
.inventory-table td {
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    vertical-align: middle;
}

.inventory-table th {
    vertical-align: top;
    /* Evita cortes de palabras agresivos */
    word-break: normal;
    hyphens: none;
}

/* Tamaños más amplios y perfectos para cada columna */
.col-foto {
    width: 80px;
    text-align: center;
}

.col-categoria {
    width: 150px;
}

.col-codigo {
    width: 150px;
}

.col-codigo-prov {
    width: 150px;
}

.col-proveedor {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-nombre {
    width: 170px;
    min-width: 170px;
    max-width: 170px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    font-size: 0.82rem;
}

.col-descripcion {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    font-size: 0.82rem;
}

.col-compatibilidad {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    font-size: 0.82rem;
}

.col-marca {
    width: 130px;
}

.col-stock {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* COD PROVEEDOR */
.col-part {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* GANANCIA */
.col-ganancia {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}


/* NUEVOS TAMAÑOS PARA PRECIOS Y ACCIONES (Nombres completos) */
.col-precio {
    width: 140px;
    min-width: 140px;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}


/* Espacio de sobra para "PRECIO PROVEEDOR" */
.col-vendidos {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* Espacio para "VENDIDOS" */
.col-acciones {
    width: 120px;
    text-align: center;
}

/* Espacio para "ACCIONES" */

/* =========================================
   7. BOTÓN FLOTANTE PARA EDITAR FOTO EN TABLA
========================================= */
.img-container-inline {
    position: relative;
    display: inline-block;
    width: 45px;
    height: 45px;
}

.img-container-inline img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: filter 0.3s;
}

.btn-edit-img {
    position: absolute;
    bottom: -8px;
    right: -8px;
    background: var(--accent-cyan);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.7rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, background 0.2s;
    z-index: 10;
}

.btn-edit-img:hover {
    transform: scale(1.2);
    background: #0096b5;
}

.img-loading {
    filter: grayscale(100%) opacity(0.5);
}

/* =========================================
   8. PUNTO DE VENTA (POS) - RESPONSIVO PERFECTO
========================================= */
.pos-container {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(320px, 1fr);
    gap: 2rem;
    align-items: start;
}

.pos-scanner-side {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Separación perfecta entre buscador y escáner */
}

/* Búsqueda manual */
.pos-manual-search {
    position: relative;
    width: 100%;
}

.pos-manual-search input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.pos-manual-search input:focus {
    border-color: var(--accent-cyan);
}

.pos-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--surface-color);
    z-index: 20;
    border-radius: 12px;
    max-height: 480px;
    /* ← de 250px a 480px */
    overflow-y: auto;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    display: none;
    border: 1px solid var(--border-color);
    margin-top: 5px;
}


.pos-search-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: 0.2s;
}

.pos-search-item:hover {
    background: rgba(0, 180, 216, 0.1);
}

/* Contenedor de la Cámara */
.pos-reader {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--accent-cyan) !important;
    background: #000;
}

/* Forzar que el video de la cámara no se desborde */
.pos-reader video {
    width: 100% !important;
    max-height: 45vh;
    /* En PC no ocupará toda la pantalla */
    object-fit: cover;
}

/* Lado del Ticket */
.pos-ticket-side {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    min-height: 450px;
    position: sticky;
    top: 20px;
}

.pos-cart-items {
    max-height: none !important;
    /* Quita el límite de altura para que crezca infinito */
    overflow-y: visible !important;
    /* Quita la barra de scroll */
    min-height: 150px;
}


.empty-cart-msg {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 3rem;
    font-style: italic;
}

.pos-cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    background: var(--bg-color);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.pos-item-info h4 {
    font-size: 0.9rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.pos-item-info p {
    color: var(--accent-cyan);
    font-weight: bold;
    font-size: 0.95rem;
}

.pos-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pos-qty-btn {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.pos-qty-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.pos-totals {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.pos-total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.grand-total {
    font-size: 1.6rem;
    font-weight: 900;
    color: #25D366;
    margin-top: 10px;
    border-top: 1px dashed var(--border-color);
    padding-top: 10px;
}

.btn-pos-checkout {
    background: linear-gradient(135deg, #25D366, #1ebe57);
    color: white;
    border: none;
    padding: 1.2rem;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    transition: 0.3s;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.btn-pos-checkout:disabled {
    background: var(--bg-color);
    color: var(--text-secondary);
    cursor: not-allowed;
    border: 1px solid var(--border-color);
}

.btn-pos-checkout:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 211, 102, 0.3);
}

/* --- MEDIA QUERIES PARA CELULARES Y TABLETS --- */
@media (max-width: 950px) {
    .pos-container {
        grid-template-columns: 1fr;
        /* Pila vertical en pantallas pequeñas */
    }

    .pos-ticket-side {
        position: static;
        /* Quita el sticky en móvil */
        height: auto;
        max-height: none;
        /* <-- ELIMINAMOS EL LÍMITE QUE APLASTABA TUS PRODUCTOS */
    }

    .pos-cart-items {
        max-height: none !important;
        /* Quita el límite de altura para que crezca infinito */
        overflow-y: visible !important;
        /* Quita la barra de scroll */
        min-height: 150px;
    }

    .pos-reader video {
        max-height: 35vh;
        /* Cámara más compacta en celular */
    }
}

/* Controles de Cámara POS */
.pos-camera-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.btn-cam-control {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.3s;
    font-size: 0.9rem;
}

.btn-cam-control:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

/* Estado Activo (Cámara Encendida - Botón Rojo para Apagar) */
.btn-cam-control.active {
    background: rgba(255, 68, 68, 0.1);
    color: #FF4444;
    border-color: #FF4444;
}

.btn-cam-control.active:hover {
    background: #FF4444;
    color: white;
}

/* =========================================
   9. ESTILOS TABLA DE CLIENTES
========================================= */
#clientsTable {
    min-width: 1600px;
    /* Ancho suficiente para que no se aplaste */
}

.col-cliente-nombre {
    width: 220px;
    line-height: 1.4;
}

.col-cliente-taller {
    width: 200px;
    line-height: 1.4;
}

.col-cliente-dir {
    width: 280px;
    line-height: 1.4;
}

.col-cliente-tel {
    width: 140px;
}

.col-cliente-cod {
    width: 160px;
    font-weight: bold;
    color: var(--accent-cyan);
}

.col-cliente-desc {
    width: 120px;
    text-align: center;
}

.col-cliente-fecha {
    width: 140px;
    text-align: center;
}

.pos-discount-section {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.pos-discount-section input {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-primary);
    outline: none;
}

.pos-discount-section button {
    padding: 10px 15px;
    background: var(--text-secondary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}

.pos-discount-section button:hover {
    background: var(--accent-cyan);
}

/* =========================================
   10. MEJORAS MODAL CLIENTES Y VISOR
========================================= */
#clientImagePreview {
    height: 240px;
    /* Hace la foto del cliente mucho más grande que la de productos */
    cursor: zoom-in;
    /* Cursor de lupa */
    transition: var(--transition);
}

#clientImagePreview:hover {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 15px rgba(0, 180, 216, 0.2);
}

/* =========================================
   11. ESTILOS NATIVOS DIALOG (VISOR FOTOS)
========================================= */
.lightbox-dialog {
    border: none;
    background: transparent;
    padding: 0;
    margin: auto;
    overflow: visible;
    cursor: zoom-out;
    outline: none;
}

/* El backdrop nativo oscurece el fondo automáticamente */
.lightbox-dialog::backdrop {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.lightbox-dialog img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    object-fit: contain;
    display: block;
}

/* =========================================
   TICKET DE VENTA - ALTURA INFINITA (PC Y MÓVIL)
========================================= */
.pos-ticket-side {
    height: auto !important;
    max-height: none !important;
}

.pos-cart-items {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
    flex: none !important;
    /* Esta es la clave: obliga a la caja a empujar lo de abajo en lugar de encimarse */
    padding-bottom: 15px;
}

/* =========================================
   1. ESTILOS GLOBALES PARA CHECKBOX (PC Y MÓVIL)
========================================= */
.col-select,
.col-select-client {
    width: 40px !important;
    max-width: 40px !important;
    text-align: center;
    padding-left: 10px !important;
    padding-right: 10px !important;
}

.col-select input[type="checkbox"],
.col-select-client input[type="checkbox"] {
    transform: scale(1.3);
    cursor: pointer;
    accent-color: var(--accent-cyan);
}

.col-select-ticket {
    width: 40px !important;
    max-width: 40px !important;
    text-align: center;
    padding-left: 10px !important;
    padding-right: 10px !important;
}

.col-select-ticket input[type="checkbox"] {
    transform: scale(1.3);
    cursor: pointer;
    accent-color: var(--accent-cyan);
}

.col-acciones-ticket {
    width: 110px !important;
    text-align: center;
}



/* =========================================
   2. TABLAS RESPONSIVAS (SOLO PARA CELULARES)
========================================= */
@media (max-width: 768px) {

    /* --- INVENTARIO MÓVIL --- */
    .inventory-table {
        min-width: 100% !important;
        table-layout: auto !important;
    }

    /* Ocultamos todas las columnas por defecto */
    .inventory-table th,
    .inventory-table td {
        display: none !important;
    }

    /* Mostramos solo: Checkbox, Acciones, Foto, Nombre, Descripción, Stock */
    .inventory-table th.col-select,
    .inventory-table td.col-select,
    .inventory-table th.col-acciones,
    .inventory-table td.col-acciones,
    .inventory-table th.col-foto,
    .inventory-table td.col-foto,
    .inventory-table th.col-nombre,
    .inventory-table td.col-nombre,
    .inventory-table th.col-descripcion,
    .inventory-table td.col-descripcion,
    .inventory-table th.col-stock,
    .inventory-table td.col-stock {
        display: table-cell !important;
    }



    /* Opcional: Ajustar el ancho para que no rompa el diseño en móvil */
    .col-vendidos {
        width: 60px !important;
        text-align: center !important;
        font-size: 0.85rem;
    }


    /* Ajustes de tamaño Inventario */
    .col-acciones {
        width: 80px !important;
        white-space: nowrap;
    }

    .col-foto {
        width: 60px !important;
    }

    .col-nombre {
        width: auto !important;
        font-size: 0.85rem;
    }

    .col-stock {
        width: 50px !important;
        text-align: center !important;
        font-size: 0.85rem;
    }


    /* --- CLIENTES MÓVIL --- */
    #clientsTable {
        min-width: 100% !important;
        table-layout: auto !important;
    }

    /* Ocultamos todas las columnas por defecto */
    #clientsTable th,
    #clientsTable td {
        display: none !important;
    }

    /* Mostramos solo: Checkbox, Acciones, Foto, Nombre, Código */
    #clientsTable th.col-select-client,
    #clientsTable td.col-select-client,
    #clientsTable th.col-acciones,
    #clientsTable td.col-acciones,
    #clientsTable th.col-foto,
    #clientsTable td.col-foto,
    #clientsTable th.col-cliente-nombre,
    #clientsTable td.col-cliente-nombre,
    #clientsTable th.col-cliente-cod,
    #clientsTable td.col-cliente-cod {
        display: table-cell !important;
    }

    /* Ajustes de tamaño Clientes */
    #clientsTable .col-cliente-nombre {
        width: auto !important;
        font-size: 0.85rem;
    }

    #clientsTable .col-cliente-cod {
        width: auto !important;
        font-size: 0.85rem;
        text-align: center;
    }

    /* --- TICKETS / HISTORIAL MÓVIL --- */
    #historyTable {
        min-width: 100% !important;
        /* Esto arregla el error de que desaparezca */
        table-layout: auto !important;
    }

    #historyTable th,
    #historyTable td {
        display: none !important;
    }

    /* Mostramos solo: Checkbox, Acciones, Ticket, Ganancia */
    #historyTable th.col-select-ticket,
    #historyTable td.col-select-ticket,
    #historyTable th.col-acciones-ticket,
    #historyTable td.col-acciones-ticket,
    #historyTable th.col-hist-ticket,
    #historyTable td.col-hist-ticket,
    #historyTable th.col-hist-ganancia,
    #historyTable td.col-hist-ganancia {
        display: table-cell !important;
    }

    #historyTable .col-hist-ticket {
        font-size: 0.85rem;
        white-space: normal !important;
    }

    #historyTable .col-hist-ganancia {
        font-size: 0.9rem;
        text-align: right;
    }
}

/* =========================================
   DISEÑO DE SIDEBAR COLAPSABLE
========================================= */
.sidebar {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    overflow-x: hidden;
    /* Evita que el texto se salga al encogerse */
}

/* Estado Colapsado */
.sidebar.collapsed {
    width: 85px;
    /* Ancho reducido */
    padding: 2rem 15px;
}

/* Header del Sidebar (Logo + Botón) */
.sidebar-header-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.sidebar.collapsed .sidebar-header-toggle {
    justify-content: center;
    /* Centra el botón cuando está colapsado */
}

.brand-logo {
    margin: 0 !important;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.sidebar.collapsed .brand-logo {
    display: none;
    /* Oculta el logo al colapsar */
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-btn:hover {
    color: var(--accent-cyan);
    transform: scale(1.1);
}

/* Textos del Menú */
.menu-text {
    white-space: nowrap;
    transition: opacity 0.2s;
}

.sidebar.collapsed .menu-text {
    display: none;
    /* Oculta los textos */
}

/* Centrar los íconos cuando está colapsado */
.sidebar.collapsed ul li {
    justify-content: center;
    padding: 1rem 0;
}

.sidebar.collapsed ul li i {
    font-size: 1.3rem;
    /* Hace el ícono un poquito más grande */
    margin: 0;
}

/* Ajuste para el botón de la tienda */
.sidebar.collapsed a[href="index.html"] li {
    justify-content: center;
    padding: 1rem 0;
}

/* Ajustes para evitar errores en Celulares */
@media (max-width: 768px) {
    .sidebar.collapsed {
        width: 100%;
        padding: 1rem;
    }

    .toggle-btn {
        display: none;
        /* En celular ocultamos el botón porque el menú ya es horizontal */
    }

    .sidebar.collapsed .menu-text {
        display: inline;
    }
}

/* =========================================
   DISEÑO SIDEBAR COLAPSABLE (PC)
========================================= */
.sidebar {
    transition: width 0.3s ease, padding 0.3s ease;
    overflow-x: hidden;
}

.sidebar-header-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.brand-logo {
    margin: 0 !important;
    white-space: nowrap;
}

.menu-text {
    white-space: nowrap;
    transition: opacity 0.2s;
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}

.toggle-btn:hover {
    color: var(--accent-cyan);
    transform: scale(1.1);
}

/* Estado Colapsado PC */
.sidebar.collapsed {
    width: 85px !important;
    padding: 2rem 15px !important;
}

.sidebar.collapsed .sidebar-header-toggle {
    justify-content: center;
}

.sidebar.collapsed .brand-logo,
.sidebar.collapsed .menu-text,
.sidebar.collapsed .sidebar-divider,
.sidebar.collapsed .sidebar-welcome-box {
    display: none !important;
}


.sidebar.collapsed ul li {
    justify-content: center !important;
    padding: 1rem 0 !important;
    font-size: 0 !important;
    gap: 0 !important;
    /* ¡ESTA ES LA MAGIA! Elimina el espacio fantasma */
}

.sidebar.collapsed ul li i {
    font-size: 1.3rem !important;
    margin: 0;
}

.sidebar.collapsed a[href="index.html"] li {
    justify-content: center !important;
    padding: 1rem 0 !important;
}

.admin-mobile-header {
    display: none;
}

.admin-sidebar-overlay {
    display: none;
}

.show-on-mobile {
    display: none !important;
}

/* =========================================
   DISEÑO SIDEBAR DESLIZANTE (MÓVIL)
========================================= */
@media (max-width: 768px) {

    /* Header superior móvil */
    .admin-mobile-header {
        display: flex;
        background: var(--surface-color);
        padding: 15px 20px;
        align-items: center;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .mobile-toggle-btn {
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
    }

    /* Ocultar botón de PC y mostrar el de cerrar */
    .hide-on-mobile {
        display: none !important;
    }

    .show-on-mobile {
        display: block !important;
    }

    /* Convertir el sidebar en un cajón deslizante */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: -320px;
        /* Oculto a la izquierda */
        width: 280px !important;
        height: 100vh !important;
        z-index: 2001;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--surface-color);
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
        padding: 2rem 15px !important;
    }

    /* Clase activa para mostrarlo */
    .sidebar.mobile-active {
        left: 0 !important;
    }

    /* Forzar que los textos y el logo SIEMPRE se vean en móvil */
    .sidebar .brand-logo,
    .sidebar .menu-text,
    .sidebar .sidebar-divider {
        display: inline-block !important;
    }

    .sidebar ul li {
        justify-content: flex-start !important;
    }

    /* Fondo oscuro */
    .admin-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 2000;
        display: none;
        backdrop-filter: blur(3px);
    }

    .admin-sidebar-overlay.active {
        display: block;
    }
}

/* =========================================
   TABLAS COMPACTAS Y RESPONSIVAS (CORREGIDAS)
========================================= */
/* Arreglo para que los títulos de los modales se vean en Modo Claro */
/* Se aplica a modales normales, pero EXCLUYE a los modales grandes (.large-modal) */
.admin-modal-content:not(.large-modal) .modal-header h2 {
    color: var(--text-primary) !important;
}

/* Los modales grandes SIEMPRE tienen fondo oscuro, por lo que el título SIEMPRE debe ser blanco */
.admin-modal-content.large-modal .modal-header h2 {
    color: #ffffff !important;
}



/* AQUÍ ESTÁ LA MAGIA: Matamos los 2800px de la tabla original */
.inventory-table.compact-table {
    min-width: 100% !important;
    width: 100% !important;
    table-layout: auto !important;
}

.compact-table th,
.compact-table td {
    font-size: 0.85rem !important;
    padding: 8px 10px !important;
    /* Reducimos el relleno para juntarlas más */
    white-space: normal !important;
    word-wrap: break-word;
    vertical-align: middle;
    line-height: 1.3;
}

/* Evitar que la columna de acciones y estado se aplasten o se estiren de más */
.compact-table .col-acciones {
    width: 80px !important;
    white-space: nowrap !important;
    text-align: center;
}

/* Darle un buen ancho a los artículos para que bajen de línea bonito */
.col-mec-arts,
.col-ped-art {
    min-width: 150px;
    max-width: 250px;
}


@media (max-width: 768px) {

    #mecanicosTable,
    #pedidosTable {
        min-width: 100% !important;
    }

    #mecanicosTable th,
    #mecanicosTable td,
    #pedidosTable th,
    #pedidosTable td {
        display: none !important;
    }

    #mecanicosTable th.col-acciones,
    #mecanicosTable td.col-acciones,
    #mecanicosTable th:nth-child(2),
    #mecanicosTable td:nth-child(2),
    /* Estado */
    #mecanicosTable th.col-mec-nombre,
    #mecanicosTable td.col-mec-nombre,
    #mecanicosTable th.col-mec-total,
    #mecanicosTable td.col-mec-total {
        display: table-cell !important;
    }

    #pedidosTable th.col-acciones,
    #pedidosTable td.col-acciones,
    #pedidosTable th:nth-child(2),
    #pedidosTable td:nth-child(2),
    /* Status */
    #pedidosTable th.col-ped-art,
    #pedidosTable td.col-ped-art,
    #pedidosTable th.col-ped-rest,
    #pedidosTable td.col-ped-rest {
        display: table-cell !important;
    }
}


@media (max-width: 768px) {

    #mecanicosTable,
    #pedidosTable {
        min-width: 100% !important;
        table-layout: auto !important;
    }

    /* Ocultar todo por defecto en móvil */
    #mecanicosTable th,
    #mecanicosTable td,
    #pedidosTable th,
    #pedidosTable td {
        display: none !important;
    }

    /* MECÁNICOS: Mostrar solo Acciones, Nombre, Artículos y Total */
    #mecanicosTable th.col-acciones,
    #mecanicosTable td.col-acciones,
    #mecanicosTable th.col-mec-nombre,
    #mecanicosTable td.col-mec-nombre,
    #mecanicosTable th.col-mec-arts,
    #mecanicosTable td.col-mec-arts,
    #mecanicosTable th.col-mec-total,
    #mecanicosTable td.col-mec-total {
        display: table-cell !important;
    }

    /* PEDIDOS: Mostrar solo Acciones, Artículo, Cliente y Restante */
    #pedidosTable th.col-acciones,
    #pedidosTable td.col-acciones,
    #pedidosTable th.col-ped-art,
    #pedidosTable td.col-ped-art,
    #pedidosTable th.col-ped-cli,
    #pedidosTable td.col-ped-cli,
    #pedidosTable th.col-ped-rest,
    #pedidosTable td.col-ped-rest {
        display: table-cell !important;
    }
}

/* =========================================
   CORRECCIÓN DEL CONTENEDOR PRINCIPAL (ADMIN APP)
========================================= */
#adminApp {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100vh;
}

/* Adaptación para dispositivos móviles */
@media (max-width: 768px) {
    #adminApp {
        flex-direction: column;
    }
}

/* =========================================
   ESTILOS PARA MENSAJE DE BIENVENIDA (ADMIN)
========================================= */
.sidebar-welcome-box {
    padding: 0px 15px 15px 15px;
    /* Quitamos padding arriba para pegarlo al logo */
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
    line-height: 1.2;
}

.sidebar-welcome-box .welcome-text {
    color: var(--text-secondary);
    font-size: 0.75rem;
    /* Letra más pequeña y sutil */
}

.sidebar-welcome-box .welcome-name {
    color: var(--accent-cyan);
    font-size: 0.9rem;
    /* Nombre más proporcionado */
    word-break: break-word;
    /* Evita que nombres largos rompan el diseño */
}

/* En celulares ocultamos el del menú lateral porque ya está en la barra superior */
@media (max-width: 768px) {
    .sidebar-welcome-box {
        display: none !important;
    }
}

/* =========================================
   JUNTAR BOTONES INFERIORES DEL MENÚ LATERAL
========================================= */

/* 1. Si los botones están dentro de un contenedor (div o ul) al final del menú */
.sidebar .sidebar-bottom,
.sidebar .sidebar-footer,
.sidebar>ul:last-of-type,
.sidebar>div:last-child {
    display: flex;
    flex-direction: column;
    gap: 5px !important;
    /* Misma separación pequeña que el menú principal */
    justify-content: flex-end;
}

/* 2. Quitamos márgenes gigantes individuales a los botones */
#adminThemeToggle,
#btnLogoutAdmin,
#adminThemeToggle~li,
#btnLogoutAdmin~li,
.sidebar-bottom li,
.sidebar-bottom a {
    margin-top: 2px !important;
    margin-bottom: 2px !important;
}

/* 3. Aseguramos que solo el PRIMER elemento de los de abajo empuje el bloque, 
      dejando a los demás pegaditos a él */
.sidebar-bottom,
.sidebar-footer,
#adminThemeToggle {
    margin-top: auto !important;
}

/* --- ESTILOS DEL DASHBOARD INTELIGENTE --- */
.dashboard-actions input[type="date"],
.dashboard-actions input[type="month"] {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    outline: none;
}

/* Scrollbar personalizado para las tablas pequeñas del dashboard */
#dash-low-stock-body::-webkit-scrollbar,
#dash-investment-results::-webkit-scrollbar {
    width: 6px;
}

#dash-low-stock-body::-webkit-scrollbar-thumb,
#dash-investment-results::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
}

.recommendation-item {
    background: rgba(40, 167, 69, 0.1);
    border-left: 3px solid #28a745;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 4px;
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr !important;
    }
}

/* CORRECCIÓN: Espaciado del menú lateral (Logo y Bienvenido) */
.sidebar-header-toggle {
    margin-bottom: 5px !important;
    padding-bottom: 0 !important;
}

.brand-logo {
    margin-bottom: 5px !important;
}

.sidebar-welcome-box {
    margin-top: 0 !important;
    padding-top: 5px !important;
}

/* =======================================================
   CORRECCIÓN RESPONSIVA PARA MÓVILES (DASHBOARD)
======================================================= */

@media (max-width: 768px) {

    /* 1. CORRECCIÓN DE BORDES: Igualamos el padding al 5% de la tienda principal */
    main.dashboard,
    .dashboard {
        margin-left: 0 !important;
        padding: 20px 5% !important;
        /* <--- MAGIA: 5% de espacio a los lados */
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Ajustar la sección principal para que no desborde */
    .admin-section {
        padding: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* =========================================
       2. CORRECCIÓN: ESPACIOTE FEO EN LOS FILTROS
    ========================================= */
    /* Sobrescribimos el estilo en línea del HTML que empuja todo a la derecha */
    #dashboard-section header,
    .admin-section header {
        flex-direction: column !important;
        align-items: stretch !important;
        /* Estira el contenido para llenar el hueco */
        width: 100% !important;
        gap: 15px !important;
    }

    /* Hacemos que la caja de acciones/filtros ocupe el 100% del ancho */
    .dashboard-actions {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 12px !important;
    }

    /* Aseguramos que los inputs de fecha (MES, DESDE, HASTA) ocupen todo el ancho */
    .dashboard-actions label,
    .dashboard-actions input,
    .dashboard-actions select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        text-align: left !important;
    }

    /* Hacemos que los botones se repartan el espacio equitativamente */
    .dashboard-actions button {
        flex: 1 !important;
        width: auto !important;
        padding: 12px 10px !important;
        /* Botones más fáciles de tocar en móvil */
        font-size: 0.9rem !important;
    }

    /* 3. Ajustar el contenedor gris del Dashboard */
    #dashboard-pdf-content {
        padding: 15px 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    /* 4. Forzar que las tarjetas y gráficas se acomoden en 1 sola columna */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 15px !important;
    }

    /* Asegurar que ninguna tarjeta se salga de la pantalla y tengan espacio entre ellas */
    .kpi-card,
    .chart-box,
    .chart-container,
    .metrics-panel,
    .inventory-alerts,
    .investment-calculator {
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 20px !important;
        /* 🚨 CAMBIO: Forzamos una separación de 20px hacia abajo */
        overflow: hidden !important;
    }


    /* 1. Mantiene el Label arriba y el Input abajo sin espacios feos */
    .dashboard-actions>div {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    /* 2. Solo los botones se ponen en fila horizontal */
    .dashboard-actions>div:last-child {
        flex-direction: row !important;
        justify-content: space-between !important;
        gap: 10px !important;
        margin-top: 5px;
    }

    .dashboard-actions>div:last-child button {
        flex: 1 !important;
        padding: 12px 0 !important;
        justify-content: center;
    }
}

/* <--- AQUÍ CIERRA EL @media (max-width: 768px) DE LOS MÓVILES */

/* Ajuste extra para pantallas de celulares muy pequeños (ej. iPhone SE) */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr !important;
        /* 1 cuadrito por fila para que se vea más grande */
    }

    .dashboard-actions {
        flex-direction: column;
        width: 100%;
    }

    .dashboard-actions input,
    .dashboard-actions button {
        width: 100% !important;
    }
}

/* =========================================
   CORRECCIÓN: FILTROS ADAPTABLES (LIGHT/DARK)
========================================= */
@media (max-width: 768px) {
    .dashboard-actions {
        background: var(--surface-color) !important;
        /* Blanco en Light, Oscuro en Dark */
        padding: 15px !important;
        border-radius: 12px !important;
        border: 1px solid var(--border-color) !important;
    }
}

/* =========================================
   TARJETAS KPI (DISEÑO PREMIUM ORIGINAL)
========================================= */
.kpi-card {
    background-color: var(--surface-color) !important;
    /* Adaptable al tema */
    border: 1px solid var(--border-color) !important;
    border-top-width: 4px !important;
    border-top-style: solid !important;
    border-radius: 12px !important;
    padding: 20px !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05) !important;
    color: var(--text-primary) !important;
    background-image: none !important;
    /* Limpiamos fondos forzados anteriores */
}

.kpi-card {
    text-align: center !important;
}

.kpi-card h3 {
    color: var(--text-secondary) !important;
    font-size: 0.9rem !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center !important;
}

.kpi-card h2 {
    text-align: center !important;
}

.kpi-card span {
    text-align: center !important;
    justify-content: center !important;
}


/* -----------------------------------------
   COLORES ESPECÍFICOS PARA CADA TARJETA
   (Línea superior + Resplandor en Modo Oscuro)
----------------------------------------- */

/* Tarjeta 1: Costo Inventario (Amarillo) */
.kpi-card:nth-child(1) {
    border-top-color: #ffc107 !important;
}

[data-theme="dark"] .kpi-card:nth-child(1) {
    background: linear-gradient(180deg, rgba(255, 193, 7, 0.15) 0%, var(--surface-color) 60%) !important;
}

/* Tarjeta 2: Venta Total (Cyan) */
.kpi-card:nth-child(2) {
    border-top-color: #00b4d8 !important;
}

[data-theme="dark"] .kpi-card:nth-child(2) {
    background: linear-gradient(180deg, rgba(0, 180, 216, 0.15) 0%, var(--surface-color) 60%) !important;
}

/* Tarjeta 3: Ganancia Neta (Verde) */
.kpi-card:nth-child(3) {
    border-top-color: #28a745 !important;
}

[data-theme="dark"] .kpi-card:nth-child(3) {
    background: linear-gradient(180deg, rgba(40, 167, 69, 0.15) 0%, var(--surface-color) 60%) !important;
}

/* Tarjeta 4: Tickets Generados (Azul) */
.kpi-card:nth-child(4) {
    border-top-color: #17a2b8 !important;
}

[data-theme="dark"] .kpi-card:nth-child(4) {
    background: linear-gradient(180deg, rgba(23, 162, 184, 0.15) 0%, var(--surface-color) 60%) !important;
}

/* Tarjeta 5: Ticket Promedio (Morado) */
.kpi-card:nth-child(5) {
    border-top-color: #6f42c1 !important;
}

[data-theme="dark"] .kpi-card:nth-child(5) {
    background: linear-gradient(180deg, rgba(111, 66, 193, 0.15) 0%, var(--surface-color) 60%) !important;
}


/* ==========================================================
   MODIFICACIÓN: MOSTRAR TODAS LAS COLUMNAS EN MÓVIL
   Fuerza a mostrar todas las celdas y habilita el scroll 
   horizontal para evitar que la información se aplaste.
========================================================== */
@media (max-width: 768px) {

    /* 1. Forzar la visualización de TODAS las columnas en todas las tablas */
    .inventory-table th,
    .inventory-table td,
    #clientsTable th,
    #clientsTable td,
    #historyTable th,
    #historyTable td,
    #mecanicosTable th,
    #mecanicosTable td,
    #pedidosTable th,
    #pedidosTable td {
        display: table-cell !important;
    }

    /* 2. Dar un ancho mínimo para que las columnas respeten su tamaño original.
          El contenedor (.table-responsive) creará el scroll horizontal automáticamente. */
    .inventory-table,
    #clientsTable,
    #historyTable,
    #mecanicosTable,
    #pedidosTable {
        min-width: 1000px !important;
        width: max-content !important;
        table-layout: auto !important;
    }

    /* 3. Ajuste opcional para que los textos largos no desborden feo */
    th,
    td {
        white-space: nowrap !important;
    }

    /* Permitimos que las columnas de descripción o nombres largos bajen de línea si es necesario */
    .col-mec-arts,
    .col-ped-art,
    .col-nombre,
    .col-cliente-nombre {
        white-space: normal !important;
        min-width: 200px !important;
    }
}

/* ==========================================================
   CORRECCIÓN: ALINEACIÓN DE TARJETAS EN FINANZAS (MÓVIL)
   Evita que el padding sume ancho extra y rompa el margen derecho
========================================================== */
@media (max-width: 768px) {

    /* Cambiamos el grid a flexbox en columna para mayor control en móvil */
    .dashboard-grid {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        box-sizing: border-box !important;
        gap: 15px !important;
        overflow: hidden !important;
    }

    /* Aplicamos box-sizing a TODAS las tarjetas dentro del dashboard-grid */
    .dashboard-grid>div {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        /* <--- Esto evita que se salgan a la derecha */
        margin: 0 !important;
    }

    /* Evitamos que los textos largos o inputs dentro de las tarjetas rompan el diseño */
    .dashboard-grid>div * {
        box-sizing: border-box !important;
        max-width: 100% !important;
    }
}

/* =========================================
   CORRECCIÓN: TABLAS PEQUEÑAS (STOCK CRÍTICO)
========================================= */
/* Forzamos a la cabecera a usar el tema dinámico y le damos estilo premium */
.chart-box table th,
.dashboard-grid table th {
    background: rgba(0, 180, 216, 0.05) !important;
    color: var(--accent-cyan) !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    font-size: 0.8rem !important;
    letter-spacing: 1px !important;
    border-bottom: 1px solid var(--border-color) !important;
    padding: 12px 8px !important;
}

/* Forzamos a las celdas a ser transparentes para que tomen el color de la tarjeta */
.chart-box table td,
.dashboard-grid table td {
    background-color: transparent !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}

/* Quitamos el fondo blanco de cualquier fila rebelde */
.chart-box table tr,
.dashboard-grid table tr {
    background-color: transparent !important;
}


/* =========================================
   CORRECCIÓN: ETIQUETAS DE LA GRÁFICA CORTADAS
========================================= */
.chart-box,
.chart-container {
    padding-bottom: 25px !important;
    /* Le da un "colchón" de espacio en la parte de abajo */
    overflow: visible !important;
    /* Quita el efecto guillotina que mutila los textos */
}

/* Asegurar que el lienzo de la gráfica no se pegue al piso de la tarjeta */
.chart-box canvas,
.chart-container canvas {
    display: block !important;
    margin-bottom: 10px !important;
}

/* =========================================================
   FIFO — Estilos generales
   ========================================================= */

/* Animación modal FIFO */
@keyframes fadeInFIFO {
    from {
        opacity: 0;
        transform: scale(0.96);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Columna Stock Inicial — informativa */
.col-stock-inicial {
    min-width: 75px;
    text-align: center;
    font-style: italic;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* Filas con stock crítico */
.row-sin-stock {
    background: rgba(231, 76, 60, 0.07) !important;
}

.row-sin-stock td {
    opacity: 0.85;
}

.row-stock-bajo {
    background: rgba(243, 156, 18, 0.05) !important;
}

/* Scroll horizontal tabla inventario */
.table-responsive,
.inventory-table-wrapper,
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-cyan, #00c8ff) transparent;
}

.table-responsive::-webkit-scrollbar,
.inventory-table-wrapper::-webkit-scrollbar {
    height: 5px;
}

.table-responsive::-webkit-scrollbar-thumb,
.inventory-table-wrapper::-webkit-scrollbar-thumb {
    background: var(--accent-cyan, #00c8ff);
    border-radius: 3px;
}

/* Responsive móvil */
@media screen and (max-width: 768px) {

    .col-stock-inicial,
    .col-descripcion,
    .col-compatibilidad,
    .col-barcode {
        display: none !important;
    }
}

/* =========================================
   STOCK CRÍTICO — COLUMNA DESCRIPCIÓN MÓVIL
========================================= */
@media (max-width: 768px) {

    #dash-low-stock-body td:first-child {
        max-width: 140px !important;
        width: 140px !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        line-height: 1.3;
    }

    /* table-layout: fixed para que respete el ancho */
    #dash-low-stock-body~*,
    #dash-low-stock-body {
        word-break: break-word;
    }

    /* Aplicar al table padre */
    .dashboard-grid table {
        table-layout: fixed !important;
        width: 100% !important;
    }
}


/* =========================================
   POS SEARCH — Highlight de términos buscados
========================================= */
.pos-highlight {
    background: rgba(0, 180, 216, 0.25);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
    font-weight: inherit;
}

/* =========================================
   NOTAS & PENDIENTES — Responsivo (móvil/tablet)
   Los estilos inline no responden a media queries por sí solos,
   por eso usamos !important para poder adaptarlos en pantallas chicas.
========================================= */
/* El modal de Nota puede crecer mucho: garantizamos scroll interno
   siempre, para que en celulares nunca se corte fuera de pantalla. */
#modalNota .admin-modal-content {
    max-height: 92vh;
    overflow-y: auto;
}

/* Tablet: el grid de campos del modal pasa de 3 a 2 columnas. */
@media (max-width: 820px) {
    .nota-campos-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* Celular: modal más compacto y todo en 1 columna. */
@media (max-width: 560px) {
    #modalNota .admin-modal-content {
        padding: 1.25rem !important;
    }

    .nota-campos-grid {
        grid-template-columns: 1fr !important;
    }
}

/* =========================================
   ANTI-CORTE GLOBAL — nada se sale de la pantalla
   El tablero de notas usa minmax(300px,...) inline; en celulares
   angostos (≤340px) eso desbordaba. Lo forzamos a 1 columna.
========================================= */
@media (max-width: 640px) {
    #notasBoard {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
}

/* Blindaje universal: ningún elemento puede provocar scroll horizontal
   ni imágenes que se salgan de su contenedor en pantallas chicas. */
@media (max-width: 768px) {

    html,
    body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    .admin-content,
    .admin-section {
        max-width: 100% !important;
        overflow-x: hidden;
    }

    /* Las imágenes (previews de notas/productos) nunca desbordan. */
    #notaImagenesPreview img,
    .admin-modal-content img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Tablas con muchas columnas: scroll propio en su contenedor,
       para que el resto de la página no se corte. */
    .table-container,
    .admin-table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}
