/* ============================================================
   Meridian Dental Surgery - application design system
   Layered on top of Bootstrap 5. Light and dark aware.
   ============================================================ */

:root {
    --ds-bg: #f4f6f9;
    --ds-surface: #ffffff;
    --ds-surface-2: #fafbfc;
    --ds-surface-3: #eef1f5;
    --ds-border: #dde3ea;
    --ds-border-strong: #c3cdd8;
    --ds-text: #1b2430;
    --ds-text-muted: #5f6b7a;
    --ds-text-faint: #8a95a3;

    --ds-primary: #1266d6;
    --ds-primary-dark: #0d4fa8;
    --ds-primary-soft: #e7f0fd;
    --ds-accent: #0aa2a2;
    --ds-accent-soft: #e2f7f6;

    --ds-danger: #d13438;
    --ds-danger-soft: #fdeaea;
    --ds-warning: #c77700;
    --ds-warning-soft: #fdf3e2;
    --ds-success: #1c7c4a;
    --ds-success-soft: #e6f5ed;
    --ds-info: #1266d6;
    --ds-info-soft: #e7f0fd;
    --ds-purple: #6a3fbf;
    --ds-purple-soft: #efe9fb;

    --ds-sidebar-bg: #16202e;
    --ds-sidebar-text: #c3ccd8;
    --ds-sidebar-text-active: #ffffff;
    --ds-sidebar-hover: #1f2b3c;
    --ds-sidebar-active: #1266d6;
    --ds-sidebar-section: #6d7b8d;

    --ds-radius: 10px;
    --ds-radius-sm: 6px;
    --ds-radius-lg: 14px;
    --ds-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --ds-shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);

    --ds-sidebar-width: 246px;
    --ds-topbar-height: 56px;

    --ds-font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    --ds-mono: "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ds-bg: #0f1520;
        --ds-surface: #17202e;
        --ds-surface-2: #1b2532;
        --ds-surface-3: #212c3b;
        --ds-border: #2a3646;
        --ds-border-strong: #3a4859;
        --ds-text: #e6ecf3;
        --ds-text-muted: #9fadbd;
        --ds-text-faint: #7b8899;

        --ds-primary: #4d94f5;
        --ds-primary-dark: #2f7de0;
        --ds-primary-soft: #16304d;
        --ds-accent: #34c9c4;
        --ds-accent-soft: #123634;

        --ds-danger: #f27078;
        --ds-danger-soft: #3d1f24;
        --ds-warning: #e8a33d;
        --ds-warning-soft: #3a2c15;
        --ds-success: #4cc98a;
        --ds-success-soft: #16311f;
        --ds-info: #4d94f5;
        --ds-info-soft: #16304d;
        --ds-purple: #a685f0;
        --ds-purple-soft: #251c3d;

        --ds-sidebar-bg: #0b111b;
        --ds-sidebar-hover: #16202e;
        --ds-shadow: 0 1px 2px rgba(0, 0, 0, .35);
        --ds-shadow-lg: 0 8px 24px rgba(0, 0, 0, .45);
    }
}

:root[data-theme="dark"] {
    --ds-bg: #0f1520;
    --ds-surface: #17202e;
    --ds-surface-2: #1b2532;
    --ds-surface-3: #212c3b;
    --ds-border: #2a3646;
    --ds-border-strong: #3a4859;
    --ds-text: #e6ecf3;
    --ds-text-muted: #9fadbd;
    --ds-text-faint: #7b8899;
    --ds-primary: #4d94f5;
    --ds-primary-dark: #2f7de0;
    --ds-primary-soft: #16304d;
    --ds-accent: #34c9c4;
    --ds-accent-soft: #123634;
    --ds-danger: #f27078;
    --ds-danger-soft: #3d1f24;
    --ds-warning: #e8a33d;
    --ds-warning-soft: #3a2c15;
    --ds-success: #4cc98a;
    --ds-success-soft: #16311f;
    --ds-info: #4d94f5;
    --ds-info-soft: #16304d;
    --ds-purple: #a685f0;
    --ds-purple-soft: #251c3d;
    --ds-sidebar-bg: #0b111b;
    --ds-sidebar-hover: #16202e;
    --ds-shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --ds-shadow-lg: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ---------------------------------------------------------- base */

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--ds-font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ds-text);
    background: var(--ds-bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--ds-text);
    font-weight: 600;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }

a {
    color: var(--ds-primary);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

code, .mono { font-family: var(--ds-mono); font-size: .85em; }

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

/* ---------------------------------------------------------- layout */

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

.app-sidebar {
    width: var(--ds-sidebar-width);
    flex: 0 0 var(--ds-sidebar-width);
    background: var(--ds-sidebar-bg);
    color: var(--ds-sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 40;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--ds-topbar-height);
    background: var(--ds-surface);
    border-bottom: 1px solid var(--ds-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 30;
}

.app-content {
    padding: 1.25rem 1.5rem 3rem;
    flex: 1 1 auto;
}

@media (max-width: 900px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--ds-shadow-lg);
    }
    .app-sidebar.open { transform: translateX(0); }
    .app-content { padding: 1rem; }
}

/* ---------------------------------------------------------- brand */

.brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    min-height: var(--ds-topbar-height);
}

.brand-mark {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    object-fit: contain;
}

.brand-name {
    color: #fff;
    font-weight: 600;
    font-size: .95rem;
    line-height: 1.15;
}

.brand-sub {
    color: var(--ds-sidebar-section);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
}

