*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* text */
    --ink: #13262B;
    --ink-2: #36494D;
    --muted: #6B7E81;

    /* lines & surfaces */
    --line: #E1E8E8;
    --line-2: #EDF1F1;
    --bg: #F4F7F6;
    --surface: #FFFFFF;
    --surface-2: #FBFCFC;

    /* accent (teal) */
    --accent: #0F766E;
    --accent-ink: #0B5C56;
    --accent-hover: #0B5C56;
    --accent-soft: #E6F1EF;

    /* semantic */
    --good: #137A43;
    --good-soft: #E4F2EA;
    --idle: #6B7E81;
    --idle-soft: #EEF2F2;
    --danger: #A8362B;
    --danger-soft: #F7E8E5;
    --warn: #955E10;

    /* component surfaces */
    --field-bg: #FFFFFF;
    --placeholder: #9AA9AB;
    --hover-bg: #FBFDFC;
    --hover-border: #CFD9D9;
    --switch-off: #CDD8D8;
    --knob: #FFFFFF;
    --topbar-bg: rgba(244, 247, 246, .86);
    --tooltip-bg: #13262B;
    --login-glow: #FFFFFF;
    --skel-base: #E7EDEC;

    --radius: 9px;
    --shadow: 0 1px 2px rgba(19, 38, 43, .05), 0 8px 24px rgba(19, 38, 43, .07);
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark theme. The sidebar is already dark in both modes; this darkens the content surfaces
   around it. Applied via data-theme on <html>, set before first paint in index.html. */
html[data-theme="dark"] {
    --ink: #E8F0EF;
    --ink-2: #B6C6C4;
    --muted: #7E9491;

    --line: #29393A;
    --line-2: #1E2C2D;
    --bg: #0D1517;
    --surface: #141F20;
    --surface-2: #1A2727;

    --accent: #18A99B;
    --accent-ink: #63D9CB;
    --accent-hover: #14887D;
    --accent-soft: #12302C;

    --good: #34D399;
    --good-soft: #10251C;
    --idle: #8FA3A1;
    --idle-soft: #1E2A2A;
    --danger: #F0857A;
    --danger-soft: #2C1613;
    --warn: #E2B15B;

    --field-bg: #0F1A1B;
    --placeholder: #5E7371;
    --hover-bg: #1A2727;
    --hover-border: #334747;
    --switch-off: #33474A;
    --knob: #C9D6D5;
    --topbar-bg: rgba(13, 21, 23, .82);
    --tooltip-bg: #2C3E3D;
    --login-glow: #16302C;
    --skel-base: #1F2E2F;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .5);
}

html[data-theme="dark"] .side {
    border-right: 1px solid var(--line);
}

/* Smooth light/dark crossfade. The class is added transiently while toggling (see index.html),
   so normal hover transitions keep their own faster timings. Skipped under reduced-motion. */
html.theme-anim,
html.theme-anim *,
html.theme-anim *::before,
html.theme-anim *::after {
    transition: background-color .3s ease, color .3s ease, border-color .3s ease,
        fill .3s ease, box-shadow .3s ease, outline-color .3s ease !important;
}

html,
body {
    margin: 0;
    height: 100%;
    /* The slide-over drawer sits off-screen at translateX(100%); clip so it can't be
       reached by horizontal scroll. `clip` (not `hidden`) avoids creating a scroll
       container, so the sticky topbar keeps working. */
    overflow-x: clip;
}

body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    margin: 0;
    text-wrap: balance;
}

button {
    font-family: inherit;
    cursor: pointer;
}

a {
    color: var(--accent);
}

.boot {
    min-height: 100vh;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 14px;
}

.eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted);
}

.mono {
    font-family: var(--mono);
    font-feature-settings: "tnum";
}

.num {
    font-variant-numeric: tabular-nums;
}

.muted-note {
    color: var(--muted);
    font-size: 13px;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1f2a2c;
    color: #fff;
    padding: 10px 16px;
    font-size: 13px;
    z-index: 100;
}

