:root {
    --background: #f4f7f6;
    --surface: #ffffff;
    --surface-soft: #f8faf9;
    --text: #15221d;
    --muted: #62716a;
    --border: #dce5e1;
    --primary: #176b52;
    --primary-dark: #0f533f;
    --primary-soft: #e6f3ee;
    --danger: #a73535;
    --danger-soft: #faeeee;
    --warning: #8a5c16;
    --warning-soft: #fff7e6;
    --info: #275d7a;
    --info-soft: #edf6fb;
    --shadow: 0 12px 32px rgba(21, 34, 29, 0.08);
    --radius: 16px;
    --radius-small: 10px;
    --sidebar-width: 248px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--background);
}

a {
    color: var(--primary);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.4rem;
    font-size: clamp(1.9rem, 4vw, 2.65rem);
    line-height: 1.08;
    letter-spacing: -0.035em;
}

h2 {
    margin-bottom: 0;
    font-size: 1.25rem;
    letter-spacing: -0.015em;
}

h3 {
    margin-bottom: 0.35rem;
    font-size: 1.05rem;
}

p {
    line-height: 1.55;
}

small {
    color: var(--muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    color: #fff;
    background: #122b23;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: #fff;
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    background: var(--primary);
    font-weight: 800;
}

.brand strong,
.auth-brand strong {
    display: block;
    font-size: 1rem;
}

.brand small,
.auth-brand small {
    display: block;
    margin-top: 0.15rem;
    color: #a9c2b9;
}

.primary-nav {
    display: grid;
    gap: 0.35rem;
    margin-top: 2rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 0.9rem;
    border-radius: 10px;
    color: #c8d9d3;
    text-decoration: none;
    font-weight: 650;
}

.nav-link:hover,
.nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.nav-link span {
    width: 1rem;
    color: #74b69f;
    font-size: 0.58rem;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 1rem;
}

.signed-in-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.signed-in-user strong,
.signed-in-user small {
    display: block;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.signed-in-user small {
    margin-top: 0.15rem;
    color: #a9c2b9;
}

.avatar {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: #42685b;
    font-size: 0.82rem;
    font-weight: 800;
}

.main-column {
    grid-column: 2;
    min-width: 0;
}

.mobile-header {
    display: none;
}

.page-content {
    width: min(1320px, 100%);
    margin: 0 auto;
    padding: 2.25rem clamp(1.25rem, 4vw, 3.5rem) 4rem;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.75rem;
}

.page-subtitle {
    margin-bottom: 0;
    color: var(--muted);
}

.eyebrow {
    margin-bottom: 0.45rem;
    color: var(--primary);
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 750;
    line-height: 1.2;
}

.button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.menu-button:focus-visible {
    outline: 3px solid rgba(23, 107, 82, 0.28);
    outline-offset: 2px;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.button-primary {
    color: #fff;
    background: var(--primary);
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.button-secondary:hover,
.button-quiet:hover {
    background: var(--surface-soft);
}

.button-quiet {
    color: inherit;
    border-color: transparent;
    background: transparent;
}

.sidebar .button-quiet {
    color: #c8d9d3;
    border-color: rgba(255, 255, 255, 0.13);
}

.button-danger {
    color: #fff;
    background: var(--danger);
}

.button-danger-quiet {
    color: var(--danger);
    border-color: #efcaca;
    background: var(--danger-soft);
}

.button-full {
    width: 100%;
}

.button-small {
    min-height: 34px;
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
}

.text-link {
    font-weight: 750;
    text-decoration: none;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card,
.content-section,
.form-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 1px rgba(21, 34, 29, 0.02);
}

.metric-card {
    display: grid;
    gap: 0.35rem;
    min-height: 142px;
    padding: 1.2rem;
}

.metric-card span {
    color: var(--muted);
    font-weight: 700;
}

.metric-card strong {
    align-self: end;
    font-size: 2.2rem;
    letter-spacing: -0.045em;
}

.metric-card small {
    min-height: 1.2em;
}

.metric-placeholder strong {
    color: #aeb9b4;
}

.content-section {
    margin-bottom: 1.25rem;
    padding: 1.35rem;
}

.flush-section {
    padding: 0;
    overflow: hidden;
}

.compact-section {
    padding: 1.15rem;
}

.narrow-section {
    max-width: 680px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.2rem;
}

.section-heading > p {
    max-width: 440px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

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

.resident-card {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-soft);
}

.resident-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.resident-card h3 {
    font-size: 1.15rem;
}

.resident-card > p {
    margin-bottom: 0.85rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.resident-initials {
    display: inline-grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 50%;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-weight: 850;
}

.resident-initials-small {
    width: 36px;
    height: 36px;
    font-size: 0.78rem;
}

.resident-initials-large {
    width: 62px;
    height: 62px;
    font-size: 1.15rem;
}

.resident-alerts {
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.care-alert {
    padding: 0.3rem 0.48rem;
    border-radius: 7px;
    color: var(--warning);
    background: var(--warning-soft);
    font-size: 0.75rem;
    font-weight: 750;
}

.muted {
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-active {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.status-temporarilyaway {
    color: var(--warning);
    background: var(--warning-soft);
}

.status-discharged {
    color: #616a66;
    background: #edf0ef;
}

.empty-state {
    display: grid;
    max-width: 520px;
    justify-items: center;
    margin: 1.5rem auto;
    padding: 2rem 1rem;
    text-align: center;
}

.empty-state p {
    margin-bottom: 1.25rem;
    color: var(--muted);
}

.empty-icon {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    margin-bottom: 1rem;
    border-radius: 14px;
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 850;
}

.future-workflow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.future-workflow > div {
    padding: 1rem;
    border-radius: 12px;
    background: var(--surface-soft);
}

.future-workflow strong {
    display: block;
    margin: 0.65rem 0 0.25rem;
}

.future-workflow p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.step-number {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 8px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-size: 0.78rem;
    font-weight: 850;
}

.alert {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid transparent;
    border-radius: 10px;
    line-height: 1.45;
}

.alert-success {
    color: var(--primary-dark);
    border-color: #bcded1;
    background: var(--primary-soft);
}

.alert-warning {
    color: var(--warning);
    border-color: #efd6a9;
    background: var(--warning-soft);
}

.alert-info {
    color: var(--info);
    border-color: #c7deeb;
    background: var(--info-soft);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background:
        radial-gradient(circle at top left, rgba(23, 107, 82, 0.12), transparent 34rem),
        var(--background);
}

.auth-card {
    width: min(440px, 100%);
    padding: clamp(1.4rem, 5vw, 2rem);
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-card-wide {
    width: min(520px, 100%);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.auth-brand small {
    color: var(--muted);
}

.auth-heading {
    margin-bottom: 1.35rem;
}

.auth-heading p:last-child {
    margin-bottom: 0;
    color: var(--muted);
}

.auth-footnote {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
}

.stack-form {
    display: grid;
    gap: 1rem;
}

.record-form {
    display: grid;
    gap: 1.25rem;
}

.form-section {
    padding: 1.35rem;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

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

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

.field-span-2 {
    grid-column: span 2;
}

.field {
    display: grid;
    gap: 0.38rem;
    min-width: 0;
}

.field label {
    font-size: 0.86rem;
    font-weight: 750;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 43px;
    padding: 0.66rem 0.72rem;
    border: 1px solid #cbd7d2;
    border-radius: 9px;
    color: var(--text);
    background: #fff;
}

.field textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--primary);
}

.field span.field-validation-error,
.validation-summary {
    color: var(--danger);
    font-size: 0.82rem;
}

.validation-summary:empty {
    display: none;
}

.validation-summary ul {
    margin: 0;
    padding-left: 1.1rem;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.check-field input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 0.25rem 0 1rem;
}

.form-actions-left {
    justify-content: flex-start;
    padding-bottom: 0;
}

.filter-tabs {
    display: flex;
    gap: 0.45rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.filter-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 750;
    white-space: nowrap;
}

.filter-tabs a.active {
    color: #fff;
    border-color: var(--primary);
    background: var(--primary);
}

.filter-tabs span {
    display: inline-grid;
    min-width: 21px;
    height: 21px;
    place-items: center;
    padding: 0 0.25rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    font-size: 0.72rem;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

.data-table th,
.data-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.resident-table-name {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--text);
    text-decoration: none;
}

.resident-table-name strong,
.resident-table-name small {
    display: block;
}

.resident-table-name small {
    margin-top: 0.12rem;
    font-size: 0.78rem;
}

.table-actions {
    text-align: right !important;
    white-space: nowrap;
}

.table-actions-wide {
    display: flex;
    justify-content: flex-end;
    gap: 0.45rem;
}

.resident-profile-header {
    align-items: center;
}

.resident-heading,
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    gap: 1.25rem;
    align-items: start;
}

.profile-main {
    min-width: 0;
}

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

.info-block {
    min-height: 115px;
    padding: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.info-block span {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.info-block p {
    margin-bottom: 0;
    white-space: pre-line;
}

.info-block-alert {
    border-color: #efd6a9;
    background: var(--warning-soft);
}

.info-block-alert span {
    color: var(--warning);
}

.info-block-muted p {
    color: var(--muted);
}

.detail-list,
.compact-details {
    margin: 0;
}

.detail-row {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 1rem;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:first-child {
    padding-top: 0;
}

.detail-row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.detail-row dt,
.compact-details dt {
    color: var(--muted);
    font-size: 0.83rem;
    font-weight: 750;
}

.detail-row dd,
.compact-details dd {
    margin: 0;
    line-height: 1.55;
    white-space: pre-line;
}

.detail-row-featured dd {
    font-weight: 650;
}

.compact-details > div {
    display: grid;
    gap: 0.2rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}

.compact-details > div:first-child {
    padding-top: 0;
}

.compact-details > div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.long-text {
    margin-bottom: 0;
    white-space: pre-line;
}

.nav-scrim {
    display: none;
}

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

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

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

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        transform: translateX(-102%);
        transition: transform 180ms ease;
        box-shadow: var(--shadow);
    }

    .nav-open .sidebar {
        transform: translateX(0);
    }

    .nav-scrim {
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(8, 20, 16, 0.45);
    }

    .nav-open .nav-scrim {
        display: block;
    }

    .main-column {
        min-height: 100vh;
    }

    .mobile-header {
        position: sticky;
        top: 0;
        z-index: 15;
        display: flex;
        height: 58px;
        align-items: center;
        gap: 0.8rem;
        padding: 0 1rem;
        border-bottom: 1px solid var(--border);
        background: rgba(255, 255, 255, 0.96);
    }

    .menu-button {
        width: 38px;
        height: 38px;
        border: 1px solid var(--border);
        border-radius: 9px;
        color: var(--text);
        background: var(--surface);
        cursor: pointer;
    }

    .page-content {
        padding-top: 1.25rem;
    }

    .profile-layout {
        grid-template-columns: 1fr;
    }

    .profile-sidebar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
}

@media (max-width: 660px) {
    .page-header,
    .section-heading,
    .resident-profile-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        justify-content: flex-start;
    }

    .metric-grid,
    .resident-card-grid,
    .future-workflow,
    .form-grid-2,
    .form-grid-3,
    .alert-grid,
    .profile-sidebar {
        grid-template-columns: 1fr;
    }

    .field-span-2 {
        grid-column: span 1;
    }

    .form-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .form-actions .button {
        width: 100%;
    }

    .resident-heading {
        align-items: flex-start;
    }

    .detail-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tr {
        padding: 0.8rem 1rem;
        border-bottom: 1px solid var(--border);
    }

    .data-table tbody tr:last-child {
        border-bottom: 0;
    }

    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.45rem 0;
        border: 0;
        text-align: right;
    }

    .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.76rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .data-table td:first-child,
    .data-table td.table-actions {
        display: block;
        text-align: left !important;
    }

    .data-table td:first-child::before,
    .data-table td.table-actions::before {
        display: none;
    }

    .table-actions,
    .table-actions-wide {
        white-space: normal;
    }

    .table-actions-wide {
        display: flex !important;
        justify-content: flex-start;
        margin-top: 0.4rem;
    }
}

/* Milestone 2: medication setup and eMAR */
[hidden] {
    display: none !important;
}

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

.metric-attention {
    border-color: #e8c98e;
    background: var(--warning-soft);
}

.section-heading-padded {
    margin: 0;
    padding: 1.35rem;
}

.compact-empty-state {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 1.4rem;
    padding-bottom: 1.4rem;
}

.quiet-empty-message {
    margin: 0;
    padding: 0.25rem 0;
    color: var(--muted);
}

.table-subtext {
    display: block;
    margin-top: 0.2rem;
    line-height: 1.35;
}

.inline-filter-form,
.mar-filter-form {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.inline-filter-form .field,
.mar-filter-form .field {
    min-width: min(280px, 100%);
}

.resident-select-field {
    max-width: 620px;
}

.check-row {
    margin-top: 1rem;
}

.check-field-prominent {
    align-items: flex-start;
    padding: 0.95rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.check-field-prominent span,
.check-field-prominent strong,
.check-field-prominent small {
    display: block;
}

.check-field-prominent strong {
    color: var(--text);
}

.check-field-prominent small {
    margin-top: 0.2rem;
}

.scheduled-fields {
    display: grid;
    gap: 1.2rem;
    margin-top: 1.2rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--border);
}

.field-label {
    font-size: 0.86rem;
    font-weight: 750;
}

.weekday-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(58px, 1fr));
    gap: 0.45rem;
}

.weekday-grid label {
    display: grid;
    gap: 0.4rem;
    justify-items: center;
    padding: 0.65rem 0.35rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--muted);
    background: var(--surface-soft);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 800;
}

.weekday-grid input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.time-slot-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 0.75rem;
}

.time-slot-grid label {
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 750;
}

.time-slot-grid input {
    min-height: 42px;
    padding: 0.6rem 0.65rem;
    border: 1px solid #cbd7d2;
    border-radius: 9px;
    background: #fff;
}

.medication-status-active {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.medication-status-future {
    color: var(--info);
    background: var(--info-soft);
}

.medication-status-ended {
    color: #616a66;
    background: #edf0ef;
}

.medication-header {
    align-items: center;
}

.medication-instructions,
.medication-table-instructions {
    white-space: pre-line;
}

.medication-table-instructions {
    max-width: 440px;
    line-height: 1.4;
}

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

.dose-list {
    display: grid;
    gap: 0.65rem;
}

.dose-row {
    display: grid;
    grid-template-columns: 74px minmax(150px, 0.7fr) minmax(240px, 1.35fr) minmax(105px, auto) auto;
    gap: 1rem;
    align-items: center;
    padding: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}

.dose-row.dose-overdue {
    border-color: #e8c98e;
    background: var(--warning-soft);
}

.dose-row.dose-completed {
    background: #fbfcfc;
}

.dose-list-completed {
    opacity: 0.92;
}

.dose-time {
    display: grid;
    align-content: center;
    line-height: 1;
}

.dose-time strong {
    font-size: 1.25rem;
}

.dose-time span {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
}

.dose-resident,
.dose-medication {
    display: grid;
    gap: 0.22rem;
    min-width: 0;
}

.dose-resident > span,
.dose-medication > span {
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.4;
}

.dose-medication > span {
    white-space: pre-line;
}

.dose-status {
    display: flex;
    justify-content: flex-start;
}

.dose-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.dose-actions form {
    margin: 0;
}

.dose-status-overdue {
    color: var(--warning);
    background: #fce9c8;
}

.dose-status-due {
    color: var(--info);
    background: var(--info-soft);
}

.dose-status-upcoming {
    color: var(--muted);
    background: #edf0ef;
}

.all-complete-banner {
    margin-bottom: 1rem;
    padding: 0.8rem 1rem;
    border-radius: 10px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-weight: 700;
}

.subsection-heading {
    margin: 1.25rem 0 0.75rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.result-pill {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    padding: 0.32rem 0.58rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 850;
    white-space: nowrap;
}

.result-given,
.result-self-administered {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.result-refused,
.result-held,
.result-missed,
.result-not-available {
    color: var(--warning);
    background: var(--warning-soft);
}

.result-unknown {
    color: var(--muted);
    background: #edf0ef;
}

.followup-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.followup-card {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}

.followup-card.followup-overdue {
    border-color: #e8c98e;
    background: var(--warning-soft);
}

.followup-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.followup-card-heading strong,
.followup-card-heading span {
    display: block;
}

.followup-card-heading > div > span {
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.followup-card h3,
.followup-card p {
    margin-bottom: 0;
}

.followup-card p {
    color: var(--muted);
    white-space: pre-line;
}

.medication-callout {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 1.1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}

.medication-callout p,
.medication-callout small {
    margin: 0;
}

.documentation-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
    gap: 1.25rem;
    align-items: start;
}

.medication-record-details {
    margin-top: 1.15rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.compact-details-inline {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0;
}

.compact-details-inline > div {
    display: grid;
    gap: 0.2rem;
    padding: 0.8rem;
    border-radius: 9px;
    background: var(--surface-soft);
}

.compact-details-inline dt {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 750;
}

.compact-details-inline dd {
    margin: 0;
    font-weight: 650;
}

.correction-reason-section {
    border-color: #c7deeb;
    background: var(--info-soft);
}

.section-divider {
    height: 1px;
    margin: 1.25rem 0;
    border: 0;
    background: var(--border);
}

.revision-timeline {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.revision-timeline li {
    position: relative;
    padding: 0 0 1.25rem 1.55rem;
    border-left: 2px solid var(--border);
}

.revision-timeline li::before {
    position: absolute;
    top: 0.2rem;
    left: -0.43rem;
    width: 0.72rem;
    height: 0.72rem;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--primary);
    content: "";
}

.revision-timeline li:last-child {
    padding-bottom: 0;
    border-left-color: transparent;
}

.revision-timeline li > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.revision-timeline li > div span,
.revision-timeline small {
    color: var(--muted);
    font-size: 0.82rem;
}

.revision-timeline p {
    margin: 0.35rem 0 0.2rem;
    white-space: pre-line;
}

.mar-month-navigation {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mar-report {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.mar-report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.mar-report-header h2,
.mar-report-header p {
    margin-bottom: 0.25rem;
}

.mar-month-heading {
    color: var(--muted);
    font-size: 1rem;
    font-weight: 700;
}

.mar-alert-line {
    padding: 0.65rem 1.25rem;
    max-width: 480px;
    color: var(--warning);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: right;
}

.mar-section {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.mar-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mar-section-heading h2 {
    flex: 0 0 auto;
}

.mar-legend {
    display: flex;
    justify-content: flex-end;
    gap: 0.35rem 0.8rem;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.73rem;
}

.mar-legend span {
    white-space: nowrap;
}

.mar-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.mar-table {
    width: 100%;
    min-width: 1080px;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.72rem;
}

.mar-table th,
.mar-table td {
    height: 34px;
    padding: 0.2rem;
    border: 1px solid #cfd9d5;
    text-align: center;
    vertical-align: middle;
}

.mar-table thead th {
    color: var(--muted);
    background: var(--surface-soft);
    font-weight: 850;
}

.mar-table thead th.weekend {
    background: #f1f4f3;
}

.mar-table thead span,
.mar-table thead small {
    display: block;
}

.mar-table thead small {
    font-size: 0.58rem;
}

.mar-table .mar-medication-column {
    width: 190px;
    padding: 0.45rem;
    text-align: left;
}

.mar-medication-column strong,
.mar-medication-column span,
.mar-medication-column small {
    display: block;
}

.mar-medication-column span {
    margin-top: 0.15rem;
    color: var(--muted);
    font-weight: 500;
}

.mar-instructions-row td {
    height: auto;
    padding: 0.35rem 0.5rem;
    color: var(--muted);
    background: #fbfcfc;
    text-align: left;
    line-height: 1.35;
}

.mar-cell {
    font-weight: 850;
}

.mar-cell a {
    display: grid;
    min-height: 28px;
    place-items: center;
    color: inherit;
    text-decoration: none;
}

.mar-cell.not-scheduled {
    background: #f2f4f3;
}

.mar-cell.pending {
    background: #fff;
}

.mar-cell.undocumented {
    color: var(--warning);
    background: var(--warning-soft);
}

.mar-cell.documented.result-given,
.mar-cell.documented.result-self-administered {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.mar-cell.documented.result-refused,
.mar-cell.documented.result-held,
.mar-cell.documented.result-missed,
.mar-cell.documented.result-not-available {
    color: var(--warning);
    background: var(--warning-soft);
}

.mar-prn-section {
    border-bottom: 0;
}

.mar-prn-table {
    min-width: 1000px;
    font-size: 0.78rem;
}

.mar-report-footer {
    padding: 0.9rem 1.25rem;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.74rem;
}

.print-only {
    display: none;
}


/* Milestone 3: recurring care tasks and ADL history */
.metric-grid-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.section-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.9rem;
    flex-wrap: wrap;
}

.detail-card-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.care-task-status-active {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.care-task-status-upcoming {
    color: var(--info);
    background: var(--info-soft);
}

.care-task-status-ended {
    color: #616a66;
    background: #edf0ef;
}

.care-task-instructions,
.care-task-table-instructions,
.care-task-callout > p {
    white-space: pre-line;
}

.care-task-table-instructions {
    max-width: 440px;
    line-height: 1.4;
}

.task-result-completed {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.task-result-declined,
.task-result-skipped {
    color: var(--warning);
    background: var(--warning-soft);
}

.task-result-not-applicable {
    color: var(--info);
    background: var(--info-soft);
}

.task-result-undocumented {
    color: var(--warning);
    background: var(--warning-soft);
}

.task-result-scheduled,
.task-result-unknown {
    color: var(--muted);
    background: #edf0ef;
}

.history-filter-form {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.history-resident-field {
    min-width: min(320px, 100%);
}

.history-filter-form .field:not(.history-resident-field) {
    min-width: 170px;
}

.filter-help {
    margin: 0.8rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.history-validation:empty {
    display: none;
}

.care-history-table {
    min-width: 1040px;
}

@media (max-width: 1050px) {
    .metric-grid-5 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-card-grid,
    .time-slot-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dose-row {
        grid-template-columns: 70px minmax(140px, 0.65fr) minmax(210px, 1fr) auto;
    }

    .dose-status {
        display: none;
    }

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

@media (max-width: 820px) {
    .documentation-layout {
        grid-template-columns: 1fr;
    }

    .dose-row {
        grid-template-columns: 64px minmax(120px, 0.7fr) minmax(190px, 1fr);
    }

    .dose-actions {
        grid-column: 2 / -1;
        justify-content: flex-start;
    }

    .weekday-grid {
        grid-template-columns: repeat(4, minmax(58px, 1fr));
    }
}

@media (max-width: 660px) {
    .metric-grid-3,
    .metric-grid-5,
    .detail-card-grid,
    .followup-grid,
    .compact-details-inline,
    .time-slot-grid {
        grid-template-columns: 1fr;
    }

    .inline-filter-form,
    .mar-filter-form,
    .history-filter-form,
    .mar-month-navigation,
    .mar-report-header,
    .mar-section-heading,
    .revision-timeline li > div {
        align-items: stretch;
        flex-direction: column;
    }

    .inline-filter-form .field,
    .mar-filter-form .field,
    .history-filter-form .field {
        width: 100%;
    }

    .weekday-grid {
        grid-template-columns: repeat(3, minmax(58px, 1fr));
    }

    .dose-row {
        grid-template-columns: 58px minmax(0, 1fr);
        gap: 0.75rem;
    }

    .dose-medication,
    .dose-actions {
        grid-column: 1 / -1;
    }

    .dose-actions,
    .dose-actions form,
    .dose-actions .button,
    .dose-actions form .button {
        width: 100%;
    }

    .followup-card-heading {
        flex-direction: column;
    }

    .mar-alert-line {
        text-align: left;
    }

    .medication-table-instructions,
    .care-task-table-instructions {
        max-width: none;
    }

    .care-history-table {
        min-width: 0;
    }
}


/* Milestone 4: progress notes, incidents, and resident timeline */
.field-span-3 {
    grid-column: span 3;
}

.documentation-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.documentation-card {
    display: flex;
    min-height: 220px;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.1rem;
    padding: 1.1rem;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-soft);
}

.documentation-card-label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 850;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.documentation-card > div > strong {
    display: block;
    margin-bottom: 0.45rem;
    font-size: 2rem;
    line-height: 1;
    letter-spacing: -0.04em;
}

.documentation-card p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.documentation-card-actions,
.stacked-actions {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.stacked-actions {
    margin-top: 1rem;
    flex-direction: column;
}

.note-category,
.incident-flag,
.timeline-status {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    padding: 0.31rem 0.58rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 850;
    line-height: 1.2;
    white-space: nowrap;
}

.note-category-general {
    color: #4c5e57;
    background: #edf1ef;
}

.note-category-health,
.note-category-condition {
    color: var(--danger);
    background: var(--danger-soft);
}

.note-category-behavior {
    color: var(--warning);
    background: var(--warning-soft);
}

.note-category-family,
.note-category-appointment {
    color: var(--info);
    background: var(--info-soft);
}

.note-category-unknown {
    color: var(--muted);
    background: #edf0ef;
}

.progress-note-table {
    min-width: 1080px;
}

.incident-table {
    min-width: 1160px;
}

.progress-note-preview,
.incident-preview {
    max-width: 430px;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.audit-indicator {
    display: inline-flex;
    width: fit-content;
    margin: 0.12rem 0.18rem 0.12rem 0;
    padding: 0.23rem 0.45rem;
    border-radius: 999px;
    color: var(--info);
    background: var(--info-soft);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
}

.clinical-narrative,
.print-narrative {
    margin: 1.1rem 0 0;
    padding: 1rem;
    border-left: 4px solid var(--primary);
    border-radius: 0 10px 10px 0;
    background: var(--surface-soft);
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.compact-narrative {
    margin-top: 0;
    padding: 0.85rem;
    font-size: 0.9rem;
}

.documentation-timeline {
    display: grid;
    gap: 0.8rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.documentation-timeline li {
    padding: 0.95rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.documentation-timeline-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.documentation-timeline-heading span {
    color: var(--muted);
    font-size: 0.8rem;
    text-align: right;
}

.documentation-timeline li > p {
    margin: 0.55rem 0 0;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.revision-note {
    display: block;
    margin-top: 0.35rem;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.conditional-section {
    margin-top: 0.9rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #fff;
}

.notification-grid,
.notification-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
}

.notification-panel,
.notification-summary {
    min-width: 0;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}

.notification-panel > .check-field-prominent {
    padding: 0;
    border: 0;
    background: transparent;
}

.notification-panel > .conditional-section {
    margin-top: 1rem;
}

.notification-summary > div {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.notification-summary h3,
.notification-summary p {
    margin-bottom: 0;
}

.notification-summary p {
    margin-top: 0.75rem;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.incident-response-grid {
    margin-top: 1rem;
}

.narrative-section {
    margin-top: 1.2rem;
}

.narrative-section h3 {
    margin-bottom: 0.55rem;
}

.narrative-section .clinical-narrative {
    margin-top: 0;
}

.incident-detail-list {
    margin-top: 1.2rem;
}

.incident-detail-list dd,
.compact-audit-details dd {
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.incident-flag {
    color: #5f625f;
    background: #ecefed;
}

.incident-flag-injury {
    color: var(--danger);
    background: var(--danger-soft);
}

.incident-warning-card {
    border-color: #efd6a9;
    background: var(--warning-soft);
}

.incident-warning-card p {
    margin-bottom: 0.65rem;
    color: var(--warning);
    font-size: 0.84rem;
}

.incident-warning-card p:last-child {
    margin-bottom: 0;
}

.revision-details {
    margin-top: 0.65rem;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-soft);
}

.revision-details summary {
    cursor: pointer;
    color: var(--primary);
    font-size: 0.83rem;
    font-weight: 800;
}

.compact-audit-details {
    margin-top: 0.8rem;
}

.compact-audit-details .detail-row {
    grid-template-columns: 145px minmax(0, 1fr);
    padding: 0.65rem 0;
}

.incident-revision-timeline > li > p {
    font-weight: 650;
}

.resident-timeline {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.resident-timeline-entry {
    display: grid;
    grid-template-columns: 86px 20px minmax(0, 1fr);
    gap: 0.85rem;
    min-width: 0;
}

.timeline-date {
    padding-top: 0.85rem;
    text-align: right;
}

.timeline-date strong,
.timeline-date span {
    display: block;
}

.timeline-date strong {
    font-size: 0.84rem;
}

.timeline-date span {
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.75rem;
}

.timeline-marker {
    position: relative;
}

.timeline-marker::before {
    position: absolute;
    z-index: 1;
    top: 1rem;
    left: 50%;
    width: 12px;
    height: 12px;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 1px var(--border);
    content: "";
    transform: translateX(-50%);
}

.timeline-marker::after {
    position: absolute;
    top: 1.8rem;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: var(--border);
    content: "";
    transform: translateX(-50%);
}

.resident-timeline-entry:last-child .timeline-marker::after {
    display: none;
}

.timeline-card {
    min-width: 0;
    margin-bottom: 0.85rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 12px;
    background: var(--surface-soft);
}

.timeline-card-heading,
.timeline-card-footer,
.timeline-card-footer > div {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.timeline-card-heading h2 {
    margin-top: 0.22rem;
    font-size: 1.05rem;
}

.timeline-type-label {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.timeline-card > p {
    margin: 0.7rem 0;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.timeline-card-footer {
    align-items: center;
    padding-top: 0.7rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.78rem;
}

.timeline-card-footer > div {
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.timeline-status-positive,
.timeline-status-completed,
.timeline-status-health {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.timeline-status-warning,
.timeline-status-behavior,
.timeline-status-injury,
.timeline-status-condition {
    color: var(--warning);
    background: var(--warning-soft);
}

.timeline-status-info,
.timeline-status-family,
.timeline-status-appointment {
    color: var(--info);
    background: var(--info-soft);
}

.timeline-status-neutral,
.timeline-status-general,
.timeline-status-unknown {
    color: var(--muted);
    background: #edf0ef;
}

.timeline-type-medication .timeline-card,
.timeline-type-medication .timeline-marker::before {
    border-left-color: var(--primary);
}

.timeline-type-care-task .timeline-card {
    border-left-color: var(--info);
}

.timeline-type-care-task .timeline-marker::before {
    background: var(--info);
}

.timeline-type-note .timeline-card,
.timeline-type-addendum .timeline-card {
    border-left-color: #715a9a;
}

.timeline-type-note .timeline-marker::before,
.timeline-type-addendum .timeline-marker::before {
    background: #715a9a;
}

.timeline-type-incident .timeline-card,
.timeline-type-follow-up .timeline-card {
    border-left-color: var(--warning);
}

.timeline-type-incident .timeline-marker::before,
.timeline-type-follow-up .timeline-marker::before {
    background: var(--warning);
}

.print-document {
    min-height: 100vh;
    padding: 1.5rem;
    background: #e9efec;
}

.print-controls {
    display: flex;
    width: min(8.5in, 100%);
    justify-content: flex-end;
    gap: 0.65rem;
    margin: 0 auto 1rem;
}

.incident-print-report {
    width: min(8.5in, 100%);
    margin: 0 auto;
    padding: 0.55in;
    border: 1px solid #d4ddd9;
    background: #fff;
    box-shadow: var(--shadow);
}

.incident-print-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--text);
}

.incident-print-header h1,
.incident-print-header p {
    margin-bottom: 0.25rem;
}

.incident-print-resident {
    display: grid;
    gap: 0.2rem;
    min-width: 190px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    text-align: right;
}

.incident-print-resident span {
    color: var(--muted);
}

.print-correction-notice {
    margin: 0.85rem 0 0;
    padding: 0.55rem 0.7rem;
    border: 1px solid #c7deeb;
    color: var(--info);
    background: var(--info-soft);
    font-size: 0.8rem;
    font-weight: 700;
}

.print-report-section {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    break-inside: avoid;
}

.print-report-section h2 {
    margin-bottom: 0.8rem;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.print-report-section h3 {
    margin: 0.85rem 0 0.35rem;
    font-size: 0.9rem;
}

.print-report-grid,
.print-report-list {
    display: grid;
    gap: 0;
    margin: 0;
}

.print-report-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border: 1px solid var(--border);
}

.print-report-grid > div,
.print-report-list > div {
    display: grid;
    gap: 0.3rem;
    min-width: 0;
}

.print-report-grid > div {
    padding: 0.7rem;
    border-right: 1px solid var(--border);
}

.print-report-grid > div:last-child {
    border-right: 0;
}

.print-report-list > div {
    grid-template-columns: 175px minmax(0, 1fr);
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
}

.print-report-list > div:last-child {
    border-bottom: 0;
}

.print-report-grid dt,
.print-report-list dt {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
}

.print-report-grid dd,
.print-report-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.print-report-list dd strong,
.print-report-list dd span {
    display: block;
}

.print-narrative {
    margin-top: 0;
    padding: 0.75rem;
}

.print-followups {
    display: grid;
    gap: 0.65rem;
    margin: 0;
    padding-left: 1.25rem;
}

.print-followups li {
    padding-left: 0.25rem;
    break-inside: avoid;
}

.print-followups strong,
.print-followups span {
    display: block;
}

.print-followups span {
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.75rem;
}

.print-followups p {
    margin: 0.35rem 0 0;
    white-space: pre-line;
}

.incident-print-footer {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem 1rem;
    padding-top: 1rem;
    font-size: 0.8rem;
}

.incident-print-footer > div {
    display: grid;
    gap: 0.15rem;
}

.incident-print-footer > p {
    grid-column: 1 / -1;
    margin-bottom: 0;
    color: var(--muted);
}

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

@media (max-width: 660px) {
    .field-span-3 {
        grid-column: span 1;
    }

    .documentation-card-grid,
    .print-report-grid,
    .incident-print-footer {
        grid-template-columns: 1fr;
    }

    .documentation-card-actions,
    .documentation-card-actions .button {
        width: 100%;
    }

    .progress-note-table,
    .incident-table {
        min-width: 0;
    }

    .documentation-timeline-heading,
    .notification-summary > div,
    .timeline-card-heading,
    .timeline-card-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .documentation-timeline-heading span {
        text-align: left;
    }

    .resident-timeline-entry {
        grid-template-columns: 56px 14px minmax(0, 1fr);
        gap: 0.55rem;
    }

    .timeline-date {
        padding-top: 0.8rem;
    }

    .timeline-card-footer > div {
        justify-content: flex-start;
    }

    .compact-audit-details .detail-row,
    .print-report-list > div {
        grid-template-columns: 1fr;
    }

    .print-document {
        padding: 0.6rem;
    }

    .incident-print-report {
        padding: 1rem;
    }

    .incident-print-header {
        flex-direction: column;
    }

    .incident-print-resident {
        width: 100%;
        text-align: left;
    }

    .print-report-grid > div {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .print-report-grid > div:last-child {
        border-bottom: 0;
    }
}

@page {
    margin: 0.45in;
}

@page mar-landscape {
    size: landscape;
    margin: 0.35in;
}

@page incident-portrait {
    size: portrait;
    margin: 0.5in;
}

.mar-report {
    page: mar-landscape;
}

.incident-print-report {
    page: incident-portrait;
}

@media print {
    :root {
        --background: #fff;
        --surface: #fff;
        --surface-soft: #fff;
        --text: #000;
        --muted: #333;
        --border: #777;
    }

    body,
    html {
        min-height: auto;
        background: #fff;
        font-family: Arial, sans-serif;
        font-size: 9pt;
    }

    .sidebar,
    .mobile-header,
    .nav-scrim,
    .print-hidden,
    .print-hidden-link,
    .alert,
    .page-header {
        display: none !important;
    }

    .app-shell,
    .main-column {
        display: block;
    }

    .page-content {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .print-only {
        display: inline;
    }

    .mar-report {
        overflow: visible;
        border: 0;
        border-radius: 0;
    }

    .mar-report-header,
    .mar-section,
    .mar-report-footer {
        padding-right: 0;
        padding-left: 0;
    }

    .mar-table-wrap,
    .table-wrap {
        overflow: visible;
    }

    .mar-table {
        min-width: 0;
        font-size: 5.5pt;
    }

    .mar-table .mar-medication-column {
        width: 1.65in;
    }

    .mar-table th,
    .mar-table td {
        height: 0.22in;
        padding: 0.02in;
        border-color: #555;
    }

    .mar-prn-table {
        min-width: 0;
        font-size: 6.5pt;
    }

    .data-table th,
    .data-table td {
        padding: 0.06in;
    }

    a {
        color: inherit;
        text-decoration: none;
    }

    .print-document {
        padding: 0;
        background: #fff;
    }

    .incident-print-report {
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
        font-size: 9pt;
    }

    .incident-print-header {
        padding-bottom: 0.12in;
    }

    .incident-print-header h1 {
        font-size: 18pt;
    }

    .print-report-section {
        padding: 0.12in 0;
    }

    .print-report-grid > div,
    .print-report-list > div,
    .print-narrative {
        padding: 0.07in;
    }

    .incident-print-footer {
        padding-top: 0.12in;
    }

    .revision-details,
    .documentation-timeline li,
    .timeline-card {
        break-inside: avoid;
    }
}

.table-secondary-text {
    display: block;
    margin-top: 0.35rem;
    color: var(--text-muted);
}
