/* ===========================================================================
   Hope Haven Hospital EMR -- application styles
   Built on Bootstrap 5. Mobile first: every rule here is the small-screen
   rule, and min-width media queries add the desktop behaviour on top.
   =========================================================================== */

:root {
    color-scheme: light;

    --hhh-primary:        #0f766e;
    --hhh-primary-dark:   #115e59;
    --hhh-primary-light:  #ccfbf1;
    --hhh-primary-rgb:    15, 118, 110;

    --hhh-bg:             #f5f7f9;
    --hhh-surface:        #ffffff;
    --hhh-surface-alt:    #f8fafc;
    --hhh-border:         #e2e8f0;
    --hhh-border-strong:  #cbd5e1;

    --hhh-text:           #1e293b;
    --hhh-text-muted:     #64748b;
    --hhh-text-faint:     #94a3b8;

    --hhh-sidebar-width:  268px;
    --hhh-topbar-height:  56px;
    --hhh-radius:         .625rem;
    --hhh-radius-sm:      .375rem;
    --hhh-shadow:         0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --hhh-shadow-lg:      0 4px 16px rgba(15, 23, 42, .10);

    /* Bootstrap variable overrides */
    --bs-primary:         #0f766e;
    --bs-primary-rgb:     15, 118, 110;
    --bs-link-color:      #0f766e;
    --bs-link-hover-color:#115e59;
    --bs-body-color:      #1e293b;
    --bs-body-bg:         #f5f7f9;
    --bs-border-color:    #e2e8f0;
    --bs-border-radius:   .625rem;
}

/* ---- Base ---------------------------------------------------------------- */

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

body {
    background: var(--hhh-bg);
    color: var(--hhh-text);
    font-size: .9375rem;
    /* Never let a wide table push the whole page sideways on a phone. */
    overflow-x: hidden;
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

.text-muted-2 { color: var(--hhh-text-faint) !important; }

/* A flex item will not shrink below its content's intrinsic width unless its
   min-width is zeroed, so a long word or a wide number pushes the whole row
   sideways. Bootstrap 5 has no such utility of its own, and the views here
   have always assumed one. */
.min-w-0 { min-width: 0 !important; }

/* Bootstrap's .btn-primary etc. follow --bs-primary, but the solid button
   needs its own hover/active pair to stay legible. */
.btn-primary {
    --bs-btn-bg: var(--hhh-primary);
    --bs-btn-border-color: var(--hhh-primary);
    --bs-btn-hover-bg: var(--hhh-primary-dark);
    --bs-btn-hover-border-color: var(--hhh-primary-dark);
    --bs-btn-active-bg: var(--hhh-primary-dark);
    --bs-btn-active-border-color: var(--hhh-primary-dark);
    --bs-btn-disabled-bg: var(--hhh-primary);
    --bs-btn-disabled-border-color: var(--hhh-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--hhh-primary);
    --bs-btn-border-color: var(--hhh-primary);
    --bs-btn-hover-bg: var(--hhh-primary);
    --bs-btn-hover-border-color: var(--hhh-primary);
    --bs-btn-active-bg: var(--hhh-primary);
    --bs-btn-active-border-color: var(--hhh-primary);
}
.text-bg-primary { background-color: var(--hhh-primary) !important; }

.form-control:focus, .form-select:focus, .form-check-input:focus, .btn:focus-visible {
    border-color: rgba(var(--hhh-primary-rgb), .5);
    box-shadow: 0 0 0 .2rem rgba(var(--hhh-primary-rgb), .18);
}
.form-check-input:checked {
    background-color: var(--hhh-primary);
    border-color: var(--hhh-primary);
}

/* ---- App shell ----------------------------------------------------------- */

.app-shell { min-height: 100vh; }

.app-main {
    padding-top: var(--hhh-topbar-height);
    /* Room for the mobile action bar so nothing hides behind it. */
    padding-bottom: 5rem;
}

.app-content {
    padding: 1rem .875rem;
    max-width: 1600px;
}

@media (min-width: 992px) {
    .app-main { margin-left: var(--hhh-sidebar-width); padding-bottom: 2rem; }
    .app-content { padding: 1.5rem; }
}

/* ---- Top bar ------------------------------------------------------------- */

.app-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--hhh-topbar-height);
    background: var(--hhh-surface);
    border-bottom: 1px solid var(--hhh-border);
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 .75rem;
}