#blazor-error-ui .reload {
    color: #9fe0d6;
    margin-left: 8px;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 550;
    transition: background .12s, border-color .12s;
}

.btn:hover {
    border-color: var(--hover-border);
    background: var(--hover-bg);
}

.btn:disabled {
    opacity: .6;
    cursor: default;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--ink-2);
    padding: 6px 10px;
}

.btn-ghost:hover {
    background: var(--line-2);
}

.btn-danger {
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-soft);
    border-color: var(--danger-soft);
}

.btn-danger-solid {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger-solid:hover {
    filter: brightness(.92);
}

/* sign-out lives on the dark sidebar, so it needs its own treatment */
.btn-signout {
    border: 1px solid rgba(255, 255, 255, .16);
    background: transparent;
    color: #cfdcdd;
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 550;
    transition: background .12s, border-color .12s, color .12s;
}

.btn-signout:hover {
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .3);
    color: #fff;
}

/* theme toggle, lives on the dark sidebar */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, .12);
    background: transparent;
    color: #bcccce;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 530;
    transition: background .12s, border-color .12s, color .12s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, .06);
    border-color: rgba(255, 255, 255, .22);
    color: #fff;
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
    flex: none;
    color: #8fa6a8;
}

.theme-toggle:hover svg {
    color: #fff;
}

.btn:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.form-error {
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 500;
}

.form-ok {
    background: var(--good-soft);
    color: var(--good);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 500;
}

/* ---------- login ---------- */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(1100px 600px at 50% -10%, var(--login-glow) 0%, var(--bg) 55%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 34px 32px 28px;
    display: flex;
    flex-direction: column;
}

.login-card h1 {
    font-size: 21px;
    letter-spacing: -.02em;
    margin: 5px 0px 5px 0px;
}

.login-card p.sub {
    color: var(--muted);
    font-size: 13.5px;
    margin: 0 0 20px;
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 11px;
    margin-top: 6px;
    font-size: 14.5px;
}

.login-foot {
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(150deg, var(--accent), #15938a);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.brand-name {
    font-weight: 650;
    letter-spacing: -.01em;
}

.brand-name span {
    color: var(--muted);
    font-weight: 500;
}

/* ---------- form fields ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
}

.field input {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14.5px;
    font-family: inherit;
    background: var(--field-bg);
    color: var(--ink);
}

.field input::placeholder {
    color: var(--placeholder);
}

.field input[readonly],
.field input:disabled {
    background: var(--line-2);
    color: var(--muted);
    cursor: not-allowed;
}

/* input with a fixed, non-editable prefix (e.g. Practitioner/) */
.input-affix {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--field-bg);
}

.input-affix:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.input-affix .affix {
    display: flex;
    align-items: center;
    padding: 10px 6px 10px 12px;
    background: var(--line-2);
    color: var(--muted);
    font-size: 14.5px;
    border-right: 1px solid var(--line);
    white-space: nowrap;
}

.input-affix input {
    flex: 1;
    min-width: 0;
    border: 0;
    border-radius: 0;
}

.input-affix input:focus,
.input-affix input:focus-visible {
    outline: none;
}

/* ---------- app shell ---------- */
.admin-shell {
    display: grid;
    grid-template-columns: 236px 1fr;
    /* Pin the shell to the viewport and scroll the main area internally, so tall
       content can't stretch the page (which would drag the sidebar sign-out down). */
    grid-template-rows: 100vh;
    height: 100vh;
    overflow: hidden;
}

.side {
    background: #102227;
    color: #cfdcdd;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    gap: 4px;
    min-height: 0;
    overflow-y: auto;
}

.side .brand {
    padding: 6px 8px 16px;
}

.side .brand-name {
    color: #fff;
}

.side .brand-name span {
    color: #8fa6a8;
}

.nav-label {
    padding: 14px 10px 6px;
    color: #7e9698;
}

