/**
 * Summit Lab - Shared Styles
 * 
 * Used by: create_order, admin_review, csv_import, client_dashboard
 * 
 * Supports: Light/Dark theme via prefers-color-scheme
 */

/* =============================================================================
   CSS CUSTOM PROPERTIES
   ============================================================================= */

:root {
    color-scheme: light dark;
    
    /* Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    
    /* Accent colours */
    --accent-primary: #2563eb;
    --accent-success: #16a34a;
    --accent-danger: #dc2626;
    --accent-warning: #d97706;
    --accent-info: #0891b2;
    
    /* Category colours */
    --cat-micro: #2563eb;
    --cat-water: #0d9488;
    --cat-chem: #ea580c;
    --cat-milk: #16a34a;
    
    /* Status colours */
    --status-draft: #6b7280;
    --status-pending: #d97706;
    --status-action: #dc2626;
    --status-approved: #16a34a;
    --status-processing: #2563eb;
    --status-complete: #059669;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Border radius */
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-tertiary: #404040;
        --text-primary: #f1f1f1;
        --text-secondary: #a0a0a0;
        --text-muted: #666666;
        --border-color: #404040;
        --shadow: rgba(0, 0, 0, 0.3);
    }
}


/* =============================================================================
   RESET & BASE
   ============================================================================= */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
}


/* =============================================================================
   LAYOUT
   ============================================================================= */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-lg);
}

.container-wide {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-lg);
}

h1 {
    font-size: 1.75rem;
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
}

h2 {
    font-size: 1.25rem;
    margin-bottom: var(--space-md);
    color: var(--text-primary);
}

h3 {
    font-size: 1.1rem;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}


/* =============================================================================
   CARDS
   ============================================================================= */

.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}


/* =============================================================================
   FORM ELEMENTS
   ============================================================================= */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-xs);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.form-group small {
    display: block;
    margin-top: var(--space-xs);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}


/* =============================================================================
   BUTTONS
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-success {
    background: var(--accent-success);
    color: white;
}
.btn-success:hover:not(:disabled) {
    background: #15803d;
}

.btn-danger {
    background: transparent;
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}
.btn-danger:hover:not(:disabled) {
    background: var(--accent-danger);
    color: white;
}

.btn-warning {
    background: var(--accent-warning);
    color: white;
}
.btn-warning:hover:not(:disabled) {
    background: #b45309;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-small {
    padding: 0.375rem 0.625rem;
    font-size: 0.8rem;
}

.btn-large {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}


/* =============================================================================
   CATEGORY TABS
   ============================================================================= */

.category-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.category-tab {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.9rem;
    font-weight: 500;
}

.category-tab:hover {
    border-color: var(--tab-colour, var(--border-color));
}

.category-tab.active {
    border-color: var(--tab-colour);
    background: var(--tab-colour);
    color: white;
}

.category-tab .count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.375rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.1);
}

.category-tab.active .count {
    background: rgba(255, 255, 255, 0.25);
}

.category-tab .count.has-items {
    background: var(--tab-colour);
    color: white;
}

.category-tab.active .count.has-items {
    background: rgba(255, 255, 255, 0.3);
}


/* =============================================================================
   CATEGORY PANELS
   ============================================================================= */

.category-panels {
    position: relative;
}

.category-panel {
    display: none;
    padding: var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
}

.category-panel.active {
    display: block;
}

.category-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--cat-colour);
}

.category-panel-header h4 {
    font-size: 0.95rem;
    color: var(--cat-colour);
    margin: 0;
}


/* =============================================================================
   TEST GRID & ITEMS
   ============================================================================= */

.tests-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-sm);
}

.test-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.test-item:hover {
    border-color: var(--cat-colour);
}

.test-item.selected {
    border-color: var(--cat-colour);
    background: color-mix(in srgb, var(--cat-colour) 10%, var(--bg-primary));
}

