/* =====================================================================
   Mobile app shell — CLINIC MISTEAMS
   Loaded last by _Layout.cshtml, so it can adapt every existing page.

   Rules:
   • Anything that changes EXISTING pages lives inside the phone media
     query (max-width: 767px) — desktop keeps its current look.
   • New components (.m-*) are styled globally but only rendered/visible
     on phones (see .mobile-only / .desktop-only).
   ===================================================================== */

:root {
    --app-primary: #1565C0;
    --app-primary-dark: #0D47A1;
    --app-primary-soft: #e3edfb;
    --app-bg: #f3f5f9;
    --app-surface: #ffffff;
    --app-text: #1f2937;
    --app-muted: #6b7280;
    --app-border: #e5e7eb;
    --app-success: #16a34a;
    --app-danger: #dc2626;
    --app-radius: 14px;
    --app-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --app-bar-h: 56px;
    --app-tabbar-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- visibility helpers ---------- */
.mobile-only,
.app-bottom-nav,
.app-bar-title {
    display: none;
}

/* ---------- offline banner (all sizes) ---------- */
.app-net-banner {
    position: fixed;
    left: 50%;
    top: calc(var(--app-bar-h) + 8px + var(--safe-top));
    transform: translate(-50%, -20px);
    opacity: 0;
    pointer-events: none;
    z-index: 2000;
    padding: 8px 16px;
    border-radius: 999px;
    background: #111827;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
    transition: opacity .2s, transform .2s;
    white-space: nowrap;
}

    .app-net-banner.show {
        opacity: 1;
        transform: translate(-50%, 0);
    }

    .app-net-banner.is-online {
        background: var(--app-success);
    }

/* =====================================================================
   PHONES
   ===================================================================== */
@media (max-width: 767px) {

    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none !important;
    }

    html {
        -webkit-text-size-adjust: 100%;
    }

    body {
        background: var(--app-bg);
        padding-top: calc(var(--app-bar-h) + var(--safe-top));
        -webkit-tap-highlight-color: transparent;
    }

        body.has-bottom-nav {
            padding-bottom: calc(var(--app-tabbar-h) + var(--safe-bottom) + 16px);
        }

    #page-wrapper {
        background: transparent;
        padding: 0;
    }

    .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* ---------- top app bar ---------- */
    .top-navbar {
        min-height: var(--app-bar-h);
        padding-top: var(--safe-top);
        box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .12) !important;
    }

        .top-navbar .navbar-header {
            display: flex;
            align-items: center;
            min-height: var(--app-bar-h);
            margin: 0 !important;
            padding: 0 4px 0 16px;
        }

            .top-navbar .navbar-header > * {
                float: none !important;
            }

        .top-navbar .navbar-toggle {
            order: 3;
            margin: 0;
            width: 48px;
            height: 48px;
            border: 0;
            border-radius: 50%;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 4px;
            color: #fff;
        }

            .top-navbar .navbar-toggle:active {
                background: rgba(255, 255, 255, .15) !important;
            }

            .top-navbar .navbar-toggle .icon-bar + .icon-bar {
                margin-top: 0;
            }

    /* The bottom bar's "Menu" tab replaces the hamburger once signed in */
    body.has-bottom-nav #mobileSidebarToggle,
    body.has-bottom-nav #sideNav,
    body #deptLogo {
        display: none !important;
    }

    .top-navbar .navbar-brand {
        display: none !important;
    }

    .app-bar-title {
        display: block;
        flex: 1;
        min-width: 0;
        order: 1;
        color: #fff;
        font-size: 18px;
        font-weight: 600;
        line-height: var(--app-bar-h);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-decoration: none !important;
    }

        .app-bar-title:hover,
        .app-bar-title:focus {
            color: #fff;
        }

    /* Account menu (collapse under the app bar) — bigger rows */
    .top-navbar .navbar-collapse {
        max-height: calc(100vh - var(--app-bar-h) - var(--app-tabbar-h)) !important;
        overflow-y: auto;
        border-top: 1px solid rgba(255, 255, 255, .15);
        box-shadow: 0 12px 24px rgba(0, 0, 0, .18);
    }

        .top-navbar .navbar-collapse .nav > li > a {
            padding: 14px 20px;
            font-size: 15px;
        }

    /* Sidebar drawer sits below the app bar's safe-area and above the tab bar */
    .navbar-side {
        padding-bottom: calc(var(--app-tabbar-h) + var(--safe-bottom));
    }

    /* Footer clock/user line is replaced by the tab bar (its wrapper also reserved 30px at the top) */
    body.has-bottom-nav #page-inner,
    body.has-bottom-nav #footer {
        display: none;
    }

    /* ---------- cards (Bootstrap panels) ---------- */
    .panel {
        border: 0;
        border-radius: var(--app-radius);
        box-shadow: var(--app-shadow);
        margin-bottom: 14px;
    }

    .panel-heading {
        border-radius: var(--app-radius) var(--app-radius) 0 0;
        padding: 14px 16px;
    }

        .panel-heading .row > [class*="col-"] {
            margin-bottom: 4px;
        }

    .panel-body {
        padding: 14px 12px;
    }

    .well {
        border-radius: 12px;
        padding: 14px;
    }

    /* ---------- touch-friendly forms & buttons ---------- */
    /* 16px stops iOS Safari from zooming into inputs on focus */
    input.form-control,
    select.form-control,
    textarea.form-control,
    .form-control.input-sm,
    .form-control.input-lg {
        font-size: 16px;
        border-radius: 10px;
    }

    input.form-control,
    select.form-control,
    .form-control.input-sm {
        height: 44px;
    }

    .form-group {
        margin-bottom: 14px;
    }

    label {
        font-size: 14px;
    }

    .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 15px;
        border-radius: 10px;
        touch-action: manipulation;
    }

    .btn-sm {
        min-height: 40px;
        padding: 8px 14px;
        font-size: 14px;
    }

    .btn-xs {
        min-height: 34px;
        padding: 6px 10px;
        font-size: 13px;
        border-radius: 8px;
    }

    .select2-container .select2-selection--single {
        height: 44px !important;
        border-radius: 10px !important;
    }

        .select2-container .select2-selection--single .select2-selection__rendered {
            line-height: 42px !important;
        }

        .select2-container .select2-selection--single .select2-selection__arrow {
            height: 42px !important;
        }

    /* ---------- DataTables: stacked toolbar, scrollable table, big pager ---------- */
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

        /* Bootstrap's .row negative margins would push the toolbar past the scroll box */
        .dataTables_wrapper > .row {
            margin-left: 0;
            margin-right: 0;
        }

            .dataTables_wrapper > .row > [class*="col-"] {
                padding-left: 0;
                padding-right: 0;
            }

        .dataTables_wrapper .dataTables_filter,
        .dataTables_wrapper .dataTables_length,
        .dataTables_wrapper .dataTables_info,
        .dataTables_wrapper .dataTables_paginate {
            float: none !important;
            width: 100%;
            text-align: left !important;
        }

            .dataTables_wrapper .dataTables_filter label {
                display: block;
                width: 100%;
                margin: 0 !important; /* some pages add margin-left to this label */
            }

            .dataTables_wrapper .dataTables_filter input {
                display: block !important;
                width: 100% !important;
                margin: 6px 0 10px 0 !important;
                height: 44px;
                font-size: 16px;
                border-radius: 10px;
            }

            .dataTables_wrapper .dataTables_paginate {
                text-align: center !important;
                margin-top: 12px;
            }

                .dataTables_wrapper .dataTables_paginate .pagination > li > a,
                .dataTables_wrapper .dataTables_paginate .pagination > li > span {
                    min-width: 40px;
                    min-height: 40px;
                    line-height: 24px;
                }

    table.dataTable tbody td,
    table.dataTable thead th {
        padding: 10px 8px !important;
    }

        /* keep room for the Responsive "+" toggle, which sits inside the first cell */
        table.dataTable.dtr-inline.collapsed > tbody > tr > td:first-child,
        table.dataTable.dtr-inline.collapsed > tbody > tr > th:first-child {
            padding-left: 40px !important;
        }

    /* ---------- modals become bottom sheets ---------- */
    .modal-dialog,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-sm {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto !important;
        margin: 0 !important;
    }

    .modal.fade .modal-dialog {
        transform: translate3d(0, 100%, 0);
        transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    }

    .modal.in .modal-dialog {
        transform: translate3d(0, 0, 0);
    }

    .modal-content {
        border: 0;
        border-radius: 18px 18px 0 0;
        max-height: 92vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: var(--safe-bottom);
        box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
    }

        .modal-content::before { /* grab handle */
            content: "";
            display: block;
            width: 40px;
            height: 4px;
            border-radius: 2px;
            background: #d1d5db;
            margin: 8px auto 0;
        }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        background: inherit;
        background-color: #fff;
    }

    /* Print preview: full screen on phones */
    #printPreviewOverlay > div {
        top: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        border-radius: 0 !important;
    }

    /* ---------- bottom navigation bar ---------- */
    .app-bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030; /* under drawer (1040/1050) and Bootstrap modals (1040+) */
        height: calc(var(--app-tabbar-h) + var(--safe-bottom));
        padding: 0 4px var(--safe-bottom);
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--app-border);
        box-shadow: 0 -2px 12px rgba(16, 24, 40, .06);
    }

    @supports (backdrop-filter: blur(10px)) {
        .app-bottom-nav {
            background: rgba(255, 255, 255, .85);
            backdrop-filter: saturate(180%) blur(14px);
        }
    }
}

