/* Adds a shared toolbar; module widths follow their roles, not their positions. */
.viewport-layout.module-layout { grid-template-rows:44px minmax(0,1fr); gap:8px 12px; }
.module-layout-toolbar { grid-column:1 / -1; grid-row:1; display:flex; align-items:center; gap:16px; min-width:0; }
.module-layout-toolbar button { min-height:44px; min-width:210px; padding:6px 18px; border:2px solid #245fa7; border-radius:9px; background:#fff; color:#164f91; font:inherit; font-size:17px; font-weight:700; cursor:pointer; }
.module-layout-toolbar button:hover { background:#edf5ff; }
.module-layout-toolbar button:focus-visible { outline:3px solid #d18a00; outline-offset:2px; }
.module-layout-toolbar button:disabled { cursor:default; opacity:.65; }
[data-layout-status] { font-size:16px; color:#25425e; line-height:1.3; }
.viewport-layout.module-layout > .layout-module { position:relative; display:grid; grid-template-rows:minmax(0,1fr); grid-row:2; min-width:0; min-height:0; overflow:hidden; overflow-anchor:none; border-radius:10px; }
.module-titlebar { cursor:grab; user-select:none; touch-action:none; }
.layout-handle-grip { display:inline-block; margin-left:8px; font-size:18px; line-height:1; }
.module-titlebar:active { cursor:grabbing; }
.layout-module.layout-drag-source { outline:2px solid #6792c3; outline-offset:-2px; }
.layout-module.layout-drop-target { outline:4px dashed #205fa9; outline-offset:-4px; }
.layout-module.layout-drop-target::after { content:'松开交换位置'; position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); padding:10px 20px; background:#174f91; color:#fff; font-size:20px; border-radius:10px; pointer-events:none; z-index:20; white-space:nowrap; }
.viewport-layout.module-layout .task-scroll, .viewport-layout.module-layout .experiment-help-panel { min-height:0; visibility:visible; pointer-events:auto; }
.viewport-layout.module-layout[data-module-order='help_task'] { grid-template-columns:400px minmax(0,1fr); }
@media (min-width:900px) and (min-height:600px) {
 .viewport-layout.module-layout[data-module-order='task_help'] { grid-template-columns:minmax(0,1fr) minmax(460px,42%); }
 .viewport-layout.module-layout[data-module-order='help_task'] { grid-template-columns:minmax(460px,42%) minmax(0,1fr); }
 /* Recover the toolbar's height from spacing, never by scaling text or hiding task content. */
 .viewport-layout.module-layout .main-wrap { padding:3px 0; }
 .viewport-layout.module-layout .page-content { padding:8px; gap:4px; }
 .viewport-layout.module-layout .info-box, .viewport-layout.module-layout .success-box,
 .viewport-layout.module-layout .warning-box, .viewport-layout.module-layout .danger-box { padding:4px 10px; }
 .viewport-layout.module-layout .patient-card, .viewport-layout.module-layout .receipt-card { padding:8px; }
 .viewport-layout.module-layout .key-button { min-height:44px; line-height:1.2; }
 .viewport-layout.module-layout .keypad { gap:4px; }
 .viewport-layout.module-layout [data-screen='patient-code'] .phone-notification { row-gap:2px; }
 .viewport-layout.module-layout .phone-notification { padding-top:6px; padding-bottom:6px; }
}
@media (min-width:900px) and (max-width:1179px) {
 .viewport-layout.module-layout[data-module-order='task_help'] { grid-template-columns:minmax(0,1fr) 46%; }
 .viewport-layout.module-layout[data-module-order='help_task'] { grid-template-columns:46% minmax(0,1fr); }
}
/* Both stacked regions remain reachable. Limited height uses region scrolling, not scaling. */
@media (max-width:899px) {
 .viewport-layout.hospital-shell.module-layout[data-module-order] { grid-template-columns:minmax(0,1fr); grid-template-rows:44px minmax(0,1fr) minmax(0,1fr); padding:8px; gap:8px; }
 .viewport-layout.module-layout > .layout-module { grid-column:1; grid-row:auto; }
 .viewport-layout.module-layout .header-inner, .viewport-layout.module-layout .experiment-help-heading { padding-right:0; }
 .viewport-layout.module-layout .experiment-help-heading { min-height:0; }
 .viewport-layout.module-layout .experiment-help-panel { display:block; overflow-y:auto; overflow-x:hidden; scrollbar-gutter:stable; overscroll-behavior:contain; }
 .viewport-layout.module-layout .experiment-help-body, .viewport-layout.module-layout .experiment-help-scroll.experiment-help-scroll { display:block; height:auto; max-height:none; overflow:visible; }
 .viewport-layout.module-layout .experiment-help-state, .viewport-layout.module-layout .experiment-help-scroll { margin-top:8px; }
 .viewport-layout.module-layout .experiment-help-footer { margin-top:8px; }
 .viewport-layout.module-layout .header-inner { padding-left:0; }
 .module-layout-toolbar { gap:8px; }
 .module-layout-toolbar button { min-width:190px; padding:6px 10px; font-size:16px; }
 [data-layout-status] { font-size:14px; }
}

/* Density-only revision: keep content, font sizes, DOM order and scroll access.
   A single result must not occupy half of the available reading width. */
.viewport-layout.module-layout [data-screen='home'] > .page-bar,
.viewport-layout.module-layout [data-screen='home'] .page-content > .eyebrow { display:none; }
.viewport-layout.module-layout [data-screen='home'] .page-content > h1 { grid-column:1 / -1; }
.viewport-layout.module-layout [data-screen='home'] .registration-type-button { min-height:76px; padding:8px 12px; }
.viewport-layout.module-layout .a-search-results > :only-child,
.viewport-layout.module-layout .a-search-results > :has([aria-expanded='true']) { grid-column:1 / -1; }
.viewport-layout.module-layout .a-search-result-card .status-chip { justify-self:start; min-height:0; padding:2px 8px; }
.viewport-layout.module-layout .a-search-result-detail > h3 { margin:0 0 4px; }
.viewport-layout.module-layout .a-search-result-detail > p { margin:4px 0; }
.viewport-layout.module-layout .a-search-result-detail > ul { margin:4px 0; padding-left:1.5em; }
.viewport-layout.module-layout .experiment-help-panel.experiment-help-panel { gap:4px; }
.viewport-layout.module-layout .experiment-help-body { gap:4px; }
.viewport-layout.module-layout .experiment-help-scroll > * + * { margin-top:4px; }
.viewport-layout.module-layout .b-chat-messages,
.viewport-layout.module-layout .c-scaffold-messages { gap:4px; }
.viewport-layout.module-layout .b-chat-message,
.viewport-layout.module-layout .c-scaffold-message { max-width:100%; padding:6px 10px; }
.viewport-layout.module-layout .c-problem-rewrite,
.viewport-layout.module-layout .c-standard-answer,
.viewport-layout.module-layout .c-waiting-outcome { margin-top:4px; padding:4px 8px; }
.viewport-layout.module-layout .experiment-help-footer.experiment-help-footer { padding-top:4px; }

@media (min-width:640px) and (min-height:600px) {
 .viewport-layout.module-layout .c-handoff-card { padding:8px; gap:6px; }
 .viewport-layout.module-layout .c-handoff-fields { grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px 12px; padding:6px 8px; }
 .viewport-layout.module-layout .c-handoff-fields > div { display:block; min-width:0; }
 .viewport-layout.module-layout .c-handoff-fields > div:last-child:nth-child(odd) { grid-column:1 / -1; }
 .viewport-layout.module-layout .c-handoff-fields dt,
 .viewport-layout.module-layout .c-handoff-fields dd { display:inline; margin:0; overflow-wrap:anywhere; }
 .viewport-layout.module-layout .c-handoff-fields dt::after { content:'：'; }
}

/* Preserve stacked modules at narrow widths; reduce wrapping caused by chrome.
   Overflow remains reachable when a short viewport or long history cannot fit. */
@media (max-width:899px) {
 .viewport-layout.module-layout .header-inner { flex-wrap:nowrap; gap:8px; min-height:52px; padding:4px 0; }
 .viewport-layout.module-layout .hospital-brand { flex:1 1 0; gap:8px; }
 .viewport-layout.module-layout .hospital-mark { width:36px; height:36px; flex:0 0 36px; }
 .viewport-layout.module-layout .header-home { flex:0 0 auto; min-height:44px; padding:6px 8px; }
 .viewport-layout.module-layout .simulation-notice { margin:4px auto; padding:6px 10px; }
 .viewport-layout.module-layout .progress-inner { min-height:0; padding:2px 0; gap:2px 10px; }
 .viewport-layout.module-layout .progress-current { display:inline; flex:1 1 180px; }
 .viewport-layout.module-layout .main-wrap { padding:3px 0; }
 .viewport-layout.module-layout .page-bar { min-height:44px; padding:4px 10px; }
 .viewport-layout.module-layout .page-content { padding:8px; gap:4px; }
 .viewport-layout.module-layout .footer-note { padding:4px 8px; }
 .viewport-layout.module-layout .experiment-help-panel.experiment-help-panel { padding:8px; }
 .viewport-layout.module-layout .experiment-help-heading.experiment-help-heading { gap:2px; }
 .viewport-layout.module-layout .experiment-help-state,
 .viewport-layout.module-layout .experiment-help-scroll { margin-top:4px; }
 .viewport-layout.module-layout .experiment-help-footer { margin-top:4px; }
}

/* Fit every department category, including the three-card oral/pediatric lists.
   The information and selection targets remain intact; only unused rows shrink. */
@media (min-width:640px) and (min-height:600px) {
 .viewport-layout.module-layout [data-screen='department'] .department-layout { gap:6px; }
 .viewport-layout.module-layout [data-screen='department'] .department-results { padding:0; }
 .viewport-layout.module-layout [data-screen='department'] .department-results .eyebrow { margin:0 0 4px; }
 .viewport-layout.module-layout [data-screen='department'] .department-results .selection-grid {
  grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr)); gap:8px;
 }
 .viewport-layout.module-layout [data-screen='department'] .selection-card {
  grid-template-columns:minmax(0,1fr) auto; align-items:center; min-height:64px; padding:8px; gap:4px 6px;
 }
 .viewport-layout.module-layout [data-screen='department'] .selection-card > strong { grid-column:1; grid-row:1; }
 .viewport-layout.module-layout [data-screen='department'] .selection-card > small { grid-column:1 / -1; grid-row:2; }
 .viewport-layout.module-layout [data-screen='department'] .selection-card > .status-chip {
  grid-column:2; grid-row:1; padding:2px 6px; min-height:0; white-space:nowrap;
 }
}