.test-item-main {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.test-item input[type="checkbox"] {
    display: none;
}

.test-checkbox-visual {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.test-item.selected .test-checkbox-visual {
    background: var(--cat-colour);
    border-color: var(--cat-colour);
}

.test-checkbox-visual::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0.5);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.test-item.selected .test-checkbox-visual::after {
    opacity: 1;
    transform: rotate(45deg) scale(1);
}

.test-item-info {
    flex: 1;
    min-width: 0;
}

.test-item-code {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--cat-colour);
    margin-right: 0.35em;
}

.test-item-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* =============================================================================
   SUB-OPTIONS
   ============================================================================= */

.test-suboptions {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding-top: 0;
    margin-top: 0;
    border-top: 1px dashed transparent;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease, margin 0.3s ease, border-color 0.3s ease;
}

.test-item.selected .test-suboptions {
    max-height: 150px;
    opacity: 1;
    padding-top: var(--space-sm);
    margin-top: var(--space-sm);
    border-top-color: var(--border-color);
}

.test-suboptions label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    display: block;
    font-weight: normal;
}

.suboption-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.suboption-checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.suboption-checkbox:hover {
    border-color: var(--cat-colour);
}

.suboption-checkbox.selected {
    background: var(--cat-colour);
    color: white;
    border-color: var(--cat-colour);
}

.suboption-checkbox input {
    display: none;
}

.suboption-text {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.85rem;
}


/* =============================================================================
   SUB-GROUP ACCORDIONS (collapsible test groups within a category)
   Purely a relocation of the checkbox — the .test-item markup inside is
   identical to the flat list, so selection/suboptions/validation are unchanged.
   Colours come from CSS vars (+ inline --cat-colour), so dark mode is covered.
   ============================================================================= */

.category-subgroups {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.subgroup-accordion {
    /* Indented + left accent vs the full-width flat grid, to signal nesting
       under the category level. */
    margin-left: var(--space-md);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--cat-colour);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    overflow: hidden;
}

.subgroup-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    min-height: 44px;            /* comfortable touch target on mobile */
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.subgroup-header:hover {
    background: rgba(0, 0, 0, 0.05);
}

.subgroup-accordion .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--cat-colour);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.subgroup-accordion.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.subgroup-label {
    min-width: 0;
}

/* Count badge: shown whenever the group has a selection (expanded or
   collapsed), hidden at zero. Guarantees a selection inside a collapsed group
   is never invisible, and gives at-a-glance feedback while expanded too. */
.subgroup-count {
    display: none;
    font-weight: 700;
    color: var(--cat-colour);
}

.subgroup-accordion.has-selected .subgroup-count {
    display: inline;
}

.subgroup-body {
    padding: var(--space-sm) var(--space-md) var(--space-md);
}

.subgroup-accordion.collapsed .subgroup-body {
    display: none;
}

@media (prefers-color-scheme: dark) {
    .subgroup-header:hover {
        background: rgba(255, 255, 255, 0.06);
    }
}

@media (max-width: 768px) {
    .subgroup-accordion {
        margin-left: var(--space-sm);
    }
    .subgroup-body {
        padding: var(--space-sm);
    }
}


/* =============================================================================
   SAMPLE CARDS
   ============================================================================= */

.samples-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.sample-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.sample-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.sample-header h4 {
    margin: 0;
    font-size: 0.95rem;
}

.sample-header-actions {
    display: flex;
    gap: var(--space-sm);
}

.sample-body {
    padding: var(--space-md);
}

.sample-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-md);
}

.sample-tests-section {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.sample-tests-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
}

.sample-actions {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}


/* =============================================================================
   SUMMARY TABLES
   ============================================================================= */

.summary-section {
    margin-top: var(--space-xl);
}

.summary-category {
    margin-bottom: var(--space-lg);
}

.summary-category-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}

.summary-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-size: 0.75rem;
}

.summary-legend-item {
    display: flex;
    gap: var(--space-xs);
}

.summary-legend-item .code {
    font-weight: 700;
}

.summary-legend-item .name {
    color: var(--text-secondary);
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.summary-table th,
.summary-table td {
    padding: var(--space-sm);
    border: 1px solid var(--border-color);
    text-align: center;
}

.summary-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.75rem;
}

