/* Base Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #1A365D;
    /* Azul Índigo Profundo */
    color: #F0F4F8;
    /* Blanco Hueso */
    font-family: 'Playfair Display', serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1,
h2,
h3,
h4,
h5,
h6,
button,
input,
select {
    font-family: 'Montserrat', sans-serif;
}

/* Efecto Glassmorphism */
/* Efecto Glassmorphism */
.glass-panel {
    background: rgba(255, 255, 255, 0.05);
    /* Cristal oscuro muy sutil */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 2px solid rgba(184, 115, 51, 0.7);
    /* Bordes cobre x2 de grosor y más opacidad */
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* UTILIDADES */
.hidden {
    display: none !important;
}

/* --- PANTALLA LOGIN --- */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background-color: #1A365D;
}

.login-panel {
    width: 90%;
    max-width: 400px;
    padding: 3rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.logo-img-login {
    width: 380px;
    /* Incrementado ~90% desde 200px */
    max-width: 90%;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 30px rgba(184, 115, 51, 1));
    /* Neón x3 (blur y opacidad) */
}

.subtitle {
    font-size: 1rem;
    color: rgba(240, 244, 248, 0.7);
    margin-bottom: 1rem;
}

.input-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

input,
select {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(184, 115, 51, 0.6);
    border-radius: 8px;
    color: #F0F4F8;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus,
select:focus {
    border-color: #B87333;
    box-shadow: 0 0 24px rgba(184, 115, 51, 1);
    /* Neón x3 (blur 8 -> 24 y opacidad 0.5 -> 1) */
    background: rgba(0, 0, 0, 0.3);
}

button {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #B87333 0%, #8c5525 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(184, 115, 51, 0.3);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(184, 115, 51, 0.5);
    background: linear-gradient(135deg, #c48245 0%, #9c602a 100%);
}

.error-msg {
    color: #ff6b6b;
    font-size: 0.9rem;
    font-family: 'Montserrat', sans-serif;
}

/* Spinner Tejiendo */
.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(184, 115, 51, 0.2);
    border-top-color: #B87333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}


/* --- DASHBOARD PRINCIPAL --- */
.dashboard {
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Header Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.logo-img-header {
    height: 72px;
    /* Incrementado ~90% desde 38px */
    width: auto;
    /* Neón Header x3 */
    filter: drop-shadow(0 0 15px rgba(184, 115, 51, 0.8));
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.last-sync {
    font-size: 0.85rem;
    color: rgba(240, 244, 248, 0.7);
}

@media (min-width: 768px) {
    .last-sync {
        font-size: 1.7rem;
        /* El doble de grande en desktop */
    }
}

.refresh-btn {
    width: auto;
    padding: 6px;
    background: transparent;
    border: 1px solid rgba(184, 115, 51, 0.4);
    box-shadow: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #B87333;
}

.refresh-btn:hover {
    background: rgba(184, 115, 51, 0.1);
    transform: rotate(30deg);
}

.refresh-btn.spinning {
    animation: spinReverse 1s linear infinite;
}

@keyframes spinReverse {
    100% {
        transform: rotate(-360deg);
    }
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}

.status-indicator.orange {
    background-color: #f39c12;
    color: #f39c12;
}

.status-indicator.green {
    background-color: #2ecc71;
    color: #2ecc71;
}

.status-indicator.red {
    background-color: #e74c3c;
    color: #e74c3c;
}


/* Filtros */
.filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .filters {
        grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
    }
}

.filter-group select,
.filter-group input {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(184, 115, 51, 0.6);
    color: #F0F4F8;
}

.filter-group.date-interval {
    display: flex;
    gap: 0.5rem;
}

.filter-group.date-interval input {
    flex: 1;
    /* Forzar color cobre y usar color scheme dark para el icono nativo de calendario */
    color: #B87333 !important;
    color-scheme: dark;
}

/* Color cobre para el texto interior (Chrome/Safari) */
.filter-group.date-interval input::-webkit-datetime-edit {
    color: #B87333;
}

.filter-group.date-interval input::-webkit-calendar-picker-indicator {
    filter: invert(53%) sepia(35%) saturate(884%) hue-rotate(345deg) brightness(96%) contrast(87%);
    /* Tono Cobre aprox */
    cursor: pointer;
}

.filter-group select option {
    background: #1A365D;
    color: #F0F4F8;
}

/* KPIs */
.kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .kpis {
        grid-template-columns: repeat(4, 1fr);
    }
}

.kpi-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Brillo muy sutil en hover original -> Ahora brillo neon x3 */
.kpi-card:hover::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(184, 115, 51, 0.3) 0%, transparent 70%);
    pointer-events: none;
}

/* Efecto Neón exterior a la tarjeta */
.kpi-card:hover {
    box-shadow: 0 0 24px rgba(184, 115, 51, 1);
    border-color: #B87333;
    transition: all 0.3s ease;
}

.kpi-card h3 {
    font-size: 0.9rem;
    color: rgba(240, 244, 248, 0.7);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: #B87333;
    font-family: 'Montserrat', sans-serif;
}

.kpi-card small {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.8rem;
    color: rgba(240, 244, 248, 0.6);
}

