/* ==================== RESET Y BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    padding: 20px;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* ==================== HEADER ==================== */
.header {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.header h1 {
    color: #667eea;
    font-size: 32px;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 16px;
}

/* ==================== STATS GRID ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

.stat-card.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.stat-card.palet {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.stat-card.paqueteria {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.stat-card.pendientes {
    background: linear-gradient(135deg, #bdc3c7 0%, #2c3e50 100%);
    color: white;
}

.stat-label {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    opacity: 0.9;
}

.stat-number {
    font-size: 48px;
    font-weight: 700;
    margin: 10px 0;
}

.stat-sublabel {
    font-size: 14px;
    opacity: 0.8;
}

/* ==================== CONTENT SECTION ==================== */
.content-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.section-title {
    font-size: 24px;
    margin-bottom: 20px;
    font-weight: 700;
    padding-bottom: 15px;
    border-bottom: 3px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.palet-title {
    color: #f5576c;
}

.paqueteria-title {
    color: #00f2fe;
}

.pendientes-title {
    color: #2c3e50;
}

/* ==================== TIENDAS LIST ==================== */
.tienda-list {
    display: grid;
    gap: 10px;
}

.tienda-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.tienda-item:hover {
    background: #e9ecef;
}

.tienda-name {
    font-weight: 600;
    color: #333;
}

.tienda-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
    color: white;
}

.palet-badge {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.paqueteria-badge {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.pendientes-badge {
    background: linear-gradient(135deg, #bdc3c7 0%, #2c3e50 100%);
}

.no-data {
    text-align: center;
    color: #999;
    padding: 30px 0;
    font-style: italic;
}

.no-data-large {
    text-align: center;
    padding: 60px 20px;
}

.no-data-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.no-data-large h3 {
    color: #667eea;
    font-size: 24px;
    margin-bottom: 10px;
}

.no-data-large p {
    color: #999;
    font-size: 16px;
}

/* ==================== TOM SELECT (buscador de tienda) ==================== */
.filter-item .ts-wrapper {
    width: 100%;
}
.filter-item .ts-control {
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    box-shadow: none;
    min-height: 44px;
    transition: border-color 0.3s ease;
}
.filter-item .ts-control:focus-within,
.filter-item .ts-wrapper.focus .ts-control {
    outline: none;
    border-color: #667eea;
    box-shadow: none;
}
.filter-item .ts-control input {
    padding: 0;
    border: none;
    font-size: 14px;
    color: #333;
}
.filter-item .ts-control input:focus {
    outline: none;
    border: none;
}
.filter-item .ts-dropdown {
    border: 2px solid #667eea;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.15);
    font-size: 14px;
    margin-top: 2px;
}
.filter-item .ts-dropdown .option {
    padding: 10px 15px;
    color: #333;
}
.filter-item .ts-dropdown .option:hover,
.filter-item .ts-dropdown .option.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.filter-item .ts-dropdown .option.selected {
    background: #f0f0ff;
    color: #667eea;
    font-weight: 600;
}
.filter-item .ts-wrapper .clear-button {
    color: #999;
    font-size: 16px;
}

/* ==================== FILTERS ==================== */
.filters {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.filters h2 {
    color: #667eea;
    font-size: 24px;
    margin-bottom: 20px;
    font-weight: 700;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.filter-item {
    display: flex;
    flex-direction: column;
}

.filter-item label {
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    font-size: 14px;
}

.filter-item input,
.filter-item select {
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    background: white;
    color: #333;
}

.filter-item input:focus,
.filter-item select:focus {
    outline: none;
    border-color: #667eea;
}

.filter-buttons {
    display: flex;
    gap: 15px;
    justify-content: flex-start;
}

/* ==================== BUTTONS ==================== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.btn-info:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 12px;
}

/* ==================== TABLE ==================== */
.table-responsive {
    overflow-x: auto;
}

.pedidos-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.pedidos-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.pedidos-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
}

/* Columnas ordenables */
.pedidos-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
    position: relative;
}

.pedidos-table th.sortable:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6a4a9a 100%);
}

.pedidos-table th.sortable .sort-arrow {
    display: inline-block;
    margin-left: 5px;
    font-size: 12px;
    opacity: 0.5;
}

.pedidos-table th.sortable.sorted-asc,
.pedidos-table th.sortable.sorted-desc {
    background: linear-gradient(135deg, #5a67d8 0%, #6a4a9a 100%);
}

.pedidos-table th.sortable.sorted-asc .sort-arrow,
.pedidos-table th.sortable.sorted-desc .sort-arrow {
    opacity: 1;
    font-weight: 900;
}

.pedidos-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: background 0.3s ease;
}

.pedidos-table tbody tr:hover {
    background: #f8f9fa;
}

.pedidos-table td {
    padding: 15px;
    font-size: 14px;
    color: #333;
}

.pedido-numero {
    font-weight: 700;
    color: #667eea;
}

.fecha-limite {
    font-weight: 600;
    color: #f5576c;
}

/* ==================== PAGINATION ==================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #f0f0f0;
}

.pagination-link {
    padding: 10px 15px;
    background: #f0f0f0;
    color: #333;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

.pagination-link:hover {
    background: #667eea;
    color: white;
}

.pagination-info {
    padding: 10px 15px;
    font-weight: 600;
    color: #667eea;
}

/* ==================== DEBUG SECTION ==================== */
.debug-section {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
}

.debug-section h2 {
    color: #856404;
    margin-bottom: 20px;
    font-size: 24px;
}

.debug-section h3 {
    color: #856404;
    margin: 20px 0 15px 0;
    font-size: 18px;
}

.debug-summary {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.debug-summary table {
    width: 100%;
    border-collapse: collapse;
}

.debug-summary td {
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
}

.debug-query {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.debug-query-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.debug-time {
    background: #28a745;
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.debug-name {
    background: #007bff;
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.debug-query pre {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.debug-note {
    color: #856404;
    font-size: 14px;
    font-style: italic;
    margin-top: 20px;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 24px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .filter-grid {
        grid-template-columns: 1fr;
    }
    
    .filter-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        text-align: center;
    }
    
    .table-responsive {
        font-size: 12px;
    }
    
    .pedidos-table th,
    .pedidos-table td {
        padding: 10px 8px;
    }
    
    .pagination {
        flex-wrap: wrap;
    }
    
    .comprobador-input-group {
        flex-direction: column;
    }
}

/* ==================== COMPROBADOR DE PEDIDOS ==================== */
.comprobador-section {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.comprobador-section h2 {
    color: #667eea;
    font-size: 28px;
    margin-bottom: 10px;
    font-weight: 700;
}

.comprobador-subtitle {
    color: #666;
    font-size: 16px;
    margin-bottom: 25px;
}

.comprobador-input-group {
    display: flex;
    gap: 15px;
    max-width: 600px;
    margin: 0 auto 30px auto;
    justify-content: center;
    align-items: stretch;
}

.comprobador-input-group input {
    flex: 1;
    padding: 15px 20px;
    border: 3px solid #667eea;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    transition: all 0.3s ease;
}

.comprobador-input-group input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.comprobador-input-group button {
    padding: 15px 40px;
    font-size: 16px;
    white-space: nowrap;
}

.resultado-comprobador {
    margin-top: 30px;
    padding: 30px;
    border-radius: 15px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    animation: fadeIn 0.5s ease;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.resultado-comprobador .resultado-icon {
    font-size: 60px;
    margin-bottom: 20px;
    display: block;
}

.resultado-comprobador .resultado-titulo {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.resultado-comprobador .resultado-detalles {
    margin-top: 25px;
    padding-top: 25px;
    border-top: 3px solid rgba(255, 255, 255, 0.3);
    font-size: 16px;
    font-weight: 600;
}

.resultado-comprobador .resultado-detalles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
    text-align: left;
}

.resultado-comprobador .detalle-item {
    background: rgba(255, 255, 255, 0.2);
    padding: 12px 15px;
    border-radius: 8px;
}

.resultado-comprobador .detalle-label {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.resultado-comprobador .detalle-valor {
    font-size: 16px;
    font-weight: 700;
}

/* Estados del comprobador */
.resultado-no-existe {
    background: linear-gradient(135deg, #868f96 0%, #596164 100%); /* Gris medio — sin resultado */
    color: white;
}

.resultado-ya-asociado {
    background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%); /* Naranja/amarillo — ya procesado */
    color: #333;
    border: 5px solid #e08c00;
}

.resultado-no-listo {
    background: linear-gradient(135deg, #bdc3c7 0%, #2c3e50 100%);
    color: white;
}

.resultado-enviar-palet {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); /* Rosa — igual que tabla palet */
    color: white;
    border: 5px solid #e04462;
}

.resultado-enviar-paqueteria {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); /* Celeste — igual que tabla paquetería */
    color: white;
    border: 5px solid #3a8bc4;
}

.resultado-excluido {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%); /* Rojo — excluido/bloqueado */
    color: white;
}

.resultado-pendiente {
    background: linear-gradient(135deg, #bdc3c7 0%, #2c3e50 100%); /* Gris — igual que tabla pendientes */
    color: white;
}

.resultado-loading {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==================== BADGES DE ORIGEN ==================== */
.badge-origen {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
}

.badge-origen-oms {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.badge-origen-warehouse {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    color: #333;
}

.badge-origen-home {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    color: #1a5c3a;
}

.badge-origen-tramas {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: #5c2000;
}
/* ── Badges: Razón de envío ──────────────────────────────────────── */
.badge-razon {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.badge-razon-limite-palet {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
}

.badge-razon-limite-paqueteria {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
}

.badge-razon-proximo-palet {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    color: #5c2a00;
}

.badge-razon-pendiente {
    background: linear-gradient(135deg, #bdc3c7 0%, #2c3e50 100%);
    color: white;
}

.badge-razon-no-paqueteria {
    background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
    color: #4a2800;
}

/* ==================== BOTÓN EXPORTAR RESUMEN ==================== */
.btn-export-resumen {
    flex-shrink: 0;
    font-size: 12px;
    padding: 4px 12px;
    border: none;
    border-radius: 5px;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.btn-export-resumen:hover {
    opacity: 0.85;
}

/* ==================== FORMULARIO MATRÍCULA PALET ==================== */
.matricula-form {
    margin-top: 25px;
    padding: 20px 25px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    text-align: left;
}

.matricula-titulo {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 15px;
    color: white;
    text-align: center;
}

.matricula-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.matricula-input {
    flex: 1;
    min-width: 180px;
    max-width: 320px;
    padding: 12px 16px;
    font-size: 20px;
    font-weight: 700;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.matricula-input:focus {
    border-color: white;
    background: white;
}

.matricula-input:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn-asociar-matricula {
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    background: white;
    color: #e04462;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.btn-asociar-matricula:hover:not(:disabled) {
    opacity: 0.85;
}

.btn-asociar-matricula:disabled {
    opacity: 0.6;
    cursor: default;
}

.palet-delete-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: #e74c3c;
    color: white;
    cursor: pointer;
    font-weight: 700;
}

.palet-delete-btn:hover {
    opacity: 0.9;
}

.matricula-ok {
    margin-top: 14px;
    font-size: 16px;
    color: #155724;
    font-weight: 600;
    text-align: center;
    background: #d4edda;
    border: 1px solid #c3e6cb;
    padding: 14px 18px;
    border-radius: 12px;
}
.scan-ok-palet {
    margin-top: 14px;
    background: linear-gradient(135deg, #d4edda 0%, #b8f0c8 100%);
    border: 2.5px solid #28a745;
    border-radius: 16px;
    padding: 22px 24px;
    box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.15);
    color: #155724;
}
.scan-ok-palet .scan-ok-titulo {
    font-size: 22px;
    font-weight: 900;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.scan-ok-palet .resultado-detalles-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.scan-ok-palet .detalle-label { color: #155724; opacity: .75; }
.scan-ok-palet .detalle-valor { color: #155724; font-weight: 700; }
.matricula-error-prominent {
    margin-top: 14px;
    font-size: 18px;
    color: #5f2120;
    font-weight: 700;
    text-align: left;
    background: linear-gradient(135deg, #ffebee 0%, #ffdce0 100%);
    border: 2px solid #d32f2f;
    padding: 20px 22px;
    border-radius: 16px;
    box-shadow: 0 0 0 4px rgba(211, 47, 47, 0.15);
}

.matricula-error-prominent strong {
    color: #b71c1c;
}
.matricula-error {
    margin-top: 14px;
    font-size: 16px;
    color: #82191b;
    font-weight: 600;
    text-align: center;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 14px 18px;
    border-radius: 12px;
}