/* Numeric-TestId catalogs have no readable short code, so the header shows the
   full test name rotated vertical — mirrors the CSV import preview and the
   report/PDF matrix. Colours come from CSS vars on the base rule above, so
   dark mode is already covered. */
.summary-table th.vname {
    vertical-align: bottom;
    text-align: center;
    padding: var(--space-sm) 2px;
}

/* The rotation lives on a child span, NOT the th itself. A th with a vertical
   writing-mode breaks vertical-align (the label centres instead of anchoring
   to the bottom). This is the same structure the CSV preview uses
   (th.rotate > .column-tag, csv_import.php). */
.summary-table th.vname .vname-label {
    display: inline-block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
}

/* Reserve header height only when vertical names are present, so short-code
   tables stay compact. Without this the rotated labels can overflow row 1. */
.summary-table.has-vnames thead tr {
    min-height: 140px;
}

/* Bottom-align every header cell in the tall vertical-header row so the
   rotated test names and the horizontal Sample/Description labels share a
   level bottom edge (matches the report/PDF matrix). */
.summary-table.has-vnames thead th {
    vertical-align: bottom;
}

.summary-table td:first-child {
    text-align: left;
    font-weight: 500;
}

.summary-table td.desc-cell {
    text-align: left;
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.summary-table .check {
    color: var(--accent-success);
    font-weight: bold;
}

.summary-table .check-with-option {
    color: var(--accent-primary);
    font-weight: bold;
}

.summary-mobile-card-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0 var(--space-sm);
    margin-bottom: var(--space-xs);
}


/* =============================================================================
   STATUS BADGES
   ============================================================================= */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.375rem;
    background: var(--accent-primary);
    color: white;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Status badges — every class returned by getOrderStatusClass() in
   templates/_func.php must have a colour rule here. Mapping:
     draft → status-draft           (uses theme vars, auto-themes)
     submitted → status-submitted
     pending_admin → status-pending
     pending_client → status-action
     approved → status-approved
     awaiting_samples → status-awaiting
     processing → status-processing
     complete → status-complete
     <unmapped fallback> → status-default
   Colours match classes/SummitLabReport.php so the on-screen badge,
   the order report, and the PDF render the same hue per status. */

.status-draft {
    background: var(--bg-tertiary);
    color: var(--status-draft);
}

.status-submitted {
    background: #fef3c7;
    color: #92400e;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-action {
    background: #fee2e2;
    color: #991b1b;
}

.status-approved {
    background: #d1fae5;
    color: #065f46;
}

.status-awaiting {
    background: #cffafe;
    color: #155e75;
}

.status-processing {
    background: #dbeafe;
    color: #1e40af;
}

.status-complete {
    background: #d1fae5;
    color: #065f46;
}

.status-default {
    background: #e5e7eb;
    color: #374151;
}

@media (prefers-color-scheme: dark) {
    /* status-draft is omitted on purpose — its light rule above uses
       theme variables (--bg-tertiary, --status-draft) which already
       follow the system colour scheme via :root overrides. */
    .status-submitted {
        background: #92400e;
        color: #fef3c7;
    }
    .status-pending {
        background: #78350f;
        color: #fef3c7;
    }
    .status-action {
        background: #7f1d1d;
        color: #fecaca;
    }
    .status-approved,
    .status-complete {
        background: #064e3b;
        color: #a7f3d0;
    }
    .status-awaiting {
        background: #155e75;
        color: #cffafe;
    }
    .status-processing {
        background: #1e3a8a;
        color: #bfdbfe;
    }
    .status-default {
        background: #374151;
        color: #e5e7eb;
    }
}


/* =============================================================================
   FORM ACTIONS
   ============================================================================= */

.form-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: space-between;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.form-actions-left,
.form-actions-right {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}


/* =============================================================================
   MODALS
   ============================================================================= */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: var(--space-xl);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 {
    margin-bottom: var(--space-md);
}

.modal-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
    margin-top: var(--space-lg);
}


