/* ── Design tokens ─────────────────────────────────────────────────── */
:root {
    --mj-primary: #2563eb;
    --mj-primary-hover: #1d4ed8;
    --mj-primary-light: #eff6ff;
    --mj-surface: #ffffff;
    --mj-bg: #f3f4f8;
    --mj-border: #e5e7eb;
    --mj-text: #111827;
    --mj-text-muted: #6b7280;
    --mj-radius: 10px;
    --mj-radius-lg: 14px;
    --mj-shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --mj-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
    --mj-transition: 0.18s ease;
}

/* ── Base ───────────────────────────────────────────────────────────── */
html, body {
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 15px;
    background-color: var(--mj-bg);
    color: var(--mj-text);
    /* Fill the viewport exactly so the single scroll container below
       can be height-constrained and overflow-y:auto actually fires.
       overflow:hidden here means the body itself never scrolls — all
       scrolling happens inside article.content. */
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
}

    h1:focus {
        outline: none;
    }

/* ── Page transition ────────────────────────────────────────────────── */
article.content {
    animation: mj-fadein 0.18s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Links ──────────────────────────────────────────────────────────── */
a, .btn-link {
    color: var(--mj-primary);
}

/* ── Primary color overrides ────────────────────────────────────────── */
.btn-primary {
    background-color: var(--mj-primary);
    border-color: var(--mj-primary);
    color: #fff;
    border-radius: 8px;
    font-weight: 500;
    padding: 0.45rem 1rem;
    transition: background-color var(--mj-transition), box-shadow var(--mj-transition);
}

    .btn-primary:hover,
    .btn-primary:focus {
        background-color: var(--mj-primary-hover);
        border-color: var(--mj-primary-hover);
        box-shadow: 0 0 0 3px rgba(37,99,235,0.18);
    }

.btn-outline-primary {
    color: var(--mj-primary);
    border-color: var(--mj-primary);
    border-radius: 8px;
    font-weight: 500;
    border-width: 2px;
}

    .btn-outline-primary:hover {
        background-color: var(--mj-primary);
        border-color: var(--mj-primary);
        transform: translateY(-2px);
        transition: transform 0.2s ease;
    }

/* ── All buttons: consistent radius + weight ────────────────────────── */
.btn {
    border-radius: 8px !important;
    font-weight: 500;
}

    /* Modern focus ring */
    .btn:focus,
    .btn:active:focus,
    .btn-link.nav-link:focus,
    .form-control:focus,
    .form-check-input:focus,
    .form-select:focus {
        outline: none;
        box-shadow: 0 0 0 3px rgba(37,99,235,0.22) !important;
    }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
    border-radius: var(--mj-radius-lg) !important;
    border: 1px solid var(--mj-border) !important;
    box-shadow: var(--mj-shadow-sm);
    background: var(--mj-surface);
}

.card-header {
    border-radius: var(--mj-radius-lg) var(--mj-radius-lg) 0 0 !important;
    border-bottom: 1px solid var(--mj-border);
}

/* ── Modals ─────────────────────────────────────────────────────────── */
.modal-content {
    border-radius: var(--mj-radius-lg) !important;
    border: none !important;
    box-shadow: var(--mj-shadow) !important;
}

.modal-header {
    border-radius: var(--mj-radius-lg) var(--mj-radius-lg) 0 0 !important;
}

/* ── Form controls ──────────────────────────────────────────────────── */
.form-control,
.form-select {
    border-radius: var(--mj-radius) !important;
    border: 1px solid var(--mj-border) !important;
    background-color: var(--mj-surface) !important;
    color: var(--mj-text) !important;
    transition: border-color var(--mj-transition), box-shadow var(--mj-transition);
}

    .form-control:focus,
    .form-select:focus {
        border-color: var(--mj-primary) !important;
        box-shadow: 0 0 0 3px rgba(37,99,235,0.15) !important;
        background-color: var(--mj-surface) !important;
    }

    .form-control::placeholder {
        color: var(--mj-text-muted);
        opacity: 1;
    }

