/* =========================================================================
   Layout: shell, sidebar (expanded ⟷ rail), top bar, phone bottom bar,
   page header with contextual tabs.
   Breakpoints: ≥1200 sidebar expanded · 768–1199 icon rail · <768 sheet + bottom bar
   ========================================================================= */
body.app-body { background: var(--backdrop); }
.shell { display: flex; min-height: calc(100vh - 2rem); margin: 1rem; background: var(--surface); border-radius: 1.75rem; overflow: clip; }
@media (max-width: 767.98px) { .shell { min-height: 100vh; margin: 0; border-radius: 0; } }

/* ---------- Sidebar ---------- */
.sidebar { width: var(--side-w); flex: 0 0 var(--side-w); background: var(--surface); border-right: 1px solid var(--line); transition: width var(--dur) var(--ease), flex-basis var(--dur) var(--ease); }
.sidebar.offcanvas-md { --bs-offcanvas-width: min(19rem, 86vw); --bs-offcanvas-bg: var(--surface); }
@media (min-width: 768px) { .sidebar.offcanvas-md { background-color: var(--surface) !important; border-right: 1px solid var(--line) !important; } }
.side-inner { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
@media (min-width: 768px) { .side-inner { height: calc(100vh - 2rem); } }
.side-head { display: flex; align-items: center; gap: .6rem; margin: 1rem 1rem .75rem; padding: .65rem .55rem .65rem .8rem; border: 1px solid var(--line); border-radius: var(--r-lg); flex: none; }
.logo { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none !important; min-width: 0; }
.logo:hover { color: var(--ink); }
.logo-mark { width: 2.25rem; height: 2.25rem; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 2px 6px color-mix(in srgb, var(--brand) 40%, transparent); }
[data-bs-theme="dark"] .logo-mark { color: #0b1a33; }
.logo-mark svg { width: 1.15rem; height: 1.15rem; }
.logo-text { font-weight: 700; letter-spacing: -.02em; font-size: var(--t-base); line-height: 1.1; white-space: nowrap; }
.logo-text small { display: block; font-size: .68rem; font-weight: 550; color: var(--ink-3); letter-spacing: 0; }
.side-toggle { margin-left: auto; }
.side-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .5rem 1rem 1rem; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.side-group + .side-group { margin-top: 1.1rem; }
.side-title { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3); padding: .3rem .6rem .45rem; text-align: center; font-weight: 600; white-space: nowrap; }
.side-link { display: flex; align-items: center; gap: .75rem; padding: .62rem .8rem; margin-bottom: .15rem; border-radius: var(--r); color: var(--ink-2); font-weight: 500; font-size: var(--t-base); text-decoration: none !important; position: relative; white-space: nowrap; transition: background-color var(--dur), color var(--dur); }
.side-link > .bi { font-size: 1.08rem; width: 1.3rem; text-align: center; color: var(--ink-3); flex: none; transition: color var(--dur); }
.side-link:hover { background: var(--sunken); color: var(--ink); }
.side-link:hover > .bi { color: var(--ink-2); }
.side-link.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.side-link.active > .bi { color: var(--brand); }
.side-count { margin-left: auto; min-width: 1.35rem; height: 1.35rem; padding: 0 .4rem; border-radius: var(--r-pill); background: var(--warn-soft); color: var(--warn); font-size: .7rem; font-weight: 700; display: inline-grid; place-items: center; }
.side-foot { flex: none; padding: .4rem 1rem .9rem; }
.side-foot .side-link { color: var(--ink-3); }

/* rail (md–lg default, or user-collapsed on xl) */
@media (min-width: 768px) {
    html[data-sidebar="rail"] .sidebar { width: var(--rail-w); flex-basis: var(--rail-w); }
    html[data-sidebar="rail"] .logo-text, html[data-sidebar="rail"] .side-title, html[data-sidebar="rail"] .side-link > span, html[data-sidebar="rail"] .side-count { display: none; }
    html[data-sidebar="rail"] .side-head { justify-content: center; flex-direction: column; gap: .4rem; margin: .8rem .7rem .5rem; padding: .5rem 0; }
    html[data-sidebar="rail"] .search-trigger.side-search { justify-content: center; margin: 0 .7rem .4rem; padding: 0; }
    html[data-sidebar="rail"] .side-search span, html[data-sidebar="rail"] .side-search kbd { display: none; }
    html[data-sidebar="rail"] .side-nav { padding: .4rem .7rem 1rem; }
    html[data-sidebar="rail"] .side-foot { padding: .4rem .7rem .9rem; }
    html[data-sidebar="rail"] .side-toggle { margin: 0; }
    html[data-sidebar="rail"] .side-link { justify-content: center; padding: .6rem; }
    html[data-sidebar="rail"] .side-link > .bi { width: auto; font-size: 1.15rem; }
    html[data-sidebar="rail"] .side-group + .side-group { margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line); }
    html[data-sidebar="rail"] .side-link[data-label]:hover::after { content: attr(data-label); position: absolute; left: calc(100% + .6rem); top: 50%; transform: translateY(-50%); background: var(--ink); color: var(--surface); font-size: var(--t-xs); font-weight: 600; padding: .3rem .55rem; border-radius: var(--r-sm); white-space: nowrap; z-index: 1100; box-shadow: var(--shadow-2); }
    html[data-sidebar="rail"] .side-link.has-count::before { content: ""; position: absolute; top: .4rem; right: .45rem; width: .45rem; height: .45rem; border-radius: 50%; background: var(--warn); }
    html[data-sidebar="rail"] .side-inner { overflow: visible; }
    html[data-sidebar="rail"] .side-nav { overflow: visible; }
}

