/* ==========================================================================
   THEATRE WHITEBOARD LAYOUT

   A responsive CSS Grid layout for NHS Theatre Team Briefing boards.

   KEY DESIGN DECISIONS:
   ----------------------
   1. Uses CSS Grid with 'fr' (fractional) units for automatic responsive scaling
   2. No media queries needed for the patient grid - it adapts to any screen width
   3. Checkbox state colors use specificity-aware selectors (no !important needed)
   4. Column proportions are defined once and apply to both header and rows

   COLUMN LAYOUT:
   --------------
   - Patient info columns (Name, Unit, Procedure): Larger share (2fr-2.2fr)
   - Checkbox columns: Equal small share (0.8fr)
   - Dropdown columns: Medium share (0.9fr-1.3fr)
   - Comments column: Largest share (4fr)

   CHECKBOX STATE HIERARCHY:
   -------------------------
   - .checkbox-blank: White/grey background (zebra striping on even positions)
   - .checkbox-tick: Green background (#007F3B)
   - .checkbox-cross: Red background (#DA291C)

   ========================================================================== */

/* ==========================================================================
   CORE CONTAINER STYLES
   ========================================================================== */

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 5px;
    background-color: var(--nhs-white);
    min-height: 100vh;
    overflow-x: hidden;
    /* Prevent page-level horizontal scroll */
}

/* ==========================================================================
   HEADER STYLES - Compact (30% smaller)
   ========================================================================== */

.header {
    background-color: var(--nhs-green);
    padding: 0.7vw 1.05vw;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35vw;
    border-radius: var(--border-radius);
    min-height: 1.75vw;
}

.header-left h1 {
    margin: 0;
    font-size: 1.2vw;
    letter-spacing: 0.07vw;
    line-height: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.7vw;
    color: var(--nhs-white);
    font-weight: 700;
    font-size: 1.2vw;
}

.nhs-logo {
    height: 1.8vw;
    background: white;
    padding: 0.2vw 0.4vw;
    border-radius: 0.21vw;
}

.subtitle {
    font-size: 1.2vw;
}

/* ==========================================================================
   CONTROLS AND DATE DISPLAY - Compact (30% smaller)
   ========================================================================== */

.controls {
    display: flex;
    gap: 0.42vw;
    margin-bottom: 0.28vw;
    flex-wrap: nowrap;
    align-items: center;
}

.controls .btn {
    padding: 0.2vw 0.5vw;
    font-size: 0.7vw;
    font-weight: 700;
    min-height: 1.6vw;
    touch-action: manipulation;
}

.controls .btn-remove {
    background: #fff;
    color: #d32f2f;
    border: 1px solid #d32f2f;
    font-size: 0.6vw;
    padding: 0.15vw 0.4vw;
    min-height: 1.4vw;
}

.controls .btn-remove:hover {
    background: #d32f2f;
    color: #fff;
}

.date-display {
    margin-left: auto;
    font-size: 0.98vw;
    font-weight: 700;
    color: var(--nhs-blue);
}

/* ==========================================================================
   TEAM SECTION STYLES - Compact (30% smaller)
   ========================================================================== */

.team-section {
    background-color: var(--nhs-grey-5);
    padding: 0.2vw 0.6vw;
    margin-bottom: 0.3vw;
    border-radius: var(--border-radius);
    border: 0.1vw solid var(--nhs-blue);
}

.team-section h2 {
    font-size: 0.8vw;
    font-weight: 700;
    margin: 0 0 0.1vw 0;
    color: var(--nhs-blue);
}

.team-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.1vw 0.3vw;
    margin-bottom: 0.1vw;
}

.team-column {
    display: contents;
}

.team-role {
    display: flex;
    flex-direction: column;
    gap: 0.04vw;
}

