/* ========================================================= */
/* HISTORIAL - HUMIDI-TEC                                   */
/* IDENTIDAD BASADA EN VARIABLES GLOBALES                   */
/* ========================================================= */

.historial-page {
    width: 100%;
    max-width: 1160px;

    margin: 0 auto;

    color: var(--text-primary);
}


/* ========================================================= */
/* ENCABEZADO                                                */
/* ========================================================= */

.historial-header {
    margin-bottom: 22px;
}

.historial-label,
.historial-section-label {
    display: block;

    margin-bottom: 4px;

    color: var(--green-700);

    font-size: 10px;
    font-weight: 850;
    letter-spacing: 1.15px;
}

.historial-header h1 {
    margin: 0;

    color: var(--green-950);

    font-size: 30px;
    font-weight: 850;
    line-height: 1.15;
}

.historial-header p {
    margin: 6px 0 0;

    max-width: 760px;

    color: var(--text-secondary);

    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
}


/* ========================================================= */
/* RESUMEN GENERAL                                           */
/* ========================================================= */

.historial-overview {
    display: grid;

    grid-template-columns:
        minmax(0, 1.65fr)
        minmax(330px, 0.8fr);

    gap: 16px;

    margin-bottom: 28px;
}


/* ========================================================= */
/* TARJETAS DE RESUMEN                                       */
/* ========================================================= */

.overview-card {
    min-height: 156px;

    padding: 18px 20px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow-small);
}


/* ========================================================= */
/* ACTIVIDAD DE HOY                                          */
/* ========================================================= */

.overview-card.activity {
    border-top: 4px solid var(--green-700);
}

.overview-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 17px;
}

.overview-title {
    display: flex;
    align-items: center;

    gap: 12px;
}

.overview-icon {
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    color: #ffffff;
    background: var(--green-700);

    border-radius: 10px;
}

.overview-icon svg {
    width: 20px;
    height: 20px;
}

.overview-title > div:last-child {
    min-width: 0;

    display: flex;
    flex-direction: column;
}

.overview-title span {
    color: var(--green-700);

    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0.9px;
}

.overview-title strong {
    margin-top: 3px;

    color: var(--green-950);

    font-size: 17px;
    font-weight: 850;
}


/* ========================================================= */
/* ESTADÍSTICAS DEL DÍA                                      */
/* ========================================================= */

.overview-stats {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 10px;
}

.overview-stat {
    min-width: 0;
    min-height: 78px;

    display: flex;
    align-items: center;

    gap: 12px;

    padding: 12px 13px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 10px;

    box-shadow:
        0 2px 7px rgba(18, 72, 46, 0.04);
}

.overview-stat-value {
    min-width: 42px;

    font-size: 28px;
    font-weight: 900;
    line-height: 1;

    text-align: center;
}

.overview-stat > div {
    min-width: 0;

    display: flex;
    flex-direction: column;
}

.overview-stat strong {
    color: var(--text-primary);

    font-size: 12px;
    font-weight: 850;
}

.overview-stat small {
    margin-top: 3px;

    color: var(--text-secondary);

    font-size: 10px;
    font-weight: 650;
}


/* ========================================================= */
/* MEDICIONES                                                */
/* ========================================================= */

.overview-stat.measurement {
    border-left: 5px solid var(--blue-600);
}

.overview-stat.measurement
.overview-stat-value {
    color: var(--blue-600);
}


/* ========================================================= */
/* RIEGOS                                                    */
/* ========================================================= */

.overview-stat.irrigation {
    border-left: 5px solid var(--green-600);
}

.overview-stat.irrigation
.overview-stat-value {
    color: var(--green-700);
}


/* ========================================================= */
/* AVISOS                                                    */
/* ========================================================= */

.overview-stat.alert {
    border-left: 5px solid var(--teal-600);
}

.overview-stat.alert
.overview-stat-value {
    color: var(--teal-600);
}


/* ========================================================= */
/* ÚLTIMA ACTIVIDAD                                          */
/* ========================================================= */

.overview-card.latest {
    display: flex;
    flex-direction: column;
    justify-content: center;

    border-top: 4px solid var(--green-600);
}

.latest-header {
    display: flex;
    align-items: center;

    gap: 10px;

    margin-bottom: 13px;
}

.latest-header > span {
    color: var(--green-700);

    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0.9px;
}

.latest-icon {
    width: 38px;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    color: #ffffff;
    background: var(--green-600);

    border-radius: 9px;
}

.latest-icon svg {
    width: 18px;
    height: 18px;
}

.latest-content {
    display: flex;
    flex-direction: column;
}