/* ---------------------------------------------------------- nav */

.nav-scroll { flex: 1 1 auto; padding: .65rem 0 1.25rem; }

.nav-section {
    color: var(--ds-sidebar-section);
    font-size: .66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    padding: .9rem 1.15rem .35rem;
}

.nav-link-ds {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .48rem 1.15rem;
    color: var(--ds-sidebar-text);
    font-size: .855rem;
    border-left: 3px solid transparent;
    text-decoration: none;
    transition: background .12s ease, color .12s ease;
}

.nav-link-ds:hover {
    background: var(--ds-sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.nav-link-ds.active {
    background: var(--ds-sidebar-hover);
    color: var(--ds-sidebar-text-active);
    border-left-color: var(--ds-sidebar-active);
    font-weight: 600;
}

.nav-link-ds .icon { width: 18px; flex: 0 0 18px; opacity: .85; }
.nav-link-ds.active .icon { opacity: 1; }

.nav-badge {
    margin-left: auto;
    background: var(--ds-danger);
    color: #fff;
    border-radius: 999px;
    font-size: .66rem;
    font-weight: 700;
    padding: .05rem .42rem;
    min-width: 20px;
    text-align: center;
}

.nav-badge.muted { background: rgba(255, 255, 255, .14); color: var(--ds-sidebar-text); }

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, .07);
    padding: .75rem 1.15rem;
    font-size: .75rem;
    color: var(--ds-sidebar-section);
}

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

.card-ds {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    box-shadow: var(--ds-shadow);
}

.card-ds-header {
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--ds-border);
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.card-ds-header h3, .card-ds-header h2 { margin: 0; font-size: .95rem; }
.card-ds-body { padding: 1rem; }
.card-ds-footer {
    padding: .65rem 1rem;
    border-top: 1px solid var(--ds-border);
    background: var(--ds-surface-2);
    border-radius: 0 0 var(--ds-radius) var(--ds-radius);
}

/* ---------------------------------------------------------- stat tiles */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
    gap: .8rem;
}

.stat-tile {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    padding: .85rem .95rem;
    box-shadow: var(--ds-shadow);
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
}

.stat-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ds-text-muted);
    display: flex;
    align-items: center;
    gap: .35rem;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.stat-caption { font-size: .74rem; color: var(--ds-text-faint); }

.stat-tile.accent-primary { border-left: 3px solid var(--ds-primary); }
.stat-tile.accent-success { border-left: 3px solid var(--ds-success); }
.stat-tile.accent-warning { border-left: 3px solid var(--ds-warning); }
.stat-tile.accent-danger  { border-left: 3px solid var(--ds-danger); }
.stat-tile.accent-purple  { border-left: 3px solid var(--ds-purple); }
.stat-tile.accent-accent  { border-left: 3px solid var(--ds-accent); }

/* ---------------------------------------------------------- page header */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.1rem;
}

.page-head h1 { margin: 0 0 .12rem; }
.page-head .subtitle { color: var(--ds-text-muted); font-size: .87rem; margin: 0; }
.page-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------------------------------------------------------- tables */

.table-ds {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .855rem;
}