/* =============================================================================
   TOAST NOTIFICATIONS
   ============================================================================= */

.toast {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    background: var(--accent-success);
    color: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1001;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    background: var(--accent-danger);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

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


/* =============================================================================
   MESSAGES
   ============================================================================= */

.message {
    padding: var(--space-md);
    border-radius: var(--radius);
    margin-bottom: var(--space-lg);
}

.message-success {
    background: #d1fae5;
    border: 1px solid #6ee7b7;
    color: #065f46;
}

.message-error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #991b1b;
}

.message-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
}

.message-info {
    background: #dbeafe;
    border: 1px solid #93c5fd;
    color: #1e40af;
}

.message ul {
    margin: var(--space-sm) 0 0 var(--space-lg);
}

@media (prefers-color-scheme: dark) {
    .message-success {
        background: #064e3b;
        border-color: #059669;
        color: #a7f3d0;
    }
    .message-error {
        background: #7f1d1d;
        border-color: #dc2626;
        color: #fecaca;
    }
    .message-warning {
        background: #78350f;
        border-color: #d97706;
        color: #fef3c7;
    }
    .message-info {
        background: #1e3a8a;
        border-color: #3b82f6;
        color: #bfdbfe;
    }
}


/* =============================================================================
   SPECIAL SECTIONS
   ============================================================================= */

.default-tests-section {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #93c5fd;
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.default-tests-section h3 {
    color: var(--accent-primary);
}

.default-tests-section > p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-md);
}

@media (prefers-color-scheme: dark) {
    .default-tests-section {
        background: linear-gradient(135deg, #1e3a5f 0%, #1e3a8a 100%);
        border-color: #3b82f6;
    }
    /* The heading uses --accent-primary (#2563eb), which is fine on the light
       panel but blue-on-blue against the dark-mode blue panel. Lighten it to a
       pale blue for contrast — same approach the amber .admin-notes-section
       uses (dark panel + pale heading). */
    .default-tests-section h3 {
        color: #bfdbfe;
    }
}

.template-section {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    border: 1px solid #d8b4fe;
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.template-section .section-header {
    cursor: pointer;
    user-select: none;
}

.template-section .section-header:hover {
    opacity: 0.9;
}

.template-section .section-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
}

.template-section .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #9333ea;
    transition: transform 0.3s ease;
}

.template-section.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.template-section .section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
    margin-top: var(--space-sm);
}

.template-section.collapsed .section-content {
    max-height: 0 !important;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
}

.template-actions {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    align-items: center;
}

.template-actions select {
    min-width: 200px;
}

.template-list {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-top: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
}

.template-list.open {
    max-height: 500px;
    opacity: 1;
    margin-top: var(--space-md);
}

.template-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
    transition: all 0.2s ease;
}

.template-list-item:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px var(--shadow);
}

.template-list-item:last-child {
    margin-bottom: 0;
}

/* Primary tab styling for "My Tests" - Gold/Amber */
.category-tab.primary {
    background: transparent;
    color: #d97706;
    border-color: #d97706;
    font-weight: 600;
}

.category-tab.primary:hover {
    background: rgba(217, 119, 6, 0.1);
    border-color: #b45309;
}

