/* K6HR Meshtastic RF Signal History */

#rf-history-panel {
    min-width: 0;
}

#rf-history-panel .rf-panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

#rf-history-panel .rf-panel-heading h2 {
    margin: 0;
}

#rf-history-panel .rf-toolbar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

#rf-history-panel .rf-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 150px;
}

#rf-history-panel .rf-node-control {
    flex: 1 1 280px;
    min-width: 0;
}

#rf-history-panel .rf-control label {
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
}

#rf-history-panel select,
#rf-history-panel button {
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid #334155;
    border-radius: 6px;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 14px;
}

#rf-history-panel select {
    width: 100%;
    color-scheme: dark;
}

#rf-history-panel button {
    cursor: pointer;
}

#rf-history-panel button:hover:not(:disabled) {
    border-color: #38bdf8;
    background: #1e293b;
}

#rf-history-panel select:focus-visible,
#rf-history-panel button:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

#rf-history-panel button:disabled,
#rf-history-panel select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#rf-history-panel .rf-status {
    color: #94a3b8;
    font-size: 13px;
    margin: 10px 0 14px;
}

#rf-history-panel .rf-error {
    padding: 12px;
    margin-bottom: 14px;
    border: 1px solid #ef4444;
    border-radius: 6px;
    background: #450a0a;
    color: #fecaca;
    font-size: 14px;
}

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

#rf-history-panel .rf-overview-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

#rf-history-panel .rf-stat-card {
    min-width: 0;
    padding: 16px;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
}

#rf-history-panel .rf-stat-card h3 {
    margin: 0 0 8px;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
}

#rf-history-panel .rf-stat-card > div {
    color: #e2e8f0;
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-chart-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

#rf-history-panel .rf-chart-card {
    min-width: 0;
    padding: 16px;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
}

#rf-history-panel .rf-chart-card h3 {
    margin: 0 0 14px;
    color: #e2e8f0;
    font-size: 16px;
}

#rf-history-panel .rf-measurement-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

#rf-history-panel .rf-measurement-grid > div {
    min-width: 0;
    padding: 12px;
    border-radius: 6px;
    background: #1e293b;
}

#rf-history-panel .rf-measurement-grid span {
    display: block;
    margin-bottom: 6px;
    color: #94a3b8;
    font-size: 12px;
}

#rf-history-panel .rf-measurement-grid strong {
    display: block;
    color: #e2e8f0;
    font-size: 22px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-measurement-grid .rf-rssi-value {
    color: #38bdf8;
}

#rf-history-panel .rf-measurement-grid .rf-snr-value {
    color: #4ade80;
}

#rf-history-panel .rf-chart-container {
    position: relative;
    width: 100%;
    height: 300px;
    min-width: 0;
}

#rf-history-panel .rf-chart-container canvas {
    display: block;
}

#rf-history-panel .rf-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 16px;
    color: #94a3b8;
    font-size: 12px;
}

#rf-history-panel .rf-disclaimer {
    margin: 12px 0 0;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.5;
}

#rf-history-panel:fullscreen {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 20px;
    overflow: auto;
    border: 0;
    border-radius: 0;
    background: #0b1120;
}

#rf-history-panel:fullscreen .rf-chart-container {
    height: clamp(280px, 32vh, 500px);
}

@media (max-width: 900px) {
    #rf-history-panel .rf-overview-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    #rf-history-panel .rf-toolbar {
        align-items: stretch;
    }

    #rf-history-panel .rf-control {
        flex: 1 1 100%;
    }

    #rf-history-panel .rf-stat-card {
        padding: 12px;
    }

    #rf-history-panel .rf-stat-card > div {
        font-size: 22px;
    }

    #rf-history-panel .rf-chart-card {
        padding: 10px;
    }

    #rf-history-panel .rf-measurement-grid {
        gap: 6px;
    }

    #rf-history-panel .rf-measurement-grid > div {
        padding: 8px;
    }

    #rf-history-panel .rf-measurement-grid strong {
        font-size: 17px;
    }

    #rf-history-panel .rf-chart-container {
        height: 240px;
    }

    #rf-history-panel:fullscreen {
        padding: 10px;
    }
}


/* RF Frequency Distributions */

#rf-history-panel .rf-distribution-panel {
    min-width: 0;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #334155;
}

#rf-history-panel #rf-distribution-heading {
    margin: 0 0 12px;
    color: #e2e8f0;
    font-size: 18px;
    font-weight: 600;
}

#rf-history-panel #rf-distribution-status {
    margin: 8px 0 16px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-distribution-panel .rf-chart-container {
    height: 320px;
}

#rf-history-panel .rf-distribution-panel .rf-chart-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

#rf-history-panel .rf-distribution-panel canvas {
    max-width: 100%;
}

#rf-history-panel:fullscreen
.rf-distribution-panel .rf-chart-container {
    height: clamp(300px, 36vh, 520px);
}

@media (max-width: 600px) {
    #rf-history-panel .rf-distribution-panel {
        margin-top: 18px;
        padding-top: 14px;
    }

    #rf-history-panel #rf-distribution-heading {
        font-size: 16px;
    }

    #rf-history-panel .rf-distribution-panel
    .rf-chart-container {
        height: 260px;
    }
}


/* RF Signal Correlation */

#rf-history-panel .rf-correlation-panel {
    min-width: 0;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #334155;
}

#rf-history-panel #rf-correlation-heading {
    margin: 0 0 12px;
    color: #e2e8f0;
    font-size: 18px;
    font-weight: 600;
}