.latest-content > strong {
    color: var(--green-950);

    font-size: 18px;
    font-weight: 850;
}

.latest-content p {
    margin: 5px 0 0;

    color: var(--text-primary);

    font-size: 13px;
    font-weight: 800;
    line-height: 1.4;
}

.latest-content small {
    margin-top: 5px;

    color: var(--text-secondary);

    font-size: 11px;
    font-weight: 650;
}


/* ========================================================= */
/* ENCABEZADO DE REGISTROS                                   */
/* ========================================================= */

.historial-section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    gap: 18px;

    margin-bottom: 11px;
}

.historial-section-header h2 {
    margin: 0;

    color: var(--green-950);

    font-size: 22px;
    font-weight: 850;
}

.historial-section-header p {
    margin: 4px 0 0;

    color: var(--text-secondary);

    font-size: 12px;
    font-weight: 600;
}

.historial-results {
    min-height: 32px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 5px 12px;

    color: #ffffff;
    background: var(--green-600);

    border: 1px solid var(--green-700);
    border-radius: 999px;

    font-size: 11px;
    font-weight: 850;

    white-space: nowrap;
}


/* ========================================================= */
/* TARJETA PRINCIPAL                                         */
/* ========================================================= */

.historial-card {
    overflow: hidden;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 13px;

    box-shadow: var(--shadow-small);
}


/* ========================================================= */
/* FILTROS                                                   */
/* ========================================================= */

.historial-filters {
    display: grid;

    grid-template-columns:
        minmax(165px, 1fr)
        minmax(175px, 1fr)
        minmax(175px, 1fr)
        minmax(155px, 0.85fr)
        auto;

    align-items: end;

    gap: 10px;

    padding: 15px;

    background: var(--green-50);

    border-bottom: 1px solid var(--border);
}

.historial-filter-field {
    min-width: 0;
}

.historial-filter-field label {
    display: block;

    margin-bottom: 6px;

    color: var(--green-900);

    font-size: 11px;
    font-weight: 850;
}

.historial-filter-field select {
    width: 100%;
    height: 41px;

    padding:
        6px
        32px
        6px
        11px;

    color: var(--text-primary);
    background: var(--surface);

    border: 1px solid var(--green-400);
    border-radius: 8px;

    font: inherit;
    font-size: 12px;
    font-weight: 700;

    outline: none;

    cursor: pointer;
}

.historial-filter-field select:hover {
    border-color: var(--green-600);
}

.historial-filter-field select:focus {
    border-color: var(--green-700);

    box-shadow:
        0 0 0 3px rgba(8, 116, 67, 0.14);
}


/* ========================================================= */
/* LIMPIAR FILTROS                                           */
/* ========================================================= */

.historial-clear-button {
    height: 41px;

    padding: 7px 13px;

    color: var(--green-700);
    background: var(--surface);

    border: 1px solid var(--green-500);
    border-radius: 8px;

    font: inherit;
    font-size: 11px;
    font-weight: 850;

    cursor: pointer;

    white-space: nowrap;
}

.historial-clear-button:hover {
    color: #ffffff;
    background: var(--green-700);

    border-color: var(--green-700);
}


/* ========================================================= */
/* CONTENEDOR DE TABLA                                       */
/* ========================================================= */

.historial-table-wrapper {
    position: relative;

    width: 100%;
    max-height: 440px;

    overflow: auto;
}


/* ========================================================= */
/* TABLA                                                     */
/* ========================================================= */

.historial-table {
    width: 100%;

    min-width: 980px;

    border-collapse: collapse;
}

.historial-table thead {
    position: sticky;

    top: 0;

    z-index: 2;
}

.historial-table th {
    padding: 12px 13px;

    color: #ffffff;
    background: var(--green-800);

    border-bottom: 1px solid var(--green-950);

    font-size: 11px;
    font-weight: 850;

    text-align: left;

    white-space: nowrap;
}

.historial-table th:last-child {
    width: 66px;
}


/* ========================================================= */
/* FILAS                                                     */
/* ========================================================= */

.historial-table td {
    padding: 13px;

    color: var(--text-primary);

    border-bottom: 1px solid var(--border-soft);

    font-size: 12px;
    font-weight: 600;

    vertical-align: middle;
}

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

.historial-table tbody tr {
    background: var(--surface);

    transition:
        background-color 0.15s ease;
}

.historial-table tbody tr:hover {
    background: var(--green-50);
}


/* ========================================================= */
/* INDICADOR SEGÚN ACTIVIDAD                                 */
/* ========================================================= */

