:root {
    --lab-green: #42b978;
    --lab-green-dark: #2d9d61;
    --lab-blue: #0b1f3a;
    --lab-bg: #f4f7fa;
    --lab-text: #1f2937;
    --lab-muted: #6c757d;
    --lab-border: #dbe3ea;
    --lab-white: #ffffff;
}

* {
    letter-spacing: 0;
}

body {
    min-height: 100vh;
    background: var(--lab-bg);
    color: var(--lab-text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    min-height: 100vh;
    height: 100vh;
    position: sticky;
    top: 0;
    flex: 0 0 280px;
    overflow-y: auto;
    padding: 24px;
    flex-direction: column;
    background: var(--lab-blue);
    color: var(--lab-white);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--lab-white);
    text-decoration: none;
    margin-bottom: 32px;
}

.sidebar-brand img,
.brand-mark {
    width: 44px;
    height: 44px;
    object-fit: contain;
}

.sidebar-brand strong {
    display: block;
    font-size: 1.1rem;
}

.sidebar-brand small {
    color: rgba(255, 255, 255, .68);
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.sidebar-nav a,
.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, .82);
    text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-logout:hover {
    background: rgba(66, 185, 120, .16);
    color: var(--lab-white);
}

.content {
    width: 100%;
    padding: 28px;
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--lab-green-dark);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.content-header h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2vw, 2.2rem);
    color: var(--lab-blue);
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    background: var(--lab-white);
    color: var(--lab-muted);
}

.app-topbar {
    background: var(--lab-blue);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.summary-card,
.data-panel,
.form-panel {
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    background: var(--lab-white);
    box-shadow: 0 10px 30px rgba(11, 31, 58, .06);
}

.summary-card {
    padding: 20px;
}

.summary-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: rgba(66, 185, 120, .12);
    color: var(--lab-green-dark);
    margin-bottom: 18px;
}

.summary-card p {
    margin: 0;
    color: var(--lab-muted);
}

.summary-card strong {
    display: block;
    margin-top: 4px;
    font-size: 2rem;
    color: var(--lab-blue);
}

.data-panel,
.form-panel {
    padding: 22px;
}

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

.panel-heading h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--lab-blue);
}

.panel-heading p {
    margin: 4px 0 0;
    color: var(--lab-muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border-radius: 8px;
    font-weight: 700;
}

.btn-primary {
    border-color: var(--lab-green);
    background: var(--lab-green);
}

.btn-primary:hover,
.btn-primary:focus {
    border-color: var(--lab-green-dark);
    background: var(--lab-green-dark);
}

.btn-secondary {
    border-color: #e6ebf0;
    background: #e6ebf0;
    color: var(--lab-blue);
}

.table {
    margin-bottom: 0;
}

.table thead th {
    color: var(--lab-muted);
    font-size: .82rem;
    text-transform: uppercase;
}

.empty-state {
    padding: 32px !important;
    color: var(--lab-muted);
    text-align: center;
}

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

.search-bar input {
    flex: 1;
}

.search-bar select {
    min-width: 220px;
}

.table a {
    color: var(--lab-blue);
    font-weight: 700;
    text-decoration: none;
}

.table-actions,
.action-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    white-space: nowrap;
}

.code-pill,
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 800;
}

.code-pill {
    background: rgba(11, 31, 58, .08);
    color: var(--lab-blue);
}

.status-pill {
    background: rgba(66, 185, 120, .13);
    color: var(--lab-green-dark);
}

.status-muted {
    background: #eef1f4;
    color: var(--lab-muted);
}

.status-danger {
    background: rgba(220, 53, 69, .12);
    color: #b4232d;
}

.interpretation-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eef1f4;
    color: var(--lab-muted);
    font-size: .82rem;
    font-weight: 800;
}

.interpretation-normal {
    background: transparent;
    color: inherit;
    padding-left: 0;
    padding-right: 0;
    font-weight: 600;
}

.interpretation-low {
    background: rgba(13, 110, 253, .12);
    color: #0b5ed7;
}

.interpretation-high,
.interpretation-abnormal {
    background: rgba(220, 53, 69, .12);
    color: #b4232d;
}