/* ---------- bottom nav tabs (component) ---------- */
.app-tab {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 2px;
    border: 0;
    background: none;
    color: var(--app-muted);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none !important;
    cursor: pointer;
    touch-action: manipulation;
}

    .app-tab:hover,
    .app-tab:focus {
        color: var(--app-primary);
    }

    .app-tab:focus-visible {
        outline: 2px solid var(--app-primary);
        outline-offset: -4px;
        border-radius: 12px;
    }

    .app-tab .tab-icon {
        position: relative;
        width: 56px;
        height: 30px;
        border-radius: 15px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background .2s, transform .12s;
    }

    .app-tab svg {
        width: 24px;
        height: 24px;
    }

    .app-tab:active .tab-icon {
        transform: scale(.92);
    }

    .app-tab.is-active {
        color: var(--app-primary);
        font-weight: 700;
    }

        .app-tab.is-active .tab-icon {
            background: var(--app-primary-soft);
        }

    .app-tab .tab-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.7; /* room for Khmer subscript consonants, which overflow:hidden would clip */
    }

    .app-tab .tab-badge {
        position: absolute;
        top: -2px;
        right: 8px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: var(--app-danger);
        color: #fff;
        font-size: 11px;
        font-weight: 700;
        line-height: 18px;
        text-align: center;
        box-shadow: 0 0 0 2px #fff;
    }

        .app-tab .tab-badge:empty,
        .app-tab .tab-badge[data-count="0"] {
            display: none;
        }