@media (min-width: 992px) {
    .app-topbar { left: var(--hhh-sidebar-width); padding: 0 1.5rem; }
}

.app-topbar .topbar-brand {
    font-weight: 700;
    color: var(--hhh-primary);
    font-size: 1.0625rem;
    white-space: nowrap;
}

.topbar-search { flex: 1 1 auto; max-width: 460px; position: relative; }
.topbar-search .form-control { padding-left: 2.25rem; background: var(--hhh-surface-alt); }
.topbar-search .bi-search {
    position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
    color: var(--hhh-text-faint); pointer-events: none;
}

.topbar-icon-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--hhh-text-muted);
    border: 0; background: transparent;
    position: relative;
    flex: 0 0 auto;
}
.topbar-icon-btn:hover { background: var(--hhh-surface-alt); color: var(--hhh-text); }
.topbar-icon-btn .badge-dot {
    position: absolute; top: 6px; right: 6px;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 9px; background: #dc3545; color: #fff;
    font-size: .625rem; line-height: 17px; font-weight: 600;
}

/* ---- Sidebar ------------------------------------------------------------- */

/*
 * Below lg this element is a Bootstrap off-canvas drawer, and its width is
 * Bootstrap's to decide (--bs-offcanvas-width). Do not set width here: a plain
 * .app-sidebar rule loses the cascade to Bootstrap's .offcanvas-start anyway,
 * and overriding it would change the drawer on phones and tablets. The width
 * is pinned only in the lg block below, where the drawer becomes a column.
 */
.app-sidebar {
    background: var(--hhh-surface);
    border-right: 1px solid var(--hhh-border);
}

@media (min-width: 992px) {
    /* Above lg the offcanvas markup is displayed as a permanent column. */
    .app-sidebar.offcanvas-start {
        /*
         * .app-main is offset by --hhh-sidebar-width, so the sidebar must be
         * exactly that wide. Bootstrap's .offcanvas-start sets
         * width: var(--bs-offcanvas-width), which defaults to 400px and beats a
         * plain .app-sidebar rule -- the sidebar then sat 132px over the
         * content and, being z-index 1035, covered it. Redefining the Bootstrap
         * custom property here fixes it at the source; the explicit width is a
         * belt-and-braces fallback. Both are scoped to this media query, so the
         * phone and tablet drawers keep Bootstrap's own width.
         */
        --bs-offcanvas-width: var(--hhh-sidebar-width);
        width: var(--hhh-sidebar-width);

        visibility: visible !important;
        transform: none !important;
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 1035;
        border-right: 1px solid var(--hhh-border);
    }
    .app-sidebar .offcanvas-header { display: none; }
    .app-sidebar .btn-close { display: none; }
}

.sidebar-brand {
    display: flex; align-items: center; gap: .625rem;
    padding: 1rem 1.125rem;
    border-bottom: 1px solid var(--hhh-border);
    min-height: var(--hhh-topbar-height);
}
.sidebar-brand .brand-mark {
    width: 34px; height: 34px; flex: 0 0 34px;
    border-radius: 9px;
    background: var(--hhh-primary); color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: .8125rem; letter-spacing: .02em;
}
/* With a real logo the coloured square would fight it, so the square is
   dropped and the artwork is simply fitted into the same footprint. */