/* ── Form floating placeholder alignment ───────────────────────────── */
.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ── Validation ─────────────────────────────────────────────────────── */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

/* ── Blazor error UI ────────────────────────────────────────────────── */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5OC45OTkzIDI5MC4yNzYgOTkgMjkzLjg1NDUgOTkgMzAxLjM2NjggOTkgMzAwLjgzODUgOTkgMzAwLjM3MjYgOTkgMzAwLjE4NjMgOTkgMTk5Ljc1NiA5OSAyNTkuMzMyIDY5Ljg2MDggMjU5LjM3MSA3MC4wODg3TDI2MS43OTUgODQuMDE2MSAyNjUuMzggODQuMDE2MSAyNjcuODIxIDY5Ljc0NzVDMjY3Ljg2IDY5LjczMDkgMjY3Ljg3OSA2OS41ODc3IDI2Ny44NzkgNjkuMzE3OSAyNjcuODc5IDY3LjExODIgMjY2LjQ0OCA2Ni4wNTQ3IDI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred.";
    }

/* ── Loading progress ───────────────────────────────────────────────── */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #e0e0e0;
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: #2563eb;
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }

code {
    color: #c02d76;
}

/* ============================================
   MainLayout — Page Shell
   ============================================ */
.page {
    position: relative;
    display: flex;
    flex-direction: column;
    /* Fill the full viewport height — required so the flex children can
       be height-constrained and overflow-y on article.content fires. */
    height: 100vh;
    overflow: hidden;
    /* iOS safe-area: viewport-fit=cover extends under the notch/Dynamic Island
       and the rounded corners. Compensate so content is never clipped. */
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

.top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── Single scroll container ────────────────────────────────────────────
   IMPORTANT: Only article.content scrolls. .page main does NOT scroll.
   This eliminates the nested overflow-y:auto problem that caused touch
   swipe to be unreliable on phones/tablets.

   touch-action: pan-y  — tells the browser that vertical swipes on this
   element (and anything inside it, including buttons) should scroll the
   container. A short tap still fires click; only a deliberate vertical
   drag triggers scroll. This is what makes "swipe anywhere — even on a
   button — to scroll" work reliably on Android Chrome and iOS Safari.

   The Chat page manages its own internal scroll via .messages-container
   and is unaffected by this change.
   ─────────────────────────────────────────────────────────────────────── */
.page main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;      /* critical: lets flex child shrink below content size */
    overflow: hidden;   /* main itself does NOT scroll */
}

    .page main article.content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
        touch-action: pan-y;              /* vertical swipe scrolls here, even when starting on a button */
        overscroll-behavior-y: contain;   /* prevent pull-to-refresh / scroll chaining */
    }

/* ============================================
   NavMenu Styles
   ============================================ */
.nav-menu-container {
    height: 100%;
    background-color: var(--bs-dark);
    display: flex;
    flex-direction: column;
}

.nav-header {
    padding: 1rem;
    background-color: rgba(0, 0, 0, 0.25);
}

.navbar-brand {
    color: white !important;
    font-size: 1.25rem;
    font-weight: bold;
    text-decoration: none;
}

    .navbar-brand:hover {
        color: white !important;
    }

.nav-scrollable {
    overflow-y: auto;
    flex: 1;
}

.nav-item {
    width: 100%;
}

.nav-link {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0 !important;
    min-height: 3rem;
    color: #d7d7d7 !important;
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

    .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: white !important;
    }

    .nav-link.active {
        background-color: rgba(255, 255, 255, 0.25);
        color: white !important;
    }

.nav-expandable {
    position: relative;
}

.nav-chevron {
    margin-left: auto;
    font-size: 0.875rem;
    transition: transform 0.3s ease;
}

.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    background-color: rgba(0, 0, 0, 0.2);
}

    .nav-submenu.expanded {
        max-height: 500px;
    }