/* nav items live in a relative track so the active pill can slide between them */
.nav-items {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* sliding active indicator: 40px item height + 4px gap = 44px per slot */
.nav-ink {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    border-radius: 8px;
    background: var(--accent);
    transform: translateY(calc(var(--nav-i, 0) * 44px));
    transition: transform .28s cubic-bezier(.22, .61, .36, 1);
    z-index: 0;
    pointer-events: none;
}

.nav-ink.hidden {
    opacity: 0;
}

.nav-item {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 11px;
    height: 40px;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: #bcccce;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 530;
    text-decoration: none;
    transition: color .18s ease;
}

.nav-item:hover {
    color: #fff;
}

/* hover tint only on inactive items so it doesn't fight the sliding pill */
.nav-item:not(.active):hover {
    background: rgba(255, 255, 255, .06);
}

.nav-item.active {
    color: #fff;
}

.nav-item svg {
    width: 17px;
    height: 17px;
    flex: none;
}

.side-foot {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, .09);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tenant {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px;
}

.tenant b {
    color: #fff;
    font-weight: 600;
    font-size: 13.5px;
    display: block;
    line-height: 1.2;
}

.tenant small {
    color: #8fa6a8;
    font-size: 11.5px;
}

/* tenant switcher (button + popover) */
.tsw {
    position: relative;
}

.tsw-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    cursor: pointer;
    background: #0b1a1e;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 9px;
    padding: 9px 12px;
    color: #fff;
}

.tsw-trigger:hover {
    border-color: rgba(255, 255, 255, .3);
}

.tsw-trigger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.tsw-ic {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent);
    display: grid;
    place-items: center;
    flex: none;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.tsw-tx {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.tsw-name {
    font-size: 13.5px;
    font-weight: 640;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tsw-sub {
    font-size: 11px;
    color: #8fa6a8;
}

.tsw-chev {
    color: #8fa6a8;
    flex: none;
    transition: transform .15s;
}

.tsw.open .tsw-chev {
    transform: rotate(180deg);
}

.tsw-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
}

.tsw-menu {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 8px);
    background: #12262b;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 11px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
    padding: 6px;
    z-index: 50;
    max-height: 260px;
    overflow: auto;
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity .14s, transform .14s;
}

.tsw.open .tsw-menu {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.tsw-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    cursor: pointer;
    background: transparent;
    border: 0;
    border-radius: 7px;
    padding: 8px 10px;
    color: #d5e0e1;
    font: inherit;
    font-size: 13px;
}

.tsw-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.tsw-item.on {
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 640;
}

.tsw-item .tsw-chk {
    margin-left: auto;
    opacity: 0;
}

.tsw-item.on .tsw-chk {
    opacity: 1;
}

.who {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
}

.who span {
    font-size: 12.5px;
    color: #aebec0;
}

.who button {
    color: #cfdcdd;
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* min-height:0 lets this grid item shrink below its content so it can scroll */
    min-height: 0;
    overflow-y: auto;
    /* This is the page's real scroll container, so clip horizontal here (not just on
       <html>) to keep the off-screen slide-over drawer from being scrolled into view. */
    overflow-x: clip;
}

/* mobile-only nav chrome; hidden on desktop where the sidebar is a fixed column */
.mobile-bar {
    display: none;
}

.hamburger {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border: 0;
    background: transparent;
    color: var(--ink);
    border-radius: 9px;
    transition: background .14s;
}

.hamburger:hover {
    background: var(--line-2);
}

.nav-scrim {
    display: none;
}

/* routed page content fades and lifts in on every navigation. */
.page-swap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    animation: page-enter .2s cubic-bezier(.22, .61, .36, 1) backwards;
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* the user detail pane fades and lifts in when a different user is selected */
.detail-swap {
    animation: page-enter .18s cubic-bezier(.22, .61, .36, 1) both;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--topbar-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    padding: 20px 30px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.topbar h1 {
    font-size: 22px;
    letter-spacing: -.02em;
}

.topbar .crumb {
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 3px;
}

.content {
    padding: 24px 30px 60px;
}

/* ---------- section headers ---------- */
.sect-h {
    margin: 2px 0 10px;
}

.sect-h-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 24px 0 10px;
}