.table-ds thead th {
    background: var(--ds-surface-2);
    color: var(--ds-text-muted);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .045em;
    text-align: left;
    padding: .55rem .7rem;
    border-bottom: 1px solid var(--ds-border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-ds tbody td {
    padding: .55rem .7rem;
    border-bottom: 1px solid var(--ds-border);
    vertical-align: middle;
}

.table-ds tbody tr:last-child td { border-bottom: 0; }
.table-ds tbody tr:hover { background: var(--ds-surface-2); }
.table-ds tbody tr.row-clickable { cursor: pointer; }
.table-ds .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-ds .nowrap { white-space: nowrap; }

.table-wrap {
    overflow-x: auto;
    border-radius: var(--ds-radius);
    border: 1px solid var(--ds-border);
    background: var(--ds-surface);
}

.table-wrap .table-ds thead th:first-child { border-top-left-radius: var(--ds-radius); }
.table-wrap .table-ds thead th:last-child { border-top-right-radius: var(--ds-radius); }

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

.badge-ds {
    display: inline-flex;
    align-items: center;
    gap: .28rem;
    padding: .12rem .48rem;
    border-radius: 999px;
    font-size: .715rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-ds.b-neutral { background: var(--ds-surface-3); color: var(--ds-text-muted); }
.badge-ds.b-primary { background: var(--ds-primary-soft); color: var(--ds-primary-dark); }
.badge-ds.b-success { background: var(--ds-success-soft); color: var(--ds-success); }
.badge-ds.b-warning { background: var(--ds-warning-soft); color: var(--ds-warning); }
.badge-ds.b-danger  { background: var(--ds-danger-soft);  color: var(--ds-danger); }
.badge-ds.b-info    { background: var(--ds-info-soft);    color: var(--ds-info); }
.badge-ds.b-purple  { background: var(--ds-purple-soft);  color: var(--ds-purple); }
.badge-ds.b-accent  { background: var(--ds-accent-soft);  color: var(--ds-accent); }

:root[data-theme="dark"] .badge-ds.b-primary { color: var(--ds-primary); }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge-ds.b-primary { color: var(--ds-primary); }
}

.dot {
    width: 8px; height: 8px; border-radius: 50%;
    display: inline-block; flex: 0 0 8px;
}

/* ---------------------------------------------------------- alerts */

.alert-ds {
    display: flex;
    gap: .65rem;
    padding: .7rem .85rem;
    border-radius: var(--ds-radius-sm);
    border: 1px solid transparent;
    font-size: .85rem;
    align-items: flex-start;
}

.alert-ds.a-danger  { background: var(--ds-danger-soft);  border-color: var(--ds-danger);  color: var(--ds-danger); }
.alert-ds.a-warning { background: var(--ds-warning-soft); border-color: var(--ds-warning); color: var(--ds-warning); }
.alert-ds.a-info    { background: var(--ds-info-soft);    border-color: var(--ds-info);    color: var(--ds-info); }
.alert-ds.a-success { background: var(--ds-success-soft); border-color: var(--ds-success); color: var(--ds-success); }
.alert-ds strong { color: inherit; }

/* ---------------------------------------------------------- forms */

.form-label {
    font-size: .76rem;
    font-weight: 600;
    color: var(--ds-text-muted);
    margin-bottom: .18rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.form-control, .form-select, .input-ds {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border-strong);
    color: var(--ds-text);
    border-radius: var(--ds-radius-sm);
    font-size: .87rem;
    padding: .38rem .6rem;
}

.form-control:focus, .form-select:focus, .input-ds:focus {
    border-color: var(--ds-primary);
    box-shadow: 0 0 0 3px var(--ds-primary-soft);
    outline: none;
    background: var(--ds-surface);
    color: var(--ds-text);
}

.form-control::placeholder { color: var(--ds-text-faint); }
.form-control:disabled, .form-select:disabled { background: var(--ds-surface-3); }

.filter-bar {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: .9rem;
}

.filter-bar .field { display: flex; flex-direction: column; min-width: 150px; }
.filter-bar .field.grow { flex: 1 1 240px; }

/* ---------------------------------------------------------- buttons */

.btn { border-radius: var(--ds-radius-sm); font-size: .85rem; font-weight: 500; }
.btn-sm { font-size: .8rem; padding: .25rem .55rem; }

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

.btn-primary:hover, .btn-primary:focus {
    background: var(--ds-primary-dark);
    border-color: var(--ds-primary-dark);
}

.btn-outline-secondary {
    color: var(--ds-text);
    border-color: var(--ds-border-strong);
    background: var(--ds-surface);
}

.btn-outline-secondary:hover {
    background: var(--ds-surface-3);
    color: var(--ds-text);
    border-color: var(--ds-border-strong);
}

.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--ds-text-muted);
    padding: .25rem .5rem;
    border-radius: var(--ds-radius-sm);
}

.btn-ghost:hover { background: var(--ds-surface-3); color: var(--ds-text); }

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

.tabs-ds {
    display: flex;
    gap: .12rem;
    border-bottom: 1px solid var(--ds-border);
    overflow-x: auto;
    margin-bottom: 1rem;
}

.tab-ds {
    padding: .5rem .8rem;
    font-size: .845rem;
    font-weight: 500;
    color: var(--ds-text-muted);
    border: 0;
    background: transparent;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    cursor: pointer;
}

.tab-ds:hover { color: var(--ds-text); }

.tab-ds.active {
    color: var(--ds-primary);
    border-bottom-color: var(--ds-primary);
    font-weight: 600;
}

.tab-ds .count {
    font-size: .7rem;
    background: var(--ds-surface-3);
    color: var(--ds-text-muted);
    border-radius: 999px;
    padding: 0 .35rem;
    margin-left: .3rem;
}

/* ---------------------------------------------------------- patient banner */

.patient-banner {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    padding: .9rem 1rem;
    box-shadow: var(--ds-shadow);
    margin-bottom: 1rem;
}

.patient-identity { display: flex; gap: .85rem; align-items: center; }

.avatar {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ds-primary) 0%, var(--ds-accent) 100%);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 650;
    font-size: 1rem;
    flex: 0 0 46px;
}

.avatar.sm { width: 30px; height: 30px; flex: 0 0 30px; font-size: .74rem; }

.patient-meta {
    display: flex;
    gap: 1.1rem;
    flex-wrap: wrap;
    font-size: .8rem;
    color: var(--ds-text-muted);
}

.patient-meta .k { color: var(--ds-text-faint); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; display: block; }
.patient-meta .v { color: var(--ds-text); font-weight: 500; }

/* ---------------------------------------------------------- odontogram */

.odontogram {
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    padding: 1rem .75rem;
    overflow-x: auto;
}

.tooth-row {
    display: flex;
    gap: 3px;
    justify-content: center;
    min-width: max-content;
}

.tooth {
    width: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    padding: 2px;
    border-radius: 6px;
    border: 2px solid transparent;
}

.tooth:hover { background: var(--ds-surface-3); }
.tooth.selected { border-color: var(--ds-primary); background: var(--ds-primary-soft); }
.tooth.is-missing { opacity: .45; }

.tooth-label {
    font-size: .68rem;
    font-weight: 600;
    color: var(--ds-text-muted);
    font-variant-numeric: tabular-nums;
}

.tooth svg { display: block; }

.arch-divider {
    height: 1px;
    background: var(--ds-border);
    margin: .75rem 0;
}

.chart-legend {
    display: flex;
    gap: .9rem;
    flex-wrap: wrap;
    font-size: .74rem;
    color: var(--ds-text-muted);
    margin-top: .75rem;
    padding-top: .6rem;
    border-top: 1px solid var(--ds-border);
}

