/* Declarative Task Status Styles */

/* Base task styling */
[data-task-type] {
    transition: all 0.3s ease;
    cursor: pointer;
}

/* Task status-based styling */
.task-status-not-yet {
    opacity: 0.3;
    background-color: #f3f4f6;
    border-left: 4px solid #d1d5db;
}

.task-status-active {
    opacity: 1;
    background-color: #ffffff;
    border-left: 4px solid #10b981;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.task-status-active:hover {
    background-color: #f9fafb;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.task-status-completed {
    opacity: 0.6;
    background-color: #ecfdf5;
    border-left: 4px solid #059669;
    text-decoration: line-through;
}

.task-status-overdue {
    opacity: 1;
    background-color: #fef2f2;
    border-left: 4px solid #dc2626;
    animation: pulse-danger 2s infinite;
}

/* E3.M3 — availability window phase cues (within active window) */
[data-window-phase="early"].task-status-active {
    border-left-color: #10b981;
}

[data-window-phase="late"].task-status-active {
    border-left-color: #f59e0b;
}

[data-window-phase="end"].task-status-active {
    border-left-color: #ef4444;
}

[data-window-phase="before"],
[data-window-phase="after"] {
    cursor: not-allowed;
}

/* Collapsible patient task-section headings — FA chevron after the title */
.task-section-heading {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    cursor: pointer;
    user-select: none;
}

.task-section-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-left: 0.15rem;
    flex-shrink: 0;
    color: #4b5563;
    font-size: 1rem;
    line-height: 1;
}

.task-section-chevron i {
    display: block;
    transition: transform 0.15s ease;
}

/* Expanded = chevron down; collapsed = points right */
.task-section-heading.is-collapsed .task-section-chevron i,
.task-section-heading[aria-expanded="false"] .task-section-chevron i {
    transform: rotate(-90deg);
}

.task-section-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    margin-left: 0.15rem;
    border-radius: 999px;
    border: 1px solid #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}

.task-section-help:hover {
    background: #dbeafe;
    border-color: #60a5fa;
}

.task-section-help:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Missed / too-late tasks ("fallouts") — hide via section heading toggle */
.task-section-hide-fallouts [data-task-type][data-fallout="1"] {
    display: none !important;
}

[data-task-type][data-fallout="1"] {
    position: relative;
    padding-right: 5.5rem;
    cursor: not-allowed;
}

.task-fallout-toggle {
    margin-left: auto;
    font-size: 0.75rem;
    font-weight: 600;
    color: #b91c1c;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.task-fallout-toggle:hover {
    color: #991b1b;
}

.task-fallout-toggle[hidden],
.task-fallout-toggle[data-count="0"] {
    display: none !important;
}

h4:has(.task-fallout-toggle) {
    flex-wrap: wrap;
    width: 100%;
    gap: 0.35rem 0.5rem;
}

@keyframes pulse-danger {
    0%, 100% {
        border-left-color: #dc2626;
    }
    50% {
        border-left-color: #fca5a5;
    }
}

/* Task type specific styling */
[data-task-type="med"].task-status-active {
    border-left-color: #3b82f6;
}

[data-task-type="assessment"].task-status-active {
    border-left-color: #10b981;
}

/* In a slot or waiting queue — Perform disabled until finished */
[data-slot-state="busy"].task-status-active,
[data-slot-state="queued"].task-status-active {
    opacity: 0.85;
    cursor: default;
    box-shadow: none;
    padding-right: 5.5rem;
}

[data-slot-state="busy"].task-status-active:hover,
[data-slot-state="queued"].task-status-active:hover {
    transform: none;
    background-color: #f3f4f6;
    box-shadow: none;
}

/* Centered spinning sprite while task occupies a slot / queue */
.task-occupancy-spin {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.16);
    font-size: 1.15rem;
    line-height: 1;
    color: #2563eb;
}

.task-occupancy-spin[data-state="queued"] {
    color: #7c3aed;
}

.task-occupancy-spin .fa-spinner {
    display: block;
}