.history-row.measurement td:first-child {
    border-left: 4px solid var(--blue-600);
}

.history-row.irrigation td:first-child {
    border-left: 4px solid var(--green-600);
}

.history-row.alert td:first-child {
    border-left: 4px solid var(--teal-600);
}

.history-row.change td:first-child {
    border-left: 4px solid var(--green-400);
}


/* ========================================================= */
/* FECHA                                                     */
/* ========================================================= */

.history-date {
    display: flex;
    flex-direction: column;
}

.history-date strong {
    color: var(--green-950);

    font-size: 12px;
    font-weight: 850;
}

.history-date span {
    margin-top: 2px;

    color: var(--text-secondary);

    font-size: 10px;
    font-weight: 650;
}


/* ========================================================= */
/* PLANTA                                                    */
/* ========================================================= */

.history-plant-name {
    color: var(--green-950);

    font-size: 12px;
    font-weight: 850;
}


/* ========================================================= */
/* DISPOSITIVO                                               */
/* ========================================================= */

.history-device {
    color: var(--text-secondary);

    font-size: 11px;
    font-weight: 700;
}


/* ========================================================= */
/* BADGES DE ACTIVIDAD - MÁS LEGIBLES                       */
/* ========================================================= */

.history-type {
    min-width: 86px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 7px 12px;

    border-radius: 999px;

    font-size: 11px;
    font-weight: 850;

    line-height: 1.2;

    letter-spacing: 0.1px;
}


/* MEDICIÓN */

.history-type.measurement {
    color: var(--blue-600);

    background: var(--blue-100);

    border: 2px solid var(--blue-500);
}


/* RIEGO */

.history-type.irrigation {
    color: var(--green-800);

    background: var(--green-100);

    border: 2px solid var(--green-500);
}


/* AVISO */

.history-type.alert {
    color: var(--teal-600);

    background: var(--teal-50);

    border: 2px solid var(--teal-600);
}


/* CAMBIO */

.history-type.change {
    color: var(--green-900);

    background: var(--green-50);

    border: 2px solid var(--green-500);
}


/* ========================================================= */
/* HUMEDAD                                                   */
/* ========================================================= */

.history-humidity {
    min-width: 58px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 6px 9px;

    border-radius: 7px;

    font-size: 12px;
    font-weight: 850;
}


/* NORMAL */

.history-humidity.good {
    color: #ffffff;
    background: var(--green-600);

    border: 1px solid var(--green-700);
}


/* REQUIERE ATENCIÓN */

.history-humidity.attention {
    color: var(--green-950);
    background: var(--green-100);

    border: 1px solid var(--green-500);
}


/* NO APLICA */

.history-humidity.none {
    color: var(--text-secondary);
    background: var(--background);

    border: 1px solid var(--border);
}


/* ========================================================= */
/* RESULTADO                                                 */
/* ========================================================= */

.history-result {
    color: var(--text-primary);

    font-size: 11px;
    font-weight: 700;
}


/* ========================================================= */
/* BOTÓN VER                                                 */
/* ========================================================= */

.history-view-button {
    min-width: 52px;
    height: 34px;

    padding: 5px 10px;

    color: #ffffff;
    background: var(--green-700);

    border: 1px solid var(--green-800);
    border-radius: 7px;

    font: inherit;
    font-size: 10px;
    font-weight: 850;

    cursor: pointer;
}

.history-view-button:hover {
    background: var(--green-800);
    border-color: var(--green-900);
}


/* ========================================================= */
/* SIN RESULTADOS                                            */
/* ========================================================= */

.historial-empty {
    min-height: 230px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: 30px;

    text-align: center;

    background: var(--surface);
}

.historial-empty[hidden] {
    display: none;
}

.historial-empty-icon {
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin-bottom: 10px;

    color: #ffffff;
    background: var(--green-600);

    border-radius: 10px;
}

.historial-empty-icon svg {
    width: 21px;
    height: 21px;
}

.historial-empty strong {
    color: var(--green-950);

    font-size: 13px;
    font-weight: 850;
}

.historial-empty p {
    margin: 4px 0 0;

    color: var(--text-secondary);

    font-size: 11px;
    font-weight: 600;
}


/* ========================================================= */
/* PIE                                                       */
/* ========================================================= */

.historial-footer {
    min-height: 44px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 15px;

    padding: 10px 14px;

    color: var(--text-secondary);
    background: var(--green-50);

    border-top: 1px solid var(--border);

    font-size: 10px;
    font-weight: 650;
}


/* ========================================================= */
/* MODAL                                                     */
/* ========================================================= */