.sidebar-brand .brand-mark.has-logo {
    background: transparent;
    border-radius: 0;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sidebar-brand .brand-text { line-height: 1.15; min-width: 0; }
.sidebar-brand .brand-name {
    font-weight: 700; font-size: .9375rem; color: var(--hhh-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand .brand-sub { font-size: .6875rem; color: var(--hhh-text-faint); text-transform: uppercase; letter-spacing: .06em; }

.sidebar-nav {
    padding: .75rem .625rem 2rem;
    overflow-y: auto;
    /* Fill the remaining height so long menus scroll inside the sidebar. */
    height: calc(100vh - var(--hhh-topbar-height));
}

.sidebar-heading {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--hhh-text-faint);
    font-weight: 600;
    padding: .875rem .75rem .375rem;
}

.sidebar-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .625rem .75rem;
    border-radius: var(--hhh-radius-sm);
    color: var(--hhh-text-muted);
    font-weight: 500;
    font-size: .875rem;
    margin-bottom: .125rem;
    /* Comfortable touch target on a phone. */
    min-height: 44px;
}
.sidebar-link:hover { background: var(--hhh-surface-alt); color: var(--hhh-text); text-decoration: none; }
.sidebar-link.active { background: var(--hhh-primary-light); color: var(--hhh-primary-dark); font-weight: 600; }
.sidebar-link .bi { font-size: 1.0625rem; width: 1.25rem; text-align: center; flex: 0 0 auto; }
.sidebar-link .sidebar-count {
    margin-left: auto;
    background: var(--hhh-surface-alt);
    color: var(--hhh-text-muted);
    border-radius: 999px;
    font-size: .6875rem; font-weight: 600;
    padding: .0625rem .4375rem;
}
.sidebar-link.active .sidebar-count { background: #fff; color: var(--hhh-primary-dark); }

/* ---- Mobile action bar --------------------------------------------------- */

.mobile-actionbar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--hhh-surface);
    border-top: 1px solid var(--hhh-border);
    display: flex;
    z-index: 1029;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-actionbar a {
    flex: 1 1 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .125rem;
    padding: .5rem .25rem;
    min-height: 56px;
    color: var(--hhh-text-muted);
    font-size: .6875rem;
    font-weight: 500;
}
.mobile-actionbar a .bi { font-size: 1.125rem; }
.mobile-actionbar a.active { color: var(--hhh-primary); }
.mobile-actionbar a:hover { text-decoration: none; }

@media (min-width: 992px) { .mobile-actionbar { display: none; } }

/* ---- Page header --------------------------------------------------------- */

.page-header { margin-bottom: 1rem; }
.page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
}
.page-header .page-subtitle { color: var(--hhh-text-muted); font-size: .8125rem; margin-top: .125rem; }
.page-header-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.page-header-actions .btn { flex: 1 1 auto; }

@media (min-width: 576px) {
    .page-header h1 { font-size: 1.4375rem; }
    .page-header-actions { margin-top: 0; }
    .page-header-actions .btn { flex: 0 0 auto; }
}

.breadcrumb { font-size: .8125rem; margin-bottom: .375rem; }
.breadcrumb-item + .breadcrumb-item::before { content: "/"; color: var(--hhh-text-faint); }

/* ---- Cards --------------------------------------------------------------- */

.card {
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius);
    box-shadow: var(--hhh-shadow);
    background: var(--hhh-surface);
}
.card-header {
    background: var(--hhh-surface);
    border-bottom: 1px solid var(--hhh-border);
    padding: .875rem 1rem;
    font-weight: 600;
    font-size: .9375rem;
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.card-header .card-header-actions { margin-left: auto; display: flex; gap: .375rem; flex-wrap: wrap; }
.card-body { padding: 1rem; }

@media (min-width: 768px) {
    .card-body { padding: 1.25rem; }
}

/* ---- Stat tiles ---------------------------------------------------------- */

.stat-tile {
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius);
    padding: .875rem 1rem;
    box-shadow: var(--hhh-shadow);
    height: 100%;
    display: block;
    color: inherit;
}
a.stat-tile:hover { text-decoration: none; border-color: var(--hhh-border-strong); box-shadow: var(--hhh-shadow-lg); }
.stat-tile .stat-label {
    font-size: .6875rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--hhh-text-muted); font-weight: 600;
}
.stat-tile .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.15; margin-top: .25rem; }
.stat-tile .stat-meta { font-size: .75rem; color: var(--hhh-text-faint); margin-top: .125rem; }
.stat-tile .stat-icon {
    width: 36px; height: 36px; border-radius: 9px;
    display: grid; place-items: center; font-size: 1.0625rem;
    background: var(--hhh-primary-light); color: var(--hhh-primary-dark);
    float: right;
}

/* ---- Quick action grid --------------------------------------------------- */

.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: .625rem; }
@media (min-width: 576px) { .quick-actions { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .quick-actions { grid-template-columns: repeat(6, 1fr); } }

.quick-action {
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius);
    padding: .875rem .5rem;
    text-align: center;
    color: var(--hhh-text);
    box-shadow: var(--hhh-shadow);
    display: flex; flex-direction: column; align-items: center; gap: .375rem;
    min-height: 88px; justify-content: center;
    font-size: .8125rem; font-weight: 500;
}
.quick-action:hover { text-decoration: none; border-color: var(--hhh-primary); color: var(--hhh-primary-dark); }
.quick-action .bi { font-size: 1.375rem; color: var(--hhh-primary); }