/* ---------- Main column & top bar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1020; height: var(--top-h); display: flex; align-items: center; gap: .5rem; padding: 0 2rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-hello { min-width: 0; line-height: 1.25; }
.top-hello-line { font-size: var(--t-lg); font-weight: 550; letter-spacing: -.015em; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-hello-date { font-size: var(--t-sm); color: var(--ink-3); }
.search-trigger { display: flex; align-items: center; gap: .6rem; width: min(26rem, 100%); height: 2.7rem; padding: 0 .6rem 0 .85rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink-3); font-size: var(--t-base); text-align: left; transition: border-color var(--dur); }
.search-trigger kbd { border: 0; background: transparent; padding: 0; }
.search-trigger.side-search { width: auto; flex: none; margin: 0 1rem .5rem; }
.search-trigger:hover { border-color: var(--line-strong); color: var(--ink-2); }
.search-trigger .bi { font-size: .95rem; }
.search-trigger span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-spacer { flex: 1; }
.top-actions { display: flex; align-items: center; gap: .6rem; }
.top-actions > .dropdown > .icon-btn, .top-actions > .icon-btn { width: 2.7rem; height: 2.7rem; border: 1px solid var(--line); border-radius: var(--r); }
.icon-btn { position: relative; width: 2.3rem; height: 2.3rem; display: inline-grid; place-items: center; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); font-size: 1.12rem; text-decoration: none !important; transition: background-color var(--dur), color var(--dur); }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--sunken); color: var(--ink); }
.icon-btn .pip { position: absolute; top: .3rem; right: .3rem; min-width: 1rem; height: 1rem; padding: 0 .25rem; border-radius: var(--r-pill); background: var(--bad); color: #fff; font-size: .6rem; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface); line-height: 1; }
[data-bs-theme="dark"] .icon-btn .pip { color: #2a0705; }
.theme-dark-icon { display: none; } [data-bs-theme="dark"] .theme-light-icon { display: none; } [data-bs-theme="dark"] .theme-dark-icon { display: inline; }
.user-chip { display: flex; align-items: center; gap: .6rem; height: 2.7rem; border: 1px solid var(--line); background: transparent; padding: 0 .8rem 0 .4rem; border-radius: var(--r); color: var(--ink); transition: background-color var(--dur); }
.user-chip:hover, .user-chip[aria-expanded="true"] { background: var(--sunken); }
.user-chip .who { text-align: left; line-height: 1.15; }
.user-chip .who strong { display: block; font-size: var(--t-base); font-weight: 500; white-space: nowrap; }

/* ---------- Page ---------- */
.page { --page-px: 2rem; width: 100%; max-width: 1440px; margin: 0 auto; padding: 1.4rem var(--page-px) 4rem; flex: 1; animation: page-in 220ms var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-narrow { max-width: 920px; }
.page-head { margin-bottom: 1.5rem; }
.page-head .crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: var(--t-sm); color: var(--ink-3); margin-bottom: .55rem; list-style: none; padding: 0; }
.page-head .crumbs a { color: var(--ink-3); }
.page-head .crumbs a:hover { color: var(--ink); }
.page-head .crumbs .bi { font-size: .7rem; opacity: .7; }
.page-head-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-title { font-size: var(--t-xl); font-weight: 700; letter-spacing: -.025em; margin: 0; display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.page-sub { color: var(--ink-3); margin: .3rem 0 0; max-width: 46rem; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.eyebrow { font-size: var(--t-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-ink); margin-bottom: .35rem; }

/* contextual tabs */
.tabs { display: flex; gap: 1.6rem; border-bottom: 1px solid var(--line); margin: 1.25rem 0 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: .45rem; padding: .7rem 0; color: var(--ink-3); font-weight: 600; font-size: var(--t-sm); white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--ink); }
.tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: transparent; transition: background-color var(--dur); }
.tab.active { color: var(--ink); }
.tab.active::after { background: var(--brand); }
.tab .count { font-size: .68rem; font-weight: 700; min-width: 1.3rem; padding: .08rem .4rem; border-radius: var(--r-pill); background: var(--sunken); color: var(--ink-2); text-align: center; }
.tab.active .count { background: var(--brand-soft); color: var(--brand-ink); }

