.calibration-results-page {
    --panel-border: #dfe3e8;
    --panel-muted: #667085;
    --panel-shadow: 0 0.25rem 1rem rgba(16, 24, 40, 0.06);
    min-height: calc(100vh - 180px);
}

.page-heading,
.overview-heading,
.results-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.page-heading {
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-heading-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.serial-batch-input {
    min-height: 16rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.45;
    resize: vertical;
}

.overview-section {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--panel-border);
    border-radius: 0.75rem;
    box-shadow: var(--panel-shadow);
}

.overview-heading {
    margin-bottom: 0.85rem;
}

.stat-card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.stat-card {
    display: flex;
    min-width: 0;
    min-height: 112px;
    padding: 0.9rem 1rem;
    flex-direction: column;
    justify-content: center;
    background: #f8fafc;
    border: 1px solid #eaecf0;
    border-left: 4px solid #667085;
    border-radius: 0.6rem;
}

.stat-card-external {
    border-left-color: #7c3aed;
}

.stat-card-helios {
    border-left-color: #0284c7;
}

.stat-label,
.stat-note {
    color: var(--panel-muted);
}

.stat-label {
    font-size: 0.82rem;
    font-weight: 600;
}

.stat-value {
    margin: 0.15rem 0;
    color: #101828;
    font-size: clamp(1.55rem, 2vw, 2rem);
    line-height: 1.1;
}

.stat-note {
    font-size: 0.72rem;
}

.distribution-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.distribution-card {
    padding: 0.85rem 1rem;
    background: #fff;
    border: 1px solid #eaecf0;
    border-radius: 0.6rem;
}

.distribution-title {
    margin-bottom: 0.65rem;
    color: #344054;
    font-size: 0.8rem;
    font-weight: 700;
}

.distribution-list {
    display: grid;
    gap: 0.55rem;
}

.distribution-row-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.2rem;
    color: #475467;
    font-size: 0.75rem;
}

.distribution-row-heading strong {
    color: #1d2939;
}

.distribution-track {
    height: 0.3rem;
    overflow: hidden;
    background: #eaecf0;
    border-radius: 999px;
}

.distribution-bar {
    display: block;
    height: 100%;
    background: #0d6efd;
    border-radius: inherit;
}

.calibration-workspace {
    display: grid;
    grid-template-columns: minmax(260px, 0.75fr) minmax(0, 3fr);
    gap: 1rem;
    min-height: 620px;
    height: min(720px, calc(100vh - 210px));
}

.month-panel,
.results-panel {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--panel-border);
    border-radius: 0.75rem;
    box-shadow: var(--panel-shadow);
}

.month-panel-header,
.results-panel-header {
    flex: 0 0 auto;
    padding: 1rem;
    background: #fff;
    border-bottom: 1px solid var(--panel-border);
}

.results-panel-header {
    align-items: center;
}

.month-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.month-item {
    display: flex;
    width: 100%;
    padding: 0.8rem 0.9rem;
    flex-direction: column;
    gap: 0.22rem;
    color: #344054;
    text-align: left;
    background: #fff;
    border: 0;
    border-bottom: 1px solid #f0f1f3;
    border-left: 3px solid transparent;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.month-item:hover {
    background: #f8fafc;
}

.month-item.is-active {
    background: #eef6ff;
    border-left-color: #0d6efd;
}

.month-item-heading,
.month-item-split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.month-item-heading strong {
    color: #1d2939;
    font-size: 0.9rem;
}

.month-item-count {
    color: #0d6efd;
    font-size: 0.75rem;
    font-weight: 700;
}

.month-item-meta,
.month-item-split {
    color: var(--panel-muted);
    font-size: 0.7rem;
}

.month-list-empty {
    padding: 1.5rem 1rem;
    color: var(--panel-muted);
    text-align: center;
}

.record-filter-bar {
    display: grid;
    grid-template-columns: minmax(180px, 1.5fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) auto;
    gap: 0.65rem;
    align-items: end;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--panel-border);
}

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

.record-filter-field .form-label {
    margin-bottom: 0.25rem;
    color: #475467;
    font-size: 0.72rem;
    font-weight: 600;
}

.results-state {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-height: 260px;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--panel-muted);
    text-align: center;
}

.results-empty-mark {
    display: grid;
    width: 4.25rem;
    height: 4.25rem;
    margin-bottom: 0.5rem;
    place-items: center;
    color: #0d6efd;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: #eef6ff;
    border: 1px solid #cfe2ff;
    border-radius: 50%;
}