.sect-h-row .sect-h {
    margin: 0;
}

/* ---------- panels & tables ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.panel-head h3 {
    font-size: 14px;
    font-weight: 620;
}

.panel-body {
    padding: 18px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

/* ---------- skeleton loading ---------- */
/* Plain static placeholders shown while a page's data loads: the real panel/table
   chrome with a few blank grey blocks. No animation, no stand-in data. */
.sk-block {
    background: var(--skel-base);
    border-radius: 6px;
    height: 13px;
}

.sk-circle {
    background: var(--skel-base);
    border-radius: 50%;
    flex: none;
}

/* Fixed layouts so the paired in-person / virtual tables share identical column widths.
   Desktop only: the pinned widths don't fit a phone, where rows render as stacked cards. */
@media (min-width: 881px) {
    .term-table,
    .access-table {
        table-layout: fixed;
    }

    .term-table th:nth-child(2),
    .term-table td:nth-child(2) {
        width: 200px;
    }

    .term-table th:nth-child(3),
    .term-table td:nth-child(3) {
        width: 120px;
    }

    .term-table th:nth-child(4),
    .term-table td:nth-child(4) {
        width: 168px;
    }

    .access-table th:nth-child(2),
    .access-table td:nth-child(2) {
        width: 210px;
    }
}

thead th {
    text-align: left;
    font-size: 11px;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--line-2);
    font-size: 14px;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--surface-2);
}

td .t-name {
    font-weight: 560;
}

td .t-sub {
    color: var(--muted);
    font-size: 12px;
}

.row-actions {
    text-align: right;
    white-space: nowrap;
}

.row-actions .btn + .btn {
    margin-left: 8px;
}

/* ---------- status pills & tags ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

.pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.pill.active {
    background: var(--good-soft);
    color: var(--good);
}

.pill.active::before {
    background: var(--good);
}

.pill.idle {
    background: var(--idle-soft);
    color: var(--idle);
}

.pill.idle::before {
    background: var(--idle);
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.tag.online {
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.tag.inperson {
    background: var(--line-2);
    color: var(--ink-2);
}

/* ---------- dashboard ---------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 16px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 15px 16px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 5px;
}

.kpi .eyebrow {
    margin-bottom: 3px;
}

.kpi-val {
    font-size: 26px;
    font-weight: 680;
    letter-spacing: -.02em;
    line-height: 1;
}

.kpi-of {
    font-size: 15px;
    color: var(--muted);
    font-weight: 500;
}

.kpi-sub {
    font-size: 12.5px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 18px;
}

.kpi-split {
    display: flex;
    gap: 10px 24px;
    flex: 1;
    align-items: center;
    flex-wrap: wrap;
}

.kpi-split .kpi-val {
    font-size: 22px;
}

.kpi-tag {
    font-size: 10.5px;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    margin-top: 3px;
}

.kpi-foot {
    margin-top: auto;
    font-size: 12.5px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 7px;
}

.kpi-foot .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--good);
    flex: none;
}

.dash-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 16px;
    align-items: start;
}

.quick {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* payments sparkline (in the KPI) */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 28px;
    margin-top: 7px;
}

.spark i {
    flex: 1;
    background: var(--accent-soft);
    border-radius: 2px;
    min-height: 3px;
}

.spark i.hi {
    background: var(--accent);
}

/* 7-day bar chart */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    height: 200px;
    padding: 22px 20px 12px;
}

.bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    height: 100%;
    justify-content: flex-end;
    cursor: pointer;
}

.bar .b {
    width: 100%;
    max-width: 40px;
    background: var(--accent-soft);
    border-radius: 5px 5px 0 0;
}