.nav-sublink {
    padding-left: 2rem !important;
    min-height: 2.5rem !important;
    font-size: 0.9rem;
}

    .nav-sublink .nav-icon {
        font-size: 1.25rem;
    }

    .nav-sublink .nav-text {
        font-size: 0.9rem;
    }

.nav-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.nav-text {
    font-size: 1rem;
    line-height: 1.5rem;
}

/* ============================================
   Responsive Tables
   ============================================ */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    .table {
        font-size: 0.875rem;
    }
}

/* ============================================
   Profile Page Styles
   ============================================ */
.profile-container {
    padding: 1rem 0;
}

.profile-avatar {
    margin: 1rem 0;
}

.card-title {
    color: #333;
    font-weight: 600;
}

.list-group-item {
    border-left: none;
    border-right: none;
    padding: 1rem 0;
}

    .list-group-item:first-child {
        border-top: none;
    }

    .list-group-item:last-child {
        border-bottom: none;
    }

@media (max-width: 991px) {
    .profile-container {
        padding: 0.5rem 0;
    }
}

/* ============================================
   Appointment & Procedure Card Styles
   ============================================ */
.appointment-card,
.procedure-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 0.5rem;
    overflow: visible;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08) !important;
}

.appointment-card {
    border-left: 4px solid #0d6efd !important;
}

    .appointment-card.past {
        border-left: 4px solid #6c757d !important;
    }

.procedure-card {
    border-left: 4px solid #198754 !important;
}

    .procedure-card.past {
        border-left: 4px solid #6c757d !important;
    }

    .appointment-card:hover,
    .procedure-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.12) !important;
    }

/* Detail rows inside cards */
.appointment-details,
.procedure-details {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e9ecef;
}

    .appointment-details .detail-row,
    .procedure-details .detail-row {
        display: flex;
        align-items: baseline;
        gap: 0.25rem;
        margin-bottom: 0.4rem;
        font-size: 0.875rem;
        color: #495057;
    }

        .appointment-details .detail-row .bi,
        .procedure-details .detail-row .bi {
            color: #0d6efd;
            flex-shrink: 0;
        }

        .procedure-details .detail-row .bi {
            color: #198754;
        }

/* Card footer */
.appointment-card .card-footer,
.procedure-card .card-footer {
    background: #f8f9fa !important;
    border-top: 1px solid #e9ecef;
    padding: 0.6rem 1rem;
}

/* ============================================
   My Schedule Page
   ============================================ */
.schedule-page-header {
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    color: #fff;
    box-shadow: 0 4px 16px rgba(13,110,253,0.25);
}

    .schedule-page-header h4 {
        color: #fff;
        margin: 0;
    }

.schedule-legend {
    display: flex;
    gap: 1.25rem;
    align-items: center;
    flex-wrap: wrap;
}

    .schedule-legend span {
        display: flex;
        align-items: center;
        font-size: 0.85rem;
        font-weight: 500;
        color: #495057;
    }

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    margin-right: 5px;
    flex-shrink: 0;
}

/* Card modal */
.schedule-card-modal .modal-content {
    border: none;
    border-radius: 0.875rem;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0,0,0,0.22);
}