.team-role label {
    font-size: 1vw;
    color: var(--nhs-black);
    font-weight: 800;
    line-height: 1.1;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.team-input {
    padding: 0.1vw 0.15vw;
    font-size: 1.2vw !important;
    border: 1px solid var(--nhs-grey-3);
    border-radius: 2px;
    height: 1.8vw;
    min-height: 0;
    max-height: 1.8vw;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.team-input:focus {
    border-color: var(--nhs-blue);
    outline: 2px solid var(--nhs-yellow);
}

/* ==========================================================================
   LUNCH BREAK AND THEATRE ROOM SELECTOR
   ========================================================================== */

/* Lunch break dropdown — compact frame, clear text, inline */
.lunch-break-select {
    padding: 0.2vw 0.4vw;
    font-size: 0.7vw;
    font-weight: 700;
    border: 0.06vw solid var(--nhs-grey-3);
    border-radius: 0.15vw;
    background-color: var(--nhs-white);
    cursor: pointer;
    width: auto;
    min-height: 1.6vw;
    touch-action: manipulation;
    flex-shrink: 0;
}

.lunch-break-select:focus {
    border-color: var(--nhs-blue);
    outline: 2px solid var(--nhs-yellow);
}

/* Theatre room selector — compact frame, bold text, inline */
.theatre-room-selector {
    padding: 0.2vw 0.4vw;
    font-size: 0.8vw;
    font-weight: 800;
    border: 0.06vw solid var(--nhs-grey-3);
    border-radius: 0.15vw;
    background-color: var(--nhs-white);
    cursor: pointer;
    width: auto;
    min-height: 1.6vw;
    touch-action: manipulation;
    flex-shrink: 0;
}

.theatre-room-selector:focus {
    border-color: var(--nhs-blue);
    outline: 2px solid var(--nhs-yellow);
}

/* ==========================================================================
   PATIENT SECTION - Scrollable container
   ========================================================================== */

.patient-section {
    margin-bottom: 30px;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   PATIENT GRID - Responsive Column Layout

   Uses minmax(MIN, FR) to create fluid columns that:
   - Scale proportionally to available space
   - Never shrink below minimum readable width
   - Automatically fill any screen width
   ========================================================================== */

/* ==========================================================================
   PATIENT GRID HEADER — Matching the Physical Whiteboard

   The physical NHS Theatre Team Briefing whiteboard has:
   - 3 info columns (Name, Unit, Procedure) with solid blue background
   - 16 checklist columns with alternating pale blue / stronger blue bands
   - Text labels rotated ~50 degrees, anchored at BOTTOM-LEFT of each column
   - A thick black horizontal line separates header from data rows
   - CRITICAL: Header columns must align EXACTLY with the patient data
     columns below, so each label sits directly above its data cell

   The background bands fill each grid cell exactly (no overflow/skew)
   so they line up perfectly with the data columns underneath.
   The text is rotated and anchored at the bottom-left corner of each cell.
   ========================================================================== */

.patient-grid-header {
    display: grid;
    /* SAME column template as .patient-row — they MUST match exactly */
    grid-template-columns:
        1.8fr 1.3fr 2.2fr
        /* Name, Unit, Proc */
        0.8fr 0.8fr 1.2fr
        /* Order, Side, Transfer */
        0.8fr 0.8fr 0.8fr
        /* Anaesth Review, Allergies, Infection */
        1.2fr 0.8fr 1.1fr
        /* Antibiotic, Equipment, Blood */
        0.8fr 1.2fr 1.3fr
        /* Imaging, Positioning, Post-op */
        1.1fr 0.7fr 0.8fr
        /* Tourniquet, ASA, Flowtrons */
        4fr;
    /* Comments */
    width: 100%;
    min-width: 0;
    gap: 0;
    border-bottom: 3px solid #000;
    align-items: stretch;
    background: white;
    font-weight: 700;
    overflow: hidden;
}

/* --- Info columns (Name, Unit, Procedure) ---
   Solid blue background with white text, horizontal layout.
   These match the left section of the physical whiteboard. */
.header-cell.info-col {
    background-color: #005EB8;
    color: white;
    font-weight: 700;
    font-size: 1.1vw;
    padding: 8px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 10vw;
    border-right: 2px solid rgba(255, 255, 255, 0.3);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    line-height: 1.2;
    z-index: 2;
    position: relative;
}

/* Last info column gets a stronger right border to separate from angled section */
.header-cell.info-col-last {
    border-right: 3px solid #000;
}

/* --- Angled columns (checklist/data columns) ---
   The ENTIRE CELL is skewed to form a parallelogram, so the background
   colour and the text are part of the same skewed shape.
   - transform-origin: bottom center — the BOTTOM edge stays aligned
     with the straight data columns below
   - skewX(-25deg) — the top leans right, creating the diagonal band
   The text inside is then COUNTER-ROTATED so it reads at the
   correct angle running through the middle of the band.
   ------------------------------------------------------------ */
.header-cell.angled-col {
    position: relative;
    min-height: 10vw;
    overflow: visible;
    padding: 0;
    border: none;
    /* Skew the ENTIRE cell — background + text move together */
    transform-origin: bottom center;
    transform: skewX(-25deg);
    /* Borders between the skewed bands */
    border-right: 2px solid rgba(255, 255, 255, 0.8);
    border-left: 1px solid rgba(255, 255, 255, 0.4);
}

/* Alternating stripe colours — applied directly to the skewed cell.
   Light = pale blue, Dark = slightly stronger blue
   Matches the physical whiteboard's alternating column bands */
.header-cell.angled-col.stripe-light {
    background-color: #D0E2F0;
}

.header-cell.angled-col.stripe-dark {
    background-color: #AECCE2;
}

/* The text label — sits INSIDE the skewed cell, so it's already
   part of the parallelogram. We counter-rotate it so it reads
   diagonally through the centre of the band.
   The skew is -25deg, and we want text at about -55deg from horizontal,
   so the rotation inside the skewed cell = -55 + 25 = -30deg
   (since the cell is already skewed -25deg).
   Text is BIG (0.95vw) for readability on the 94.5" touchscreen. */
.header-cell.angled-col .col-label {
    position: absolute;
    top: 50%;
    left: 50%;
    /* Counter-skew (+25deg) undoes the cell skew, then rotate(-65deg) aligns
       text exactly along the parallelogram's edge (90 - 25 = 65 from horizontal) */
    transform: translate(-50%, -50%) skewX(25deg) rotate(-65deg);
    white-space: nowrap;
    font-size: 0.95vw;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1;
    letter-spacing: 0.01em;
}

/* --- Comments column ---
   White background, straight (no skew), horizontal text.
   Styled like the info columns but white. */
.header-cell.comments-col {
    background-color: white;
    color: #1a1a1a;
    font-weight: 700;
    font-size: 1vw;
    padding: 8px 6px 8px 1.5vw;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    text-align: left;
    min-height: 10vw;
    border-right: none;
    border-left: 2px solid rgba(200, 200, 200, 0.6);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    line-height: 1.2;
    transform: none;
    padding-bottom: 1.5vw;
}

/* ==========================================================================
   PATIENT ROW - Uses same column layout as header
   ========================================================================== */

.patient-row {
    display: grid;
    grid-template-columns:
        1.8fr 1.3fr 2.2fr
        /* Name, Unit, Proc */
        0.8fr 0.8fr 1.2fr
        /* Order, Side, Transfer */
        0.8fr 0.8fr 0.8fr
        /* Checkboxes */
        1.2fr 0.8fr 1.1fr
        /* Antibiotic, Equip, Blood */
        0.8fr 1.2fr 1.3fr
        /* Imaging, Pos, Post-op */
        1.1fr 0.7fr 0.8fr
        /* Tourniquet, ASA, Flowtrons */
        4fr;
    /* Comments */
    width: 100%;
    min-width: 0;
    gap: 0;
    padding: 0;
    background-color: var(--nhs-white);
    border: 2px solid var(--nhs-grey-4);
    border-top: none;
    align-items: stretch;
    transition: all 0.3s ease;
    min-height: 60px;
}

.patient-row:hover {
    background-color: var(--nhs-grey-5);
}

.patient-row.focused {
    border: 3px solid var(--nhs-blue);
    background-color: var(--nhs-white);
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 94, 184, 0.2);
    z-index: 10;
}

.patient-row.hidden {
    opacity: 0.3;
    pointer-events: none;
}

/* Dragging state for patient row reordering */
.patient-row.dragging {
    opacity: 0.6;
    border: 2px dashed var(--nhs-blue);
    background-color: rgba(0, 94, 184, 0.1);
}

/* Drag-over state for drop target indication */
.patient-row.drag-over {
    border-top: 4px solid var(--nhs-blue);
}

/* ==========================================================================
   PATIENT CELL STYLING
   ========================================================================== */

.patient-cell {
    padding: 4px;
    border-right: 1px solid var(--nhs-grey-3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    background-color: var(--nhs-white);
}

/* Checkbox cells need to fill entire height and center content */
.patient-cell.checklist-cell.checkbox-cell {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Alternating column stripe backgrounds in patient rows ---
   Continues the header's pale/stronger blue banding down through the data.
   Columns 4,6,8,10,12,14,16,18 = stripe-light (child indices are 1-based)
   Columns 5,7,9,11,13,15,17 = stripe-dark
   Columns 1-3 (info) and 19 (comments) have no stripe */
.patient-row > .patient-cell:nth-child(4),
.patient-row > .patient-cell:nth-child(6),
.patient-row > .patient-cell:nth-child(8),
.patient-row > .patient-cell:nth-child(10),
.patient-row > .patient-cell:nth-child(12),
.patient-row > .patient-cell:nth-child(14),
.patient-row > .patient-cell:nth-child(16),
.patient-row > .patient-cell:nth-child(18) {
    background-color: #EEF4FA;
}

.patient-row > .patient-cell:nth-child(5),
.patient-row > .patient-cell:nth-child(7),
.patient-row > .patient-cell:nth-child(9),
.patient-row > .patient-cell:nth-child(11),
.patient-row > .patient-cell:nth-child(13),
.patient-row > .patient-cell:nth-child(15),
.patient-row > .patient-cell:nth-child(17) {
    background-color: #E3EDF6;
}

/* Patient info cells (name, unit, procedure) */
.patient-cell.patient-name-cell,
.patient-cell.patient-unit-cell,
.patient-cell.patient-proc-cell {
    border-right: 2px solid var(--nhs-grey-3);
}

.patient-cell.patient-proc-cell {
    border-right: 2px solid var(--nhs-grey-4);
}

/* Patient info textareas */
.patient-cell textarea {
    width: 100%;
    padding: 0;
    font-size: var(--font-size-md);
    font-weight: 600;
    border: none;
    border-radius: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    font-family: inherit;
    resize: none;
    overflow: hidden;
    line-height: 1.4;
    background: transparent;
    text-align: center;
}

/* Dropdown cells */
.patient-cell.dropdown-cell select,
.patient-cell.dropdown-cell input[type="text"],
.patient-cell.dropdown-cell input[type="number"] {
    width: 100%;
    padding: 4px 6px;
    font-size: 20px;
    font-weight: 600;
    border: 2px solid var(--nhs-grey-3);
    border-radius: 4px;
    background-color: var(--nhs-white);
    cursor: pointer;
    text-align: center;
}

.patient-cell.dropdown-cell select:focus,
.patient-cell.dropdown-cell input:focus {
    border-color: var(--nhs-blue);
    outline: 2px solid var(--nhs-yellow);
}

/* Checkbox cells */
.patient-cell.checkbox-cell {
    padding: 8px;
    cursor: pointer;
    position: relative;
}

/* Comments cell */
.patient-cell.comments-cell {
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-left: 2px solid var(--nhs-grey-4);
    border-right: none;
    position: relative;
}

/* Small remove button — sits at top-right of comments cell */
.patient-remove-btn {
    position: absolute !important;
    top: 2px;
    right: 2px;
    width: 1.4vw !important;
    height: 1.4vw !important;
    min-height: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    font-size: 1vw !important;
    font-weight: 900;
    line-height: 1;
    border-radius: 50%;
    background: transparent !important;
    color: #d32f2f !important;
    border: none !important;
    opacity: 0.85;
    transition: opacity 0.2s ease, color 0.2s ease;
    z-index: 5;
    cursor: pointer;
    text-shadow: 0 0 1px #d32f2f;
}

.patient-remove-btn:hover {
    opacity: 1;
    color: #b71c1c !important;
    text-shadow: 0 0 2px #b71c1c;
}

.patient-cell.comments-cell textarea {
    width: 100% !important;
    align-self: stretch !important;
    max-width: none !important;
    min-width: 100% !important;
    min-height: 50px;
    padding: 8px !important;
    margin: 0 !important;
    border: none;
    border-radius: 0;
    box-sizing: border-box !important;
    text-align: left;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
}

/* ==========================================================================
   RESPONSIVE SIZING VIA VIEWPORT UNITS (vw)
   ========================================================================== */

.patient-row {
    font-size: 1.1vw;
}

/* Header text sizes are set in the header section above:
   - Info columns: 1.1vw (in .header-cell.info-col)
   - Angled column labels: 0.95vw (in .angled-col .col-label)
   Both scale with viewport for the 94.5" touchscreen */

.patient-row .patient-cell textarea {
    padding: 0.3vw;
    font-size: 1.1vw;
}

/* Narrow column text in rows — still readable */
.patient-row>.patient-cell:nth-child(4) select,
.patient-row>.patient-cell:nth-child(5) select,
.patient-row>.patient-cell:nth-child(17) input,
.patient-row>.patient-cell:nth-child(18) {
    font-size: 0.9vw !important;
}

.patient-row .checkbox-cell {
    min-height: 5vw;
    font-size: 1.8vw;
}

.patient-row .checkbox-cell.checkbox-tick::after,
.patient-row .checkbox-cell.checkbox-cross::after {
    font-size: 2.8vw !important;
}

.patient-row .checkbox-cell.checkbox-na::after {
    font-size: 1.2vw !important;
    font-weight: 900 !important;
}

/* Dropdown text scaling */
.patient-cell.dropdown-cell select,
.patient-cell.dropdown-cell input[type="text"],
.patient-cell.dropdown-cell input[type="number"] {
    font-size: 1vw;
    padding: 0;
    height: 100%;
    width: 100%;
}

/* ==========================================================================
   CHECKBOX STYLING - Touch-friendly with tick/cross symbols
   ========================================================================== */

.checkbox-cell {
    width: 100%;
    height: 100%;
    min-height: 5vw;
    border: none;
    border-right: 1px solid var(--nhs-grey-3);
    border-radius: 0;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-weight: 700;
    font-size: 1.8vw;
    user-select: none;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.checkbox-cell:hover {
    opacity: 0.9;
}

.checkbox-cell:active {
    opacity: 0.8;
    animation: checkbox-ripple 0.6s ease-out;
}

/* Touch ripple effect animation for 94.5" screen */
@keyframes checkbox-ripple {
    0% {
        box-shadow: inset 0 0 0 0 rgba(0, 94, 184, 0.4);
    }
    100% {
        box-shadow: inset 0 0 0 40px rgba(0, 94, 184, 0);
    }
}

/* Blank state - white background by default */
.checkbox-cell.checkbox-blank {
    background-color: var(--nhs-white);
}

.checkbox-cell.checkbox-blank::after {
    content: '';
}

/* Zebra striping for blank checkboxes uses the column stripe colours.
   When checkbox state changes to tick/cross, .checkbox-blank is removed,
   so this rule no longer matches and the state color shows cleanly. */
.patient-row > .checkbox-cell.checkbox-blank:nth-child(even) {
    background-color: #EEF4FA;
}

.patient-row > .checkbox-cell.checkbox-blank:nth-child(odd) {
    background-color: #E3EDF6;
}

/* Tick state - green tick on white background */
.checkbox-cell.checkbox-tick {
    background-color: var(--nhs-white);
}

.checkbox-cell.checkbox-tick::after {
    content: '✓';
    color: var(--nhs-green);
    font-size: 2.8vw;
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Cross state - red cross on white background */
.checkbox-cell.checkbox-cross {
    background-color: var(--nhs-white);
}

.checkbox-cell.checkbox-cross::after {
    content: '✗';
    color: var(--nhs-red);
    font-size: 2.8vw;
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* N/A state - grey text on white background, sized to fit the cell */
.checkbox-cell.checkbox-na {
    background-color: var(--nhs-white);
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-cell.checkbox-na::after {
    content: 'N/A';
    color: #777;
    font-size: 1.2vw;
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}

/* ==========================================================================
   DRAG HANDLE FOR PATIENT ROW REORDERING
   ========================================================================== */

.drag-handle {
    cursor: grab;
    padding: 0 0.5vw;
    font-size: 1.2vw;
    color: var(--nhs-grey-2);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none;
    min-height: 5vw;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drag-handle:active {
    cursor: grabbing;
    color: var(--nhs-blue);
}

/* ==========================================================================
   NOTE INDICATOR
   ========================================================================== */

.note-indicator {
    position: absolute;
    top: 1px;
    right: 1px;
    font-size: 1.5vw;
    opacity: 1;
    pointer-events: none;
    z-index: 5;
    background-color: white;
    border-radius: 50%;
    padding: 1px;
    line-height: 1;
}

/* ==========================================================================
   COLUMN RESIZE HANDLE
   ========================================================================== */

.column-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none;
    background-color: transparent;
    transition: background-color 0.2s ease;
}

.column-resize-handle:hover {
    background-color: var(--nhs-blue);
}

.column-resize-handle:active {
    background-color: var(--nhs-blue);
}


/* ==========================================================================
   CUSTOM MODAL SYSTEM - Replaces browser alert/confirm/prompt
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    flex-direction: column;
}

.modal-box {
    background-color: var(--nhs-white);
    border-radius: var(--border-radius);
    min-width: 400px;
    max-width: 600px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: modal-slide-in 0.3s ease-out;
}

@keyframes modal-slide-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    background-color: var(--nhs-green);
    color: var(--nhs-white);
    padding: 1vw 1.5vw;
    font-size: 1.1vw;
    font-weight: 700;
}

.modal-body {
    padding: 1.2vw 1.5vw;
    font-size: 0.9vw;
    line-height: 1.6;
    color: var(--nhs-black);
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    flex-direction: row;
    gap: 0.8vw;
    padding: 1vw 1.5vw;
    background-color: var(--nhs-grey-5);
    justify-content: flex-end;
}

.modal-footer .btn {
    min-height: 60px;
    min-width: 120px;
    font-size: 0.85vw;
    padding: 0.6vw 1.2vw;
}

/* Modal input for prompt-style modals */
.modal-input {
    width: 100%;
    padding: 0.6vw 0.8vw;
    font-size: 0.9vw;
    border: 1px solid var(--nhs-grey-3);
    border-radius: 0.3vw;
    margin: 0.6vw 0;
    box-sizing: border-box;
    font-family: inherit;
    min-height: 3vw;
}

.modal-input:focus {
    border-color: var(--nhs-blue);
    outline: 2px solid var(--nhs-yellow);
}

/* ==========================================================================
   DARK MODE STYLES
   ========================================================================== */

body.dark-mode .container {
    background-color: #1a1a1a;
}

body.dark-mode .header {
    background-color: #004d2c;
}

body.dark-mode .team-section {
    background-color: #2a2a2a;
    border-color: #3a5f7f;
}

body.dark-mode .team-section h2 {
    color: #5eb3d6;
}

body.dark-mode .team-input {
    background-color: #2a2a2a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .team-input::placeholder {
    color: #808080;
}

body.dark-mode .team-input:focus {
    border-color: #5eb3d6;
}

body.dark-mode .lunch-break-select {
    background-color: #2a2a2a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .lunch-break-select:focus {
    border-color: #5eb3d6;
}

body.dark-mode .theatre-room-selector {
    background-color: #2a2a2a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .theatre-room-selector:focus {
    border-color: #5eb3d6;
}

body.dark-mode .patient-grid-header {
    background-color: #1a2a3a;
    border-bottom-color: #555;
}

body.dark-mode .header-cell.info-col {
    background-color: #1a3a5a;
    color: #e0e0e0;
}

body.dark-mode .header-cell.angled-col.stripe-light {
    background-color: #1e2e3e;
}

body.dark-mode .header-cell.angled-col.stripe-dark {
    background-color: #253545;
}

body.dark-mode .header-cell.angled-col .col-label {
    color: #d0d0d0;
}

body.dark-mode .patient-row {
    background-color: #2a2a2a;
    border-color: #404040;
}

body.dark-mode .patient-row:hover {
    background-color: #3a3a3a;
}

body.dark-mode .patient-row.focused {
    background-color: #2a2a2a;
    border-color: #5eb3d6;
}

body.dark-mode .patient-cell {
    background-color: #2a2a2a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .patient-cell textarea {
    background-color: #3a3a3a;
    color: #e0e0e0;
}

body.dark-mode .patient-cell.dropdown-cell select,
body.dark-mode .patient-cell.dropdown-cell input[type="text"],
body.dark-mode .patient-cell.dropdown-cell input[type="number"] {
    background-color: #3a3a3a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .patient-cell.dropdown-cell select:focus,
body.dark-mode .patient-cell.dropdown-cell input:focus {
    border-color: #5eb3d6;
}

body.dark-mode .checkbox-cell.checkbox-blank {
    background-color: #2a2a2a;
    color: #808080;
}

body.dark-mode .patient-row > .checkbox-cell.checkbox-blank:nth-child(even) {
    background-color: #1e2e3e;
}

body.dark-mode .patient-row > .checkbox-cell.checkbox-blank:nth-child(odd) {
    background-color: #253545;
}

/* Dark mode alternating column stripes for data rows */
body.dark-mode .patient-row > .patient-cell:nth-child(4),
body.dark-mode .patient-row > .patient-cell:nth-child(6),
body.dark-mode .patient-row > .patient-cell:nth-child(8),
body.dark-mode .patient-row > .patient-cell:nth-child(10),
body.dark-mode .patient-row > .patient-cell:nth-child(12),
body.dark-mode .patient-row > .patient-cell:nth-child(14),
body.dark-mode .patient-row > .patient-cell:nth-child(16),
body.dark-mode .patient-row > .patient-cell:nth-child(18) {
    background-color: #1e2e3e;
}

body.dark-mode .patient-row > .patient-cell:nth-child(5),
body.dark-mode .patient-row > .patient-cell:nth-child(7),
body.dark-mode .patient-row > .patient-cell:nth-child(9),
body.dark-mode .patient-row > .patient-cell:nth-child(11),
body.dark-mode .patient-row > .patient-cell:nth-child(13),
body.dark-mode .patient-row > .patient-cell:nth-child(15),
body.dark-mode .patient-row > .patient-cell:nth-child(17) {
    background-color: #253545;
}

body.dark-mode .footer {
    background-color: #2a2a2a;
    border-color: #404040;
}

body.dark-mode .footer p {
    color: #e0e0e0;
}

body.dark-mode .key-legend {
    background-color: #2a2a2a;
    border-color: #404040;
}

body.dark-mode .key-title {
    color: #e0e0e0;
    border-color: #404040;
}

body.dark-mode .key-item {
    color: #c0c0c0;
}

body.dark-mode .modal-box {
    background-color: #2a2a2a;
    color: #e0e0e0;
}

body.dark-mode .modal-header {
    background-color: #004d2c;
}

body.dark-mode .modal-body {
    color: #e0e0e0;
}

body.dark-mode .modal-footer {
    background-color: #1a1a1a;
}

body.dark-mode .modal-input {
    background-color: #3a3a3a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .modal-input::placeholder {
    color: #808080;
}

body.dark-mode .modal-input:focus {
    border-color: #5eb3d6;
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .controls,
    .modal-overlay,
    .footer {
        display: none !important;
    }

    .container {
        padding: 0;
        background-color: white;
    }

    .header {
        margin-bottom: 20px;
        page-break-after: avoid;
    }

    .patient-section {
        margin-bottom: 0;
        overflow-x: visible;
    }

    .patient-grid-header {
        background-color: #005eb8;
        color: white;
        border-radius: 0;
        page-break-after: avoid;
    }

    .patient-row {
        background-color: white;
        border: 1px solid #000;
        page-break-inside: avoid;
    }

    .patient-row:hover {
        background-color: white;
    }

    .patient-cell {
        border-color: #000;
        background-color: white;
    }

    .checkbox-cell.checkbox-tick,
    .checkbox-cell.checkbox-cross {
        background-color: white;
    }

    .checkbox-cell.checkbox-tick::after {
        color: var(--nhs-green);
    }

    .checkbox-cell.checkbox-cross::after {
        color: var(--nhs-red);
    }
}

/* ==========================================================================
   FOOTER & KEY LEGEND - Compact (40% smaller)
   ========================================================================== */

.footer {
    background-color: var(--nhs-grey-5);
    padding: 0.3vw 0.6vw;
    border-radius: var(--border-radius);
    margin-top: 0.5vw;
}

.footer p {
    font-weight: 700;
    margin-bottom: 0.3vw;
    font-size: 0.7vw;
    line-height: 1.3;
}

.key-legend {
    display: grid;
    grid-template-columns: auto 1fr 1fr 1fr 1fr 1fr;
    gap: 0.3vw 0.5vw;
    align-items: center;
    background-color: var(--nhs-white);
    padding: 0.3vw 0.5vw;
    border-radius: var(--border-radius);
    border: 1px solid var(--nhs-grey-3);
}

.key-title {
    font-weight: 800;
    font-size: 0.9vw;
    padding-right: 0.5vw;
    border-right: 0.1vw solid var(--nhs-grey-3);
}

.key-item {
    display: flex;
    align-items: center;
    gap: 0.3vw;
    font-size: 0.7vw;
    font-weight: 600;
}

.key-symbol {
    font-size: 1vw;
    font-weight: 900;
}

.key-symbol.square {
    width: 0.7vw;
    height: 0.7vw;
    border: 0.1vw solid var(--nhs-grey-3);
    border-radius: 0.2vw;
    display: inline-block;
}

.key-symbol.blank {
    background-color: white;
    color: var(--nhs-grey-3);
}

.key-symbol.tick {
    background-color: transparent;
    color: var(--nhs-green);
    border: none;
    font-size: 1.2vw;
}

.key-symbol.cross {
    background-color: transparent;
    color: var(--nhs-red);
    border: none;
    font-size: 1.2vw;
}

.key-symbol.na {
    background-color: transparent;
    color: #777;
    border: none;
    font-size: 0.8vw;
    font-weight: 800;
}

.key-symbol.note {
    background-color: var(--nhs-grey-5);
    border-color: var(--nhs-grey-3);
    font-size: 0.85vw;
}

/* ==========================================================================
   PRIVACY MODE STYLES
   ========================================================================== */

body.privacy-mode .patient-row:not(.focused) {
    filter: blur(8px);
    opacity: 0.5;
}

body.privacy-mode .patient-row.focused {
    filter: none;
    opacity: 1;
}

/* ==========================================================================
   ALERT STYLES
   ========================================================================== */

.alert {
    padding: 20px;
    margin: 20px 0;
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 600;
}

.alert-warning {
    background-color: var(--nhs-warm-yellow);
    border: 2px solid #d69a00;
    color: var(--nhs-black);
}

.alert-success {
    background-color: #e8f5e9;
    border: 2px solid var(--nhs-green);
    color: var(--nhs-green);
}

.alert-danger {
    background-color: #ffebee;
    border: 2px solid var(--nhs-red);
    color: var(--nhs-red);
}

/* ==========================================================================
   LOADING AND EMPTY STATE STYLES
   ========================================================================== */

.loading {
    text-align: center;
    padding: 40px;
    font-size: var(--font-size-lg);
    color: var(--nhs-grey-1);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--nhs-grey-1);
}

.empty-state h3 {
    margin-bottom: 15px;
    color: var(--nhs-blue);
}

.empty-state p {
    font-size: var(--font-size-md);
    margin-bottom: 20px;
}

/* ==========================================================================
   FLOATING UTILITY BUTTONS — Bottom-right corner
   ========================================================================== */

.floating-utils {
    position: fixed;
    bottom: 1vw;
    right: 1vw;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 0.3vw;
    z-index: 500;
}

/* The toggle button — always visible */
.floating-toggle {
    opacity: 0.6;
}

.floating-toggle:hover {
    opacity: 1;
}

/* The expandable menu — hidden by default */
.floating-menu {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.3vw;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

.floating-menu.open {
    max-height: 15vw;
    opacity: 1;
}

.floating-btn {
    width: 2.2vw;
    height: 2.2vw;
    border-radius: 50%;
    border: 2px solid var(--nhs-grey-3);
    background-color: var(--nhs-white);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9vw;
    touch-action: manipulation;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.floating-btn:hover {
    background-color: var(--nhs-grey-5);
}

.floating-btn:active {
    transform: scale(0.9);
}

body.dark-mode .floating-btn {
    background-color: #2a2a2a;
    border-color: #404040;
    color: #e0e0e0;
}

body.dark-mode .floating-btn:hover {
    background-color: #3a3a3a;
}