[data-slot-state="busy"][data-task-type].task-status-active::after,
[data-slot-state="queued"][data-task-type].task-status-active::after {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid;
    border-radius: 0.25rem;
    padding: 0.15rem 0.4rem;
    opacity: 1;
    pointer-events: none;
    white-space: nowrap;
}

[data-slot-state="busy"][data-task-type].task-status-active::after {
    content: "In progress";
    color: #1e40af;
    background: #dbeafe;
    border-color: #93c5fd;
}

[data-slot-state="queued"][data-task-type].task-status-active::after {
    content: "Queued";
    color: #6b21a8;
    background: #f3e8ff;
    border-color: #d8b4fe;
}

/* Chart assessment locked until bedside shift assessment completes */
[data-task-kind="chart-assessment"][data-task-locked="1"] {
    opacity: 0.55;
    filter: grayscale(0.15);
}

[data-task-kind="chart-assessment"][data-task-locked="1"].task-status-active::after,
[data-task-type="assessment"][data-task-locked="1"].task-status-active::after {
    content: "Locked · prior step first";
    color: #92400e;
    background: #fffbeb;
}

/* Dependent pathway steps (stroke alert, etc.) — hidden until prerequisite completes */
[data-task-reveal="on-prereq"][data-task-locked="1"] {
    display: none;
}

[data-task-type="procedure"].task-status-active {
    border-left-color: #8b5cf6;
}