.category-tab.primary.active {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: white;
    border-color: #d97706;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}

.category-tab.primary .count {
    background: rgba(217, 119, 6, 0.15);
}

.category-tab.primary.active .count {
    background: rgba(255, 255, 255, 0.25);
}

.category-tab.primary .count.has-items {
    background: #d97706;
    color: white;
}

.category-tab.primary.active .count.has-items {
    background: rgba(255, 255, 255, 0.4);
}

/* My Tests panel header styling */
.category-panel[id*="-panel-ASSIGNED"] .category-panel-header h4 {
    color: #d97706;
}

/* Summary section styling for two-section layout */
.summary-category + .summary-category {
    margin-top: var(--space-lg);
}

/* My Tests summary header */
.summary-category-header {
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* My Tests summary header keeps its orange gradient — keyed to the ASSIGNED
   section by class (set in renderSummarySection), NOT by DOM position. The old
   `:first-child` selector painted whichever section rendered first orange, so a
   summary with only a general-category test selected (no My Tests) wrongly
   showed e.g. Chemistry in orange. Non-ASSIGNED sections keep their inline
   per-category palette colour, matching their tab pill. `!important` still
   needed to override the inline solid #d97706 with the gradient. */
.summary-category-assigned .summary-category-header {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important;
}

/* Ensure legend items wrap nicely */
.summary-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-size: 0.8rem;
}

.summary-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.summary-legend-item .code {
    font-weight: 700;
    font-family: monospace;
}

.summary-legend-item .name {
    color: var(--text-secondary);
}


/* =============================================================================
   COLLAPSIBLE SECTIONS
   ============================================================================= */

/* Default Tests Section - Collapsible */
.default-tests-section {
    position: relative;
}

.default-tests-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
    border-bottom: 2px solid #d97706;
}

.default-tests-section .section-header:hover {
    opacity: 0.9;
}

.default-tests-section .section-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
}

.default-tests-section .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #d97706;
    transition: transform 0.3s ease;
}

.default-tests-section.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.default-tests-section .section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

.default-tests-section.collapsed .section-content {
    max-height: 0 !important;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.default-tests-section .collapse-summary {
    display: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: var(--space-sm) 0;
}

.default-tests-section.collapsed .collapse-summary {
    display: block;
}

/* Sample Cards - Collapsible */
.sample-card {
    transition: box-shadow 0.2s ease;
}

.sample-card .sample-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.sample-card .sample-header:hover {
    background: var(--bg-tertiary);
}

.sample-card .sample-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

.sample-card .sample-header-left h4 {
    margin: 0;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sample-card .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-secondary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-right: var(--space-xs);
}

.sample-card.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.sample-card .sample-summary-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sample-card .sample-summary-badge.has-tests {
    background: rgba(37, 99, 235, 0.15);
    color: var(--accent-primary);
}
@media (prefers-color-scheme: dark) {
    /* --accent-primary (#2563eb) is too dim as text on the dark sample card.
       Lighten the expanded "has tests" chip to a pale blue (matches the
       default-tests heading fix). The mobile block (@media max-width:768px)
       uses solid accent-primary + white and is unaffected — it comes later in
       source order, so it still wins on small screens. */
    .sample-card .sample-summary-badge.has-tests {
        background: rgba(96, 165, 250, 0.2);
        color: #bfdbfe;
    }
}

.sample-card .sample-body {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
    padding: var(--space-md);
}

.sample-card.collapsed .sample-body {
    max-height: 0 !important;
    opacity: 0;
    padding: 0 var(--space-md);
}

/* Collapsed sample shows summary badge prominently */
.sample-card.collapsed .sample-summary-badge {
    background: var(--accent-primary);
    color: white;
}

/* Sample expand/collapse all buttons */
.samples-collapse-controls {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.samples-collapse-controls .btn {
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}


/* Summary section styling for two-section layout */
.summary-category + .summary-category {
    margin-top: var(--space-lg);
}

/* My Tests summary header */
.summary-category-header {
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* My Tests summary header keeps its orange gradient — keyed to the ASSIGNED
   section by class (set in renderSummarySection), NOT by DOM position. The old
   `:first-child` selector painted whichever section rendered first orange, so a
   summary with only a general-category test selected (no My Tests) wrongly
   showed e.g. Chemistry in orange. Non-ASSIGNED sections keep their inline
   per-category palette colour, matching their tab pill. `!important` still
   needed to override the inline solid #d97706 with the gradient. */
.summary-category-assigned .summary-category-header {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important;
}

/* Ensure legend items wrap nicely */
.summary-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-size: 0.8rem;
}

.summary-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.summary-legend-item .code {
    font-weight: 700;
    font-family: monospace;
}

.summary-legend-item .name {
    color: var(--text-secondary);
}


/* Loading state — shown while lazy-rendering test tabs on first expand */
.sample-card.sample-loading {
    cursor: wait;
}

.sample-card.sample-loading .sample-summary-badge {
    display: none;
}

.sample-card.sample-loading .sample-title-text::after {
    content: ' \2014 loading\2026';
    font-weight: 400;
    color: var(--text-secondary);
    animation: loading-pulse 1s ease-in-out infinite;
}

@keyframes loading-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* Shown above #samples-list while drafts/templates with many samples load */
.samples-loading-overlay {
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    justify-content: center;
}

.samples-loading-inner {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    color: var(--text-secondary);
    font-weight: 600;
}

.samples-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary, #0366d6);
    border-radius: 50%;
    animation: samples-loading-spin 0.8s linear infinite;
}

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

/* Full-viewport busy overlay used by saveDraft / submitOrder / saveAsTemplate
   while the synchronous tab-rendering + serialize work runs for large orders. */
.page-busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.page-busy-overlay.visible { display: flex; }

.page-busy-inner {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-xl, 2rem);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.page-busy-text { white-space: nowrap; }

/* Sticky group navigation bar */
.sticky-group-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: rgba(30, 30, 30, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.sticky-group-bar.hidden {
    display: none;
}

@media (min-width: 1025px) {
    .sticky-group-bar {
        display: none !important;
    }
    #samples-list.has-sticky-bar {
        padding-bottom: 0;
    }
}

.sticky-group-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.4rem 1rem;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}