.bar:hover .b {
    background: var(--accent);
}

.bar.selected .b {
    background: var(--accent-ink);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.bar small {
    font-size: 11px;
    color: var(--muted);
}

.bar.today small {
    color: var(--accent-ink);
    font-weight: 700;
}

.bar.today small::after {
    content: "";
    display: block;
    margin: 2px auto 0;
    width: 14px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
}

.bar.selected small {
    color: var(--ink);
    font-weight: 600;
}

/* recent activity feed */
.activity-scroll {
    max-height: 200px;
    overflow-y: auto;
}

.activity {
    list-style: none;
    margin: 0;
    padding: 6px 0;
}

.activity li {
    display: flex;
    gap: 11px;
    padding: 9px 18px;
    font-size: 13px;
    align-items: flex-start;
    line-height: 1.45;
}

.activity li b {
    font-weight: 620;
}

.activity .adot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 6px;
    flex: none;
}

.activity time {
    display: block;
    color: var(--muted);
    font-size: 11.5px;
    margin-top: 1px;
}

/* ---------- users: master-detail ---------- */
.split {
    display: grid;
    grid-template-columns: 330px 1fr;
    gap: 18px;
    align-items: start;
}

/* Keep the roster in view while a tall detail panel scrolls beside it.
   Offset clears the sticky topbar. */
.roster {
    position: sticky;
    top: 96px;
}

.search {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-family: inherit;
    background: var(--surface);
    color: var(--ink);
}

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

.search-wrap {
    position: relative;
}

.search-wrap .search {
    padding-right: 34px;
}

.search-clear {
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}

.search-clear:hover {
    background: var(--line-2);
    color: var(--ink);
}

/* TPN reveal (press-and-hold eye) */
.tpn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.tpn-eye {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    cursor: pointer;
    flex: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.tpn-eye:hover {
    background: var(--line-2);
    color: var(--ink);
}

.tpn-eye.on {
    color: var(--accent);
}

.tpn-eye svg {
    width: 15px;
    height: 15px;
}

.ulist {
    margin-top: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    /* Cap the roster to the viewport so a long list scrolls inside the panel
       instead of stretching the page. Offset = topbar + page padding + search box. */
    max-height: calc(100vh - 236px);
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow);
    scrollbar-width: thin;
    scrollbar-color: var(--line-2) transparent;
}

.ulist::-webkit-scrollbar {
    width: 11px;
}

.ulist::-webkit-scrollbar-thumb {
    background: var(--line-2);
    border: 3px solid var(--surface);
    border-radius: 999px;
}

.ulist::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.urow {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    /* buttons don't inherit color; set it so names use --ink (not the black default) in both themes */
    color: var(--ink);
    padding: 11px 14px;
    border-bottom: 1px solid var(--line-2);
}

.urow:last-child {
    border-bottom: 0;
}

.urow:hover {
    background: var(--surface-2);
}

.urow.sel {
    background: var(--accent-soft);
}

.urow.sel .uname {
    color: var(--accent-ink);
}

.ava {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex: none;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 650;
    color: var(--accent-ink);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px rgba(15, 118, 110, .15);
}

.uname {
    font-weight: 560;
    font-size: 13.5px;
    line-height: 1.25;
}

.uid {
    font-size: 11.5px;
    color: var(--muted);
}

.ucount {
    margin-left: auto;
    font-size: 11.5px;
    color: var(--muted);
    background: var(--line-2);
    border-radius: 999px;
    padding: 2px 8px;
    font-variant-numeric: tabular-nums;
}

.detail {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.detail-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 13px;
}

.detail-head .ava {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

.detail-head h2 {
    font-size: 16px;
    letter-spacing: -.01em;
}

.detail-empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13.5px;
}

.detail-tabs {
    display: flex;
    gap: 4px;
    padding: 0 20px;
    border-bottom: 1px solid var(--line-2);
}

.detail-tab {
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 12px 6px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}