/* =====================================================================
   Reusable mobile components (.m-*) — used by card-list pages
   ===================================================================== */

.m-page {
    padding-top: 4px;
    padding-bottom: 8px;
}

.m-page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 2px 12px;
}

    .m-page-head h1 {
        font-size: 22px;
        font-weight: 700;
        color: var(--app-text);
        margin: 0;
    }

.m-count {
    font-size: 13px;
    color: var(--app-muted);
}

/* search field */
.m-search {
    position: relative;
    margin-bottom: 10px;
}

    .m-search svg {
        position: absolute;
        left: 14px;
        top: 50%;
        width: 20px;
        height: 20px;
        transform: translateY(-50%);
        color: #9ca3af;
        pointer-events: none;
    }

    .m-search input {
        width: 100%;
        height: 48px;
        padding: 0 44px 0 44px;
        border: 1px solid var(--app-border);
        border-radius: 14px;
        background: var(--app-surface);
        font-size: 16px;
        color: var(--app-text);
        outline: none;
        -webkit-appearance: none;
        appearance: none;
        box-shadow: var(--app-shadow);
    }

        .m-search input:focus {
            border-color: var(--app-primary);
            box-shadow: 0 0 0 4px rgba(21, 101, 192, .12);
        }

    .m-search .m-search-clear {
        position: absolute;
        right: 4px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        border: 0;
        background: none;
        color: #9ca3af;
        font-size: 22px;
        line-height: 1;
        border-radius: 50%;
    }

/* horizontally scrollable filter chips */
.m-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 10px;
    margin: 0 -2px 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

    .m-chips::-webkit-scrollbar {
        display: none;
    }

.m-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--app-border);
    border-radius: 18px;
    background: var(--app-surface);
    color: var(--app-text);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
}

    .m-chip.is-active {
        background: var(--app-primary);
        border-color: var(--app-primary);
        color: #fff;
    }

    .m-chip input[type=date] {
        border: 0;
        background: transparent;
        color: inherit;
        font: inherit;
        height: 34px;
        padding: 0;
        outline: none;
        max-width: 140px;
    }

/* list + cards */
.m-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.m-card {
    background: var(--app-surface);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
    padding: 14px;
    animation: m-in .18s ease-out;
}

.m-card-top {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.m-avatar {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
    color: var(--app-primary);
    background: var(--app-primary-soft);
}

.m-card-main {
    flex: 1;
    min-width: 0;
}

.m-card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--app-text);
    line-height: 1.35;
    word-break: break-word;
}

.m-card-meta {
    margin-top: 3px;
    font-size: 13px;
    color: var(--app-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
}

    .m-card-meta a {
        color: var(--app-primary);
        font-weight: 600;
        text-decoration: none;
    }

.m-card-sub {
    margin-top: 6px;
    font-size: 13px;
    color: var(--app-muted);
    line-height: 1.5;
}

.m-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: #dcfce7;
    color: #166534;
    vertical-align: middle;
}

.m-icon-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    margin: -6px -6px 0 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--app-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .m-icon-btn:active {
        background: #f3f4f6;
    }

    .m-icon-btn svg {
        width: 22px;
        height: 22px;
    }

.m-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.m-btn {
    flex: 1;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    font-size: 14px;
    font-weight: 600;
    touch-action: manipulation;
    cursor: pointer;
}

    .m-btn svg {
        width: 18px;
        height: 18px;
    }

    .m-btn:active {
        transform: scale(.98);
    }

.m-btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: #fff;
}

.m-btn-success {
    background: #e8f7ee;
    border-color: #c7ebd4;
    color: #166534;
}

/* loading skeletons */
.m-skeleton .m-card {
    animation: none;
}

.m-skel {
    border-radius: 6px;
    background: linear-gradient(90deg, #eef0f4 25%, #f6f7f9 37%, #eef0f4 63%);
    background-size: 400% 100%;
    animation: m-shimmer 1.2s ease-in-out infinite;
}

/* empty / error state */
.m-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--app-muted);
}

    .m-state svg {
        width: 48px;
        height: 48px;
        color: #cbd5e1;
        margin-bottom: 10px;
    }

    .m-state p {
        margin: 0 0 14px;
        font-size: 15px;
    }

.m-sentinel {
    height: 1px;
}

.m-more {
    text-align: center;
    padding: 14px 0 4px;
    color: var(--app-muted);
    font-size: 13px;
}