.history-detail-dialog {
    width: min(
        600px,
        calc(100% - 32px)
    );

    padding: 0;

    color: var(--text-primary);
    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow-medium);
}

.history-detail-dialog::backdrop {
    background: rgba(4, 61, 39, 0.55);
}


/* ========================================================= */
/* CABECERA MODAL                                            */
/* ========================================================= */

.history-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 18px;

    padding: 18px 20px;

    background: var(--green-900);

    border-bottom: 1px solid var(--green-950);
}

.history-detail-label {
    display: block;

    margin-bottom: 3px;

    color: var(--green-400);

    font-size: 9px;
    font-weight: 850;
    letter-spacing: 1px;
}

.history-detail-header h2 {
    margin: 0;

    color: #ffffff;

    font-size: 19px;
    font-weight: 850;
}

.history-detail-close {
    width: 33px;
    height: 33px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    padding: 0;

    color: var(--green-950);
    background: #ffffff;

    border: none;
    border-radius: 8px;

    font-size: 20px;
    line-height: 1;

    cursor: pointer;
}


/* ========================================================= */
/* CUERPO MODAL                                              */
/* ========================================================= */

.history-detail-body {
    padding: 18px 20px;
}

.history-detail-grid {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 10px;
}

.history-detail-grid > div,
.history-detail-result,
.history-detail-extra {
    padding: 12px;

    background: var(--green-50);

    border: 1px solid var(--border);
    border-radius: 9px;
}

.history-detail-grid span,
.history-detail-result > span,
.history-detail-extra > span {
    display: block;

    color: var(--text-secondary);

    font-size: 9px;
    font-weight: 750;
}

.history-detail-grid strong,
.history-detail-result strong {
    display: block;

    margin-top: 3px;

    color: var(--green-950);

    font-size: 12px;
    font-weight: 850;
}

.history-detail-result,
.history-detail-extra {
    margin-top: 10px;
}

.history-detail-extra p {
    margin: 4px 0 0;

    color: var(--text-primary);

    font-size: 11px;
    font-weight: 650;
    line-height: 1.5;
}


/* ========================================================= */
/* ACCIONES MODAL                                            */
/* ========================================================= */

.history-detail-actions {
    display: flex;
    justify-content: flex-end;

    padding: 12px 20px;

    background: var(--background);

    border-top: 1px solid var(--border);
}

.history-detail-button {
    min-height: 38px;

    padding: 7px 15px;

    color: #ffffff;
    background: var(--green-700);

    border: 1px solid var(--green-800);
    border-radius: 8px;

    font: inherit;
    font-size: 11px;
    font-weight: 850;

    cursor: pointer;
}

.history-detail-button:hover {
    background: var(--green-800);
    border-color: var(--green-900);
}


/* ========================================================= */
/* SCROLL                                                    */
/* ========================================================= */

.historial-table-wrapper {
    scrollbar-width: thin;

    scrollbar-color:
        var(--green-500)
        var(--green-50);
}

.historial-table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.historial-table-wrapper::-webkit-scrollbar-track {
    background: var(--green-50);
}

.historial-table-wrapper::-webkit-scrollbar-thumb {
    background: var(--green-500);

    border-radius: 999px;
}


/* ========================================================= */
/* ACCESIBILIDAD                                             */
/* ========================================================= */

.historial-page :focus-visible,
.history-detail-dialog :focus-visible {
    outline: 3px solid var(--blue-600);
    outline-offset: 3px;
}


/* ========================================================= */
/* PANTALLAS MEDIANAS                                        */
/* ========================================================= */

@media (max-width: 1050px) {

    .historial-overview {
        grid-template-columns: 1fr;
    }


    .historial-filters {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }


    .historial-clear-button {
        width: 100%;
    }

}


/* ========================================================= */
/* TABLET                                                    */
/* ========================================================= */

@media (max-width: 760px) {

    .overview-stats {
        grid-template-columns: 1fr;
    }


    .overview-stat {
        min-height: 66px;
    }

}


/* ========================================================= */
/* MÓVIL                                                     */
/* ========================================================= */

@media (max-width: 650px) {

    .historial-header h1 {
        font-size: 27px;
    }


    .historial-section-header {
        align-items: flex-start;
        flex-direction: column;
    }


    .historial-filters {
        grid-template-columns: 1fr;
    }


    .historial-table-wrapper {
        max-height: 400px;
    }


    .historial-footer {
        align-items: flex-start;
        flex-direction: column;

        gap: 3px;
    }


    .history-detail-grid {
        grid-template-columns: 1fr;
    }

}