.sticky-group-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sticky-group-chevron {
    transition: transform 0.2s ease;
}

.group-picker-popup {
    position: absolute;
    bottom: calc(100% + var(--space-sm));
    left: 50%;
    transform: translateX(-50%);
    min-width: 260px;
    max-width: 90vw;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.group-picker-popup.hidden {
    display: none;
}

.group-picker-row {
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.group-picker-row:last-child {
    border-bottom: none;
}

.group-picker-row:hover {
    background: var(--bg-secondary);
}

/* Bottom padding when sticky bar is visible */
#samples-list.has-sticky-bar {
    padding-bottom: 56px;
}


/* =============================================================================
   SAMPLE GROUPS (bulk add auto-grouping)
   ============================================================================= */

.sample-group {
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: var(--space-md);
    background: var(--bg-secondary);
}

.sample-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 1rem;
    border-radius: var(--radius);
}

.sample-group-header:hover {
    background: rgba(0, 0, 0, 0.03);
}

.sample-group .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-secondary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.sample-group.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.sample-group-count {
    margin-left: auto;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
}

.sample-group-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: 0 var(--space-md) var(--space-md);
}

.sample-group.collapsed .sample-group-body {
    display: none;
}

/* Summary groups (mirrors sample groups in summary section) */
.summary-group {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: var(--space-md);
    overflow: hidden;
}

.summary-group-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    background: var(--bg-secondary);
}

.summary-group-header:hover {
    background: rgba(0, 0, 0, 0.05);
}

.summary-group .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-secondary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.summary-group.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.summary-group-body {
    padding: var(--space-md);
}

.summary-group.collapsed .summary-group-body {
    display: none;
}

@media (prefers-color-scheme: dark) {
    .sample-group-header:hover {
        background: rgba(255, 255, 255, 0.05);
    }
    .summary-group-header:hover {
        background: rgba(255, 255, 255, 0.08);
    }
}