/* ---------- Phone bottom bar ---------- */
.bottombar { display: none; }
@media (max-width: 767.98px) {
    .topbar { height: 3.6rem; padding: 0 .75rem; gap: .35rem; }
    .top-actions { gap: .35rem; }
    .user-chip { padding: 0 .4rem; }
    .search-trigger { width: auto; flex: 1; }
    .search-trigger kbd { display: none; }
    .user-chip .who, .user-chip .bi-chevron-down { display: none; }
    .page { --page-px: 1rem; padding: 1rem var(--page-px) calc(var(--bottom-h) + 2rem + env(safe-area-inset-bottom)); }
    .search-trigger { min-width: 0; }
    .search-trigger span { font-size: var(--t-xs); }
    .top-actions .theme-toggle { display: none; }
    .page-title { font-size: var(--t-lg); }
    .page-head-row { flex-direction: column; align-items: stretch; }
    .page-actions > .btn { flex: 1; }
    .bottombar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; height: calc(var(--bottom-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
    .bottombar a, .bottombar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; color: var(--ink-3); font-size: .66rem; font-weight: 600; text-decoration: none !important; border: 0; background: transparent; position: relative; }
    .bottombar .bi { font-size: 1.25rem; }
    .bottombar a.active { color: var(--brand-ink); }
    .bottombar a.active .bi { color: var(--brand); }
    .bottombar .fab { width: 3rem; height: 3rem; border-radius: 1rem; background: var(--brand); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-2); margin-top: -1.1rem; }
    [data-bs-theme="dark"] .bottombar .fab { color: #0b1a33; }
    .bottombar .fab .bi { font-size: 1.4rem; }
    .bottombar .pip { position: absolute; top: .45rem; left: calc(50% + .35rem); min-width: 1rem; height: 1rem; border-radius: var(--r-pill); background: var(--warn); color: #fff; font-size: .6rem; display: grid; place-items: center; padding: 0 .25rem; }
}
@media (min-width: 768px) and (max-width: 1199.98px) { .page { --page-px: 1.5rem; padding: 1.25rem var(--page-px) 3rem; } }

/* ---------- Navigation progress ---------- */
.navprog { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--brand); z-index: 3000; opacity: 0; }
html.is-navigating .navprog { opacity: 1; animation: navprog 8s cubic-bezier(.1, .7, .2, 1) forwards; }
@keyframes navprog { 0% { width: 0; } 10% { width: 35%; } 50% { width: 70%; } 100% { width: 92%; } }

@media print {
    body.app-body { background: #fff; }
    .shell { margin: 0; border-radius: 0; }
    .sidebar, .topbar, .bottombar, .page-actions, .tabs, .toast-region { display: none !important; }
    .page { padding: 0; max-width: none; animation: none; }
    body { background: #fff; }
}

/* Organisation branding: uploaded logo or abbreviation in place of the default mark */
.logo-img { height: 2rem; width: 2rem; object-fit: contain; flex: none; border-radius: 7px; }
.logo-img.is-wide { width: auto; max-width: 10.5rem; height: 2.1rem; border-radius: 0; }
[data-bs-theme="dark"] .logo-img { background: #fff; padding: 2px; border-radius: 7px; } /* dark logos stay visible */
html[data-sidebar="rail"] .logo-img.is-wide { width: 2rem; max-width: 2rem; object-fit: cover; object-position: left center; }
.logo-abbr { font-size: .78rem; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.logo-abbr.is-long { font-size: .62rem; }
.logo-text { min-width: 0; }
.logo-name { display: block; overflow: hidden; text-overflow: ellipsis; max-width: 9.5rem; }