#rf-history-panel #rf-correlation-status {
    margin: 8px 0 16px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-correlation-chart-container {
    height: 420px;
    min-width: 0;
}

#rf-history-panel .rf-correlation-details {
    margin-top: 18px;
    margin-bottom: 12px;
}

#rf-history-panel #rf-correlation-equation {
    padding: 12px;
    margin: 12px 0 0;
    border: 1px solid #334155;
    border-radius: 6px;
    background: #1e293b;
    color: #fbbf24;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-correlation-panel canvas {
    max-width: 100%;
}

#rf-history-panel:fullscreen
.rf-correlation-chart-container {
    height: clamp(360px, 48vh, 680px);
}

@media (max-width: 600px) {
    #rf-history-panel .rf-correlation-panel {
        margin-top: 18px;
        padding-top: 14px;
    }

    #rf-history-panel #rf-correlation-heading {
        font-size: 16px;
    }

    #rf-history-panel .rf-correlation-chart-container {
        height: 300px;
    }

    #rf-history-panel #rf-correlation-equation {
        padding: 10px;
        font-size: 12px;
    }

    #rf-history-panel .rf-correlation-details {
        margin-top: 12px;
    }
}


/* RF Statistical Analysis */

#rf-history-panel .rf-statistics-panel {
    min-width: 0;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #334155;
}

#rf-history-panel #rf-statistics-heading {
    margin: 0 0 12px;
    color: #e2e8f0;
    font-size: 18px;
    font-weight: 600;
}

#rf-history-panel #rf-statistics-status {
    margin: 8px 0 16px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#rf-history-panel .rf-statistics-table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

#rf-history-panel .rf-statistics-table {
    width: 100%;
    min-width: 320px;
    border-collapse: collapse;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

#rf-history-panel .rf-statistics-table th,
#rf-history-panel .rf-statistics-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #334155;
}

#rf-history-panel .rf-statistics-table thead th {
    background: #1e293b;
    color: #e2e8f0;
    font-weight: 600;
}

#rf-history-panel .rf-statistics-table th:first-child {
    text-align: left;
    white-space: normal;
}

#rf-history-panel .rf-statistics-table th:not(:first-child),
#rf-history-panel .rf-statistics-table td {
    text-align: right;
    white-space: nowrap;
}

#rf-history-panel .rf-statistics-table tbody th {
    color: #cbd5e1;
    font-weight: 500;
}

#rf-history-panel .rf-statistics-table tbody tr:nth-child(even) {
    background: rgba(148, 163, 184, 0.04);
}

#rf-history-panel .rf-statistics-table tbody tr:hover {
    background: rgba(148, 163, 184, 0.08);
}

#rf-history-panel .rf-statistics-table .rf-stat-rssi,
#rf-history-panel .rf-statistics-table thead th:nth-child(2) {
    color: #38bdf8;
}

#rf-history-panel .rf-statistics-table .rf-stat-snr,
#rf-history-panel .rf-statistics-table thead th:nth-child(3) {
    color: #4ade80;
}

#rf-history-panel .rf-statistics-table .rf-stat-rssi,
#rf-history-panel .rf-statistics-table .rf-stat-snr {
    font-weight: 600;
}

#rf-history-panel .rf-statistics-table tbody tr:last-child th,
#rf-history-panel .rf-statistics-table tbody tr:last-child td {
    border-bottom: 0;
}

@media (max-width: 600px) {
    #rf-history-panel .rf-statistics-panel {
        margin-top: 18px;
        padding-top: 14px;
    }

    #rf-history-panel #rf-statistics-heading {
        font-size: 16px;
    }

    #rf-history-panel .rf-statistics-table {
        font-size: 12px;
    }

    #rf-history-panel .rf-statistics-table th,
    #rf-history-panel .rf-statistics-table td {
        padding: 10px 8px;
    }
}


/* Step 16G: Automatic RF refresh controls */

#rf-history-panel .rf-auto-refresh-control {
    display: flex;
    align-items: center;
    align-self: flex-end;
    min-height: 40px;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #1e293b;
}

#rf-history-panel .rf-auto-refresh-control label {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

#rf-history-panel #rf-auto-refresh {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: #4ade80;
    cursor: pointer;
}

#rf-history-panel #rf-auto-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#rf-history-panel #rf-auto-refresh:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 4px;
}

#rf-history-panel .rf-auto-refresh-status {
    margin: 8px 0 12px;
    min-height: 20px;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
}

#rf-history-panel
.rf-auto-refresh-status[data-state="enabled"] {
    color: #4ade80;
}

#rf-history-panel
.rf-auto-refresh-status[data-state="refreshing"] {
    color: #38bdf8;
}

#rf-history-panel
.rf-auto-refresh-status[data-state="disabled"] {
    color: #94a3b8;
}

#rf-history-panel
.rf-auto-refresh-status[data-state="paused"] {
    color: #fbbf24;
}

#rf-history-panel
.rf-auto-refresh-status[data-state="error"] {
    color: #f87171;
}

#rf-history-panel:fullscreen .rf-auto-refresh-control {
    flex-shrink: 0;
}

@media (max-width: 600px) {
    #rf-history-panel .rf-auto-refresh-control {
        align-self: stretch;
        justify-content: center;
    }

    #rf-history-panel .rf-auto-refresh-status {
        font-size: 12px;
        overflow-wrap: anywhere;
    }
}