@media (prefers-color-scheme: dark) {
    .template-section {
        background: linear-gradient(135deg, #2e1065 0%, #3b0764 100%);
        border-color: #d97706;
    }
}

.admin-notes-section {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.admin-notes-section h3 {
    color: #92400e;
}

@media (prefers-color-scheme: dark) {
    .admin-notes-section {
        background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
        border-color: #f59e0b;
    }
    .admin-notes-section h3 {
        color: #fef3c7;
    }
}


/* =============================================================================
   RESPONSIVE
   ============================================================================= */

@media (max-width: 768px) {
    .container {
        padding: var(--space-md);
    }
    
    .sample-grid {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions-left,
    .form-actions-right {
        width: 100%;
        justify-content: stretch;
    }
    
    .form-actions .btn {
        width: 100%;
    }
    
    .tests-grid {
        grid-template-columns: 1fr;
    }
    
    .category-tabs {
        flex-direction: column;
    }
    
    .category-tab {
        justify-content: space-between;
    }
}
/* =============================================================================
   ADD THESE STYLES TO summit-lab.css
   CSS additions for "My Tests" / "General Tests" two-section layout
   + Collapsible sections
   ============================================================================= */

/* =============================================================================
   COLLAPSIBLE SECTIONS
   ============================================================================= */

/* Default Tests Section - Collapsible */
.default-tests-section {
    position: relative;
}

.default-tests-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
    border-bottom: 2px solid #d97706;
}

.default-tests-section .section-header:hover {
    opacity: 0.9;
}

.default-tests-section .section-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
}

.default-tests-section .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #d97706;
    transition: transform 0.3s ease;
}

.default-tests-section.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.default-tests-section .section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