.schedule-card-modal .modal-header {
    padding: 0.75rem 1rem;
    border-bottom: none;
}

    .schedule-card-modal .modal-header.appt-header {
        background: linear-gradient(90deg, #0d6efd, #6ea8fe);
        color: #fff;
    }

        .schedule-card-modal .modal-header.appt-header .btn-close {
            filter: invert(1);
        }

    .schedule-card-modal .modal-header.proc-header {
        background: linear-gradient(90deg, #198754, #75b798);
        color: #fff;
    }

        .schedule-card-modal .modal-header.proc-header .btn-close {
            filter: invert(1);
        }

.schedule-card-modal .modal-body {
    padding: 0;
}

/* Remove double-border when card lives inside modal */
.schedule-card-modal .appointment-card,
.schedule-card-modal .procedure-card {
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: none !important;
}

    .schedule-card-modal .appointment-card::before,
    .schedule-card-modal .procedure-card::before {
        display: none;
    }

/* ============================================
   Custom Agenda / Upcoming List
   ============================================ */
.agenda-list {
    display: flex;
    flex-direction: column;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.agenda-item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background 0.15s;
}

    .agenda-item:last-child {
        border-bottom: none;
    }

    .agenda-item:hover {
        background: #f8f9fa;
    }

.agenda-date-col {
    width: 64px;
    min-width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border-right: 1px solid #e9ecef;
    background: #f8f9fa;
}

.agenda-appt .agenda-date-col {
    border-left: 4px solid #3b82f6;
}

.agenda-proc .agenda-date-col {
    border-left: 4px solid #10b981;
}

.agenda-month {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #6c757d;
    text-transform: uppercase;
}

.agenda-day {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.1;
    color: #212529;
}

.agenda-dow {
    font-size: 0.65rem;
    color: #6c757d;
    font-weight: 500;
}

.agenda-detail-col {
    flex: 1;
    padding: 12px 14px;
}

.agenda-subject {
    font-weight: 600;
    font-size: 0.9rem;
    color: #212529;
    margin-bottom: 3px;
}

.agenda-meta {
    font-size: 0.78rem;
    color: #6c757d;
}

.agenda-appt .agenda-meta .bi-calendar-check {
    color: #3b82f6;
}

.agenda-proc .agenda-meta .bi-journal-medical {
    color: #10b981;
}

.agenda-arrow {
    padding: 0 12px;
}

/* ============================================
   Syncfusion Calendar — Safe Styling
   ============================================ */
.e-schedule {
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    border: 1px solid #dee2e6;
}

    /* Today cell tint */
    .e-schedule .e-work-cells.e-current-day,
    .e-schedule .e-month-view .e-work-cells.e-current-date {
        background: #eef3ff !important;
    }

/* Event block polish */
.e-appointment {
    border-radius: 5px !important;
    font-weight: 600 !important;
    font-size: 0.78rem !important;
}

/* Event template */
.sched-event-tpl {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    overflow: hidden;
    min-width: 0;
}

.sched-ev-icon {
    font-size: 0.7rem;
    flex-shrink: 0;
    opacity: 0.85;
}

.sched-ev-subject {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
    font-weight: 600;
}

.sched-ev-recur {
    font-size: 0.7rem;
    flex-shrink: 0;
    opacity: 0.75;
}

/* Settings panel */
.schedule-settings-panel {
    background: var(--mj-surface);
    border: 1px solid var(--mj-border);
    border-radius: var(--mj-radius);
    box-shadow: var(--mj-shadow-sm);
}

    .schedule-settings-panel .form-label-sm {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--mj-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

/* ============================================
   Quick Action Card Styles
   ============================================ */
.appointment-quick-action {
    cursor: pointer;
    transition: all 0.3s ease;
    border-width: 2px !important;
    border-style: solid !important;
}

    .appointment-quick-action h6,
    .appointment-quick-action .form-check-label {
        color: var(--bs-primary);
        transition: color 0.2s ease-in-out;
    }

    .appointment-quick-action .form-check-input:checked {
        background-color: #fd7e14;
        border-color: #fd7e14;
    }

    .appointment-quick-action .form-check-input:focus {
        border-color: #fd7e14;
        box-shadow: 0 0 0 0.25rem rgba(253, 126, 20, 0.25);
    }

    .appointment-quick-action:hover {
        background-color: var(--bs-primary);
        border-color: var(--bs-primary) !important;
        transform: translateY(-2px);
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    }

        .appointment-quick-action:hover h6,
        .appointment-quick-action:hover .form-check-label,
        .appointment-quick-action:hover .bi {
            color: white !important;
        }

        .appointment-quick-action:hover .form-check-input {
            border-color: white;
        }

            .appointment-quick-action:hover .form-check-input:checked {
                background-color: #fd7e14 !important;
                border-color: #fd7e14 !important;
            }

        .appointment-quick-action:hover .btn-primary {
            background-color: white !important;
            border-color: white !important;
            color: var(--bs-primary) !important;
        }

            .appointment-quick-action:hover .btn-primary .bi {
                color: var(--bs-primary) !important;
            }

/* ============================================
   CHAT UI (Medical Theme, Full-width, No Sidebar)
   ============================================ */

/* Outer chat container fills article.content */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--mj-bg);
    border-radius: var(--mj-radius-lg);
    box-shadow: var(--mj-shadow);
    overflow: hidden;
}

.chat-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* CRITICAL */
}