/* ---- Tables that become cards on small screens --------------------------- */

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .6875rem .75rem; }
.table thead th {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--hhh-text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--hhh-border);
    white-space: nowrap;
}
.table tbody tr:hover { background: var(--hhh-surface-alt); }
.table td { vertical-align: middle; }

/* Wide tables that must stay tabular scroll inside their own container. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/*
 * .table-cards: below md each row becomes a card and each cell shows its
 * column name from data-label. Nothing is lost and nothing scrolls sideways.
 */
@media (max-width: 767.98px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr {
        border: 1px solid var(--hhh-border);
        border-radius: var(--hhh-radius);
        margin-bottom: .625rem;
        padding: .25rem .75rem .5rem;
        background: var(--hhh-surface);
        box-shadow: var(--hhh-shadow);
    }
    .table-cards tr:hover { background: var(--hhh-surface); }
    .table-cards td {
        border: 0;
        border-bottom: 1px dashed var(--hhh-border);
        padding: .4375rem 0;
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        text-align: right;
    }
    .table-cards td:last-child { border-bottom: 0; }
    .table-cards td::before {
        content: attr(data-label);
        font-size: .6875rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--hhh-text-muted);
        font-weight: 600;
        text-align: left;
        flex: 0 0 40%;
    }
    /* A cell marked data-primary reads as the card's heading. */
    .table-cards td[data-primary] {
        display: block;
        text-align: left;
        font-weight: 600;
        font-size: .9375rem;
        padding-top: .625rem;
    }
    .table-cards td[data-primary]::before { display: none; }
    .table-cards td[data-actions] { justify-content: flex-end; }
    .table-cards td[data-actions]::before { display: none; }
}

.table-empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--hhh-text-muted);
}
.table-empty .bi { font-size: 2rem; color: var(--hhh-text-faint); display: block; margin-bottom: .5rem; }

/* ---- Filter bar ---------------------------------------------------------- */

.filter-bar { display: grid; grid-template-columns: 1fr; gap: .625rem; }
/* A grid track is auto-sized to its content unless min-width is zeroed, so a
   long option in a select widens the whole bar past the screen. */
