.history-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.history-trigger {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid #cfe3d5;
    border-radius: 13px;
    background: #eaf4ed;
    color: #398565;
    cursor: pointer;
    font-size: 21px;
    transition:
        background 0.2s ease,
        transform 0.2s ease,
        border-color 0.2s ease;
}

.history-trigger:hover {
    background: #deeee3;
    border-color: #b9d7c3;
    transform: translateY(-1px);
}

.history-trigger:focus-visible,
.history-close:focus-visible,
.history-tab:focus-visible,
.history-refresh:focus-visible {
    outline: 3px solid rgba(57, 133, 101, 0.25);
    outline-offset: 3px;
}

.history-panel {
    position: absolute;
    z-index: 100;
    top: calc(100% + 12px);
    left: 0;
    width: min(440px, calc(100vw - 32px));
    max-height: min(680px, calc(100vh - 110px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #e1eae4;
    border-radius: 17px;
    box-shadow: 0 12px 35px rgba(45, 85, 62, 0.13);
    opacity: 0;
    transform: translateY(-7px);
    transition:
        opacity 0.18s ease,
        transform 0.18s ease;
}

.history-panel[hidden] {
    display: none !important;
}

.history-panel.is-open {
    opacity: 1;
    transform: translateY(0);
}

.history-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 19px 20px 16px;
    background: #f8fbf9;
    border-bottom: 1px solid #e8efe9;
}

.history-eyebrow {
    display: block;
    margin-bottom: 5px;
    color: #82968c;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.2px;
}

.history-panel-header h2 {
    margin: 0;
    color: #30483a;
    font-size: 20px;
    font-weight: 750;
}

.history-panel-subtitle {
    margin: 5px 0 0;
    color: #82968c;
    font-size: 12px;
    line-height: 1.5;
}

.history-close {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border: 1px solid #e1eae4;
    border-radius: 10px;
    background: #ffffff;
    color: #71857a;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s ease;
}

.history-close:hover {
    background: #edf5ef;
}

.history-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin: 15px 18px 0;
    padding: 4px;
    border-radius: 11px;
    background: #f1f6f2;
}

.history-tab {
    min-height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #82968c;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    transition:
        background 0.2s ease,
        color 0.2s ease,
        box-shadow 0.2s ease;
}

.history-tab.active {
    background: #ffffff;
    color: #398565;
    box-shadow: 0 1px 4px rgba(45, 85, 62, 0.08);
}

.history-content {
    min-height: 150px;
    padding: 17px 18px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.history-view[hidden] {
    display: none !important;
}

.history-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 13px;
}

.history-section-heading h3 {
    margin: 0;
    color: #384d40;
    font-size: 13px;
    font-weight: 750;
}

.history-section-heading p {
    margin: 4px 0 0;
    color: #82968b;
    font-size: 11px;
}

.history-refresh {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid #d7e8dc;
    border-radius: 8px;
    background: #f1f8f3;
    color: #398565;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    transition: background 0.2s ease;
}

.history-refresh:hover {
    background: #e4f1e8;
}

.history-log {
    margin-bottom: 12px;
    padding: 15px;
    border: 1px solid #e5eee7;
    border-radius: 13px;
    background: #ffffff;
}

.history-log:last-child {
    margin-bottom: 0;
}

.history-log-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.history-log-label {
    display: block;
    margin-bottom: 5px;
    color: #91a096;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
}

.history-log-time {
    display: block;
    color: #30483a;
    font-size: 19px;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.4px;
}

.history-condition {
    padding: 5px 9px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 750;
    white-space: nowrap;
}

.history-condition.good {
    background: #e9f5eb;
    color: #43845a;
}

.history-condition.fair {
    background: #f0f5df;
    color: #778f3d;
}

.history-condition.moderate {
    background: #fbf4d9;
    color: #9c8427;
}

.history-condition.elevated {
    background: #fff0df;
    color: #b97535;
}

.history-condition.poor {
    background: #f9e8e8;
    color: #b65d5d;
}

.history-condition.pending {
    background: #f0f1ef;
    color: #7f8980;
}

.history-log-readings {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 15px;
    padding: 12px 0;
    border-top: 1px solid #edf1ed;
    border-bottom: 1px solid #edf1ed;
}