/* Main chat panel */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--mj-surface);
    min-height: 0; /* CRITICAL for overflow to work */
}

/* ── Chat header: explicit 4-row × 3-column grid ───────────────────── */
/*                                                                       */
/*   Columns: [col 1 = 50%] [col 2 = 25%] [col 3 = 25%]                */
/*   Row 1:   load-more link | (spacer)   | (spacer)                    */
/*   Row 2:   select + New   | search     | action buttons              */
/*   Row 3:   date range     | (spacer)   | (spacer)                    */
/*   Row 4:   textarea + Send (spans all 3 cols)                        */

.chat-header {
    display: grid;
    grid-template-columns: 50% 25% 25%;
    grid-template-rows: auto auto auto auto;
    align-items: center;
    column-gap: 0.75rem;
    row-gap: 0;
    padding: 0.4rem 1rem 0.55rem;
    border-bottom: 1px solid var(--mj-border);
    background: var(--mj-surface);
    box-shadow: var(--mj-shadow-sm);
    flex-shrink: 0;
    z-index: 10;
}

/* ── Row 1 ──────────────────────────────────────────────────────────── */
.chat-header-loadmore {
    grid-column: 1;
    grid-row: 1;
    padding-bottom: 0.15rem;
    min-height: 1.3rem;
    display: flex;
    align-items: center;
}

.chat-header-search-spacer {
    grid-column: 2;
    grid-row: 1;
}

.chat-header-actions-spacer {
    grid-column: 3;
    grid-row: 1;
}

.load-more-btn {
    padding: 0;
    background: none;
    border: none;
    color: var(--mj-primary);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    text-align: left;
    transition: color var(--mj-transition);
}

    .load-more-btn:hover {
        color: var(--mj-primary-hover);
        text-decoration: underline;
    }

.load-more-placeholder {
    font-size: 0.78rem;
    color: var(--mj-text-muted);
}

/* ── Row 2 ──────────────────────────────────────────────────────────── */

/* Col 1, row 2: select + New button — together fill the full 50% column */
.chat-header-select-row {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

/* conversation-select grows to fill remaining space after the New button */
.conversation-select {
    flex: 1 1 0;
    min-width: 0;
    font-size: 0.88rem !important;
}

.chat-new-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Col 2: search box */
.chat-header-search {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

/* conversation-search gets .form-control; just add right padding for the X */
.conversation-search {
    padding-right: 2rem !important;
    font-size: 0.88rem !important;
}

.search-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--mj-text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--mj-transition);
    z-index: 2;
}

    .search-clear-btn:hover {
        color: var(--mj-text);
    }

/* Col 3: action buttons (Summarize, Rename, Delete) */
.chat-header-actions {
    grid-column: 3;
    grid-row: 2;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 0.35rem;
    padding-right: 1rem;
}

/* ── Row 3 ──────────────────────────────────────────────────────────── */
.chat-header-daterange {
    grid-column: 1;
    grid-row: 3;
    padding-top: 0.12rem;
    min-height: 1rem;
}

.chat-header-daterange-spacer {
    grid-column: 2 / -1;
    grid-row: 3;
}