.interpretation-critical_low {
    background: rgba(13, 110, 253, .2);
    color: #073b8e;
    font-weight: 900;
}

.interpretation-critical_high {
    background: rgba(220, 53, 69, .12);
    color: #b4232d;
    font-weight: 900;
}

.history-row td {
    background: #fbfcfd;
}

.history-list {
    margin: 10px 0 0;
    padding-left: 18px;
    color: var(--lab-muted);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field-wide {
    grid-column: 1 / -1;
}

.form-control,
.form-select,
input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
}

textarea {
    min-height: 96px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.detail-layout {
    display: grid;
    gap: 18px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 0;
}

.detail-grid div {
    padding: 12px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    background: #fbfcfd;
}

.detail-grid dt {
    color: var(--lab-muted);
    font-size: .8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.detail-grid dd {
    margin: 3px 0 0;
    color: var(--lab-blue);
}

.test-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.test-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    background: #fbfcfd;
    font-weight: 700;
}

.test-option input {
    width: 18px;
    min-height: 18px;
}

.test-search {
    margin-bottom: 14px;
}

.test-tree {
    display: grid;
    gap: 14px;
}

.test-area {
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.test-area h3,
.result-area-block h3 {
    margin: 0;
    padding: 10px 14px;
    background: rgba(11, 31, 58, .08);
    color: var(--lab-blue);
    font-size: 1rem;
}

.test-parent {
    border-top: 1px solid var(--lab-border);
}

.test-parent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #fbfcfd;
}

.tree-toggle,
.tree-spacer {
    width: 28px;
    height: 28px;
}

.tree-toggle {
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    background: #fff;
    color: var(--lab-blue);
}

.test-check {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    font-weight: 700;
}

.test-check input {
    width: 18px;
    height: 18px;
}

.test-children {
    display: grid;
    gap: 6px;
    padding: 8px 14px 12px 50px;
}

.test-parent.is-collapsed .test-children {
    display: none;
}

.child-check {
    color: var(--lab-text);
    font-weight: 600;
}

.result-area-block {
    margin-top: 18px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
    overflow: hidden;
}

.result-area-block.is-validated {
    background: #f7f9fb;
}

.result-area-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    background: rgba(11, 31, 58, .05);
}

.result-area-heading h3 {
    margin: 0 0 4px;
    color: var(--lab-blue);
    font-size: 1rem;
}

.area-actions {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.result-area-heading .area-observation-box {
    flex: 1 1 320px;
    min-width: 260px;
    padding: 9px 11px;
    border-left: 3px solid var(--lab-green);
    background: #f3fbf6;
    border-radius: 6px;
}

.result-area-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--lab-border);
    background: #fbfcfd;
}

.area-observation-box {
    padding: 12px 14px;
    border-top: 1px solid var(--lab-border);
    border-left: 3px solid var(--lab-green);
    background: #f3fbf6;
}

.area-observation-box label,
.annul-box label {
    display: block;
    color: var(--lab-muted);
    font-size: .78rem;
    font-weight: 800;
}

.area-observation-box textarea,
.annul-box input,
.master-annul-box input,
.general-observations-body textarea {
    width: 100%;
    min-height: 38px;
    padding: 7px 9px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
}

.master-annul-box {
    display: flex;
    align-items: center;
    gap: 6px;
}

.master-annul-box label {
    margin: 0;
    color: var(--lab-muted);
    font-size: .78rem;
    font-weight: 800;
}

.master-annul-box input {
    width: 150px;
}

.result-profile-block h4 {
    margin: 0;
    padding: 10px 14px;
    color: var(--lab-green-dark);
    font-size: .95rem;
    background: #fbfcfd;
    border-top: 1px solid var(--lab-border);
}

.result-entry-table input,
.result-entry-table textarea {
    width: 100%;
    min-width: 130px;
    min-height: 38px;
    padding: 7px 9px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
}

.result-entry-table input:disabled,
.result-entry-table textarea:disabled,
.area-observation-box textarea:disabled,
.general-observations-body textarea:disabled {
    background: #eef2f5;
    color: #6f7a88;
    opacity: .72;
}

.general-observations-form {
    margin-top: 18px;
}

