/* Application shell and legacy page adapters, loaded after page structure styles.
   Original clinical/manual content retains its markup and semantic formatting. */
:root { --ui-sidebar-width:240px; --ui-header-height:0px; }
:root, html { background:var(--ui-canvas); scroll-padding-top:calc(var(--ui-header-height) + 24px); }
body { background:var(--ui-canvas); color:var(--ui-ink); font:400 16px/1.5 var(--ui-font); }
body:has(>.app-header),body:has(.remain-page),body:has(#admin-app:not([hidden])) { padding-left:var(--ui-sidebar-width); padding-top:var(--ui-header-height); }
body .app-header { display:block; position:fixed; inset:0 auto 0 0; z-index:45; width:var(--ui-sidebar-width); max-width:none; height:100vh; height:100dvh; margin:0; padding:0; border:0; border-right:1px solid var(--ui-line-soft); border-radius:0; background:var(--ui-soft); color:var(--ui-ink); }
.app-header-inner { display:flex; flex-direction:column; align-items:stretch; gap:20px; width:100%; height:100%; min-height:0; margin:0; padding:16px 12px; }
.app-sidebar-heading { display:flex; align-items:center; gap:8px; min-height:40px; }
.app-brand { display:inline-flex; flex:1; align-items:center; min-width:0; line-height:1; }
.app-brand img { display:block; width:150px; max-width:100%; height:auto; }
body .app-sidebar-toggle { display:inline-flex; flex:0 0 40px; align-items:center; justify-content:center; width:40px; height:40px; min-height:40px; padding:10px; border:0; border-radius:8px; background:transparent; color:var(--ui-ink); box-shadow:none; cursor:pointer; }
body .app-sidebar-toggle:hover,body .app-sidebar-toggle:focus-visible { background:var(--ui-line-soft); }
body .app-sidebar-toggle:focus-visible { outline-offset:-2px; }
.app-sidebar-toggle svg { display:block; flex-shrink:0; width:20px; height:20px; }
.app-sidebar-panel { display:flex; flex:1; flex-direction:column; gap:24px; min-height:0; overflow-y:auto; padding-bottom:8px; }
body .app-nav { display:flex; flex-direction:column; flex-wrap:nowrap; align-items:stretch; justify-content:flex-start; gap:4px; margin:0; padding:0; border:0; }
.app-nav a { display:inline-flex; flex:0 0 auto; align-items:center; gap:12px; min-height:48px; padding:12px 16px; border-radius:8px; color:var(--ui-ink); font-size:14px; font-weight:500; white-space:nowrap; text-decoration:none; }
.app-nav-icon { display:block; flex:0 0 20px; width:20px; height:20px; }
.app-nav a:hover { background:var(--ui-line-soft); }
.app-nav a[aria-current="page"] { background:#e8e8e8; }
.app-account { display:flex; flex-direction:column; align-items:stretch; gap:8px; min-width:0; width:100%; margin-top:auto; }
.app-account-name { padding:0 16px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--ui-muted); font-size:13px; }
body .app-account .ui-button { justify-content:flex-start; gap:12px; width:100%; min-height:48px; padding:12px 16px; border-radius:8px; font:500 14px/20px var(--ui-font); color:var(--ui-ink); background:transparent; border:1px solid transparent; }
body .app-account .ui-button:hover { background:var(--ui-line-soft); border-color:transparent; }
:root[data-sidebar="collapsed"] { --ui-sidebar-width:0px; --ui-header-height:64px; }
body .app-header[data-collapsed="true"] { width:64px; height:64px; border:0; background:white; }
.app-header[data-collapsed="true"] .app-header-inner { padding:12px; }
.app-header[data-collapsed="true"] .app-brand { display:none; }
body .app-sidebar-backdrop { position:fixed; inset:0 0 0 min(280px,calc(100vw - 56px)); z-index:44; width:auto; height:100%; margin:0; padding:0; border:0; border-radius:0; background:rgb(0 0 0 / 50%); cursor:pointer; }
body.site-menu-open { overflow:hidden; }
@media screen and (min-width:640px) and (max-width:1023px) {
  :root:not([data-sidebar="collapsed"]) { --ui-sidebar-width:208px; }
}
@media screen and (max-width:639px) {
  :root { --ui-sidebar-width:0px; --ui-header-height:64px; }
  body .app-header:not([data-collapsed="true"]) { width:min(280px,calc(100vw - 56px)); }
}
.app-skip { position:fixed; top:-80px; left:16px; z-index:100; padding:12px 20px; background:var(--ui-ink); color:white; border-radius:8px; }
.app-skip:focus { top:12px; }
.app-subnav { border-bottom:1px solid var(--ui-line-soft); background:white; }
.app-subnav-inner { display:flex; align-items:center; gap:24px; width:min(var(--ui-content),calc(100% - 2 * var(--ui-gutter))); margin:auto; min-height:56px; }
.app-subnav .primary-nav { flex:1; min-height:56px; gap:24px; }
.app-subnav .primary-nav a { padding:0; color:var(--ui-muted); font:500 14px/1.5 var(--ui-font); }
.app-subnav .primary-nav a.is-active { color:var(--ui-ink); }
.app-subnav .primary-nav a::after { left:0; right:0; background:var(--ui-ink); }
.app-subnav .global-search-link { color:var(--ui-ink); font-size:14px; font-weight:500; }
/* Scoped type scale, excluding original document bodies. */
body :is(.assistant-heading h1,.page-heading h1,.selected-hero h1,.home-intro h1,.editorial-page-header h1,.index-wrap>h1,.source-document>h1,.auth-card h1,.auth-card [data-slot="card-title"],.workspace-title) { font:600 28px/1.43 var(--ui-font); letter-spacing:-.4px; color:var(--ui-ink); }
body :is(.section-heading h2,.panel-heading h2,.source-panel h2,.consultation-heading h2,.card-heading h2,.selected-related h2) { font-size:22px; font-weight:500; line-height:1.3; letter-spacing:-.3px; }
body :is(.selected-article-header h1,.manual-article>header h1) { font:600 28px/1.43 var(--ui-font); letter-spacing:-.4px; }
body :is(.eyebrow,.section-kicker,.section-label) { color:var(--ui-muted); font-size:12px; font-weight:500; letter-spacing:0; }
body :is(.page-heading>div>p:last-child,.selected-hero-copy>p:last-child,.editorial-page-header>p:last-child) { margin-top:12px; color:var(--ui-muted); font-size:14px; line-height:1.5; }
/* Buttons and fields. */
body :is(.primary-button,.secondary-button,.ghost-button,.text-button,.solid-button,.print-button,.section-download,.guide-filter>button,.selected-topic-filter>button,.search-field button,.index-actions>a,.index-actions>button) { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:48px; padding:12px 24px; border:1px solid var(--ui-line-strong); border-radius:8px; font:500 16px/1.25 var(--ui-font); color:var(--ui-ink); background:white; text-decoration:none; box-shadow:none; }
body :is(.primary-button,.solid-button,.guide-filter>button,.selected-topic-filter>button,.search-field button) { color:white; background:var(--ui-primary); border-color:var(--ui-primary); }
body :is(.primary-button,.solid-button,.guide-filter>button,.selected-topic-filter>button,.search-field button):hover { background:var(--ui-primary-hover); border-color:var(--ui-primary-hover); }
body :is(.secondary-button,.ghost-button,.text-button,.print-button,.section-download):hover { background:var(--ui-soft); border-color:var(--ui-ink); }
body :is(.primary-button,.secondary-button,.ghost-button,.text-button):disabled { color:var(--ui-muted-soft); background:var(--ui-soft); border-color:var(--ui-line); opacity:1; }
body .primary-button:disabled { background:var(--ui-primary-disabled); color:var(--ui-ink); border-color:var(--ui-primary-disabled); }
body :is(.login-card input,#staff-auth-form input,.guide-filter input,.guide-filter select,.selected-topic-filter input,.selected-topic-filter select,#search,.search-box input,#document-title,#block-format) { min-height:56px; padding:14px 12px; border:1px solid var(--ui-line-strong); border-radius:8px; font:400 16px/1.5 var(--ui-font); color:var(--ui-ink); background:white; box-shadow:none; }
body :is(.icon-button,.manual-icon-button) { min-width:48px; min-height:48px; border-radius:50%; }
body :is(button,input,select,textarea,a):focus-visible { outline:2px solid var(--ui-ink); outline-offset:3px; }
body.home-page .search-form input:focus,
body.knowledge-page .search-field input:focus,
body.knowledge-page .search-field:focus-within { outline:none; }
/* Shared page grid. */
body .portal-shell,body .dashboard,body.patients-page>.page-shell { width:min(var(--ui-content),calc(100% - 2 * var(--ui-gutter))); margin:auto; padding:48px 0 64px; }
body .assistant-shell { margin-top:0; }
body .assistant-heading h1 { margin-bottom:24px; }
/* Home and knowledge use the same search control. */
body .app-search { display:flex; flex-wrap:nowrap; align-items:center; width:min(680px,100%); height:64px; min-height:64px; padding:7px; gap:8px; border:1px solid var(--ui-line); border-radius:var(--ui-pill-radius); background:white; box-shadow:var(--ui-shadow); }
body .app-search input { flex:1; min-width:0; width:100%; height:48px; min-height:48px; padding:0 16px; border:0; border-radius:24px; background:transparent; color:var(--ui-ink); font:400 16px/1.5 var(--ui-font); }
body .app-search .search-submit { display:inline-flex; align-items:center; justify-content:center; flex:0 0 48px; width:48px; min-width:48px; height:48px; min-height:48px; padding:0; border:1px solid var(--ui-primary); border-radius:50%; background:var(--ui-primary); color:white; box-shadow:none; }
body .app-search .search-submit:hover { background:var(--ui-primary-hover); border-color:var(--ui-primary-hover); }
body .app-search .search-submit svg { display:block; flex:none; width:24px; height:24px; margin:0; fill:none; stroke:currentColor; stroke-width:2; }
/* The empty home is a centered prompt; answers and authentication use normal document flow. */
body.home-page:has(>.app-header) { padding-top:0; }
body.home-page .portal-shell { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:24px; width:100%; min-height:100vh; min-height:100dvh; margin:0; padding:32px 24px; }
body.home-page .assistant-shell { width:min(680px,100%); margin:0; }
body.home-page .assistant-heading h1 { margin:0 0 28px; font-size:32px; font-weight:500; line-height:1.4; letter-spacing:-.7px; text-align:center; word-break:keep-all; text-wrap:balance; }
body.home-page .search-form { width:100%; margin:0; }
body.home-page #staff-auth-panel { width:min(680px,100%); margin:0; }
body.home-page:has(#chatbot-result:not([hidden]),#staff-auth-panel:not([hidden])) { padding-top:var(--ui-header-height); }
body.home-page:has(#chatbot-result:not([hidden]),#staff-auth-panel:not([hidden])) .portal-shell { min-height:calc(100dvh - var(--ui-header-height)); justify-content:flex-start; padding-top:64px; }
@media(max-width:639px) {
  body.home-page .portal-shell { padding:24px 16px; }
  body.home-page .assistant-heading h1 { margin-bottom:24px; font-size:26px; }
  body .app-search input { padding-inline:12px; font-size:15px; }
}
body .page-heading { margin-bottom:32px; }
body .dashboard :is(.summary-grid,.content-grid,.consultation-summary) { gap:16px; }
body .dashboard .panel { margin-bottom:16px; }
body .dashboard .content-grid .panel { margin-bottom:0; }
body :is(.summary-card,.panel,.kpi-card,.dashboard-card) { border:1px solid var(--ui-line); border-radius:14px; padding:24px; box-shadow:none; }
body .summary-card.primary { background:white; color:var(--ui-ink); border-color:var(--ui-line); }
body .summary-card.primary>span,body .summary-card.primary small { color:var(--ui-muted); }
body .summary-card.accent { padding-top:24px; border-top:1px solid var(--ui-line); }
body .warning-note { padding:16px; border:1px solid #ead9b9; border-radius:8px; color:var(--ui-warning); background:var(--ui-warning-soft); font-size:14px; line-height:1.5; }
body .quality-metrics span,body .treatment-group { background:var(--ui-soft); }
body .dashboard-layout { grid-template-columns:280px minmax(0,1fr); gap:24px; }
body.patients-page .patient-panel { top:calc(var(--ui-header-height) + 24px); }
/* Knowledge list/search/detail. */
body.knowledge-page { --content:var(--ui-content); }
body.knowledge-page .page-shell,body.knowledge-page .site-footer { width:min(var(--ui-content),calc(100% - 2 * var(--ui-gutter))); }
body :is(.home-intro,.selected-hero) { padding:48px max(var(--ui-gutter),calc((100% - var(--ui-content)) / 2)); background:white; color:var(--ui-ink); }
body :is(.area-entry-section,.situation-original-section,.featured-original-section) { padding-top:48px; }
body :is(.selected-search,.search-page-form) { width:min(680px,100%); max-width:680px; }
body :is(.area-entry-card,.situation-original-card,.featured-original-card,.tool-card) { border-radius:14px; padding:24px; border-color:var(--ui-line); background:white; box-shadow:none; }
body :is(.area-entry-card,.situation-original-card,.featured-original-card):hover { box-shadow:var(--ui-shadow); border-color:var(--ui-line-strong); transform:none; }
body :is(.selected-filter-chips button,.section-nav a) { min-height:48px; display:inline-flex; align-items:center; padding:12px 20px; border:1px solid var(--ui-line); border-radius:var(--ui-pill-radius); font-size:14px; font-weight:500; }
body .selected-filter-chips button.is-active { background:var(--ui-ink); color:white; border-color:var(--ui-ink); }
body .selected-original-toc { top:calc(var(--ui-header-height) + 24px); }
body .selected-original-toc a { font-size:14px; }
body .source-original-block { scroll-margin-top:calc(var(--ui-header-height) + 24px); }
body .manual-use-note { background:var(--ui-soft); border-color:var(--ui-line); color:var(--ui-body); }
body .manual-use-note>span { color:var(--ui-ink); }
body .article-pagination a { min-width:0; overflow-wrap:anywhere; }
/* Archive and document provenance. */
body .index-wrap { width:min(var(--ui-content),calc(100% - 2 * var(--ui-gutter))); margin:0 auto; padding:48px 0 64px; border:0; border-radius:0; }
body .index-actions { position:static; display:flex; justify-content:flex-end; margin:0 0 24px; }
body .index-actions a { min-height:48px; padding:12px 16px; font-size:14px; }
body .index-wrap>p { color:var(--ui-muted); font-size:14px; }
body #search { width:100%; border-radius:var(--ui-pill-radius); padding-inline:24px; }
body .archive-header,body .archive-content { width:min(var(--ui-reading),calc(100% - 2 * var(--ui-gutter))); margin:0 auto; padding:32px 0; border:0; border-radius:0; }
body .archive-header { border-bottom:1px solid var(--ui-line-soft); }
body .archive-header .archive-home-brand { display:none; }
body .archive-header .archive-admin-link { top:24px; right:0; min-height:48px; padding:12px 16px; border-radius:8px; color:var(--ui-ink); background:white; border:1px solid var(--ui-line); font-size:14px; }
body .archive-path { padding-right:120px; color:var(--ui-ink); font-size:22px; font-weight:500; }
body .archive-content { overflow-wrap:anywhere; }
body .archive-content :is(.ck-content,.markdown-body) { color:var(--ui-body); line-height:1.75; }
body .source-document { width:min(var(--ui-reading),calc(100% - 2 * var(--ui-gutter))); max-width:none; margin:0 auto 64px; padding:48px 0 0; border:0; border-radius:0; }
body .source-context { display:flex; align-items:center; gap:16px; width:min(var(--ui-reading),calc(100% - 2 * var(--ui-gutter))); margin:24px auto 0; color:var(--ui-muted); font-size:14px; }
body .source-document :is(.pending,.approved) { padding:16px; border-radius:8px; font-size:14px; line-height:1.5; }
body .source-document .pending { color:var(--ui-warning); background:var(--ui-warning-soft); border:1px solid #ead9b9; }
body .source-document .approved { color:var(--ui-success); background:var(--ui-success-soft); border:1px solid #c9e2c9; }
body .source-document h2 { font-size:22px; line-height:1.3; font-weight:500; }
/* Authentication. */
body :is(.login-shell,.login-view,.login-page) { min-height:100vh; min-height:100dvh; display:grid; place-items:center; padding:32px 16px; background:white; }
body .auth-card { width:min(440px,100%); max-width:440px; margin:0; padding:32px; border:1px solid var(--ui-line); border-radius:14px; background:white; box-shadow:none; }
body .auth-card :is(.brand-logo,.login-brand-logo) { display:block; width:176px; height:auto; margin:0 0 32px; }
body .auth-card h1 { margin:0 0 24px; }
body .auth-card :is(label,[data-slot="label"]) { font-size:14px; font-weight:500; line-height:1.5; color:var(--ui-ink); }
body .auth-card label { display:grid; gap:8px; margin-bottom:24px; }
body .auth-card input { width:100%; min-height:56px; }
body .auth-card button[type="submit"] { width:100%; min-height:48px; padding:12px 24px; font:500 16px/1.25 var(--ui-font); }
body .auth-card .login-copy { margin:-8px 0 24px; font-size:14px; color:var(--ui-muted); }
body .auth-card [data-slot="card-header"],body .auth-card [data-slot="card-content"] { padding:0; }
body .auth-card [data-slot="card-header"] { gap:0; }
body .auth-card [data-slot="card-title"] { margin:0 0 24px; }
body .auth-card [data-slot="label"] { margin-bottom:0; }
body .auth-card [data-slot="card-description"] { margin:-8px 0 24px; font-size:14px; }
/* Editor / React app. */
body .editor-statusbar { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:16px; padding:16px var(--ui-gutter); border-bottom:1px solid var(--ui-line-soft); }
body .editor-statusbar h1 { margin:0; font-size:22px; font-weight:500; line-height:1.3; }
body .editor-statusbar>div { display:flex; align-items:center; gap:16px; }
body .admin-app>.workspace { grid-template-columns:260px minmax(0,1fr) 240px; min-height:calc(100vh - 160px); }
body .admin-app :is(.page-sidebar,.history-sidebar) { top:var(--ui-header-height); height:calc(100vh - var(--ui-header-height)); background:var(--ui-soft); }
body .admin-app .search-box { min-width:0; }
body .admin-app .search-box input { width:100%; min-width:0; }
body .admin-app .toolbar { gap:8px; }
body .admin-app .editor-workspace { min-width:0; }
body .admin-app .preview-dialog { border-radius:14px; border:1px solid var(--ui-line); box-shadow:var(--ui-shadow); }
@media(max-width:1100px) {
  body .admin-app>.workspace { grid-template-columns:240px minmax(0,1fr); }
  body .admin-app .history-sidebar { position:static; grid-column:1/-1; height:auto; border-top:1px solid var(--ui-line); }
  body .dashboard-layout { grid-template-columns:240px minmax(0,1fr); }
}
@media(max-width:760px) {
  .app-subnav-inner { min-width:0; gap:16px; overflow-x:auto; }
  .app-subnav .primary-nav { gap:20px; }
  .app-subnav .primary-nav a,.app-subnav .global-search-link { white-space:nowrap; }
  body .portal-shell,body .dashboard,body.patients-page>.page-shell { padding:32px 0 48px; }
  body :is(.home-intro,.selected-hero) { padding:32px var(--ui-gutter); }
  body :is(.summary-card,.panel,.kpi-card,.dashboard-card,.area-entry-card,.tool-card) { padding:20px; }
  body .page-heading { align-items:flex-start; flex-direction:column; gap:24px; }
  body .dashboard-layout { grid-template-columns:minmax(0,1fr); }
  body.patients-page .patient-panel { position:static; }
  body .source-document { padding-top:32px; }
  body .index-wrap { padding:32px 0 48px; }
  body .archive-header,body .archive-content { padding:24px 0; }
  body .archive-path { font-size:20px; }
  body .auth-card { padding:24px; }
  body .admin-app>.workspace { grid-template-columns:minmax(0,1fr); }
  body .admin-app :is(.page-sidebar,.history-sidebar) { position:static; height:auto; max-height:none; border:0; border-bottom:1px solid var(--ui-line); }
  body .admin-app .page-list { max-height:240px; overflow-y:auto; }
  body .admin-app .editor-heading,body .admin-app .publish-actions { flex-wrap:wrap; }
  body .admin-app .visual-editor,body .admin-app .html-editor { padding:20px; }
  body .editor-statusbar { padding:16px; }
  body .editor-statusbar>div { flex-wrap:wrap; }
}
@media print {
  body { padding:0!important; }
  body .app-sidebar-backdrop { display:none!important; }
  body .app-header,.app-subnav,.app-skip,.editor-statusbar,.source-context { display:none!important; }
  body .archive-content,body .source-document { width:100%; max-width:none; margin:0; padding:0; }
}
body .app-subnav .primary-nav { order:0; width:auto; overflow:visible; flex:1 0 auto; }
body .app-subnav .primary-nav a { flex:0 0 auto; }
body .app-subnav-inner { overflow-y:hidden; scrollbar-width:none; }
body .patient-demo-note { width:min(var(--ui-content),calc(100% - 2 * var(--ui-gutter))); margin:24px auto -24px; color:var(--ui-muted); font-size:13px; }
@media(max-width:760px) {
  body .app-subnav .global-search-link { flex-shrink:0; margin-left:auto; }
  body .app-subnav .primary-nav { min-height:56px; }
  body .patients-page .print-button { width:auto; }
  body .selected-filter-chips { display:flex; flex-wrap:wrap; gap:8px; }
  body .selected-filter-chips button { width:auto; padding:12px 16px; }
}
body .admin-app .search-box { display:flex; align-items:center; gap:8px; min-height:56px; padding:0 12px; border:1px solid var(--ui-line-strong); border-radius:var(--ui-pill-radius); background:white; }
body .admin-app .search-box input { border:0; min-height:54px; padding:12px 0; background:transparent; }
body .admin-app .toolbar button { min-width:40px; min-height:40px; border-radius:8px; font:500 14px/1.25 var(--ui-font); }
body .editor-tabs [role="tab"] { min-height:48px; font:500 14px/1.25 var(--ui-font); }
/* Portal-rendered dialogs use the same surface, shadow, and input rules. */
[data-slot="sheet-overlay"] { background:rgb(0 0 0 / 50%); backdrop-filter:none; }
[data-slot="sheet-content"] { background:white; box-shadow:var(--ui-shadow); }
[data-slot="select-content"] { background:white; border:1px solid var(--ui-line); border-radius:8px; box-shadow:var(--ui-shadow); }
[data-slot="select-item"] { min-height:40px; padding:10px 32px 10px 12px; font:400 14px/1.43 var(--ui-font); }
[data-slot="textarea"] { min-height:112px; }
body [data-slot="sheet-header"] { padding-right:72px; }
body .admin-app #page-search { border:0; border-radius:0; min-height:54px; padding:12px 0; background:transparent; box-shadow:none; }
body .admin-app .history-sidebar { display:block; }
body .admin-app #open-page { display:inline-flex; }
body .search-page-form { padding:24px 0; border:0; background:white; box-shadow:none; }
@media(max-width:760px) {
  body .admin-app .publish-actions { width:100%; }
  body .admin-app .publish-actions .status-badge { flex:0 0 100%; margin:0 0 8px; }
  body .admin-app .publish-actions button { flex:1; min-width:0; padding:12px; font-size:14px; }
}
