/*
 * The app shell. Wide screens: a top bar whose centre is the patient search, a slim rail of sections on the left.
 * Phones: the same top bar, and the sections as a tab bar under the thumb. Markup: Views/Shared/_Layout.cshtml.
 */
:root {
    --topbar-height: 60px;
    --rail-width: 88px;
    --tabbar-height: 62px;
    --content-max: 1320px;
}

/* ============================================
   TOP BAR
   ============================================ */
.app-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: .75rem;
    height: var(--topbar-height);
    padding: 0 1rem 0 0;
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
}

.app-brand {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .6rem;
    min-width: var(--rail-width);
    height: 100%;
    padding: 0 1rem;
    color: var(--ink);
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -.01em;
    white-space: nowrap;
    text-decoration: none !important;
}

.app-brand img {
    width: auto;
    max-width: 150px;
    height: 34px;
    object-fit: contain;
}

/* Without a logo: the first letter of the name on the accent. */
.app-brand-mark {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background-color: var(--app-primary);
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
}

.app-search {
    position: relative;
    flex: 1 1 auto;
    max-width: 560px;
    margin: 0 auto;
}

.app-search > i.bx {
    position: absolute;
    top: 50%;
    left: .85rem;
    transform: translateY(-50%);
    font-size: 1.25rem;
    color: var(--muted);
    pointer-events: none;
}

.app-search input {
    width: 100%;
    height: 40px;
    padding: 0 2.6rem 0 2.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background-color: var(--paper);
    color: var(--ink);
    font-size: var(--fs-body);
}

.app-search input::placeholder {
    color: var(--muted);
}

.app-search input:focus {
    border-color: var(--app-primary);
    background-color: #fff;
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .16);
}

/* The key that jumps to the search, shown until the box has focus. */
.app-search kbd {
    position: absolute;
    top: 50%;
    right: .7rem;
    transform: translateY(-50%);
    padding: .05rem .4rem;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    background-color: var(--surface);
    color: var(--muted);
    font-family: inherit;
    font-size: .75rem;
    font-weight: 600;
}

.app-search input:focus ~ kbd {
    display: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    z-index: 1040;
    max-height: min(70vh, 480px);
    overflow-y: auto;
    padding: .35rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background-color: var(--surface);
    box-shadow: var(--shadow-raised);
}

.search-results[hidden] {
    display: none;
}

.search-result {
    display: flex;
    align-items: baseline;
    gap: .75rem;
    padding: .55rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none !important;
}

.search-result:hover,
.search-result.is-active {
    background-color: var(--app-primary-subtle);
    color: var(--ink);
}

.search-result strong {
    color: var(--ink);
    font-weight: 650;
}

.search-result .meta {
    margin-left: auto;
    color: var(--muted);
    font-size: var(--fs-meta);
    white-space: nowrap;
}

.search-empty {
    padding: .75rem;
    color: var(--muted);
    font-size: var(--fs-meta);
}

.app-topbar-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .25rem;
    margin-left: auto;
}

.topbar-button {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    height: 40px;
    padding: 0 .65rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-body);
    font-weight: 600;
    white-space: nowrap;
}

.topbar-button:hover,
.topbar-button.show {
    background-color: var(--hover);
    color: var(--ink);
}

.topbar-button > i.bx {
    font-size: 1.4rem;
}

.user-initials {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--app-primary-subtle);
    color: var(--app-primary-dark);
    font-size: .8125rem;
    font-weight: 700;
}

.user-menu-head {
    padding: .5rem 1rem .6rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: .35rem;
}

.user-menu-head strong {
    display: block;
    color: var(--ink);
}

.user-menu-head span {
    color: var(--muted);
    font-size: var(--fs-meta);
}

/* ============================================
   RAIL (wide screens) / TAB BAR (phones)
   ============================================ */
.app-nav {
    position: fixed;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    z-index: 1020;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    width: var(--rail-width);
    padding: .75rem .5rem;
    overflow-y: auto;
    background-color: var(--surface);
    border-right: 1px solid var(--line);
}

.app-nav a,
.app-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    padding: .6rem .25rem .5rem;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    text-decoration: none !important;
}

.app-nav a > i.bx,
.app-nav button > i.bx {
    font-size: 1.5rem;
}

.app-nav a:hover,
.app-nav button:hover {
    background-color: var(--hover);
    color: var(--ink);
}

.app-nav a.active {
    background-color: var(--app-primary-subtle);
    color: var(--app-primary-dark);
}

.app-nav .nav-spacer {
    flex: 1 1 auto;
}

/* Only the phone's tab bar has the "more" button; the rail shows every section. */
.app-nav .nav-more {
    display: none;
}

/* ============================================
   PAGE
   ============================================ */
.app-main {
    min-height: 100vh;
    margin-left: var(--rail-width);
    padding-top: var(--topbar-height);
}

.app-content {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 1.5rem 1.75rem 3rem;
}

/* ============================================
   PHONES AND TABLETS
   ============================================ */
@media (max-width: 991.98px) {
    .app-topbar {
        padding-right: .5rem;
    }

    .app-brand {
        min-width: 0;
        padding: 0 .5rem 0 .85rem;
    }

    .app-brand span.app-brand-name {
        display: none;
    }

    .app-search kbd {
        display: none;
    }

    .user-name {
        display: none;
    }

    .app-nav {
        top: auto;
        right: 0;
        flex-direction: row;
        gap: 0;
        width: auto;
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
        padding: .25rem .25rem env(safe-area-inset-bottom);
        overflow: visible;
        border-top: 1px solid var(--line);
        border-right: 0;
    }

    .app-nav a,
    .app-nav button {
        flex: 1 1 0;
        min-width: 0;
        padding: .4rem .1rem .3rem;
        border-radius: var(--radius-sm);
        font-size: .6875rem;
    }

    .app-nav .nav-spacer,
    .app-nav .nav-secondary {
        display: none;
    }

    .app-nav .nav-more {
        display: flex;
    }

    .app-main {
        margin-left: 0;
        padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    }

    .app-content {
        padding: 1rem .9rem 2rem;
    }

    /* Dialogs fill the screen: the header and the footer stay put and only the body scrolls. */
    .modal-dialog:not(.modal-sm) {
        width: 100%;
        max-width: 100%;
        height: 100%;
        margin: 0;
    }

    .modal-dialog:not(.modal-sm) .modal-content {
        display: flex;
        flex-direction: column;
        min-height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .modal-dialog:not(.modal-sm) .modal-body {
        flex: 1 1 auto;
        overflow-y: auto;
    }
}

@media print {
    .app-topbar,
    .app-nav,
    .no-print {
        display: none !important;
    }

    .app-main {
        margin: 0;
        padding: 0;
    }

    .app-content {
        max-width: none;
        padding: 0;
    }

    body {
        background: #fff;
    }
}