.general-observations-body {
    padding: 12px 14px;
}

.result-row-alert td {
    background: #fffafa;
}

.calculated-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #eef7f2;
    color: var(--lab-green-dark);
    font-size: .72rem;
    font-weight: 700;
}

.calculation-alert {
    margin-top: 14px;
}

.report-custom-table input,
.report-custom-table textarea,
.manual-row-form input,
.manual-row-form select,
.manual-row-form textarea {
    width: 100%;
}

.correction-field {
    margin-top: 8px;
}

.correction-field label {
    display: block;
    color: var(--lab-muted);
    font-size: .78rem;
    font-weight: 800;
}

.bulk-actions {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.status-pending {
    background: #eef2f5;
    color: #4a5565;
}

.status-saved {
    background: rgba(72, 181, 116, .12);
    color: var(--lab-green-dark);
}

.status-validated {
    background: rgba(11, 31, 58, .12);
    color: var(--lab-blue);
}

.report-page {
    background: #e9eef3;
    color: #172033;
}

.report-sheet {
    width: min(100%, 920px);
    min-height: 1120px;
    margin: 24px auto;
    padding: 30px 34px;
    background: #fff;
    box-shadow: 0 18px 60px rgba(11, 31, 58, .16);
    font-size: .86rem;
}

.report-print-table {
    width: 100%;
    border-collapse: collapse;
}

.report-print-table > thead > tr > td,
.report-print-table > tbody > tr > td {
    padding: 0;
}

.report-header,
.report-brand,
.report-grid,
.report-signature {
    display: flex;
    justify-content: space-between;
    gap: 24px;
}

.report-brand {
    align-items: center;
}

.report-brand img {
    width: 62px;
    height: 62px;
    object-fit: contain;
}

.report-brand h1 {
    margin: 0;
    color: var(--lab-blue);
    font-size: 1.45rem;
}

.report-brand p,
.report-grid p,
.report-footer,
.report-signature p {
    margin: 4px 0;
    color: var(--lab-muted);
}

.report-grid {
    margin: 10px 0 12px;
}

.report-grid > div {
    flex: 1;
    padding: 6px 9px;
    border: 1px solid var(--lab-border);
    border-radius: 8px;
}

.report-grid h2 {
    margin: 0 0 4px;
    color: var(--lab-blue);
    font-size: .84rem;
}

.report-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}

.report-col-test {
    width: 31%;
}

.report-col-result {
    width: 18%;
}

.report-col-unit {
    width: 13%;
}

.report-col-reference {
    width: 38%;
}

.report-table th,
.report-table td {
    padding: 2px 4px;
    border-bottom: 1px solid var(--lab-border);
    text-align: left;
    vertical-align: top;
    overflow-wrap: anywhere;
}

.report-table th {
    color: var(--lab-blue);
    font-size: .62rem;
    text-transform: uppercase;
}

.report-area {
    margin-top: 7px;
    break-inside: auto;
    page-break-inside: auto;
}

.report-area-short {
    break-inside: avoid;
    page-break-inside: avoid;
}

.report-area h2 {
    margin: 0 0 4px;
    padding: 3px 5px;
    background: rgba(11, 31, 58, .08);
    color: var(--lab-blue);
    font-size: .82rem;
    break-after: avoid;
    page-break-after: avoid;
}

.report-area h3 {
    margin: 5px 0 2px;
    color: var(--lab-green-dark);
    font-size: .78rem;
    break-after: avoid;
    page-break-after: avoid;
}

.report-profile {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 4px;
}

.report-result-value {
    color: #111827;
    font-weight: 700;
    white-space: nowrap;
}

.report-result-value.interpretation-low {
    color: #1f5fbf;
    font-weight: 800;
}

.report-result-value.interpretation-critical_low {
    color: #0d3d8f;
    font-weight: 900;
}

.report-result-value.interpretation-high,
.report-result-value.interpretation-abnormal {
    color: #b4232d;
    font-weight: 800;
}

.report-result-value.interpretation-critical_high {
    color: #8f121c;
    font-weight: 900;
}