.filter-bar > * { min-width: 0; }
@media (min-width: 576px) { .filter-bar { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 992px) { .filter-bar { grid-template-columns: repeat(4, 1fr); } }
.filter-bar .filter-actions { display: flex; gap: .5rem; }
.filter-bar .filter-actions .btn { flex: 1 1 auto; }

/* ---- Forms --------------------------------------------------------------- */

.form-label { font-weight: 600; font-size: .8125rem; margin-bottom: .3125rem; color: var(--hhh-text); }
.form-label .required { color: #dc3545; }
.form-text { font-size: .75rem; }

/* Inputs are 16px on mobile so iOS does not zoom the page when focused. */
.form-control, .form-select {
    font-size: 1rem;
    padding: .5rem .75rem;
    border-color: var(--hhh-border-strong);
    border-radius: var(--hhh-radius-sm);
    min-height: 44px;
}
textarea.form-control { min-height: 88px; }

@media (min-width: 768px) {
    .form-control, .form-select { font-size: .9375rem; min-height: 40px; }
}

/*
 * Row actions on a phone.
 *
 * Bootstrap's .btn-sm lands at 31px, which is a pixel under a comfortable
 * thumb target and the whole point of a small button is that there are several
 * of them side by side in a table row. On a pointer device the density is
 * worth keeping, so the floor only applies where the input is a finger.
 */
@media (max-width: 991.98px) {
    .btn-sm, .btn-group-sm > .btn {
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

.form-section { margin-bottom: 1.5rem; }
.form-section-title {
    font-size: .8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--hhh-primary-dark);
    padding-bottom: .5rem; margin-bottom: .875rem;
    border-bottom: 2px solid var(--hhh-primary-light);
}

.input-group-text { background: var(--hhh-surface-alt); border-color: var(--hhh-border-strong); }

/* Sticky save bar so the primary action is always reachable on a long form. */
.form-actions {
    position: sticky;
    bottom: 56px;
    background: var(--hhh-surface);
    border-top: 1px solid var(--hhh-border);
    padding: .75rem;
    margin: 1rem -0.875rem -1rem;
    display: flex; gap: .5rem;
    z-index: 5;
}
.form-actions .btn { flex: 1 1 auto; min-height: 46px; }

@media (min-width: 992px) {
    .form-actions {
        position: static;
        margin: 1.25rem 0 0;
        padding: 1rem 0 0;
        border-top: 1px solid var(--hhh-border);
        background: transparent;
        justify-content: flex-end;
    }
    .form-actions .btn { flex: 0 0 auto; min-width: 130px; }
}

/* ---- Wizard / stepper ---------------------------------------------------- */

.wizard-steps {
    display: flex;
    gap: .375rem;
    overflow-x: auto;
    padding: .25rem .125rem .625rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.wizard-step {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .75rem;
    border-radius: 999px;
    border: 1px solid var(--hhh-border);
    background: var(--hhh-surface);
    font-size: .8125rem;
    color: var(--hhh-text-muted);
    white-space: nowrap;
    font-weight: 500;
}
.wizard-step:hover { text-decoration: none; color: var(--hhh-text); }
.wizard-step .step-index {
    width: 22px; height: 22px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--hhh-surface-alt); color: var(--hhh-text-muted);
    font-size: .6875rem; font-weight: 700;
    flex: 0 0 22px;
}
.wizard-step.current {
    border-color: var(--hhh-primary);
    background: var(--hhh-primary-light);
    color: var(--hhh-primary-dark);
    font-weight: 600;
}
.wizard-step.current .step-index { background: var(--hhh-primary); color: #fff; }
.wizard-step.done { color: var(--hhh-primary-dark); border-color: var(--hhh-primary-light); }
.wizard-step.done .step-index { background: var(--hhh-primary); color: #fff; }

.wizard-progress { height: 5px; border-radius: 999px; background: var(--hhh-border); overflow: hidden; margin-bottom: .875rem; }
.wizard-progress .bar { height: 100%; background: var(--hhh-primary); transition: width .3s ease; }

/* ---- Patient header ------------------------------------------------------ */

.patient-header {
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius);
    box-shadow: var(--hhh-shadow);
    padding: .875rem 1rem;
    margin-bottom: 1rem;
}
.patient-header .patient-identity { display: flex; gap: .75rem; align-items: flex-start; }
.patient-avatar {
    width: 48px; height: 48px; flex: 0 0 48px;
    border-radius: 50%;
    background: var(--hhh-primary-light); color: var(--hhh-primary-dark);
    display: grid; place-items: center;
    font-weight: 700; font-size: 1.0625rem;
}
.patient-header .patient-name { font-size: 1.0625rem; font-weight: 700; line-height: 1.25; }
.patient-header .patient-no { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8125rem; color: var(--hhh-text-muted); }
.patient-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem .875rem;
    margin-top: .875rem;
    padding-top: .875rem;
    border-top: 1px solid var(--hhh-border);
}
@media (min-width: 768px) { .patient-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .patient-facts { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.patient-facts .fact-label { font-size: .6875rem; text-transform: uppercase; letter-spacing: .04em; color: var(--hhh-text-muted); font-weight: 600; }
.patient-facts .fact-value { font-size: .875rem; font-weight: 500; word-break: break-word; }

.alert-strip {
    display: flex; flex-wrap: wrap; gap: .375rem;
    margin-top: .75rem;
}
.alert-chip {
    display: inline-flex; align-items: center; gap: .3125rem;
    background: #fef2f2; color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 999px;
    padding: .1875rem .625rem;
    font-size: .75rem; font-weight: 600;
}
.alert-chip.info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-chip.warn { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* ---- Profile tabs -------------------------------------------------------- */

.profile-tabs {
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--hhh-border);
    margin-bottom: 1rem;
    padding-bottom: 0;
    scrollbar-width: thin;
}
.profile-tabs .nav-link {
    white-space: nowrap;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: var(--hhh-text-muted);
    font-size: .875rem;
    font-weight: 500;
    padding: .625rem .75rem;
}
.profile-tabs .nav-link:hover { color: var(--hhh-text); text-decoration: none; }
.profile-tabs .nav-link.active {
    color: var(--hhh-primary-dark);
    border-bottom-color: var(--hhh-primary);
    font-weight: 600;
    background: transparent;
}

/* ---- Timeline ------------------------------------------------------------ */

.timeline { position: relative; padding-left: 2.125rem; }
.timeline::before {
    content: "";
    position: absolute;
    left: .8125rem; top: .5rem; bottom: .5rem;
    width: 2px;
    background: var(--hhh-border);
}
.timeline-day {
    font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--hhh-text-muted);
    margin: 1.25rem 0 .625rem -2.125rem;
    padding-left: 2.125rem;
    position: relative;
}
.timeline-item { position: relative; padding-bottom: .875rem; }
.timeline-item .timeline-marker {
    position: absolute;
    left: -2.125rem; top: .125rem;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--hhh-primary-light);
    color: var(--hhh-primary-dark);
    display: grid; place-items: center;
    font-size: .8125rem;
    border: 2px solid var(--hhh-surface);
}
.timeline-card {
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius-sm);
    padding: .625rem .75rem;
}
.timeline-card .timeline-title { font-weight: 600; font-size: .875rem; }
.timeline-card .timeline-meta { font-size: .75rem; color: var(--hhh-text-muted); margin-top: .125rem; }
.timeline-card .timeline-body { font-size: .8125rem; color: var(--hhh-text-muted); margin-top: .3125rem; }

/* ---- Queue cards --------------------------------------------------------- */

.queue-card {
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    border-left: 3px solid var(--hhh-border-strong);
    border-radius: var(--hhh-radius-sm);
    padding: .75rem;
    margin-bottom: .625rem;
    box-shadow: var(--hhh-shadow);
}
.queue-card.priority-urgent { border-left-color: #f59e0b; }
.queue-card.priority-emergency { border-left-color: #dc3545; }
.queue-card .queue-ticket {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .75rem; font-weight: 700;
    color: var(--hhh-primary-dark);
    background: var(--hhh-primary-light);
    border-radius: var(--hhh-radius-sm);
    padding: .125rem .375rem;
}
.queue-card .queue-wait { font-size: .75rem; color: var(--hhh-text-muted); }

/* ---- Vitals grid --------------------------------------------------------- */

.vitals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .625rem; }
@media (min-width: 576px) { .vitals-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .vitals-grid { grid-template-columns: repeat(6, 1fr); } }
.vital-box {
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius-sm);
    padding: .625rem;
    text-align: center;
    background: var(--hhh-surface);
}
.vital-box .vital-label { font-size: .625rem; text-transform: uppercase; letter-spacing: .05em; color: var(--hhh-text-muted); font-weight: 600; }
.vital-box .vital-value { font-size: 1.125rem; font-weight: 700; line-height: 1.2; }
.vital-box .vital-unit { font-size: .6875rem; color: var(--hhh-text-faint); font-weight: 400; }
.vital-box.is-abnormal { border-color: #fecaca; background: #fef2f2; }
.vital-box.is-abnormal .vital-value { color: #b91c1c; }

/* ---- Definition lists ---------------------------------------------------- */

.detail-list { display: grid; grid-template-columns: 1fr; gap: .0625rem; }
@media (min-width: 768px) { .detail-list { grid-template-columns: repeat(2, 1fr); gap: .0625rem 1.5rem; } }
.detail-list .detail-row {
    display: flex; justify-content: space-between; gap: 1rem;
    padding: .5rem 0;
    border-bottom: 1px dashed var(--hhh-border);
    font-size: .875rem;
}
.detail-list .detail-label { color: var(--hhh-text-muted); font-weight: 500; flex: 0 0 45%; }
.detail-list .detail-value { text-align: right; font-weight: 500; word-break: break-word; }

/* ---- Review cards (wizard step 9) --------------------------------------- */

.review-card { margin-bottom: .875rem; }
.review-card .card-header { font-size: .875rem; }

/* ---- Badges & misc ------------------------------------------------------- */

.badge { font-weight: 600; font-size: .6875rem; padding: .3em .6em; border-radius: 999px; letter-spacing: .01em; }
.badge.text-bg-secondary { background: #e2e8f0 !important; color: #475569 !important; }

.locked-panel {
    border: 1px dashed var(--hhh-border-strong);
    border-radius: var(--hhh-radius);
    padding: 1.75rem 1rem;
    text-align: center;
    background: var(--hhh-surface-alt);
    color: var(--hhh-text-muted);
}
.locked-panel .bi { font-size: 2rem; color: var(--hhh-text-faint); display: block; margin-bottom: .625rem; }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.conditional-field { display: none; }
.conditional-field.is-visible { display: block; }

/* Toasts sit above the mobile action bar. */
.toast-container { z-index: 1090; }

/* ---- Print --------------------------------------------------------------- */

@media print {
    .app-sidebar, .app-topbar, .mobile-actionbar, .page-header-actions,
    .no-print, .form-actions, .filter-bar, .profile-tabs, .breadcrumb,
    .pagination, .btn { display: none !important; }

    .app-main { margin-left: 0 !important; padding: 0 !important; }
    .app-content { padding: 0 !important; max-width: none; }

    body { background: #fff; font-size: 11pt; color: #000; }
    .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
    .card-header { background: #f2f2f2 !important; }
    a[href]:after { content: ""; }

    .print-only { display: block !important; }
    .print-header {
        text-align: center;
        border-bottom: 2px solid #000;
        padding-bottom: .5rem;
        margin-bottom: 1rem;
    }
    .print-header h1 { font-size: 16pt; margin: 0; }
    .print-header .print-sub { font-size: 9pt; }
    /* Fixed physical size so the letterhead is the same on every printer, and
       print-color-adjust so the logo is not dropped by "ink saver" defaults. */
    .print-header .print-logo {
        height: 18mm; width: auto; margin: 0 auto .3rem;
        display: block; object-fit: contain;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    table { width: 100%; border-collapse: collapse; }
    .table th, .table td { border: 1px solid #999 !important; padding: 4px 6px !important; }
    .table-cards thead { display: table-header-group !important; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: revert !important; }
    .table-cards td::before { display: none !important; }

    .page-break { page-break-before: always; }
}

.print-only { display: none; }

/* ---- Condition / reaction rows -------------------------------------------
   One set of inputs that reads as a card on a phone and as a table row from
   lg up. Rendering two copies would submit every field twice. */

.condition-row {
    display: block;
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius-sm);
    padding: .75rem;
    margin-bottom: .625rem;
    background: var(--hhh-surface);
}
.condition-row .condition-name { font-weight: 600; font-size: .875rem; margin-bottom: .5rem; }
.condition-row .condition-answer { margin-bottom: .625rem; }
.condition-row .condition-detail + .condition-detail { margin-top: .5rem; }

.condition-head { display: none; }

@media (min-width: 992px) {
    .condition-row {
        display: grid;
        grid-template-columns: minmax(200px, 1.4fr) 250px 1fr 1fr;
        gap: .75rem;
        align-items: center;
        border: 0;
        border-bottom: 1px solid var(--hhh-border);
        border-radius: 0;
        padding: .5rem .25rem;
        margin-bottom: 0;
    }
    .condition-row .condition-name,
    .condition-row .condition-answer { margin-bottom: 0; }
    .condition-row .condition-detail + .condition-detail { margin-top: 0; }

    .condition-head {
        display: grid;
        font-size: .6875rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--hhh-text-muted);
        font-weight: 600;
        border-bottom: 1px solid var(--hhh-border);
        padding-bottom: .375rem;
    }
}

/* Repeatable slot rows (drug reactions, invoice lines) */
.slot-row {
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius-sm);
    padding: .875rem;
    margin-bottom: .75rem;
    background: var(--hhh-surface);
}
.slot-row .slot-index {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--hhh-text-muted);
    font-weight: 600;
    margin-bottom: .5rem;
}
@media (min-width: 992px) {
    .slot-row { border: 0; border-bottom: 1px solid var(--hhh-border); border-radius: 0; padding: .625rem .25rem; }
}

/* ---- Printed documents, as they look on screen ---------------------------
   The print rules live inside @media print, so without these the preview a
   member of staff sees before pressing Print looks nothing like the paper. */

.print-header {
    text-align: center;
    border-bottom: 2px solid var(--hhh-text);
    padding-bottom: .75rem;
    margin-bottom: 1.25rem;
}
.print-header h1 { font-size: 1.375rem; margin: 0; font-weight: 700; }
.print-header .print-sub { font-size: .8125rem; color: var(--hhh-text-muted); }
.print-header .print-logo {
    height: 72px; width: auto;
    margin: 0 auto .5rem;
    display: block;
    object-fit: contain;
}

/* ---- Activation code, shown once when a portal account is issued ---------- */

.portal-code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: .15em;
    color: var(--hhh-primary-dark);
    word-break: break-all;
}

/* ===========================================================================
   E-Consultation
   Shared by the doctor's room and the patient's waiting room.
   =========================================================================== */

/* ---- Video --------------------------------------------------------------- */

.econsult-video {
    position: relative;
    background: #12161c;
    border-radius: var(--hhh-radius);
    overflow: hidden;
    /* 16:9 until a call connects, then the frame fills it. A fixed height would
       letterbox on a phone and crop on a desktop. */
    aspect-ratio: 16 / 9;
    /* No min-height here. Combined with aspect-ratio it becomes a *minimum
       width* (220px x 16/9 = 391px), which is wider than a grid column on a
       1024px screen and pushes the whole page sideways. The floor is applied
       further down, only where the column is certainly wide enough for it. */
    min-width: 0;
    max-width: 100%;
}
.econsult-video [data-video-frame] { position: absolute; inset: 0; }
.econsult-video [data-video-frame] iframe { width: 100%; height: 100%; border: 0; }

.econsult-video-placeholder {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    text-align: center;
    padding: 1.25rem;
    color: #cbd5e1;
}
.econsult-video.is-live .econsult-video-placeholder { display: none; }

/* On a phone the call is the page, so give it the room. */
@media (max-width: 767.98px) {
    .econsult-video { aspect-ratio: 3 / 4; }
}

/* Wide enough that a 220px floor cannot make the box wider than its column. */
@media (min-width: 1200px) {
    .econsult-video { min-height: 220px; }
}

/* ---- Chat ---------------------------------------------------------------- */

.econsult-chat { display: flex; flex-direction: column; min-height: 0; }

.chat-log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: .75rem;
    background: var(--hhh-surface-alt);
    border: 1px solid var(--hhh-border);
    border-radius: var(--hhh-radius);
    /* Tall enough to hold a conversation, short enough to leave the video and
       the notes visible beside it. */
    height: 320px;
    scroll-behavior: smooth;
}
@media (min-width: 992px) { .chat-log { height: 380px; } }

.chat-line { display: flex; margin-bottom: .5rem; }
.chat-mine { justify-content: flex-end; }

.chat-bubble {
    max-width: min(85%, 32rem);
    padding: .5rem .75rem;
    border-radius: 1rem;
    background: var(--hhh-surface);
    border: 1px solid var(--hhh-border);
    font-size: .875rem;
    /* A pasted hospital number or a long word must not widen the column. */
    overflow-wrap: anywhere;
}
.chat-mine .chat-bubble {
    background: var(--hhh-primary);
    border-color: var(--hhh-primary);
    color: #fff;
}
.chat-sender { font-size: .6875rem; font-weight: 700; opacity: .75; margin-bottom: .125rem; }
.chat-time   { font-size: .625rem; opacity: .6; text-align: right; margin-top: .125rem; }

.chat-system {
    text-align: center;
    font-size: .75rem;
    color: var(--hhh-text-faint);
    margin: .5rem 0;
}

.chat-empty { text-align: center; color: var(--hhh-text-faint); font-size: .8125rem; padding: 2rem 0; }

.chat-compose { display: flex; gap: .5rem; margin-top: .5rem; }
.chat-compose textarea {
    resize: none;
    /* 16px keeps iOS from zooming the whole page when the box is focused. */
    font-size: 1rem;
    min-height: 44px;
    max-height: 120px;
}

/* ---- The doctor's workspace ---------------------------------------------- */

/* One column on a phone -- patient, then video, then chat, then notes, which is
   the order a doctor needs them. Two columns from lg, where there is room. */
.econsult-room { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 992px) {
    .econsult-room { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .econsult-room .econsult-span { grid-column: 1 / -1; }
}

.econsult-patient-card dt { font-weight: 400; color: var(--hhh-text-muted); }
.econsult-patient-card dd { font-weight: 600; }

/* ---- Waiting room -------------------------------------------------------- */

.econsult-waiting {
    text-align: center;
    padding: 1.5rem 1rem;
}
.econsult-waiting-mark {
    width: 72px; height: 72px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: grid; place-items: center;
    background: var(--hhh-primary-light);
    color: var(--hhh-primary-dark);
    font-size: 2rem;
}
.econsult-waiting-mark.is-ready {
    background: #dcfce7;
    color: #15803d;
    animation: econsult-pulse 2s ease-in-out infinite;
}
@keyframes econsult-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}
@media (prefers-reduced-motion: reduce) {
    .econsult-waiting-mark.is-ready { animation: none; }
}

/* ---- Status badges ------------------------------------------------------- */

.econsult-status { font-size: .75rem; font-weight: 600; }