.detail-tab:hover {
    color: var(--ink-2);
}

.detail-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.sect {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line-2);
}

.sect:last-child {
    border-bottom: 0;
}

.sect-title {
    font-size: 16px;
    font-weight: 640;
    letter-spacing: -.01em;
    margin: 0 0 4px;
}

.sect-note {
    color: var(--muted);
    font-size: 12.5px;
    margin: 0 0 14px;
}

/* question-mark hint with a custom tooltip bubble */
.tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
    vertical-align: middle;
    cursor: help;
}

.tip:hover,
.tip:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.tip-pop {
    position: absolute;
    bottom: calc(100% + 9px);
    /* Anchor near the "?" and grow rightward so a long bubble isn't clipped by the panel edge. */
    left: -14px;
    width: max-content;
    max-width: 260px;
    transform: translateY(3px);
    padding: 7px 11px;
    border-radius: 7px;
    background: var(--tooltip-bg);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0;
    text-transform: none;
    white-space: normal;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 40;
}

.tip-pop::after {
    content: "";
    position: absolute;
    top: 100%;
    /* Sit under the center of the "?" (8px from tip left = 22px from the bubble's left edge). */
    left: 22px;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--tooltip-bg);
}

.tip:hover .tip-pop,
.tip:focus-visible .tip-pop {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* terminal-access table: the allow-toggle column */
.ta-allow {
    width: 84px;
    text-align: center;
}

.perm {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    padding: 13px 0;
    border-bottom: 1px solid var(--line-2);
}

.perm:last-child {
    border-bottom: 0;
}

.perm .ptext b {
    font-size: 14px;
    font-weight: 580;
    display: block;
}

.perm .ptext span {
    font-size: 12.5px;
    color: var(--muted);
}

/* toggle switch */
.sw {
    width: 38px;
    height: 22px;
    border-radius: 999px;
    background: var(--switch-off);
    flex: none;
    padding: 2px;
    transition: .15s;
    border: 0;
}

.sw::after {
    content: "";
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--knob);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    transition: .15s;
}

.sw.on {
    background: var(--accent);
}

.sw.on::after {
    transform: translateX(16px);
}

.sw:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.perm .sw {
    margin-left: auto;
}

/* ---------- slide-over drawer ---------- */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(16, 34, 39, .36);
    opacity: 0;
    pointer-events: none;
    transition: .18s;
    z-index: 40;
}

.scrim.show {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 420px;
    max-width: 92vw;
    background: var(--surface);
    box-shadow: -12px 0 40px rgba(19, 38, 43, .18);
    transform: translateX(100%);
    transition: transform .22s ease;
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.drawer.show {
    transform: none;
}

.drawer-head {
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-head h2 {
    font-size: 17px;
    letter-spacing: -.01em;
}

/* round icon button for closing drawers */
.icon-close {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 50%;
    transition: background .14s, color .14s;
}

.icon-close:hover {
    background: var(--line-2);
    color: var(--ink);
}

.icon-close svg {
    width: 16px;
    height: 16px;
}

.drawer-body {
    padding: 20px 22px;
    /* Take the space between head and foot and scroll inside it, so the footer (Save)
       stays visible on short viewports instead of being pushed off the bottom.
       min-height:0 lets a flex item shrink below its content for overflow to engage. */
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer-body .field {
    margin: 0;
}

.hint {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: -2px;
}

.hint-warn {
    font-size: 12px;
    color: var(--warn);
    margin-top: 6px;
}

/* Longer body/intro text (ported from BDP admin) — a muted caption, not a full-size paragraph. */
.muted-note {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    max-width: 60ch;
}

/* One-time reveal of a generated secret (new-tenant API key). */
.secret-reveal {
    display: flex;
    gap: .5rem;
    align-items: center;
}
.secret-reveal input {
    flex: 1;
    font-family: var(--mono, ui-monospace, monospace);
    font-size: 12.5px;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 13px;
}

.toggle-row .tr-text b {
    font-size: 13.5px;
}

.toggle-row .tr-text span {
    font-size: 11.5px;
    color: var(--muted);
    display: block;
}

.drawer-foot {
    margin-top: auto;
    padding: 16px 22px;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
}

/* ---------- modal (centered confirm dialog) ---------- */
.modal-scrim {
    position: fixed;
    inset: 0;
    background: rgba(16, 34, 39, .5);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 100;
}

.modal {
    /* clamp against the viewport itself so the card can never poke past the right edge */
    width: min(440px, calc(100vw - 32px));
    min-width: 0;
    /* dvh so the visible height is respected when mobile browser chrome is showing */
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--surface);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(19, 38, 43, .3);
}

.modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 22px 0;
}

.modal-head h2 {
    font-size: 17px;
    letter-spacing: -.01em;
}

.modal-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex: none;
}