/* floating action button */
.m-fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--app-tabbar-h) + var(--safe-bottom) + 16px);
    z-index: 1031;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 18px;
    background: var(--app-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(21, 101, 192, .4);
    touch-action: manipulation;
}

    .m-fab svg {
        width: 26px;
        height: 26px;
    }

    .m-fab:active {
        transform: scale(.94);
    }

/* action sheet (built by MobileUI.actionSheet) */
.m-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1060;
    background: rgba(17, 24, 39, .45);
    opacity: 0;
    transition: opacity .2s;
}

.m-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1061;
    background: #fff;
    border-radius: 18px 18px 0 0;
    padding: 8px 8px calc(10px + var(--safe-bottom));
    transform: translate3d(0, 100%, 0);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    max-height: 85vh;
    overflow-y: auto;
}

    .m-sheet::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: #d1d5db;
        margin: 2px auto 8px;
    }

.m-sheet-open .m-sheet-backdrop {
    opacity: 1;
}

.m-sheet-open .m-sheet {
    transform: translate3d(0, 0, 0);
}

.m-sheet-title {
    padding: 6px 14px 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--app-muted);
    border-bottom: 1px solid #f1f2f4;
    margin-bottom: 4px;
}

.m-sheet-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 52px;
    padding: 0 14px;
    border: 0;
    border-radius: 12px;
    background: none;
    color: var(--app-text);
    font-size: 16px;
    text-align: left;
}

    .m-sheet-item:active {
        background: #f3f4f6;
    }

    .m-sheet-item svg {
        width: 22px;
        height: 22px;
        color: var(--app-muted);
    }

    .m-sheet-item.is-danger,
    .m-sheet-item.is-danger svg {
        color: var(--app-danger);
    }

    .m-sheet-item.is-cancel {
        justify-content: center;
        font-weight: 600;
        margin-top: 4px;
        background: #f3f4f6;
    }

@keyframes m-shimmer {
    0% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0 50%;
    }
}

@keyframes m-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* =====================================================================
   PHONES — design polish for the existing (legacy) screens
   One consistent look: white cards, dark titles, tonal action buttons,
   hairline tables, pill pagers, clean bottom sheets.
   `#page-wrapper` prefixes outrank page-level <style> blocks without
   needing !important everywhere.
   ===================================================================== */