.conversation-range {
    font-size: 0.72rem;
    color: var(--mj-text-muted);
    padding-left: 2px;
}

/* ── Row 4: full-width textarea + Send ──────────────────────────────── */
.chat-header-input {
    grid-column: 1 / -1;
    grid-row: 4;
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    border-top: 1px solid var(--mj-border);
    margin-top: 0.5rem;
    padding-top: 0.65rem;
    padding-right: 1rem;
}

/* textarea gets .form-control; override for auto-expand behaviour */
.chat-input-textarea {
    resize: none !important;
    overflow: hidden !important;
    line-height: 1.5 !important;
    min-height: calc(1.5em + 0.75rem + 2px); /* one row, same as Bootstrap's form-control height */
    max-height: 200px !important;
    transition: border-color var(--mj-transition), box-shadow var(--mj-transition),
                height 0.1s ease !important;
}

/* Send button extra sizing — .btn.btn-primary handles colour */
.chat-send-btn {
    white-space: nowrap;
    align-self: flex-end;
    padding: 0.45rem 1.1rem;
}

/* Messages list */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--mj-surface);
    min-height: 0;
    max-height: calc(100vh - 56px - 160px);
}

/* Message row */
.message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

    .message.user {
        justify-content: flex-end;
    }

    .message.assistant {
        justify-content: flex-start;
    }

/* Avatars */
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--mj-primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Bubbles */
.bubble {
    padding: 10px 14px;
    border-radius: 16px;
    box-shadow: var(--mj-shadow-sm);
    font-size: 0.95rem;
    line-height: 1.4;
}

.bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.dig-deeper-btn {
    align-self: flex-start;
    margin-top: 6px;
    font-size: 0.75rem;
    opacity: 0.75;
    transition: opacity 0.2s;
}

.dig-deeper-btn:hover {
    opacity: 1;
}

.message.user .bubble {
    background: var(--mj-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: #f3f4f6;
    color: var(--mj-text);
    border-bottom-left-radius: 4px;
}

/* Timestamp under bubble */
.timestamp {
    margin-top: 6px;
    font-size: 0.72rem;
    opacity: 0.6;
    text-align: right;
}

/* Animated typing indicator — three bouncing dots */
.bubble.typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    min-width: 54px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: dotBounce 1.2s infinite ease-in-out;
}

    .dot:nth-child(1) { animation-delay: 0s; }
    .dot:nth-child(2) { animation-delay: 0.2s; }
    .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

/* Popup menu (⋮ actions) */
@keyframes fadeInMenu {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.popup-menu {
    position: absolute;
    right: 16px;
    top: 48px;
    background: var(--mj-surface);
    border: 1px solid var(--mj-border);
    border-radius: var(--mj-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    padding: 6px 0;
    z-index: 20;
    animation: fadeInMenu 0.18s ease-out;
}

    .popup-menu button {
        display: block;
        width: 100%;
        padding: 8px 16px;
        background: none;
        border: none;
        text-align: left;
        cursor: pointer;
        font-size: 0.9rem;
    }

        .popup-menu button:hover {
            background: var(--mj-primary-light);
        }

/* Chat AI Shortcut Chips */
.chat-ai-shortcuts {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.35rem 0 0;
}

.chat-shortcut-btn {
    font-size: 0.8rem;
    border-radius: 20px;
    padding: 0.2rem 0.75rem;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 3000;
    pointer-events: none;
}

.app-toast {
    pointer-events: auto;
    min-width: 260px;
    max-width: 360px;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateX(100%);
}

.toast-success { background: #28a745; }
.toast-error   { background: #dc3545; }
.toast-warning { background: #ffc107; color: #333; }
.toast-info    { background: #17a2b8; }

.slide-in {
    animation: slideIn 0.35s ease-out forwards;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100%); }
    to   { opacity: 1; transform: translateX(0); }
}

.fade-out.slide-out {
    animation: fadeSlideOut 0.45s ease-in forwards;
}

@keyframes fadeSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(100%); }
}

/* ============================================
   AI Insight Panel
   ============================================ */
.ai-insight-panel {
    border: 1px solid #c3d9f7;
    border-radius: 10px;
    background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%);
    margin-top: 1rem;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.1);
}