/* MAIN LAYOUT (Gráfico + Tabla) */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 2fr;
    }
}

.section-title {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    color: #F0F4F8;
    border-bottom: 1px solid rgba(184, 115, 51, 0.3);
    padding-bottom: 0.5rem;
}

/* Carta Gráfico */
.chart-container {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 350px;
}

.canvas-wrapper {
    flex-grow: 1;
    position: relative;
    width: 100%;
}

/* Carta Tabla */
.table-container {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.table-header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.table-header-controls .section-title {
    margin-bottom: 0;
    border: none;
    padding: 0;
}

.pagination-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
}

.pagination-selector select {
    width: auto;
    padding: 4px 8px;
}

/* Grid Tabla General */
.data-grid {
    width: 100%;
    margin-bottom: 1rem;
}

.grid-header {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr 1fr 1fr 1fr;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(184, 115, 51, 0.3);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85rem;
    color: rgba(240, 244, 248, 0.8);
    text-transform: uppercase;
}

.text-right {
    text-align: right;
}

.data-rows {
    max-height: 500px;
    overflow-y: auto;
    /* Custom Scrollbar minimalista */
    scrollbar-width: thin;
    scrollbar-color: rgba(184, 115, 51, 0.5) transparent;
}

.data-rows::-webkit-scrollbar {
    width: 6px;
}

.data-rows::-webkit-scrollbar-track {
    background: transparent;
}

.data-rows::-webkit-scrollbar-thumb {
    background-color: rgba(184, 115, 51, 0.5);
    border-radius: 10px;
}

/* Fila de Datos */
.grid-row {
    display: grid;
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s ease;
    cursor: pointer;
    gap: 0.5rem;
}

.grid-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.grid-row .col-monto {
    color: #B87333;
    font-weight: bold;
    font-family: 'Montserrat', sans-serif;
}

/* Contenido Expandible Móvil */
.mobile-details {
    display: none;
    grid-column: 1 / -1;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    color: rgba(240, 244, 248, 0.7);
}

.grid-row.expanded .mobile-details {
    display: block;
    animation: fadeIn 0.3s ease;
}

.mobile-details p {
    margin: 0.2rem 0;
}

/* Responsive Grid Rows */
@media (min-width: 768px) {
    .desktop-only {
        display: grid;
    }

    .grid-row {
        grid-template-columns: 1fr 1.5fr 1fr 1fr 1fr 1fr;
        align-items: center;
        cursor: default;
        /* En desktop no expande info principal */
    }

    .grid-row .col {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-details {
        /* En desktop, mostramos solo si hiciera falta IDs, etc. pero
           para mantener minimalismo, usaremos el grid en vez de collapse */
        display: none !important;
    }

    .grid-row.expanded .mobile-details {
        display: none !important;
    }
}

@media (max-width: 767px) {
    .desktop-only {
        display: none;
    }

    .grid-row {
        /* En móvil: layout tipo tarjeta/fila simplificada */
        grid-template-columns: 1.5fr 1fr;
        grid-auto-flow: row;
        font-size: 0.95rem;
    }

    .col-fecha {
        font-size: 0.8rem;
        color: rgba(240, 244, 248, 0.6);
        grid-column: 1 / -1;
    }

    .col-entidad {
        font-weight: bold;
    }

    .col-trabajador {
        font-size: 0.85rem;
        color: rgba(240, 244, 248, 0.7);
        grid-column: 1 / -1;
    }

    .col-monto {
        text-align: right;
        grid-column: 2;
        grid-row: 2;
        font-size: 1.1rem;
    }

    /* Ocultamos algunas cols básicas en la vista principal móvil */
    .col-categoria,
    .col-localizacion {
        display: none;
    }

    /* Al expandir, las cosas vuelven */
    .mobile-details .detail-item {
        display: flex;
        justify-content: space-between;
    }
}

.pagination-info {
    text-align: right;
    font-size: 0.85rem;
    color: rgba(240, 244, 248, 0.6);
}

/* --- OVERLAY BLOQUEO DE ROTACIÓN (Portrait Lock) --- */
#portrait-lock-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    background-color: rgba(26, 54, 93, 0.9);
    /* Azul Índigo al 90% */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    color: #F0F4F8;
    /* Blanco Hueso */
    font-family: 'Montserrat', sans-serif;
    gap: 1.5rem;
}

#portrait-lock-overlay p {
    font-size: 1.1rem;
    line-height: 1.5;
    text-shadow: 0 0 10px rgba(184, 115, 51, 0.5);
}

.phone-spin-icon {
    animation: rotatePhone 2.5s ease-in-out infinite;
    filter: drop-shadow(0 0 12px rgba(184, 115, 51, 0.8));
    color: #B87333;
}

@keyframes rotatePhone {
    0% {
        transform: rotate(0deg);
    }

    30% {
        transform: rotate(-90deg);
    }

    70% {
        transform: rotate(-90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

@media screen and (max-width: 850px) and (orientation: portrait) {
    #portrait-lock-overlay {
        display: flex;
    }

    /* Desenfoque del fondo cuando el overlay está activo */
    .login-screen,
    .dashboard {
        filter: blur(5px);
        pointer-events: none;
        overflow: hidden;
    }

    body {
        overflow: hidden;
    }
}