.modal-icon.danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.modal-icon svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 12px 22px 4px;
    font-size: 13.5px;
    color: var(--ink-2);
    line-height: 1.5;
    /* long unbroken values (masked TPNs, FHIR ids) wrap instead of widening the modal */
    overflow-wrap: anywhere;
}

.modal-foot {
    padding: 18px 22px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

/* ---------- responsive ---------- */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation-duration: .001ms !important;
    }
}

@media (max-width: 1000px) {
    .kpis {
        grid-template-columns: 1fr;
    }

    .dash-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 880px) {
    .admin-shell {
        grid-template-columns: 1fr;
    }

    /* sidebar becomes an off-canvas drawer */
    .side {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 264px;
        max-width: 82vw;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform .24s ease;
        z-index: 60;
    }

    .side.open {
        transform: none;
    }

    .nav-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(16, 34, 39, .42);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
        z-index: 55;
    }

    .nav-scrim.show {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: sticky;
        top: 0;
        z-index: 30;
        padding: 10px 14px;
        background: var(--topbar-bg);
        backdrop-filter: blur(8px);
        border-bottom: 1px solid var(--line);
    }

    .mobile-bar .brand-mark {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }

    /* the page's own topbar is no longer sticky, so it doesn't fight the mobile bar */
    .topbar {
        position: static;
        padding: 16px 16px;
    }

    .content {
        padding: 18px 16px 48px;
    }

    .split {
        grid-template-columns: 1fr;
    }

    /* single column: the roster stacks above the detail, so don't pin it */
    .roster {
        position: static;
    }

    /* ---- terminal tables become stacked cards ---- */
    .term-table thead,
    .access-table thead {
        display: none;
    }

    .term-table tbody tr,
    .access-table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        row-gap: 8px;
        align-items: center;
        padding: 13px 14px;
        border-bottom: 1px solid var(--line-2);
    }

    .term-table tbody tr:last-child,
    .access-table tbody tr:last-child {
        border-bottom: 0;
    }

    .term-table td,
    .access-table td {
        display: block;
        padding: 0;
        border: 0;
    }

    /* terminals: name + status share the top row, TPN below, actions at the bottom */
    .term-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .term-table td:nth-child(3) { grid-column: 2; grid-row: 1; justify-self: end; }
    .term-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
    .term-table td:nth-child(4) {
        grid-column: 1 / -1;
        grid-row: 3;
        text-align: left;
        margin-top: 2px;
    }

    /* access: name + allow-toggle share the top row, TPN below */
    .access-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .access-table td.ta-allow {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        width: auto;
    }
    .access-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }

    /* small label so a bare masked number reads as the TPN */
    .term-table td:nth-child(2)::before,
    .access-table td:nth-child(2)::before {
        content: "TPN";
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .08em;
        color: var(--muted);
        margin-right: 8px;
    }

    /* empty-state rows span the whole card */
    .term-table td[colspan],
    .access-table td[colspan] {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .term-table td[colspan]::before,
    .access-table td[colspan]::before {
        content: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .side {
        transition: none;
    }
}