.legend-item { display: flex; align-items: center; gap: .3rem; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--ds-border-strong); }

/* ---------------------------------------------------------- schedule grid */

.diary {
    display: grid;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background: var(--ds-surface);
    overflow: auto;
    max-height: calc(100vh - 230px);
}

.diary-header {
    display: contents;
}

.diary-cell-head {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--ds-surface-2);
    border-bottom: 1px solid var(--ds-border);
    border-left: 1px solid var(--ds-border);
    padding: .5rem .6rem;
    font-size: .78rem;
    font-weight: 600;
    text-align: center;
}

.diary-time {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--ds-surface-2);
    border-bottom: 1px solid var(--ds-border);
    padding: .2rem .5rem;
    font-size: .7rem;
    color: var(--ds-text-faint);
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.diary-time.corner { z-index: 4; top: 0; }

.diary-slot {
    border-bottom: 1px solid var(--ds-border);
    border-left: 1px solid var(--ds-border);
    min-height: 26px;
    position: relative;
    padding: 1px;
}

.diary-slot.hour { border-bottom-color: var(--ds-border-strong); }
.diary-slot:hover { background: var(--ds-surface-2); }

.appt {
    border-radius: 5px;
    padding: 2px 5px;
    font-size: .72rem;
    line-height: 1.25;
    overflow: hidden;
    height: 100%;
    border-left: 3px solid;
    cursor: pointer;
    color: var(--ds-text);
}

.appt .name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt .detail { color: var(--ds-text-muted); font-size: .68rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.appt.s-unconfirmed { background: var(--ds-surface-3); border-left-color: var(--ds-text-faint); }
.appt.s-confirmed   { background: var(--ds-info-soft);  border-left-color: var(--ds-info); }
.appt.s-waiting     { background: var(--ds-warning-soft); border-left-color: var(--ds-warning); }
.appt.s-seated      { background: var(--ds-purple-soft); border-left-color: var(--ds-purple); }
.appt.s-complete    { background: var(--ds-success-soft); border-left-color: var(--ds-success); }
.appt.s-cancelled   { background: var(--ds-danger-soft); border-left-color: var(--ds-danger); text-decoration: line-through; opacity: .75; }

/* ---------------------------------------------------------- perio grid */

.perio-grid { font-size: .72rem; border-collapse: collapse; }
.perio-grid th, .perio-grid td { border: 1px solid var(--ds-border); padding: 1px 3px; text-align: center; }
.perio-grid th { background: var(--ds-surface-2); font-weight: 600; }
.perio-grid input {
    width: 26px;
    border: 0;
    background: transparent;
    text-align: center;
    font-size: .72rem;
    color: var(--ds-text);
    padding: 1px;
}
.perio-grid input:focus { outline: 2px solid var(--ds-primary); border-radius: 3px; }
.perio-grid td.pd-shallow { background: transparent; }
.perio-grid td.pd-moderate { background: var(--ds-warning-soft); }
.perio-grid td.pd-deep { background: var(--ds-danger-soft); font-weight: 700; }
.perio-grid td.bop { color: var(--ds-danger); font-weight: 700; }

/* ---------------------------------------------------------- charts */

.bar-track {
    height: 6px;
    background: var(--ds-surface-3);
    border-radius: 999px;
    overflow: hidden;
    min-width: 60px;
}

.bar-fill { height: 100%; border-radius: 999px; background: var(--ds-primary); }
.bar-fill.success { background: var(--ds-success); }
.bar-fill.warning { background: var(--ds-warning); }
.bar-fill.danger  { background: var(--ds-danger); }

.spark { display: block; }

/* ---------------------------------------------------------- timeline */

.timeline { position: relative; padding-left: 1.25rem; }

.timeline::before {
    content: "";
    position: absolute;
    left: 5px; top: 4px; bottom: 4px;
    width: 2px;
    background: var(--ds-border);
}

.timeline-item { position: relative; padding-bottom: 1rem; }

.timeline-item::before {
    content: "";
    position: absolute;
    left: -1.25rem; top: 5px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--ds-surface);
    border: 2px solid var(--ds-primary);
}

.timeline-item.done::before { background: var(--ds-success); border-color: var(--ds-success); }
.timeline-item.warn::before { background: var(--ds-warning); border-color: var(--ds-warning); }

/* ---------------------------------------------------------- empty state */

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--ds-text-muted);
}

.empty-state .icon { opacity: .35; margin-bottom: .6rem; }
.empty-state h4 { color: var(--ds-text); margin-bottom: .25rem; }
.empty-state p { font-size: .85rem; margin-bottom: .8rem; }

/* ---------------------------------------------------------- misc */

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: .3rem .9rem; font-size: .85rem; }
.kv dt { color: var(--ds-text-muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--ds-text); }

.divider { height: 1px; background: var(--ds-border); margin: 1rem 0; }

.scroll-y { overflow-y: auto; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--ds-surface-3);
    border-radius: 999px;
    padding: .12rem .55rem;
    font-size: .74rem;
    color: var(--ds-text-muted);
}

.loading-bar {
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--ds-primary), transparent);
    background-size: 200% 100%;
    animation: slide 1.1s linear infinite;
    border-radius: 999px;
}

@keyframes slide {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--ds-surface-3) 25%, var(--ds-surface-2) 37%, var(--ds-surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
    border-radius: 4px;
}

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

