/* Compact dashboard header layout for phones and narrow tablets. */
@media (max-width: 768px) {
    /* Keep floating utilities above the mobile navigation bar. */
    #task-fab,
    .task-fab,
    #help-fab,
    .help-fab,
    #ai-chat-fab,
    .ai-chat-fab {
        bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    }

    #task-fab,
    .task-fab {
        left: 12px !important;
    }

    #help-fab,
    .help-fab {
        left: 60px !important;
    }

    #ai-chat-fab,
    .ai-chat-fab {
        right: 12px !important;
    }

    /* Prevent the consent checkbox from inheriting full-width form controls. */
    #patientForm #patientConsent {
        width: 20px !important;
        min-width: 20px !important;
        max-width: 20px !important;
        height: 20px !important;
        min-height: 20px !important;
        padding: 0 !important;
        flex: 0 0 20px;
    }

    #patientForm #patientConsent + span {
        min-width: 0;
        flex: 1 1 auto;
    }

    /* Turn profile navigation into a readable two-row mobile control. */
    .profile-hub-modal {
        width: calc(100% - 16px) !important;
        max-width: none !important;
        max-height: calc(100vh - 16px) !important;
        border-radius: 12px;
    }

    .profile-hero-banner {
        padding: 16px 14px !important;
    }

    .profile-hero-banner > div:first-of-type {
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .profile-avatar-circle {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }

    .profile-hub-tabs-bar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        padding: 8px;
        overflow: visible;
    }

    .profile-hub-tab {
        min-width: 0;
        min-height: 44px;
        justify-content: center;
        padding: 8px 6px;
        font-size: 0.75rem;
        line-height: 1.15;
        white-space: normal;
        text-align: center;
        border: 1px solid #dbe3ec;
        border-radius: 7px;
    }

    .profile-hub-tab.active {
        border-color: #0284c7;
    }

    .profile-hub-body {
        padding: 14px;
    }

}

/* Stack the header on narrow screens; the compact dashboard layout below keeps
   it in one row again when tablet-width screens have enough room. */