/* Reveal scheduled tasks animation */
li[data-status="active"] {
    animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Context menu affordance — left-click opens Perform / Details */
[data-task-type].task-status-active {
    position: relative;
    padding-right: 5.5rem;
}

[data-task-type="med"].task-status-active::after,
[data-task-type="orders"].task-status-active::after,
[data-task-type="assessment"].task-status-active::after,
[data-task-type="bedprep"].task-status-active::after {
    content: "Click · Perform";
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #1d4ed8;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.25rem;
    padding: 0.15rem 0.4rem;
    opacity: 1;
    pointer-events: none;
    white-space: nowrap;
}

/* Fallout badge — must follow Perform / slot / locked ::after rules */
[data-task-type][data-fallout="1"]::after,
[data-task-type][data-fallout="1"].task-status-active::after,
[data-slot-state][data-task-type][data-fallout="1"].task-status-active::after,
[data-task-kind="chart-assessment"][data-fallout="1"][data-task-locked="1"].task-status-active::after,
[data-task-type="assessment"][data-fallout="1"][data-task-locked="1"].task-status-active::after {
    content: "Too late";
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 0.25rem;
    padding: 0.15rem 0.4rem;
    opacity: 1;
    pointer-events: none;
    white-space: nowrap;
    z-index: 2;
}

/* Patient section styling */
[data-patient-id] {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    transition: all 0.3s ease;
}

[data-patient-id]:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Collapsible sections */
.collapsible-header {
    transition: background-color 0.2s ease;
}

.collapsible-header:hover {
    background-color: #f3f4f6 !important;
}

/* Task queue styling */
.task-queue-item {
    transition: all 0.3s ease;
}

.task-queue-item.active {
    background-color: #dbeafe;
    border-color: #3b82f6;
}

.task-queue-item.completed {
    background-color: #dcfce7;
    border-color: #16a34a;
    opacity: 0.7;
}

.task-queue-item.overdue {
    background-color: #fee2e2;
    border-color: #dc2626;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* E3.M2 — concurrent slots */
.task-queue-bar {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    background: #fff;
    padding: 0.45rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.task-slot {
    width: 5.5rem;
    min-height: 4.25rem;
    border: 1px solid #d1d5db;
    border-radius: 0.4rem;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.3rem 0.25rem;
    position: relative;
    overflow: hidden;
}

.task-slot--empty {
    justify-content: center;
    gap: 0.15rem;
}

.task-slot--empty .task-slot-label {
    font-size: 0.7rem;
    color: #9ca3af;
    font-weight: 600;
}

.task-slot--empty .task-slot-hint {
    font-size: 0.6rem;
    color: #d1d5db;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Exclusive task active — remaining empty slots locked */
.task-slot--disabled {
    justify-content: center;
    gap: 0.15rem;
    background: #f3f4f6;
    border-color: #d1d5db;
    border-style: dashed;
    opacity: 0.55;
    cursor: not-allowed;
}

.task-slot--disabled .task-slot-label {
    font-size: 0.7rem;
    color: #9ca3af;
    font-weight: 600;
}

.task-slot--disabled .task-slot-hint {
    font-size: 0.6rem;
    color: #9ca3af;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.task-queue-bar--exclusive .task-slot--busy {
    border-color: #f59e0b;
    background: #fffbeb;
}

.task-slot--busy {
    background: #eff6ff;
    border-color: #93c5fd;
}

.task-slot-abort {
    position: absolute;
    top: 0.1rem;
    right: 0.1rem;
    z-index: 3;
    margin: 0;
    padding: 0.1rem 0.28rem;
    border: 0;
    border-radius: 0.25rem;
    background: #b45309;
    color: #fff;
    font-size: 0.55rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.task-slot-abort:hover,
.task-slot-abort:focus-visible {
    background: #92400e;
    outline: none;
}

.task-slot--abortable {
    padding-top: 0.85rem;
}

.task-abort-remaining {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    color: #92400e;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

[data-aborted="1"] {
    box-shadow: inset 0 0 0 1px #f59e0b;
}

.task-slot-media-btn {
    display: block;
    width: 100%;
    max-width: 4.75rem;
    margin: 0 auto 0.15rem;
    padding: 0;
    border: 0;
    border-radius: 0.3rem;
    background: #1e293b;
    cursor: pointer;
    line-height: 0;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.task-slot-media-btn:hover,
.task-slot-media-btn:focus-visible {
    transform: scale(1.04);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45);
    outline: none;
}

.task-slot-media {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    /* cover: generated thumbs often have dark margins; crop so type icons read at ~80px */
    object-fit: cover;
    object-position: center;
    border-radius: 0.25rem;
    display: block;
    background: #1e293b;
    pointer-events: none;
}

.task-slot-media.media-ph--video {
    aspect-ratio: 16 / 9;
}

.task-slot-name {
    font-size: 0.65rem;
    font-weight: 700;
    color: #1e3a8a;
    text-align: center;
    line-height: 1.15;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-slot-progress {
    width: 100%;
    height: 0.35rem;
    background: #dbeafe;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.25rem 0;
}

.task-slot-progress-fill {
    height: 100%;
    background: #2563eb;
    transition: width 200ms ease;
}

.task-slot-timemark {
    font-size: 0.7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #1d4ed8;
    text-align: center;
}

.task-slot--completing {
    background: #ecfdf5;
    border-color: #34d399;
    animation: task-slot-complete-pulse 0.7s ease;
}

.task-slot--completing .task-slot-progress-fill {
    background: #059669;
    transition: width 0.45s ease;
}

.task-slot-done-badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 185, 129, 0.88);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    animation: task-slot-done-pop 0.45s ease;
}

@keyframes task-slot-complete-pulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

@keyframes task-slot-done-pop {
    0% { opacity: 0; transform: scale(0.85); }
    100% { opacity: 1; transform: scale(1); }
}

/* E3.M6 — waiting queue */
.slot-cluster {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
}

/* Mobile: shell.css owns show/hide (floating slots). Do not force flex here. */
@media (max-width: 900px) {
    .slot-cluster {
        display: none;
    }

    body.shell-slots-visible .slot-cluster {
        display: flex;
    }
}

.slot-waiting-queue {
    min-width: 11rem;
    max-width: 14rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.45rem;
    padding: 0.35rem 0.45rem;
    font-size: 0.72rem;
    text-align: left;
}

.slot-queue-empty {
    margin: 0;
    color: #9ca3af;
}

.slot-queue-heading {
    margin: 0 0 0.25rem;
    font-weight: 700;
    color: #4b5563;
}

.slot-queue-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.slot-queue-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.2rem;
    border-radius: 0.25rem;
    background: #f3f4f6;
}

.slot-queue-pos {
    font-weight: 700;
    color: #6b7280;
    min-width: 1rem;
}

.slot-queue-name {
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .task-queue-bar {
        gap: 0.3rem;
        padding: 0.3rem;
    }

    .task-slot {
        width: 4.1rem;
        min-height: 3.1rem;
        padding: 0.25rem 0.2rem 0.2rem;
    }

    .task-slot--empty .task-slot-label,
    .task-slot--disabled .task-slot-label {
        font-size: 0.62rem;
    }

    .task-slot--empty .task-slot-hint,
    .task-slot--disabled .task-slot-hint {
        font-size: 0.55rem;
    }

    .task-slot-media-btn {
        max-width: 3.5rem;
        margin-bottom: 0.1rem;
    }

    .task-slot-name {
        font-size: 0.58rem;
    }

    .task-slot-progress {
        height: 0.28rem;
        margin: 0.15rem 0;
    }

    .task-slot-timemark {
        font-size: 0.62rem;
    }

    .slot-waiting-queue {
        min-width: 0;
        max-width: none;
        width: 100%;
        padding: 0.25rem 0.35rem;
        font-size: 0.65rem;
    }

    .slot-queue-list {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.2rem;
    }

    .slot-queue-item {
        max-width: 100%;
        padding: 0.1rem 0.25rem;
    }
}

/* Accucheck / finger-stick outcome dice on task rows */
.finger-stick-dice {
    flex-shrink: 0;
    margin-left: 0.35rem;
    margin-right: 0.35rem;
    width: 1.85rem;
    height: 1.85rem;
    border: 1px solid #fda4af;
    border-radius: 0.4rem;
    background: #fff1f2;
    color: #be123c;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 0.9rem;
}

.finger-stick-dice:hover {
    background: #ffe4e6;
    border-color: #fb7185;
}

.finger-stick-dice:focus-visible {
    outline: 2px solid #e11d48;
    outline-offset: 2px;
}

.finger-stick-odds-popover {
    position: fixed;
    z-index: 60;
    min-width: 15rem;
    max-width: min(20rem, calc(100vw - 1rem));
    padding: 0.75rem 0.85rem;
    border-radius: 0.55rem;
    background: #fff;
    border: 1px solid #fecdd3;
    box-shadow: 0 10px 28px rgba(190, 18, 60, 0.14), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
}

.finger-stick-odds-popover[hidden] {
    display: none !important;
}

.finger-stick-odds__title {
    margin: 0 0 0.45rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #9f1239;
}

.finger-stick-odds__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.finger-stick-odds__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    color: #374151;
}

.finger-stick-odds__row--critical {
    color: #b91c1c;
    font-weight: 600;
}

.finger-stick-odds__pct {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: #881337;
}

/* Doctor-orders check — trivial new-order dice */
.orders-trivial-dice {
    flex-shrink: 0;
    margin-left: 0.35rem;
    width: 1.85rem;
    height: 1.85rem;
    border: 1px solid #a5b4fc;
    border-radius: 0.4rem;
    background: #eef2ff;
    color: #4338ca;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 0.9rem;
}

.orders-trivial-dice:hover {
    background: #e0e7ff;
    border-color: #818cf8;
}

.orders-trivial-dice:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.orders-trivial-odds-popover {
    position: fixed;
    z-index: 60;
    min-width: 15rem;
    max-width: min(20rem, calc(100vw - 1rem));
    padding: 0.75rem 0.85rem;
    border-radius: 0.55rem;
    background: #fff;
    border: 1px solid #c7d2fe;
    box-shadow: 0 10px 28px rgba(67, 56, 202, 0.14), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
}

.orders-trivial-odds-popover[hidden] {
    display: none !important;
}

.orders-trivial-odds__title {
    margin: 0 0 0.45rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #3730a3;
}

.orders-trivial-odds__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.orders-trivial-odds__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    color: #374151;
}

.orders-trivial-odds__pct {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: #312e81;
}