/* Blazor framework UI */
#blazor-error-ui {
    background: var(--ds-warning-soft);
    color: var(--ds-warning);
    border-top: 2px solid var(--ds-warning);
    bottom: 0;
    box-shadow: var(--ds-shadow-lg);
    display: none;
    left: 0;
    padding: .8rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1080;
    font-size: .87rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: .9rem;
    top: .6rem;
    font-size: 1.1rem;
}

.blazor-error-boundary {
    background: var(--ds-danger-soft);
    color: var(--ds-danger);
    padding: 1rem;
    border-radius: var(--ds-radius);
    border: 1px solid var(--ds-danger);
}

.validation-message { color: var(--ds-danger); font-size: .78rem; }

/* Print */
@media print {
    .app-sidebar, .app-topbar, .page-head-actions, .no-print { display: none !important; }
    .app-content { padding: 0; }
    .card-ds { box-shadow: none; border-color: #ccc; break-inside: avoid; }
    body { background: #fff; font-size: 11pt; }
}

/* ============================================================
   Authentication surface
   A separate shell from the application. Nothing behind the
   sign-in wall renders here, so an anonymous visitor sees the
   practice identity and a form, and nothing else.
   ============================================================ */

.auth-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    min-height: 100vh;
    background: var(--ds-bg);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 2rem;
    padding: 3rem 3.25rem;
    color: #e8eef6;
    background: linear-gradient(160deg, #16202e 0%, #10314f 58%, #0d4fa8 100%);
}

.auth-brand-inner { margin-top: auto; max-width: 26rem; }

.auth-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .13);
    border: 1px solid rgba(255, 255, 255, .18);
}

.auth-mark.sm { width: 34px; height: 34px; border-radius: 9px; }

.auth-brand-name {
    margin: 1.35rem 0 .35rem;
    font-size: 1.9rem;
    font-weight: 650;
    letter-spacing: -.02em;
    line-height: 1.15;
    color: #fff;
}

.auth-brand-line {
    margin: 0 0 2rem;
    font-size: .95rem;
    color: rgba(232, 238, 246, .72);
}

.auth-brand-points {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .7rem;
}

.auth-brand-points li {
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: .875rem;
    color: rgba(232, 238, 246, .82);
}

.auth-brand-points svg { flex: none; opacity: .8; }

.auth-brand-foot {
    margin: 0;
    max-width: 26rem;
    font-size: .78rem;
    line-height: 1.5;
    color: rgba(232, 238, 246, .55);
    border-top: 1px solid rgba(255, 255, 255, .12);
    padding-top: 1.15rem;
}

.auth-panel {
    display: flex;
    flex-direction: column;
    padding: 2rem 2.5rem 1.5rem;
    background: var(--ds-surface);
}

.auth-panel-head {
    display: none;
    align-items: center;
    gap: .6rem;
    margin-bottom: 2rem;
    font-weight: 600;
    color: var(--ds-text);
}

.auth-panel-head .auth-mark { background: var(--ds-primary); border-color: transparent; }

.auth-card {
    width: 100%;
    max-width: 25rem;
    margin: auto;
}

.auth-card-head { margin-bottom: 1.75rem; }

.auth-title {
    margin: 0 0 .35rem;
    font-size: 1.55rem;
    font-weight: 650;
    letter-spacing: -.015em;
    color: var(--ds-text);
}

.auth-subtitle {
    margin: 0;
    font-size: .9rem;
    color: var(--ds-text-muted);
}

.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    margin-bottom: 1.25rem;
    padding: .8rem .9rem;
    border-radius: var(--ds-radius-sm);
    border: 1px solid;
    font-size: .855rem;
    line-height: 1.45;
}

.auth-alert strong { display: block; font-weight: 600; }
.auth-alert span { color: inherit; opacity: .88; }
.auth-alert-icon { flex: none; margin-top: .05rem; }

.auth-alert.is-danger  { background: var(--ds-danger-soft);  border-color: var(--ds-danger);  color: var(--ds-danger); }
.auth-alert.is-warning { background: var(--ds-warning-soft); border-color: var(--ds-warning); color: var(--ds-warning); }
.auth-alert.is-info    { background: var(--ds-info-soft);    border-color: var(--ds-info);    color: var(--ds-info); }

.auth-form .field { margin-bottom: 1.05rem; }

.field-label {
    display: block;
    margin-bottom: .35rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--ds-text);
}

.field-label .req { color: var(--ds-danger); margin-left: .1rem; }

.auth-form .form-control {
    height: 44px;
    font-size: .93rem;
    background: var(--ds-surface);
    border-color: var(--ds-border-strong);
    color: var(--ds-text);
}

.auth-form .form-control:focus {
    border-color: var(--ds-primary);
    box-shadow: 0 0 0 3px var(--ds-primary-soft);
}

.field-error {
    display: block;
    margin-top: .3rem;
    font-size: .8rem;
    color: var(--ds-danger);
}

.password-wrap { position: relative; }
.password-wrap .form-control { padding-right: 2.75rem; }

.password-toggle {
    position: absolute;
    top: 50%;
    right: .4rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: var(--ds-radius-sm);
    background: transparent;
    color: var(--ds-text-muted);
    cursor: pointer;
}

.password-toggle:hover { background: var(--ds-surface-3); color: var(--ds-text); }

.password-toggle:focus-visible {
    outline: 2px solid var(--ds-primary);
    outline-offset: 1px;
}

.auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: .25rem 0 1.4rem;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    margin: 0;
    font-size: .85rem;
    color: var(--ds-text);
    cursor: pointer;
}