.results-table-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.calibration-results-table {
    font-size: 0.84rem;
    white-space: nowrap;
}

.calibration-results-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.calibration-results-table th {
    padding: 0.75rem;
    color: #475467;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    background: #f8fafc;
    border-bottom: 1px solid var(--panel-border);
}

.calibration-results-table td {
    padding: 0.7rem 0.75rem;
}

.record-serial {
    color: #1d2939;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
}

.source-badge,
.program-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 999px;
}

.source-app {
    color: #075985;
    background: #e0f2fe;
}

.source-pc {
    color: #5b21b6;
    background: #ede9fe;
}

.source-manual {
    color: #92400e;
    background: #fef3c7;
}

.source-eeprom,
.source-unknown {
    color: #344054;
    background: #eaecf0;
}

.program-badge {
    color: #166534;
    background: #dcfce7;
}

.reading-value {
    color: #101828;
    font-weight: 600;
}

.reading-gas {
    display: block;
    color: var(--panel-muted);
    font-size: 0.68rem;
}

/* This dialog is intentionally self-contained: QC pages may block CDN Bootstrap JS. */
#serialBatchQueryModal {
    position: fixed;
    inset: 0;
    z-index: 1055;
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    background: rgb(16 24 40 / 52%);
}

#serialBatchQueryModal.is-open {
    display: block;
    opacity: 1;
}

#serialBatchQueryModal.is-open .modal-dialog {
    transform: none;
}

#serialBatchQueryModal .modal-dialog {
    width: min(680px, calc(100% - 2rem));
    max-height: calc(100vh - 2rem);
    margin: 1rem auto;
}

#serialBatchQueryModal .modal-content {
    display: flex;
    max-height: calc(100vh - 2rem);
    flex-direction: column;
    overflow: hidden;
    border: 0;
    border-radius: 0.9rem;
    color: #101828;
    background: #fff;
    box-shadow: 0 24px 48px rgb(16 24 40 / 28%);
}

#serialBatchQueryModal .modal-header,
#serialBatchQueryModal .modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.2rem 1.4rem;
}

#serialBatchQueryModal .modal-header {
    align-items: flex-start;
    border-bottom: 1px solid #eaecf0;
}

#serialBatchQueryModal .modal-title {
    margin: 0;
    font-size: 1.15rem;
}

#serialBatchQueryModal .modal-header p {
    margin: 0.35rem 0 0;
    color: var(--panel-muted);
}

#serialBatchQueryModal .btn-close {
    display: inline-grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 0.375rem;
    color: #475467;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
}

#serialBatchQueryModal .btn-close::before {
    content: "×";
}

#serialBatchQueryModal .btn-close:hover {
    color: #101828;
    background: #f2f4f7;
}

#serialBatchQueryModal .modal-body {
    overflow-y: auto;
    padding: 1.3rem 1.4rem;
}

#serialBatchQueryModal .form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: #344054;
    font-size: 0.9rem;
    font-weight: 600;
}

#serialBatchQueryModal .serial-batch-input {
    width: 100%;
    min-height: 14rem;
    resize: vertical;
    padding: 0.75rem;
    border: 1px solid #98a2b3;
    border-radius: 0.375rem;
    color: #101828;
    font: inherit;
}

#serialBatchQueryModal .serial-batch-input:focus {
    border-color: #2e90fa;
    outline: 3px solid rgb(46 144 250 / 20%);
}

#serialBatchQueryModal .modal-footer {
    justify-content: flex-end;
    border-top: 1px solid #eaecf0;
}

@media (max-width: 1199.98px) {
    .stat-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .record-filter-bar {
        grid-template-columns: minmax(180px, 1fr) repeat(2, minmax(130px, 0.7fr));
    }

    .record-filter-bar .btn {
        grid-column: 1 / -1;
        justify-self: end;
    }
}

@media (max-width: 991.98px) {
    .calibration-workspace {
        grid-template-columns: 1fr;
        height: auto;
    }

    .month-panel {
        max-height: 420px;
    }

    .results-panel {
        min-height: 620px;
    }
}

@media (max-width: 767.98px) {
    .stat-card-grid,
    .distribution-grid,
    .record-filter-bar {
        grid-template-columns: 1fr;
    }

    .record-filter-bar .btn {
        grid-column: auto;
        justify-self: stretch;
    }

    .page-heading-actions {
        width: 100%;
    }

    .page-heading-actions .btn {
        flex: 1 1 auto;
    }
}
