<?php Session::init(); if (Session::get('rol') == 1 OR Session::get('rol') == 2 OR Session::get('rol') == 3) { ?>
<?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;
}

/* === 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;   
}

.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;
}

.btn-action-modern {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.btn-action-modern:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.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-boxes mr-2"></i>Control de Stock</h4>
        <div class="breadcrumb-modern">
            <span class="breadcrumb-item"><i class="fas fa-home mr-1"></i>Inicio</span>
            <span class="breadcrumb-item">/</span>
            <span class="breadcrumb-item active">Stock Actual</span>
        </div>
    </div>
    
    <div class="btn-group">
        <button type="button" class="btn btn-action-modern dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <i class="fas fa-download mr-1"></i> Exportar
        </button>
        <div class="dropdown-menu dropdown-menu-right border-0 shadow-lg" style="border-radius: 12px; overflow: hidden; margin-top: 10px;">
            <a class="dropdown-item py-2" href="javascript:void();" id="excel"><i class="fas fa-file-excel mr-2 text-success"></i> Excel</a>
            <a class="dropdown-item py-2" href="javascript:void();" id="pdf"><i class="fas fa-file-pdf mr-2 text-danger"></i> PDF</a>
            <div class="dropdown-divider"></div>
            <a href="javascript:void();" id="downticket" class="dropdown-item py-2" title="Descargar Pdf"><i class="fas fa-file-alt mr-2 text-info"></i> Ticket</a>
        </div>
    </div>
</div>

<!-- FILTERS -->
<div class="filters-card animate-in">
    <div class="row align-items-end">
        <div class="col-md-3">
             <div class="form-group-modern">
                <label><i class="fas fa-filter mr-1"></i>Tipo de Item</label>
                <select class="selectpicker form-control" name="filtro_tipo_ins" id="filtro_tipo_ins" data-style="btn-white border" data-live-search="true" autocomplete="off" data-size="5">
                    <option value="%" active>Mostrar Todo</option>
                    <optgroup label="Tipos">
                        <option value="1">INSUMO</option>
                        <option value="2">PRODUCTO</option>
                    </optgroup>
                </select>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group-modern" style="padding-bottom: 5px;">
                  <div class="custom-control custom-checkbox">
                    <input type="checkbox" class="custom-control-input" id="filtro_stock_minimo" name="filtro_stock_minimo" value="%">
                    <label class="custom-control-label" for="filtro_stock_minimo">Ver solo items bajo stock mínimo</label>
                </div>
            </div>
        </div>
        <div class="col-md-5">
            <div class="form-group-modern">
                <label><i class="fas fa-search mr-1"></i>Búsqueda Rápida</label>
                <input type="text" class="form-control-modern global_filter" id="global_filter" placeholder="Buscar por código, nombre..." autocomplete="off">
            </div>
        </div>
    </div>
</div>

<!-- TABLE -->
<div class="table-card animate-in">
    <div class="table-responsive">
        <table id="table" class="table table-modern" width="100%">
            <thead>
                <tr>
                    <th>Tipo</th>
                    <th>Código</th>
                    <th>Categoría</th>
                    <th>Nombre</th>
                    <th>Unidad Medida</th>
                    <th class="text-right">Stock Mín.</th>
                    <th class="text-right">Stock Real</th>
                </tr>
            </thead>
            <tbody class="tb-st"></tbody>
        </table>
    </div>
</div>
<!-- Pusher JS (Required for Realtime Stock Updates) -->
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<?php } ?>