.ai-insight-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: linear-gradient(90deg, #e8f1fb 0%, #f5f9ff 100%);
    border-bottom: 1px solid #c3d9f7;
}

.ai-insight-panel-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #0057b8;
}

.ai-insight-panel-body {
    padding: 1rem;
}

.ai-insight-content {
    font-size: 0.92rem;
    line-height: 1.65;
    color: #2c3e50;
}

.ai-insight-content h1,
.ai-insight-content h2,
.ai-insight-content h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 0.75rem;
    color: #0057b8;
}

.ai-insight-content ul,
.ai-insight-content ol {
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
}

.ai-insight-content p:last-child {
    margin-bottom: 0;
}

.ai-insight-content strong {
    color: #1a1a2e;
}

/* ============================================
   Health Timeline — Inline List (Chat widget)
   ============================================ */
.timeline-dialog {
    border: 1px solid #c3d9f7;
    border-radius: 10px;
    background: #f8fbff;
    margin-top: 0.5rem;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 102, 204, 0.12);
}

.timeline-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: linear-gradient(90deg, #e8f1fb 0%, #f5f9ff 100%);
    border-bottom: 1px solid #c3d9f7;
    font-size: 0.9rem;
}

.timeline-dialog-body {
    padding: 0.65rem 1rem;
}

.timeline-list {
    display: flex;
    flex-direction: column;
}

.timeline-entry {
    display: grid;
    grid-template-columns: 7rem 1.5rem 1fr;
    align-items: baseline;
    gap: 0 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--mj-border, #e9ecef);
    font-size: 0.85rem;
}

    .timeline-entry:last-child {
        border-bottom: none;
    }