.check .form-check-input { margin: 0; cursor: pointer; }

.auth-link {
    font-size: .85rem;
    color: var(--ds-primary);
    text-decoration: none;
}

.auth-link:hover { text-decoration: underline; }

.auth-submit {
    width: 100%;
    height: 44px;
    font-size: .95rem;
    font-weight: 600;
}

.auth-submit[disabled] { opacity: .72; cursor: progress; }

.auth-foot {
    margin: 1.6rem 0 0;
    padding-top: 1.1rem;
    border-top: 1px solid var(--ds-border);
    font-size: .8rem;
    line-height: 1.55;
    color: var(--ds-text-muted);
}

.auth-panel-foot {
    margin-top: 2rem;
    font-size: .76rem;
    color: var(--ds-text-faint);
    text-align: center;
}

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-panel-head { display: flex; }
    .auth-panel { padding: 1.75rem 1.25rem 1.25rem; }
}

/* ------------------------------------------------------------
   Access denied
   ------------------------------------------------------------ */

.denied-wrap { display: flex; justify-content: center; padding: 2rem 0; }

.denied-card {
    width: 100%;
    max-width: 34rem;
    padding: 2rem;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow);
}

.denied-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--ds-warning-soft);
    color: var(--ds-warning);
    margin-bottom: 1.1rem;
}

.denied-title {
    margin: 0 0 .75rem;
    font-size: 1.3rem;
    font-weight: 650;
    letter-spacing: -.01em;
    color: var(--ds-text);
}

.denied-body, .denied-next {
    margin: 0 0 1rem;
    font-size: .9rem;
    line-height: 1.6;
    color: var(--ds-text-muted);
}

.denied-who {
    display: flex;
    flex-wrap: wrap;
    gap: 1.75rem;
    margin: 1.25rem 0;
    padding: .9rem 1rem;
    background: var(--ds-surface-3);
    border-radius: var(--ds-radius-sm);
}

.denied-who-label {
    display: block;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ds-text-faint);
}

.denied-who-value { font-size: .88rem; font-weight: 600; color: var(--ds-text); }

.denied-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.4rem; }

/* ============================================================
   Collapsible navigation groups
   ============================================================ */

.nav-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: .9rem 1.15rem .35rem;
    border: 0;
    background: transparent;
    color: var(--ds-sidebar-section);
    font-size: .66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    cursor: pointer;
    text-align: left;
}

.nav-group-head:hover { color: var(--ds-sidebar-text); }

.nav-group-head:focus-visible {
    outline: 2px solid var(--ds-primary);
    outline-offset: -2px;
}

.nav-group-chevron { transition: transform .15s ease; opacity: .7; }
.nav-group-head.collapsed .nav-group-chevron { transform: rotate(-90deg); }

.nav-help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: var(--ds-radius-sm);
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.nav-help-btn:hover { background: var(--ds-sidebar-hover); }

.nav-help-btn:focus-visible {
    outline: 2px solid var(--ds-primary);
    outline-offset: 1px;
}

/* ============================================================
   Dialogs
   ============================================================ */

.modal-backdrop-ds {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 27, .55);
    z-index: 1040;
}

.modal-ds {
    position: fixed;
    z-index: 1050;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(46rem, calc(100vw - 2rem));
    max-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-lg);
}

.modal-ds-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--ds-border);
}

.modal-ds-head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--ds-text);
}

.modal-ds-body { padding: 1.25rem; overflow-y: auto; }

.modal-ds-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    padding: .9rem 1.25rem;
    border-top: 1px solid var(--ds-border);
    background: var(--ds-surface-2);
    border-radius: 0 0 var(--ds-radius-lg) var(--ds-radius-lg);
}

.form-label-sm {
    display: block;
    margin-bottom: .25rem;
    font-size: .78rem;
    font-weight: 600;
    color: var(--ds-text);
}

.req { color: var(--ds-danger); }

/* ============================================================
   Role and permission administration
   ============================================================ */

.role-summary {
    height: 100%;
    padding: .8rem .9rem;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background: var(--ds-surface-2);
    cursor: pointer;
    transition: border-color .12s ease, background .12s ease;
}

.role-summary:hover { border-color: var(--ds-border-strong); }

.role-summary:focus-visible {
    outline: 2px solid var(--ds-primary);
    outline-offset: 1px;
}

.role-summary.is-focus {
    border-color: var(--ds-primary);
    background: var(--ds-primary-soft);
}

.role-summary-name { font-weight: 600; font-size: .9rem; color: var(--ds-text); }
.role-summary-count { font-size: .76rem; color: var(--ds-text-muted); }

.perm-matrix th.perm-col,
.perm-matrix td.perm-col { min-width: 17rem; }

.perm-matrix .perm-name { font-weight: 600; font-size: .84rem; color: var(--ds-text); }
.perm-matrix .perm-desc { font-size: .75rem; color: var(--ds-text-muted); font-weight: 400; }

.perm-matrix .perm-role-head {
    display: inline-block;
    font-size: .74rem;
    line-height: 1.15;
    max-width: 5.5rem;
}

.perm-matrix .perm-module-row th {
    background: var(--ds-surface-3);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ds-text-muted);
    padding-top: .5rem;
    padding-bottom: .5rem;
}

.perm-matrix .is-focus { background: var(--ds-primary-soft); }

.perm-matrix .form-check-input { cursor: pointer; }
.perm-matrix .form-check-input:disabled { cursor: not-allowed; opacity: .55; }