.report-area-note,
.report-profile-note,
.report-general-note {
    margin-top: 4px;
    padding: 3px 5px;
    border-left: 4px solid var(--lab-green);
    background: #f3fbf6;
    font-size: .74rem;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.report-area-note p,
.report-area-note ul,
.report-profile-note ul,
.report-general-note p {
    margin: 4px 0 0;
}

.report-profile-note {
    margin-bottom: 4px;
    background: #f3fbf6;
}

.report-general-note {
    margin-top: 8px;
}

.report-area-validation {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--lab-border);
    color: var(--lab-muted);
    font-size: .7rem;
}

.report-signature {
    justify-content: flex-end;
    margin-top: 28px;
    text-align: center;
}

.signature-line {
    width: 250px;
    border-top: 1px solid #172033;
    margin: 38px 0 6px;
}

.report-footer {
    margin-top: 22px;
    padding-top: 8px;
    border-top: 1px solid var(--lab-border);
    text-align: center;
    font-size: .78rem;
}

@media print {
    @page {
        size: Letter;
        margin: 8mm 9mm 12mm;

        @bottom-right {
            content: "Pag. " counter(page) " / " counter(pages);
            color: #172033;
            font-size: 7.4pt;
            font-family: "Segoe UI", Arial, sans-serif;
            text-align: right;
            vertical-align: bottom;
            padding-bottom: 2mm;
        }
    }

    .report-page {
        background: #fff;
    }

    .report-sheet {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
        font-size: 8.4pt;
    }

    .report-print-table {
        width: 100%;
        border-collapse: collapse;
    }

    .report-print-table > thead {
        display: table-header-group;
    }

    .report-print-table > tbody {
        display: table-row-group;
    }

    .report-print-header {
        padding-bottom: 2mm;
    }

    .report-brand img {
        width: 14mm;
        height: 14mm;
    }

    .report-brand h1 {
        font-size: 15pt;
    }

    .report-brand p,
    .report-grid p {
        margin: 1px 0;
    }

    .report-grid {
        margin: 2mm 0 3mm;
        gap: 5mm;
    }

    .report-grid > div {
        padding: 2mm 2.5mm;
        border-radius: 4px;
    }

    .report-table th,
    .report-table td {
        padding: 1.2mm 1.6mm;
        line-height: 1.15;
    }

    .report-area-note,
    .report-profile-note,
    .report-general-note {
        border-left: 1.4mm solid #42b978;
        background: #f3fbf6 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .report-header,
    .report-grid {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .report-area {
        break-inside: auto;
        page-break-inside: auto;
    }

    .report-profile {
        break-inside: avoid-page;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .report-area-short {
        break-inside: avoid-page;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .report-table tr,
    .report-profile-note,
    .report-area-note,
    .report-area-validation,
    .report-general-note {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .report-body {
        padding-bottom: 0;
    }

    .report-signature {
        display: flex;
        break-inside: avoid;
        page-break-inside: avoid;
        margin-top: 8mm;
    }

    .signature-line {
        margin-top: 14mm;
    }

    .report-footer {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-top: 4mm;
    }

    .no-print {
        display: none !important;
    }
}

.login-page {
    background: var(--lab-blue);
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(100%, 420px);
    padding: 32px;
    border-radius: 8px;
    background: var(--lab-white);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .26);
}

.login-logo {
    display: block;
    width: 110px;
    height: 110px;
    object-fit: contain;
    margin: 0 auto 14px;
}

.login-panel h1 {
    text-align: center;
    color: var(--lab-blue);
}

.login-copy {
    margin-bottom: 24px;
    color: var(--lab-muted);
    text-align: center;
}

@media (max-width: 991.98px) {
    .app-shell {
        display: block;
        min-height: auto;
    }

    .content {
        padding: 18px;
    }

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

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

@media (max-width: 575.98px) {
    .summary-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .panel-heading,
    .result-area-heading,
    .form-actions,
    .search-bar,
    .action-row {
        align-items: stretch;
        flex-direction: column;
    }

    .panel-heading .btn,
    .result-area-heading .btn,
    .form-actions .btn,
    .search-bar .btn,
    .action-row .btn {
        width: 100%;
    }

    .area-actions {
        align-items: stretch;
        justify-content: stretch;
    }

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