<?php Session::init(); if (Session::get('rol') == 1 OR Session::get('rol') == 2) { ?>
<?php
date_default_timezone_set($_SESSION["zona_horaria"]);
setlocale(LC_ALL,"es_ES@euro","es_ES","esp");
$fecha = date("d-m-Y");
$fechaa = date("m-Y");
?>
<input type="hidden" id="moneda" value="<?php echo Session::get('moneda'); ?>"/>

<style>
/* === VARIABLES CSS === */
:root {
    --primary-color: #5664d2;
    --success-color: #1bc943;
    --warning-color: #f4a100;
    --danger-color: #e74c3c;
    --info-color: #3498db;
    --dark-color: #2c3e50;
    --light-bg: #f8f9fa;
    --card-shadow: 0 2px 10px rgba(0,0,0,0.08);
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

/* === HEADER MEJORADO === */
.page-titles-modern {
    background: linear-gradient(135deg, var(--primary-color) 0%, #667eea 100%);
    padding: 1.5rem 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    color: white;
    box-shadow: var(--card-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-titles-modern h4 {
    color: white;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.breadcrumb-modern {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    display: inline-block;
    font-size: 0.9rem;
}

.breadcrumb-modern .breadcrumb-item, .breadcrumb-modern a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
}

.breadcrumb-modern .breadcrumb-item.active {
    color: white;
    font-weight: 500;
}

/* === BUTTON NEW === */
.btn-new-modern {
    background: linear-gradient(135deg, #f4a100 0%, #e67e22 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 0.8rem 2rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(244, 161, 0, 0.3);
    transition: var(--transition);
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
}

.btn-new-modern:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(244, 161, 0, 0.4);
    color: white;
}

/* === FILTERS CARD === */
.filters-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}

.form-group-modern label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.4rem;
    display: block;   
}

.input-group-modern {
    display: flex;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.input-group-modern .form-control {
    border: none;
    text-align: center;
}

.input-group-modern span {
    background: #f1f3f5;
    padding: 0.6rem 1rem;
    color: #666;
    font-size: 0.9rem;
    border-left: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
}

.form-control-modern {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    width: 100%;
}

/* === TABLE MODERN === */
.table-card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    border: 1px solid #f0f0f0;
}

.table-modern {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead th {
    background: #fff;
    color: #8898aa;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    padding: 1rem 1.5rem;
    letter-spacing: 1px;
    border-bottom: 1px solid #e9ecef;
}

.table-modern tbody td {
    padding: 1rem 1.5rem;
    vertical-align: middle;
    border-bottom: 1px solid #f6f9fc;
    font-size: 0.875rem;
    color: #525f7f;
}

.table-modern tbody tr:last-child td {
    border-bottom: none;
}

.table-modern tbody tr:hover td {
    background-color: #f6f9fc;
}

/* === MODAL MODERN === */
.modal-content-modern {
    border: none;
    border-radius: 15px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.2);
}

.modal-header-modern {
    background: linear-gradient(135deg, var(--primary-color) 0%, #667eea 100%);
    padding: 1.5rem;
    border-radius: 15px 15px 0 0;
    color: white;
}

.modal-body-modern {
    padding: 0;
}

.modal-footer-modern {
    padding: 1rem;
    border-top: 1px solid #f0f0f0;
}

.animate-in { animation: fadeInUp 0.6s ease; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
</style>

<!-- HEADER -->
<div class="page-titles-modern animate-in">
    <div>
        <h4><i class="fas fa-balance-scale mr-2"></i>Ajustes de Stock</h4>
        <div class="breadcrumb-modern">
            <span class="breadcrumb-item"><i class="fas fa-home mr-1"></i>Inventario</span>
            <span class="breadcrumb-item">/</span>
            <span class="breadcrumb-item active">Historial de Ajustes</span>
        </div>
    </div>
    
    <div>
        <a href="<?php echo URL; ?>inventario/nuevoajuste" class="btn-new-modern">
            <i class="fas fa-plus mr-2"></i>Nuevo Ajuste
        </a>
    </div>
</div>

<!-- FILTERS -->
<div class="filters-card animate-in">
    <form method="post" enctype="multipart/form-data" target="_blank" action="#">
        <div class="row">
            <div class="col-md-4">
                 <div class="form-group-modern">
                    <label><i class="far fa-calendar-alt mr-1"></i>Rango de Fechas</label>
                    <div class="input-group-modern">
                        <input type="text" class="form-control" name="start" id="start" value="<?php echo '01-'.$fechaa; ?>" autocomplete="off" placeholder="Inicio"/>
                        <span>al</span>
                        <input type="text" class="form-control" name="end" id="end" value="<?php echo $fecha; ?>" autocomplete="off" placeholder="Fin"/>
                    </div>
                </div>
            </div>
             <div class="col-md-8">
                <div class="form-group-modern">
                    <label><i class="fas fa-search mr-1"></i>Búsqueda</label>
                     <input type="text" class="form-control-modern global_filter" id="global_filter" placeholder="Buscar por responsable, concepto..." autocomplete="off">
                </div>
            </div>
        </div>
    </form>
</div>

<!-- TABLE -->
<div class="table-card animate-in">
    <div class="table-responsive">
        <table id="table" class="table table-modern" width="100%">
            <thead>
                <tr>
                    <th style="width:15%">Fecha</th>
                    <th style="width:20%">Tipo Operación</th>
                    <th style="width:20%">Responsable</th>
                    <th style="width:25%">Concepto</th>
                    <th style="width:10%" class="text-center">Estado</th>
                    <th style="width:10%" class="text-right">Acciones</th>
                </tr>
            </thead>
            <tbody class="tb-st"></tbody>
        </table>
    </div>
</div>

<!-- MODAL DETALLE -->
<div class="modal inmodal" id="modal-detalle" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="true">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content modal-content-modern">
            <div class="modal-header modal-header-modern">
                <h5 class="modal-title m-0" id="modal-detalle-titulo">Detalle del Ajuste</h5>
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cerrar</span></button>
            </div>
            <div class="modal-body modal-body-modern">
                <div class="table-responsive">
                    <table class="table table-modern table-sm mb-0" width="100%">
                        <thead class="bg-light">
                            <tr>
                                <th class="pl-4">Código</th>
                                <th>Categoría</th>
                                <th>Producto</th>
                                <th>Cantidad</th>
                                <th>Unidad de Medida</th>
                                <th class="text-right pr-4">Precio Costo</th>
                            </tr>
                        </thead>
                        <tbody class="tb-st" id="table-detalle"></tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer modal-footer-modern">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
            </div>
        </div>
    </div>
</div>
<?php } ?>