/* ------------------------------------------------------------
   Home panels
   ------------------------------------------------------------ */

.panel-subhead {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ds-text-muted);
}

.open-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem .7rem;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-surface-2);
    color: inherit;
    text-decoration: none;
}

.open-row:hover { border-color: var(--ds-border-strong); background: var(--ds-surface-3); }

.open-row:focus-visible { outline: 2px solid var(--ds-primary); outline-offset: 1px; }

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1rem;
}

.quick-action {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .8rem;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-surface);
    color: var(--ds-text);
    font-size: .84rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.quick-action:hover {
    border-color: var(--ds-primary);
    background: var(--ds-primary-soft);
    color: var(--ds-primary);
}

.quick-action:focus-visible { outline: 2px solid var(--ds-primary); outline-offset: 1px; }

.quick-action.is-primary {
    background: var(--ds-primary);
    border-color: var(--ds-primary);
    color: #fff;
}

.quick-action.is-primary:hover { background: var(--ds-primary-dark); color: #fff; }

/* ============================================================
   Contextual help panel
   ============================================================ */

.help-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 27, .4);
    z-index: 1060;
}

.help-panel {
    position: fixed;
    z-index: 1070;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(28rem, 100vw);
    display: flex;
    flex-direction: column;
    background: var(--ds-surface);
    border-left: 1px solid var(--ds-border);
    box-shadow: var(--ds-shadow-lg);
}

.help-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--ds-border);
}

.help-eyebrow {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--ds-text-faint);
}

.help-head h2 {
    margin: .15rem 0 0;
    font-size: 1.1rem;
    font-weight: 650;
    color: var(--ds-text);
}

.help-body { padding: 1.25rem; overflow-y: auto; }

.help-purpose {
    margin: 0 0 1.25rem;
    font-size: .88rem;
    line-height: 1.65;
    color: var(--ds-text);
}

.help-section { margin-bottom: 1.4rem; }

.help-section h3 {
    margin: 0 0 .5rem;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--ds-text-muted);
}

.help-section ul { margin: 0; padding-left: 1.1rem; }

.help-section li {
    margin-bottom: .5rem;
    font-size: .85rem;
    line-height: 1.6;
    color: var(--ds-text-muted);
}

.help-keys {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .4rem .8rem;
    margin: 0;
    align-items: baseline;
}

.help-keys dt { margin: 0; }
.help-keys dd { margin: 0; font-size: .83rem; color: var(--ds-text-muted); }

.help-keys kbd {
    display: inline-block;
    padding: .12rem .4rem;
    font-family: var(--ds-mono);
    font-size: .74rem;
    color: var(--ds-text);
    background: var(--ds-surface-3);
    border: 1px solid var(--ds-border-strong);
    border-radius: 4px;
    white-space: nowrap;
}

@media (max-width: 520px) {
    .help-panel { width: 100vw; }
}


/* ---------------------------------------------------------------- brand */

/* The sign-in lockup. Sized by width with height following, so the artwork
   keeps its proportions whatever it is replaced with later. */
.auth-logo {
    display: block;
    width: min(320px, 78%);
    height: auto;
    margin-bottom: 1.25rem;
}

/* The mark beside the practice name on the light sign-in panel. Same treatment
   as the sidebar: artwork on its own, no plate behind it. */
.auth-mark.sm {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    object-fit: contain;
    background: none;
    border-radius: 0;
}


/* ================================================================
   Account settings
   ================================================================ */

.settings-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

/* The rail sticks while a long page scrolls, so the section you are in stays
   in view rather than disappearing off the top. */
.settings-nav {
    position: sticky;
    top: calc(var(--ds-topbar-height) + 1rem);
}

.settings-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.settings-nav-link {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .6rem .7rem;
    border-radius: var(--ds-radius-sm);
    color: var(--ds-text);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .12s ease, border-color .12s ease;
}

.settings-nav-link:hover { background: var(--ds-surface-3); }

.settings-nav-link.active {
    background: var(--ds-primary-soft);
    border-color: var(--ds-primary);
    color: var(--ds-primary-dark);
}

.settings-nav-link > svg { flex: 0 0 auto; margin-top: .15rem; }

.settings-nav-text { display: flex; flex-direction: column; min-width: 0; }
.settings-nav-label { font-size: .87rem; font-weight: 500; }

.settings-nav-hint {
    font-size: .75rem;
    color: var(--ds-text-muted);
    line-height: 1.3;
}

.settings-nav-link.active .settings-nav-hint { color: var(--ds-primary-dark); opacity: .8; }

.settings-body { min-width: 0; }

/* Content ------------------------------------------------------- */

.settings-lede { font-size: .88rem; margin: 0 0 .5rem; max-width: 60ch; }
.settings-note { font-size: .8rem; margin: 0; max-width: 60ch; }

.settings-identity { display: flex; align-items: center; gap: .9rem; }
.settings-identity-name { font-weight: 600; font-size: 1rem; }

/* Forms in settings are single-column and read top to bottom. A field is
   comfortable to hit rather than packed, because these pages are used rarely
   and often on a phone. */
.settings-form .field + .field { margin-top: 1rem; }
.settings-field { max-width: 26rem; }

.form-hint {
    font-size: .78rem;
    color: var(--ds-text-muted);
    margin: .4rem 0 0;
    max-width: 46ch;
}