.history-log-reading {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.history-log-reading strong {
    color: #384d40;
    font-size: 15px;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}

.history-log-reading span {
    color: #82968c;
    font-size: 10px;
}

.history-log-summary {
    margin: 12px 0 0;
    color: #687b70;
    font-size: 11px;
    line-height: 1.6;
}

.history-daily-card {
    margin-bottom: 13px;
    padding: 16px;
    border: 1px solid #e2ebe4;
    border-radius: 14px;
    background: #ffffff;
}

.history-daily-card:last-child {
    margin-bottom: 0;
}

.history-daily-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.history-daily-heading h3 {
    margin: 0;
    color: #30483a;
    font-size: 15px;
    font-weight: 750;
}

.history-daily-heading span {
    display: block;
    margin-top: 4px;
    color: #91a096;
    font-size: 10px;
}

.history-daily-values {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}

.history-daily-values > div {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.history-daily-values strong {
    color: #398565;
    font-size: clamp(17px, 4vw, 21px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.history-daily-values span {
    color: #82968c;
    font-size: 10px;
    line-height: 1.4;
}

.history-daily-card.is-empty {
    background: #fbfcfb;
}

.history-no-readings {
    margin: 0;
    padding: 12px 0 4px;
    color: #91a096;
    font-size: 12px;
    text-align: center;
}

.history-empty {
    padding: 35px 18px;
    text-align: center;
}

.history-empty-icon {
    display: inline-grid;
    width: 39px;
    height: 39px;
    place-items: center;
    margin-bottom: 11px;
    border-radius: 13px;
    background: #edf6ef;
    color: #70a487;
    font-size: 19px;
}

.history-empty h3 {
    margin: 0 0 7px;
    color: #405749;
    font-size: 13px;
    font-weight: 750;
}

.history-empty p {
    max-width: 270px;
    margin: 0 auto;
    color: #87958b;
    font-size: 11px;
    line-height: 1.6;
}

.history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 35px 15px;
    color: #82968c;
    font-size: 11px;
}

.history-loading p {
    margin: 0;
}

.history-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid #e1eee5;
    border-top-color: #398565;
    border-radius: 50%;
    animation: history-spin 0.8s linear infinite;
}

@keyframes history-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 480px) {
    .history-panel {
        position: fixed;
        top: 76px;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: calc(100dvh - 90px);
    }

    .history-panel-header {
        padding: 16px;
    }

    .history-content {
        padding: 14px;
    }

    .history-log {
        padding: 13px;
    }
}

@media (max-width: 350px) {
    .history-daily-values {
        gap: 5px;
    }

    .history-daily-values strong {
        font-size: 15px;
    }

    .history-daily-values span {
        font-size: 9px;
    }

    .history-log-time {
        font-size: 17px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .history-panel,
    .history-trigger,
    .history-tab,
    .history-refresh,
    .history-spinner {
        transition: none;
        animation: none;
    }
}

.history-daily-card {
    margin-bottom: 15px;
    overflow: hidden;
    border: 1px solid #e2ebe4;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 3px 12px rgba(45, 85, 62, 0.045);
}

.history-daily-card:last-child {
    margin-bottom: 0;
}

.history-daily-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    padding: 13px 15px 11px;
    background: #ffffff;
    border-bottom: 1px solid #edf1ed;
}

.history-daily-heading h3 {
    margin: 0;
    color: #30483a;
    font-size: 14px;
    font-weight: 750;
}

.history-period {
    padding: 15px;
}

.history-period.sun_up {
    background: #eaf4fa;
}

.history-period.sun_down {
    background: #fff5dc;
}

.history-period + .history-period {
    border-top: 1px solid rgba(100, 120, 100, 0.09);
}

.history-period-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.history-period-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-period-title h4 {
    margin: 0;
    color: #40566a;
    font-size: 13px;
    font-weight: 800;
}

.history-period-title > div > span {
    display: block;
    margin-top: 3px;
    color: #7e929e;
    font-size: 10px;
}

.history-period.sun_down .history-period-title h4 {
    color: #78633a;
}

.history-period.sun_down .history-period-title > div > span {
    color: #9b885f;
}

.history-period-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.7);
    color: #d5a33c;
}

.history-period.sun_down .history-period-icon {
    color: #bd8c3c;
}

.history-period-icon svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.history-daily-values {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.history-daily-values > div {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.history-daily-values strong {
    color: #42677d;
    font-size: clamp(17px, 4vw, 21px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.history-period.sun_down .history-daily-values strong {
    color: #876b35;
}

.history-daily-values span {
    color: #7e929e;
    font-size: 10px;
    line-height: 1.4;
}

.history-period.sun_down .history-daily-values span {
    color: #9b885f;
}

.history-no-readings {
    margin: 0;
    padding: 9px 0 3px;
    color: #8296a0;
    font-size: 11px;
    text-align: center;
}

.history-period.sun_down .history-no-readings {
    color: #9b885f;
}

@media (max-width: 350px) {
    .history-period {
        padding: 12px;
    }

    .history-daily-values {
        gap: 5px;
    }

    .history-daily-values strong {
        font-size: 15px;
    }

    .history-daily-values span {
        font-size: 9px;
    }
}