.timeline-date {
    color: var(--mj-text-muted, #6c757d);
    white-space: nowrap;
    font-size: 0.78rem;
}

.timeline-icon {
    text-align: center;
    font-size: 0.9rem;
}

.timeline-body {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem;
}

.timeline-title {
    font-weight: 600;
}

.timeline-detail {
    color: var(--mj-text-muted, #6c757d);
    font-size: 0.8rem;
}

/* ============================================
   My Timeline Page (full-width)
   ============================================ */
.timeline-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 0.5rem;
}

.timeline-page-header {
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    color: #fff;
    box-shadow: 0 4px 16px rgba(13,110,253,0.2);
}

    .timeline-page-header h4,
    .timeline-page-header small {
        color: #fff;
    }

    .timeline-page-header small {
        opacity: 0.85;
    }

.timeline-ai-summary {
    background: #f0f7ff;
    border-left: 3px solid #0d6efd;
    border-radius: 0 0.5rem 0.5rem 0;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
}

.timeline-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.timeline-list-wide {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--mj-border, #e9ecef);
    border-radius: 0.5rem;
    overflow: hidden;
}

.timeline-entry-wide {
    display: grid;
    grid-template-columns: 8rem 2rem 7rem 1fr;
    align-items: center;
    gap: 0 0.75rem;
    padding: 0.45rem 1rem;
    border-bottom: 1px solid var(--mj-border, #e9ecef);
    font-size: 0.875rem;
    transition: background 0.1s;
}

    .timeline-entry-wide:last-child {
        border-bottom: none;
    }

    .timeline-entry-wide:hover {
        background: #f8fbff;
    }

    .timeline-entry-wide.appointment { border-left: 3px solid #0d6efd; }
    .timeline-entry-wide.lab         { border-left: 3px solid #198754; }
    .timeline-entry-wide.procedure   { border-left: 3px solid #6f42c1; }
    .timeline-entry-wide.event       { border-left: 3px solid #fd7e14; }
    .timeline-entry-wide.medication  { border-left: 3px solid #dc3545; }

.tl-date {
    color: var(--mj-text-muted, #6c757d);
    font-size: 0.78rem;
    white-space: nowrap;
}

.tl-icon {
    text-align: center;
    font-size: 1rem;
}

.tl-type {
    font-size: 0.75rem;
    color: var(--mj-text-muted, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tl-body {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem;
}

.tl-title {
    font-weight: 600;
}

.tl-detail {
    color: var(--mj-text-muted, #6c757d);
    font-size: 0.82rem;
}

/* ============================================
   To-Do Tasks — Row Colours
   ============================================ */
.task-overdue-row td   { background-color: #ffe5e5 !important; }
.task-completed-row td { background-color: #e6ffe6 !important; }
.task-upcoming-row td  { background-color: #fff8e1 !important; }

.task-completed-row:hover td,
.task-upcoming-row:hover td,
.task-overdue-row:hover td {
    background-color: inherit !important;
}

.clickable-row {
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

    .clickable-row:hover {
        background-color: rgba(0, 0, 0, 0.04);
    }

    .clickable-row:focus-within {
        outline: 2px solid #007bff;
        outline-offset: -2px;
    }

/* ============================================
   To-Do Tasks — Stats Bar
   ============================================ */
.task-stats {
    display: flex;
    gap: 1rem;
}

.task-stat {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: #f8f9fa;
    cursor: pointer;
    text-align: center;
    min-width: 80px;
    transition: background 0.2s ease;
}

    .task-stat:hover {
        background: #eef2f4;
    }

    .task-stat.active {
        background: #dceeff;
        border: 1px solid #99caff;
    }

.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #666;
}

.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
    pointer-events: none;
}

/* ============================================
   MyToDoTasks — Search / Create Toolbar
   ============================================ */
.task-toolbar {
    display: flex;
    align-items: stretch;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.task-toolbar-btn {
    height: 2.5rem;
    padding: 0 1rem;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.task-toolbar-search {
    flex: 1 1 340px;
    max-width: 520px;
    height: 2.5rem !important;
    min-height: 2.5rem;
}

/* ============================================
   MyToDoTasks — Accordion Notes Row
   ============================================ */
.task-notes-toggle {
    color: var(--mj-text-muted);
    line-height: 1;
    text-decoration: none !important;
    flex-shrink: 0;
}

    .task-notes-toggle:hover {
        color: var(--mj-primary);
    }

.task-notes-chevron {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.task-notes-chevron-placeholder {
    display: inline-block;
    width: 1rem;
    flex-shrink: 0;
}

.task-notes-row td {
    padding-top: 0 !important;
    border-top: none !important;
}

.task-notes-content {
    background: var(--mj-primary-light);
    border-left: 3px solid var(--mj-primary);
    border-radius: 0 6px 6px 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--mj-text);
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 0.4rem;
}

.task-notes-row.task-completed-row .task-notes-content {
    background: #f0fdf4;
    border-left-color: #28a745;
}

.task-notes-row.task-overdue-row .task-notes-content {
    background: #fff5f5;
    border-left-color: #dc3545;
}

.task-notes-row.task-upcoming-row .task-notes-content {
    background: #fff8f0;
    border-left-color: #ff8800;
}

/* ============================================
   Home Page — Feature Grid
   ============================================ */
.home-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--mj-text-muted, #6c757d);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--mj-border, #dee2e6);
}

.home-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 0.5rem;
    min-height: 80px;
    font-size: 0.82rem;
    font-weight: 500;
    gap: 0.35rem;
    border-radius: 0.5rem;
    transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.home-nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.home-nav-btn:active {
    transform: translateY(0);
}

.home-nav-icon {
    font-size: 1.6rem;
    line-height: 1;
}

@media (max-width: 576px) {
    .home-nav-btn {
        min-height: 70px;
        font-size: 0.78rem;
    }

    .home-nav-icon {
        font-size: 1.3rem;
    }
}