.validation-summary { color: var(--ds-danger); font-size: .82rem; }
.validation-summary ul { margin: 0 0 .75rem; padding-left: 1.1rem; }
.validation-summary:empty { display: none; }

.avatar.lg {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    font-size: 1rem;
}

/* The footer holds the actions. Wraps rather than overflowing when a card
   carries three of them and the screen is narrow. */
.card-ds-footer { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

@media (max-width: 820px) {
    /* The rail becomes a horizontal scroller above the content. Stacking it
       would push the form itself below the fold on a phone. */
    .settings-shell { grid-template-columns: 1fr; gap: .9rem; }

    .settings-nav {
        position: static;
        overflow-x: auto;
        margin: 0 -1rem;
        padding: 0 1rem .25rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .settings-nav::-webkit-scrollbar { display: none; }

    .settings-nav-list { flex-direction: row; gap: .4rem; }

    .settings-nav-link {
        white-space: nowrap;
        border: 1px solid var(--ds-border);
        background: var(--ds-surface);
        align-items: center;
    }

    /* The hint is what makes the rail readable in a column; in a row it is
       what makes it unreadably wide. */
    .settings-nav-hint { display: none; }

    .settings-field { max-width: none; }
}


/* ---------------------------------------------------------------- confirm

   A single decision on an otherwise empty page: signing out, and anything else
   that needs a deliberate yes. Centred and narrow, so the choice is the only
   thing on screen rather than a pair of buttons lost under the topbar. */

.confirm-wrap { display: flex; justify-content: center; padding: 2rem 1rem; }

.confirm-card {
    width: 100%;
    max-width: 30rem;
    padding: 2rem;
    text-align: center;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow);
}

.confirm-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--ds-primary-soft);
    color: var(--ds-primary);
    margin-bottom: 1rem;
}

.confirm-title { margin: 0 0 .4rem; font-size: 1.15rem; }

.confirm-lede {
    margin: 0 auto 1.4rem;
    max-width: 34ch;
    font-size: .88rem;
    color: var(--ds-text-muted);
}

.confirm-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }

/* On a phone the two choices go full width and stack, so neither is a small
   target next to the other. */
@media (max-width: 460px) {
    .confirm-card { padding: 1.5rem 1.1rem; }
    .confirm-actions { flex-direction: column-reverse; }
    .confirm-actions .btn { width: 100%; }
}


/* ================================================================
   Responsive

   The layout already collapsed the sidebar and the sign-in split at 900px.
   What follows covers what a clinical screen actually does on a small one:
   wide tables, dense toolbars, and controls that were sized for a mouse.
   ================================================================ */

/* Nothing should make the page itself scroll sideways. A wide table scrolls
   inside its own frame; a long unbroken string - a storage path, an X12
   segment - wraps instead of stretching the document. */
html, body { overflow-x: hidden; }

.table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* Tablet ------------------------------------------------------- */

@media (max-width: 1100px) {
    /* Two panels side by side stop being two panels. Bootstrap's own columns
       already do this at its breakpoints; these are the app's own grids. */
    .row.g-3 > [class*="col-xl-"] { flex: 0 0 100%; max-width: 100%; }
}

/* Phone -------------------------------------------------------- */

@media (max-width: 700px) {
    .app-content { padding: .85rem; }

    /* The title and its actions stack, and the actions go full width. Side by
       side they leave the title on one line and a cramped button beside it. */
    .page-head { flex-direction: column; align-items: stretch; gap: .75rem; }
    .page-head-actions .btn { flex: 1 1 auto; justify-content: center; }

    /* Two tiles across rather than one: the numbers are short, and one per row
       turns eight figures into a page of scrolling. */
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .stat-tile { padding: .7rem .75rem; }
    .stat-value { font-size: 1.35rem; }

    /* A card's actions become a stack of full-width targets. */
    .card-ds-footer > .btn { flex: 1 1 100%; justify-content: center; }

    /* Filter bars are built as inline rows of selects; they wrap to one per
       line rather than squeezing each to a few characters wide. */
    .filter-bar, .toolbar-ds { flex-direction: column; align-items: stretch; }
    .filter-bar > *, .toolbar-ds > * { width: 100%; }

    /* Comfortable to hit with a thumb. 44px is the size a finger actually
       needs; the desktop sizes are set for a pointer. */
    .btn, .form-control, .form-select, .input-ds { min-height: 44px; }
    .btn-sm { min-height: 38px; }

    /* iOS zooms the whole page when a focused field is under 16px. */
    .form-control, .form-select, .input-ds, input, select, textarea { font-size: 16px; }

    /* A table that will not fit is scrolled, not shrunk to unreadable. The
       frame keeps its own scrollbar so the page stays put. */
    .table-wrap { max-width: 100%; }
    .table-ds { min-width: 34rem; }
    .table-ds th, .table-ds td { white-space: nowrap; }
}

@media (max-width: 420px) {
    /* Below this a two-column tile grid gives each number about ten
       characters, which is not enough for money. */
    .stat-grid { grid-template-columns: 1fr; }
}

/* Pointer-coarse ------------------------------------------------

   Size by input device rather than by width alone: a tablet in a surgery is a
   wide screen operated with a finger, and would otherwise keep the mouse-sized
   controls. */

@media (pointer: coarse) {
    .btn, .nav-link, .settings-nav-link, .tab-ds { min-height: 40px; }
    .btn-ghost { padding: .45rem; }
}

/* Reduced motion ----------------------------------------------- */

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