@media (max-width: 767px) {

    body {
        color: var(--app-text);
    }

    /* ---------- app bar ---------- */
    .app-bar-title {
        font-size: 19px;
        letter-spacing: .15px;
    }

    .top-navbar #mobileNavFuncToggle {
        order: 3;
        width: 48px;
        height: 48px;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

        .top-navbar #mobileNavFuncToggle .glyphicon {
            display: none;
        }

    .app-avatar {
        display: flex;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, .2);
        box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .5);
        color: #fff;
        font-size: 15px;
        font-weight: 700;
        line-height: 1;
    }

    /* ---------- page rhythm ---------- */
    #page-wrapper > .container-fluid,
    #page-wrapper > .container {
        padding-top: 12px;
    }

    /* ---------- panels → clean cards ---------- */
    #page-wrapper .panel {
        background: var(--app-surface);
        border: 0;
        border-radius: 16px;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
        overflow: hidden;
    }

        #page-wrapper .panel > .panel-heading {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 8px;
            padding: 14px 16px 12px;
            background: var(--app-surface) !important;
            background-image: none !important;
            border: 0;
            border-bottom: 1px solid #eef0f3;
            border-radius: 0;
            color: var(--app-text) !important;
            font-size: 17px;
            font-weight: 700;
            line-height: 1.5;
        }

            #page-wrapper .panel > .panel-heading::before,
            #page-wrapper .panel > .panel-heading::after {
                display: none;
            }

            /* title first and full width, action buttons wrap underneath it */
            #page-wrapper .panel > .panel-heading > h1,
            #page-wrapper .panel > .panel-heading > h2,
            #page-wrapper .panel > .panel-heading > h3,
            #page-wrapper .panel > .panel-heading > h4,
            #page-wrapper .panel > .panel-heading > h5,
            #page-wrapper .panel > .panel-heading > h6,
            #page-wrapper .panel > .panel-heading > .panel-title,
            #page-wrapper .panel > .panel-heading > .modal-title {
                order: -1;
                flex: 1 0 100%;
                margin: 0;
                color: var(--app-text) !important;
                font-size: 17px;
                font-weight: 700;
                line-height: 1.5;
            }

            #page-wrapper .panel > .panel-heading > .row {
                flex: 1 0 100%;
                margin: 0;
            }

            #page-wrapper .panel > .panel-heading .btn {
                float: none !important;
                margin: 0 !important;
                min-height: 36px;
                padding: 6px 14px;
                border: 0;
                border-radius: 999px;
                background: var(--app-primary-soft);
                color: var(--app-primary);
                font-size: 13.5px;
                font-weight: 600;
                box-shadow: none;
            }

                #page-wrapper .panel > .panel-heading .btn:active {
                    background: #d3e3f8;
                }

        /* the app bar already shows the screen name — drop an identical card title */
        #page-wrapper .panel > .panel-heading.is-dup-title,
        #page-wrapper .panel > .panel-heading > .is-dup-title {
            display: none;
        }

        #page-wrapper .panel > .panel-body {
            padding: 16px;
        }

        /* panels nested inside panels/tabs: flatten instead of box-in-a-box */
        #page-wrapper .panel .panel,
        #page-wrapper .tab-content .panel {
            background: transparent;
            box-shadow: none;
            border: 0;
            border-radius: 0;
            margin-bottom: 0;
            overflow: visible;
        }

            #page-wrapper .panel .panel > .panel-heading,
            #page-wrapper .tab-content .panel > .panel-heading {
                background: transparent !important;
                padding: 4px 0 12px;
                font-size: 16px;
            }

            #page-wrapper .panel .panel > .panel-body,
            #page-wrapper .tab-content .panel > .panel-body {
                padding: 12px 0 0;
            }

    #page-wrapper .tabbable-panel {
        border: 0 !important;
        padding: 0 !important;
    }

        /* a tab block placed straight in a .row (no column) would sit on the card edge */
        #page-wrapper .row > .tabbable-panel {
            padding: 0 15px !important;
        }

    #page-wrapper .tabbable-line > .tab-content {
        border-top: 0 !important;
        padding-top: 0 !important;
    }

    #page-wrapper .panel > .panel-footer {
        padding: 12px 16px;
        background: #fff;
        border-top: 1px solid #eef0f3;
        color: var(--app-muted);
        font-size: 12.5px;
    }

    #page-wrapper .well {
        background: #f8fafc;
        border: 1px solid #eef0f3;
        box-shadow: none;
    }

    /* ---------- tabs: one swipeable row with an underline indicator ---------- */
    #page-wrapper .nav-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        margin: 0 0 14px;
        padding: 0;
        border-bottom: 1px solid var(--app-border) !important;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

        #page-wrapper .nav-tabs::-webkit-scrollbar {
            display: none;
        }

        #page-wrapper .nav-tabs::before,
        #page-wrapper .nav-tabs::after {
            display: none;
        }

        #page-wrapper .nav-tabs > li,
        #page-wrapper .nav-tabs > li.active,
        #page-wrapper .nav-tabs > li:hover {
            float: none;
            flex: 0 0 auto;
            margin: 0 !important;
            border: 0 !important;
            background: transparent !important;
        }

            #page-wrapper .nav-tabs > li > a {
                margin: 0 !important;
                padding: 12px 14px 11px !important;
                border: 0 !important;
                border-bottom: 2.5px solid transparent !important;
                border-radius: 0 !important;
                background: transparent !important;
                color: var(--app-muted) !important;
                font-size: 14.5px;
                font-weight: 600;
                white-space: nowrap;
            }

            #page-wrapper .nav-tabs > li.active > a,
            #page-wrapper .nav-tabs > li.active > a:hover,
            #page-wrapper .nav-tabs > li.active > a:focus {
                color: var(--app-primary) !important;
                border-bottom-color: var(--app-primary) !important;
            }

    /* ---------- forms ---------- */
    #page-wrapper label,
    .modal label {
        color: #334155;
        font-size: 13.5px;
        font-weight: 600;
        margin-bottom: 6px;
    }

    #page-wrapper .form-control,
    .modal .form-control {
        border: 1px solid #d6dce4;
        background-color: #fff;
        box-shadow: none;
        color: var(--app-text);
        padding-left: 14px;
        padding-right: 14px;
        transition: border-color .15s, box-shadow .15s;
    }

        #page-wrapper .form-control:focus,
        .modal .form-control:focus {
            border-color: var(--app-primary);
            box-shadow: 0 0 0 4px rgba(21, 101, 192, .12);
        }

    #page-wrapper .form-control[readonly],
    .modal .form-control[readonly] {
        background-color: #f8fafc;
    }

    /* ---------- buttons: one primary colour, consistent weight ---------- */
    .btn {
        font-weight: 600;
        box-shadow: none !important;
    }

    /* btn-info is this app's everyday "save / add" button — give it the primary colour too */
    .btn-primary,
    .btn-primary:focus,
    .btn-info,
    .btn-info:focus {
        background-color: var(--app-primary);
        border-color: var(--app-primary);
        color: #fff;
    }

        .btn-primary:hover,
        .btn-primary:active,
        .btn-info:hover,
        .btn-info:active {
            background-color: var(--app-primary-dark);
            border-color: var(--app-primary-dark);
            color: #fff;
        }

    .btn-default,
    .btn-default:focus {
        background-color: #f1f5f9;
        border-color: #e2e8f0;
        color: #334155;
    }

        .btn-default:hover,
        .btn-default:active {
            background-color: #e2e8f0;
            border-color: #e2e8f0;
            color: #1f2937;
        }

    /* ---------- DataTables ---------- */
    /* "Search:" label → a single search field with an icon */
    #page-wrapper .dataTables_wrapper .dataTables_filter label,
    .modal .dataTables_wrapper .dataTables_filter label {
        font-size: 0 !important;
        color: transparent;
        margin: 0 !important;
    }

    .dataTables_wrapper .dataTables_filter input {
        margin: 0 0 14px 0 !important;
        height: 46px;
        padding: 0 14px 0 42px !important;
        border: 1px solid var(--app-border);
        border-radius: 12px;
        background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 14px center / 18px 18px;
        color: var(--app-text);
        font-size: 16px;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
    }

        .dataTables_wrapper .dataTables_filter input:focus {
            outline: none;
            border-color: var(--app-primary);
            box-shadow: 0 0 0 4px rgba(21, 101, 192, .12);
        }

    .dataTables_wrapper .dataTables_length label {
        font-size: 13px;
        color: var(--app-muted);
        font-weight: 500;
    }

    .dataTables_wrapper .dataTables_length select {
        height: 36px;
        font-size: 15px;
        border-radius: 8px;
        margin: 0 4px;
    }

    /* hairline table inside a rounded frame */
    #page-wrapper table.dataTable,
    .modal table.dataTable {
        border: 1px solid var(--app-border) !important;
        border-collapse: separate !important;
        border-spacing: 0;
        border-radius: 12px;
        overflow: hidden;
        margin-top: 0 !important;
        background: #fff;
    }

        #page-wrapper table.dataTable > thead > tr > th,
        #page-wrapper table.dataTable > tbody > tr > td,
        .modal table.dataTable > thead > tr > th,
        .modal table.dataTable > tbody > tr > td {
            border-top: 0 !important;
            border-left: 0 !important;
            border-right: 0 !important;
            border-bottom: 1px solid #f0f2f5 !important;
            vertical-align: middle;
        }

        #page-wrapper table.dataTable > thead > tr > th,
        .modal table.dataTable > thead > tr > th {
            background: #f8fafc !important;
            color: #64748b !important;
            font-size: 12.5px;
            font-weight: 700;
            letter-spacing: .2px;
            white-space: nowrap;
            padding-right: 26px !important;
            border-bottom: 1px solid var(--app-border) !important;
        }

        #page-wrapper table.dataTable > tbody > tr > td,
        .modal table.dataTable > tbody > tr > td {
            color: var(--app-text);
            font-size: 14.5px;
        }

        #page-wrapper table.dataTable > tbody > tr:last-child > td {
            border-bottom: 0 !important;
        }

        #page-wrapper table.dataTable.table-striped > tbody > tr:nth-of-type(odd),
        #page-wrapper table.dataTable > tbody > tr.odd {
            background: #fcfcfd;
        }

        /* sort arrows: quieter */
        #page-wrapper table.dataTable thead .sorting::after,
        #page-wrapper table.dataTable thead .sorting_asc::after,
        #page-wrapper table.dataTable thead .sorting_desc::after {
            right: 8px;
            bottom: 50%;
            transform: translateY(50%);
            font-size: 10px;
            opacity: .35;
        }

        #page-wrapper table.dataTable thead .sorting_asc::after,
        #page-wrapper table.dataTable thead .sorting_desc::after {
            opacity: .8;
            color: var(--app-primary);
        }

    /* Responsive "+" / "−" row toggle: small tonal square */
    table.dataTable.dtr-inline.collapsed > tbody > tr > td:first-child::before,
    table.dataTable.dtr-inline.collapsed > tbody > tr > th:first-child::before {
        top: 50%;
        left: 10px;
        width: 22px;
        height: 22px;
        margin-top: -11px;
        border: 0;
        border-radius: 7px;
        box-shadow: none;
        background: var(--app-primary-soft);
        color: var(--app-primary);
        font-family: inherit;
        font-size: 16px;
        font-weight: 700;
        line-height: 22px;
        text-align: center;
        text-indent: 0;
    }

    table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td:first-child::before,
    table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th:first-child::before {
        background: var(--app-primary);
        color: #fff;
    }

    /* expanded row details: label / value lines */
    table.dataTable > tbody > tr.child > td.child {
        padding: 4px 14px 8px !important;
        background: #fbfcfe;
    }

    table.dataTable > tbody > tr.child ul {
        display: block !important;
        width: 100%;
        margin: 0;
        padding: 0;
        list-style: none;
    }

        table.dataTable > tbody > tr.child ul > li {
            display: flex;
            justify-content: space-between;
            align-items: baseline;
            gap: 12px;
            padding: 10px 0 !important;
            border-bottom: 1px solid #eef0f3 !important;
            white-space: normal !important;
        }

            table.dataTable > tbody > tr.child ul > li:last-child {
                border-bottom: 0 !important;
            }

    table.dataTable > tbody > tr.child .dtr-title {
        flex: 0 0 auto;
        min-width: 0;
        color: var(--app-muted);
        font-size: 13px;
        font-weight: 600;
    }

    table.dataTable > tbody > tr.child .dtr-data {
        min-width: 0;
        text-align: right;
        word-break: break-word;
    }

    /* loading indicator: a small floating pill instead of text over the header */
    .dataTables_wrapper .dataTables_processing {
        position: absolute;
        top: 70px !important;
        left: 50% !important;
        width: auto !important;
        height: auto !important;
        margin: 0 !important;
        padding: 8px 16px !important;
        transform: translateX(-50%);
        z-index: 3;
        border: 0 !important;
        border-radius: 999px;
        background: #111827 !important;
        color: #fff !important;
        font-size: 13px;
        box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
    }

    .dataTables_wrapper {
        position: relative;
    }

    /* select2 boxes match the other fields */
    .select2-container--default .select2-selection--single,
    .select2-container .select2-selection--single {
        border: 1px solid #d6dce4 !important;
    }

    /* info + pager */
    .dataTables_wrapper .dataTables_info {
        padding-top: 12px !important;
        text-align: center !important;
        color: var(--app-muted);
        font-size: 12.5px;
        white-space: normal !important;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        display: inline-flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
        margin: 0;
    }

        .dataTables_wrapper .dataTables_paginate .pagination > li > a,
        .dataTables_wrapper .dataTables_paginate .pagination > li > span {
            float: none;
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 40px;
            height: 40px;
            margin: 0 !important;
            padding: 0 10px;
            border: 0 !important;
            border-radius: 10px !important;
            background: #fff;
            box-shadow: inset 0 0 0 1px var(--app-border);
            color: var(--app-text);
            font-weight: 600;
        }

        .dataTables_wrapper .dataTables_paginate .pagination > .active > a,
        .dataTables_wrapper .dataTables_paginate .pagination > .active > span {
            background: var(--app-primary) !important;
            box-shadow: none;
            color: #fff;
        }

        .dataTables_wrapper .dataTables_paginate .pagination > .disabled > a {
            background: #fff;
            color: #cbd5e1;
        }

        /* "Previous" / "Next" → chevrons */
        .dataTables_wrapper .dataTables_paginate .pagination > .previous > a,
        .dataTables_wrapper .dataTables_paginate .pagination > .next > a {
            font-size: 0;
            width: 40px;
        }

            .dataTables_wrapper .dataTables_paginate .pagination > .previous > a::before,
            .dataTables_wrapper .dataTables_paginate .pagination > .next > a::before {
                content: "";
                width: 9px;
                height: 9px;
                border: solid currentColor;
                border-width: 0 0 2px 2px;
                transform: translateX(2px) rotate(45deg);
            }

            .dataTables_wrapper .dataTables_paginate .pagination > .next > a::before {
                transform: translateX(-2px) rotate(-135deg);
            }

    /* ---------- bottom sheets (Bootstrap modals) ---------- */
    .modal-header {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px 12px;
        border-bottom: 1px solid #eef0f3;
    }

        .modal-header::before,
        .modal-header::after {
            display: none;
        }

        .modal-header .modal-title,
        .modal-header > h1, .modal-header > h2, .modal-header > h3,
        .modal-header > h4, .modal-header > h5, .modal-header > h6 {
            order: -1;
            flex: 1 1 0;
            min-width: 0;
            margin: 0;
            color: var(--app-text) !important;
            font-size: 17px;
            font-weight: 700;
            line-height: 1.5;
        }

        .modal-header .close {
            order: 3;
            float: none;
            width: 36px;
            height: 36px;
            margin: 0 -6px 0 0;
            border-radius: 50%;
            background: #f1f5f9;
            opacity: 1;
            color: #475569;
            font-size: 22px;
            text-shadow: none;
        }

        .modal-header .btn {
            float: none !important;
            margin: 0 !important;
            min-height: 36px;
            padding: 6px 14px;
            border-radius: 999px;
            font-size: 14px;
        }

        /* a header "Close" button is navigation, not a destructive action */
        .modal-header .btn-danger,
        .modal-header .btn-default {
            background: #f1f5f9;
            border-color: #f1f5f9;
            color: #334155;
        }

    .modal-body {
        padding: 16px;
    }

        /* drop the grey box-inside-a-sheet */
        #page-wrapper .modal-body .well,
        .modal-body .well,
        .modal-body > .panel,
        .modal-body > form > .panel {
            background: transparent;
            border: 0;
            box-shadow: none;
            padding: 0;
            margin-bottom: 0;
        }

    .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
        display: flex;
        gap: 10px;
        padding: 12px 16px calc(12px + var(--safe-bottom));
        background: #fff;
        border-top: 1px solid #eef0f3;
    }

        .modal-footer::before,
        .modal-footer::after {
            display: none;
        }

        .modal-footer .btn {
            flex: 1 1 0;
            margin: 0 !important;
        }

    /* ---------- side drawer ---------- */
    body .navbar-side {
        width: 300px;
        padding-top: 0;
        border-right: 0;
        border-radius: 0 20px 20px 0;
    }

    .drawer-head {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: calc(20px + var(--safe-top)) 60px 20px 18px;
        margin-bottom: 8px;
        background: linear-gradient(135deg, var(--app-primary), var(--app-primary-dark));
        color: #fff;
    }

    .drawer-logo {
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, .18);
    }

        .drawer-logo svg {
            width: 24px;
            height: 24px;
        }

    .drawer-id {
        min-width: 0;
    }

        .drawer-id strong {
            display: block;
            font-size: 16px;
            letter-spacing: .3px;
        }

        .drawer-id small {
            display: block;
            margin-top: 2px;
            font-size: 12.5px;
            opacity: .85;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

    body #mobileSidebarClose {
        top: calc(24px + var(--safe-top));
        right: 14px;
        z-index: 2;
        line-height: 34px;
        background: rgba(255, 255, 255, .18);
        color: #fff;
    }

    #main-menu .nav-item.has-submenu > .nav-link {
        display: flex;
        align-items: center;
        margin: 2px 10px;
        padding: 12px 14px;
        border-left: 0;
        border-radius: 12px;
        color: #1f2937;
        font-size: 15px;
        font-weight: 600;
    }

        #main-menu .nav-item.has-submenu > .nav-link > span:first-child,
        #main-menu .nav-item.has-submenu > .nav-link > i:first-child {
            flex: 0 0 24px;
            margin-right: 12px !important;
            color: #64748b;
            font-size: 16px;
            text-align: center;
        }

        #main-menu .nav-item.has-submenu > .nav-link .glyphicon-chevron-down {
            margin: 0 0 0 auto;
            float: none;
        }

    #main-menu .nav-item.has-submenu.open > .nav-link {
        color: var(--app-primary);
    }

        #main-menu .nav-item.has-submenu.open > .nav-link > span:first-child {
            color: var(--app-primary);
        }

    #main-menu .submenu {
        margin: 0 10px 6px 31px;
        padding-left: 8px;
        border-left: 2px solid #eef1f6;
    }

        #main-menu .submenu > li {
            padding: 1px 0 !important;
            background: transparent !important;
        }

            #main-menu .submenu > li > a {
                display: flex;
                align-items: center;
                padding: 10px 12px;
                border-radius: 10px;
                font-size: 14.5px;
            }

                #main-menu .submenu > li > a > span:first-child,
                #main-menu .submenu > li > a > i:first-child {
                    flex: 0 0 20px;
                    margin-right: 10px;
                    font-size: 14px;
                    text-align: center;
                    opacity: .8;
                }

            #main-menu .submenu > li.active > a {
                background: var(--app-primary-soft) !important;
                color: var(--app-primary) !important;
                font-weight: 600;
            }

    /* ---------- Dashboard: 2-up stat tiles ---------- */
    #page-wrapper .dashboard-wrapper {
        padding: 14px 12px 4px;
        background: transparent;
    }

        /* header row: the app bar already says "Dashboards"; the name pill repeats the greeting */
        #page-wrapper .dashboard-wrapper > .row:first-child h1,
        #page-wrapper .dashboard-wrapper > .row:first-child .col-12 > div > div:last-child {
            display: none;
        }

        #page-wrapper .dashboard-wrapper > .row:first-child {
            margin-bottom: 12px !important;
        }

            #page-wrapper .dashboard-wrapper > .row:first-child p {
                font-size: 14px !important;
                color: var(--app-muted) !important;
            }

        #page-wrapper .dashboard-wrapper .row {
            margin: 0 -6px;
        }

        #page-wrapper .dashboard-wrapper .col-3,
        #page-wrapper .dashboard-wrapper .col-4,
        #page-wrapper .dashboard-wrapper .col-6,
        #page-wrapper .dashboard-wrapper .col-8,
        #page-wrapper .dashboard-wrapper .col-12 {
            padding: 0 6px;
            margin-bottom: 12px;
        }

        #page-wrapper .dashboard-wrapper .col-3 {
            flex: 0 0 50%;
            max-width: 50%;
        }

        #page-wrapper .dashboard-wrapper .card {
            border-radius: 16px;
            border-color: #eef0f3;
        }

        #page-wrapper .dashboard-wrapper .stat-card {
            height: 100%;
            border: 0;
            box-shadow: 0 6px 16px -8px rgba(16, 24, 40, .35);
        }

            #page-wrapper .dashboard-wrapper .stat-card .card-body {
                position: relative;
                display: block;
                height: 100%;
                padding: 14px 14px 12px;
            }

        #page-wrapper .dashboard-wrapper .stat-info h6 {
            padding-right: 30px;
            margin-bottom: 6px;
            font-size: 12.5px;
            line-height: 1.4;
        }

        #page-wrapper .dashboard-wrapper .stat-number {
            font-size: 22px;
            letter-spacing: -.3px;
            white-space: nowrap;
        }

        #page-wrapper .dashboard-wrapper .stat-trend {
            margin-top: 6px;
            padding: 2px 8px;
            font-size: 11px;
        }

        #page-wrapper .dashboard-wrapper .stat-icon-big {
            position: absolute;
            top: 12px;
            right: 12px;
            font-size: 20px;
            opacity: .45;
        }

        #page-wrapper .dashboard-wrapper .card-header {
            padding: 14px 16px 10px;
        }

        #page-wrapper .dashboard-wrapper .card-body {
            padding: 14px 16px;
        }

    /* ---------- Patients card list ---------- */
    .m-skeleton {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .m-page-head {
        margin: 2px 2px 10px;
    }

    .m-total {
        font-size: 13.5px;
        color: var(--app-muted);
    }

        .m-total b {
            color: var(--app-text);
            font-weight: 700;
        }

    .m-tonal-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 34px;
        padding: 0 12px;
        border: 0;
        border-radius: 17px;
        background: var(--app-primary-soft);
        color: var(--app-primary);
        font-size: 13.5px;
        font-weight: 600;
        touch-action: manipulation;
    }

        .m-tonal-btn svg {
            width: 16px;
            height: 16px;
        }
}

/* date chip: the native picker is an invisible overlay; the chip shows a readable label */
.m-chip-date {
    position: relative;
}

    .m-chip-date input[type=date] {
        position: absolute;
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        opacity: 0;
        cursor: pointer;
    }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}