@media (max-width: 1100px) {
    .header {
        padding: 0.7rem 0.75rem 0.8rem;
    }

    .header-main-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .header-left {
        width: 100%;
        justify-content: flex-start;
    }

    .header-brand-lockup {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 0.65rem;
        width: 100%;
        text-align: left;
    }

    .brand-divider-pipe {
        display: none;
    }

    .brand-badge-link {
        padding: 4px 8px 4px 6px;
    }

    .brand-gem-icon {
        width: 26px;
        height: 26px;
        font-size: 0.85rem;
    }

    .brand-prefix,
    .brand-suffix {
        font-size: 1.05rem;
        letter-spacing: 0;
    }

    .brand-headline-block {
        align-items: flex-start;
        min-width: 0;
        text-align: left;
    }

    .header-title {
        font-size: 1.05rem;
        line-height: 1.12;
        letter-spacing: 0;
        max-width: 100%;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .header-sub-meta {
        justify-content: flex-start;
        gap: 5px;
        font-size: 0.7rem;
    }

    .header-subtitle {
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-welcome-text,
    .header-meta-dot {
        display: none;
    }

    .header-right {
        align-items: stretch;
        width: 100%;
    }

    .header-utility-row {
        width: auto;
        max-width: 100%;
        align-self: flex-end;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .header-utility-row .user-info {
        flex: 0 1 auto;
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 0.45rem 0.65rem;
    }

    .header-utility-row .user-info #currentUserRole {
        display: none;
    }

    .header-utility-row .user-info #currentUserName {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-utility-row .logout-btn {
        padding: 0.5rem 0.65rem;
        white-space: nowrap;
    }

    .header-utility-row .logout-btn span {
        display: none;
    }

    .header-district-row {
        justify-content: flex-end;
        width: auto;
        max-width: 100%;
        align-self: flex-end;
    }

    .district-scope-pill {
        width: auto;
        max-width: 100%;
        justify-content: center;
    }

    .district-scope-select {
        min-width: 0;
        width: auto;
        max-width: 240px;
        flex: 0 1 auto;
    }
}

@media (max-width: 380px) {
    .header-title {
        font-size: 0.95rem;
    }

    .header-utility-row .theme-toggle-btn {
        width: 34px;
        min-width: 34px;
        padding: 0.45rem;
    }
}
@media (max-width: 1100px) {
    .header.header--compact { min-height: 0; padding: 12px 16px; }
    .header--compact .header-main-bar { align-items: stretch; gap: 12px; min-width: 0; }
    .header--compact .header-left, .header--compact .header-right { min-width: 0; width: 100%; }
    .header--compact .header-brand-lockup { grid-template-columns: auto minmax(0, 1fr); min-width: 0; }
    .header--compact .header-title { font-size: 1.05rem; line-height: 1.25; }
    .header--compact .brand-headline-block { width: 100%; overflow: hidden; }
    .header--compact .header-sub-meta { width: 100%; min-width: 0; }
    .header--compact .header-subtitle { display: block; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .header--compact .header-right.logout-container { align-items: stretch; gap: 8px; }
    .header--compact .header-utility-row { flex-wrap: wrap; justify-content: flex-end; }
    .header--compact .header-utility-row .user-info { font-size: 0; display: flex; align-items: center; gap: 8px; }
    .header--compact .header-utility-row .user-info #currentUserName { font-size: .875rem; }
    .header--compact .header-utility-row .user-info > i { font-size: 1.1rem; }
    .header--compact .header-district-row:has(.district-scope-pill[style*="display: none"]) { display: none; }
    .header--compact .district-scope-pill { max-width: 100%; }
    .header--compact .district-scope-select { width: auto; max-width: min(240px, 100%); }
}

@media (min-width: 960px) and (max-width: 1100px) {
    .header.header--compact {
        padding: 10px 14px;
    }

    .header--compact .header-main-bar {
        flex-direction: row;
        align-items: center;
        gap: 12px;
    }

    .header--compact .header-left {
        flex: 1 1 auto;
        width: auto;
    }

    .header--compact .header-brand-lockup {
        display: flex;
        width: auto;
        gap: 8px;
    }

    .header--compact .brand-divider-pipe {
        display: block;
        height: 26px;
    }

    .header--compact .brand-badge-link {
        padding: 4px 7px;
    }

    .header--compact .header-title {
        display: block;
        font-size: 0.9rem;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header--compact .header-sub-meta {
        display: none;
    }

    .header--compact .header-right.logout-container {
        flex: 0 0 auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        width: auto;
    }

    .header--compact .header-utility-row {
        flex-wrap: nowrap;
        gap: 5px;
    }

    .header--compact .header-utility-row .user-info {
        max-width: 170px;
        flex: 0 1 auto;
    }

    .header--compact .header-district-row {
        flex: 0 1 auto;
    }

    .header--compact .district-scope-pill {
        justify-content: flex-start;
    }

    .header--compact .district-scope-select {
        max-width: 190px;
    }
}

@media (min-width: 769px) and (max-width: 1100px) {
    .header.header--compact {
        padding: 10px 14px;
    }

    .header--compact .header-main-bar {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .header--compact .header-left {
        flex: 1 1 0;
        width: auto;
    }

    .header--compact .header-brand-lockup {
        display: flex;
        width: 100%;
        gap: 7px;
    }

    .header--compact .brand-divider-pipe {
        display: block;
        height: 24px;
    }

    .header--compact .brand-badge-link {
        padding: 4px 6px;
    }

    .header--compact .header-title {
        display: block;
        font-size: 0.88rem;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header--compact .header-sub-meta {
        display: none;
    }

    .header--compact .header-right.logout-container {
        flex: 0 1 auto;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        width: auto;
    }

    .header--compact .header-utility-row {
        flex-wrap: nowrap;
        gap: 4px;
    }

    .header--compact .header-utility-row .user-info {
        max-width: 135px;
        flex: 0 1 auto;
        padding: 0.4rem 0.5rem;
    }

    .header--compact .header-utility-row .logout-btn {
        margin-right: 0 !important;
        padding: 0.45rem 0.55rem;
    }

    .header--compact .header-district-row {
        flex: 0 1 auto;
        width: auto;
        min-width: 0;
    }

    .header--compact .district-scope-pill {
        justify-content: flex-start;
        min-width: 0;
        padding: 3px 7px;
        gap: 5px;
    }

    .header--compact .district-scope-select {
        width: 150px;
        max-width: 150px;
        min-width: 0;
    }
}