.default-tests-section.collapsed .section-content {
    max-height: 0 !important;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.default-tests-section .collapse-summary {
    display: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: var(--space-sm) 0;
}

.default-tests-section.collapsed .collapse-summary {
    display: block;
}

/* Sample Cards - Collapsible */
.sample-card {
    transition: box-shadow 0.2s ease;
}

.sample-card .sample-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.sample-card .sample-header:hover {
    background: var(--bg-tertiary);
}

.sample-card .sample-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

.sample-card .sample-header-left h4 {
    margin: 0;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sample-card .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-secondary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-right: var(--space-xs);
}

.sample-card.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.sample-card .sample-summary-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sample-card .sample-summary-badge.has-tests {
    background: rgba(37, 99, 235, 0.15);
    color: var(--accent-primary);
}
@media (prefers-color-scheme: dark) {
    /* --accent-primary (#2563eb) is too dim as text on the dark sample card.
       Lighten the expanded "has tests" chip to a pale blue (matches the
       default-tests heading fix). The mobile block (@media max-width:768px)
       uses solid accent-primary + white and is unaffected — it comes later in
       source order, so it still wins on small screens. */
    .sample-card .sample-summary-badge.has-tests {
        background: rgba(96, 165, 250, 0.2);
        color: #bfdbfe;
    }
}

.sample-card .sample-body {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
    padding: var(--space-md);
}

.sample-card.collapsed .sample-body {
    max-height: 0 !important;
    opacity: 0;
    padding: 0 var(--space-md);
}

/* Collapsed sample shows summary badge prominently */
.sample-card.collapsed .sample-summary-badge {
    background: var(--accent-primary);
    color: white;
}

/* Sample expand/collapse all buttons */
.samples-collapse-controls {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.samples-collapse-controls .btn {
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}


/* Summary section styling for two-section layout */
.summary-category + .summary-category {
    margin-top: var(--space-lg);
}

/* My Tests summary header */
.summary-category-header {
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* My Tests summary header keeps its orange gradient — keyed to the ASSIGNED
   section by class (set in renderSummarySection), NOT by DOM position. The old
   `:first-child` selector painted whichever section rendered first orange, so a
   summary with only a general-category test selected (no My Tests) wrongly
   showed e.g. Chemistry in orange. Non-ASSIGNED sections keep their inline
   per-category palette colour, matching their tab pill. `!important` still
   needed to override the inline solid #d97706 with the gradient. */
.summary-category-assigned .summary-category-header {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important;
}

/* Ensure legend items wrap nicely */
.summary-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-size: 0.8rem;
}

.summary-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.summary-legend-item .code {
    font-weight: 700;
    font-family: monospace;
}

.summary-legend-item .name {
    color: var(--text-secondary);
}

/* =============================================================================
   MOBILE SUMMARY CARDS
   ============================================================================= */

/* Desktop: show table, hide mobile cards */
.summary-table-wrapper {
    display: block;
    overflow-x: auto;
}

.summary-mobile-cards {
    display: none;
}

/* Mobile: hide table, show cards */
@media (max-width: 768px) {
    .summary-table-wrapper {
        display: none;
    }
    
    .summary-mobile-cards {
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
    }
    
    .summary-mobile-card {
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        overflow: hidden;
    }
    
    .summary-mobile-card-header {
        background: var(--bg-secondary);
        padding: var(--space-sm) var(--space-md);
        font-weight: 600;
        border-bottom: 1px solid var(--border-color);
    }
    
    .summary-mobile-card-header a {
        color: var(--accent-primary);
        text-decoration: none;
    }
    
    .summary-mobile-card-header a:hover {
        text-decoration: underline;
    }
    
    .summary-mobile-card-tests {
        padding: var(--space-sm) var(--space-md);
        display: flex;
        flex-direction: column;
        gap: var(--space-xs);
    }
    
    .summary-mobile-test {
        display: flex;
        align-items: baseline;
        gap: var(--space-sm);
        padding: var(--space-xs) 0;
        border-bottom: 1px dashed var(--border-color);
        font-size: 0.9rem;
    }
    
    .summary-mobile-test:last-child {
        border-bottom: none;
    }
    
    .summary-mobile-test .code {
        font-weight: 700;
        font-family: monospace;
        min-width: 60px;
    }
    
    .summary-mobile-test .name {
        color: var(--text-secondary);
        flex: 1;
    }
    
    /* Compact legend on mobile */
    .summary-legend {
        font-size: 0.75rem;
        padding: var(--space-xs) var(--space-sm);
    }
    
    .summary-legend-item {
        font-size: 0.7rem;
    }
    
    /* Mobile sample header layout */
    .sample-card .sample-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-sm);
        padding: var(--space-sm);
    }
    
    .sample-card .sample-header-left {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-xs);
        width: 100%;
    }
    
    .sample-card .sample-header-left h4 {
        font-size: 1rem;
        display: inline-flex;
        align-items: center;
        gap: var(--space-sm);
    }
    
    .sample-card .sample-summary-badge {
        font-size: 0.8rem;
        padding: var(--space-xs) var(--space-sm);
        flex-basis: 100%;
        text-align: left;
        border-radius: var(--radius-sm);
        background: var(--bg-secondary);
    }
    
    .sample-card .sample-summary-badge.has-tests {
        background: var(--accent-primary);
        color: white;
    }
    
    .sample-card .sample-header-actions {
        display: flex;
        gap: var(--space-xs);
        width: 100%;
    }
    
    .sample-card .sample-header-actions .btn {
        flex: 1;
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.8rem;
    }
    
    /* When collapsed - cleaner display */
    .sample-card.collapsed .sample-header {
        padding: var(--space-sm);
    }
    
    .sample-card.collapsed .sample-header-actions {
        display: none;
    }
    
    .sample-card.collapsed .sample-summary-badge {
        font-size: 0.85rem;
        padding: var(--space-sm);
    }
}


.category-panel[id*="-panel-ASSIGNED"] .test-item {
    --cat-colour: #d97706 !important;
}

/* =============================================================================
   ORDER FORM INSTRUCTIONS — collapsible info panel at top of create_order.php
   ============================================================================= */
.instructions-section {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-info);
    border-radius: var(--radius);
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-lg);
}

.instructions-section .section-header {
    cursor: pointer;
    user-select: none;
}

.instructions-section .section-header:hover {
    opacity: 0.9;
}

.instructions-section .section-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
    color: var(--text-primary);
}

.instructions-section .collapse-indicator {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--accent-info);
    transition: transform 0.3s ease;
}

.instructions-section.collapsed .collapse-indicator {
    transform: rotate(-90deg);
}

.instructions-section .section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    overflow: hidden;
    margin-top: var(--space-sm);
    color: var(--text-primary);
    line-height: 1.5;
}

.instructions-section .section-content > *:first-child {
    margin-top: 0;
}

.instructions-section .section-content > *:last-child {
    margin-bottom: 0;
}

.instructions-section.collapsed .section-content {
    max-height: 0 !important;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
}