/**
 * 响应式与输入方式增强
 * 只负责断点、触摸与系统偏好，避免覆盖桌面端组件定义。
 */

@media (max-width:1180px){
  .clinic-shell{
    display:block;
    height:auto;
    min-height:100dvh;
    overflow:visible;
    padding:12px;
  }

  .topbar{
    position:relative;
    grid-template-columns:minmax(240px,0.65fr) minmax(0,1.35fr);
    margin-bottom:12px;
  }

  .layout{
    grid-template-columns:minmax(248px,0.36fr) minmax(0,1fr);
    grid-template-rows:minmax(620px,calc(100dvh - 126px)) minmax(400px,auto);
    height:auto;
    overflow:visible;
  }

  .queue-panel,
  .encounter-panel{
    min-height:620px;
  }

  .review-panel{
    grid-column:1/-1;
    min-height:440px;
    height:auto;
  }

  .workflow-progress{
    grid-template-columns:repeat(7,minmax(104px,1fr));
    overflow-x:auto;
    padding-bottom:3px;
    scrollbar-width:thin;
  }
}

@media (max-width:1000px){
  .topbar{
    grid-template-columns:minmax(0,1fr);
    gap:10px;
  }

  .session-meta{
    grid-template-columns:minmax(148px,1fr) repeat(8,auto);
    justify-content:start;
  }

  .session-meta strong{
    grid-column:auto;
    align-self:center;
    justify-self:end;
    margin:0 0 0 auto;
  }
}

@media (max-width:860px){
  .clinic-shell{
    padding:10px 10px calc(82px + env(safe-area-inset-bottom));
  }

  .topbar{
    gap:10px;
    margin-bottom:10px;
    padding:12px 14px;
  }

  .session-meta{
    grid-template-columns:minmax(148px,1fr) repeat(5,auto);
  }

  .voice-status,
  .session-meta>span:not(.ai-status):not(.voice-status){
    display:none;
  }

  .layout{
    grid-template-columns:minmax(0,1fr);
    grid-template-rows:none;
    gap:0;
  }

  .queue-panel,
  .encounter-panel,
  .review-panel{
    grid-column:auto;
    min-height:calc(100dvh - 178px);
    height:auto;
  }

  .layout[data-mobile-panel="queue"] .encounter-panel,
  .layout[data-mobile-panel="queue"] .review-panel,
  .layout[data-mobile-panel="encounter"] .queue-panel,
  .layout[data-mobile-panel="encounter"] .review-panel,
  .layout[data-mobile-panel="review"] .queue-panel,
  .layout[data-mobile-panel="review"] .encounter-panel{
    display:none;
  }

  .layout[data-mobile-panel="queue"] .queue-panel,
  .layout[data-mobile-panel="encounter"] .encounter-panel,
  .layout[data-mobile-panel="review"] .review-panel{
    display:grid;
  }

  .encounter-panel{
    overflow:visible;
    scroll-padding-bottom:calc(84px + env(safe-area-inset-bottom));
  }

  /* Keep the patient summary compact on tablets. The base breakpoint stacks
     these controls, which otherwise consumes most of the visible viewport. */
  .patient-strip{
    align-items:flex-start;
    flex-direction:row;
  }

  .status-stack{
    align-items:center;
    flex-direction:row;
    justify-content:flex-end;
  }

  .status-stack .primary-btn,
  .status-stack .danger-btn,
  .status-stack .ghost-btn{
    min-height:44px;
  }

  .encounter-view,
  .workspace{
    height:auto;
  }

  .chat-card{
    min-height:0;
  }

  .chat-log{
    height:min(48dvh,520px);
    min-height:340px;
  }

  .queue-list{
    max-height:calc(100dvh - 360px);
    min-height:260px;
  }

  .review-box{
    max-height:46dvh;
  }

  .records-list{
    max-height:40dvh;
  }

  .workflow-progress{
    grid-template-columns:repeat(7,minmax(118px,1fr));
    overflow-x:auto;
    scroll-snap-type:x proximity;
    overscroll-behavior-inline:contain;
  }

  .workflow-step{
    scroll-snap-align:start;
  }

  .actions-card.tool-open,
  .actions-card.inline-open.tool-open{
    top:0;
    right:0;
    bottom:0;
    left:0;
    width:100vw;
    max-width:100vw;
    max-height:100dvh;
    border:0;
    border-radius:0;
  }

  .mobile-panel-nav{
    position:fixed;
    right:10px;
    bottom:max(10px,env(safe-area-inset-bottom));
    left:10px;
    z-index:55;
    display:flex;
    gap:6px;
    padding:7px;
    border:1px solid var(--glass-border);
    border-radius:999px;
    background:rgba(255,255,255,0.9);
    box-shadow:var(--shadow-modal);
    backdrop-filter:blur(20px) saturate(160%);
    -webkit-backdrop-filter:blur(20px) saturate(160%);
  }

  :where(button,input,textarea,select,[tabindex]):focus-visible{
    scroll-margin-bottom:92px;
  }

  .mobile-panel-nav button{
    flex:1 1 0;
    min-width:0;
    min-height:44px;
    border:0;
    border-radius:999px;
    background:transparent;
    color:var(--muted);
    font-weight:800;
  }

  .mobile-panel-nav button.active{
    background:var(--accent);
    color:var(--on-accent);
    box-shadow:var(--shadow-xs);
  }
}

@media (max-width:640px){
  .clinic-shell{
    padding:8px 8px calc(80px + env(safe-area-inset-bottom));
  }

  .topbar{
    min-height:0;
    padding:11px 12px;
    border-radius:14px;
  }

  .topbar h1{
    font-size:22px;
  }

  .welcome-text{
    display:none;
  }

  .session-meta{
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:7px;
  }

  .doctor-name-field,
  .ai-status{
    grid-column:1/-1;
  }

  .ai-status{
    max-width:none;
  }

  .voice-status,
  .session-meta>span:not(.ai-status):not(.voice-status){
    display:none;
  }

  .session-meta strong{
    grid-column:1/-1;
    justify-self:start;
    margin:0;
    font-size:15px;
  }

  .doctor-name-field input{
    width:100%;
  }

  .queue-panel,
  .encounter-panel,
  .review-panel{
    min-height:calc(100dvh - 196px);
    padding:8px;
    border-radius:14px;
  }

  .panel-head,
  .card-head,
  .pending-order-head,
  .record-toolbar,
  .section-title{
    flex-direction:row;
    align-items:center;
    flex-wrap:wrap;
  }

  .toolbar-actions{
    width:auto;
    flex:1 1 auto;
    justify-content:flex-end;
    flex-wrap:wrap;
  }

  .patient-strip{
    flex-direction:column;
    align-items:stretch;
    gap:10px;
    padding:12px;
  }

  #patientMeta{
    -webkit-line-clamp:3;
  }

  .status-stack{
    display:flex;
    flex-direction:row;
    width:100%;
    justify-content:flex-start;
  }

  .status-stack button{
    flex:1 1 92px;
  }

  .status-stack .primary-btn,
  .status-stack .danger-btn,
  .status-stack .ghost-btn{
    min-height:44px;
  }

  .workflow-progress{
    margin-inline:0;
    grid-template-columns:repeat(7,minmax(112px,1fr));
  }

  .tool-launcher{
    display:grid;
    grid-template-columns:none;
    grid-auto-flow:column;
    grid-auto-columns:minmax(76px,1fr);
    overflow-x:auto;
    padding-bottom:2px;
    scroll-snap-type:x proximity;
  }

  .tool-launch{
    min-height:44px;
    scroll-snap-align:start;
  }

  .chat-card{
    grid-template-rows:auto minmax(320px,50dvh) auto auto auto auto;
  }

  .chat-log{
    height:auto;
    min-height:320px;
    max-height:50dvh;
  }

  .message{
    max-width:94%;
  }

  .chat-form,
  .director-form{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .chat-form input,
  .director-form input{
    grid-column:1/-1;
  }

  .chat-form .voice-input-btn,
  .chat-form .primary-btn{
    width:100%;
  }

  .quick-questions{
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .quick-questions button{
    min-height:44px;
  }

  .workflow-hint{
    align-items:flex-start;
  }

  .actions-card.tool-open .tool-card-head{
    padding:10px 12px;
  }

  .actions-card.tool-open .tabs{
    top:60px;
    grid-template-columns:repeat(5,minmax(70px,1fr));
    margin:7px 8px;
    overflow-x:auto;
  }

  .actions-card.tool-open .tab{
    font-size:12px;
    white-space:nowrap;
  }

  .actions-card.tool-open .tabs::before{
    display:none;
  }

  .actions-card.tool-open .tab.active{
    background:var(--accent-soft);
    color:var(--accent-dark);
    box-shadow:var(--shadow-xs);
  }

  .actions-card.tool-open .tab-view{
    padding:10px 12px calc(18px + env(safe-area-inset-bottom));
  }

  .catalog-grid,
  .actions-card.tool-open .catalog-grid{
    grid-template-columns:minmax(0,1fr);
  }

  .rx-table-wrap{
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
  }

  .rx-table{
    min-width:800px;
  }

  .pending-order-row{
    grid-template-columns:28px minmax(0,1fr) 44px;
  }

  .pending-order-row .order-priority,
  .pending-order-row .order-purpose,
  .pending-order-row .order-diagnosis{
    grid-column:2/4;
  }

  .exam-preview-panel{
    grid-template-columns:minmax(0,1fr);
  }

  .exam-preview-actions{
    justify-content:stretch;
  }

  .exam-preview-actions button{
    flex:1 1 140px;
  }

  .result-meta div{
    grid-template-columns:1fr;
  }

  .safety-panel{
    width:calc(100vw - 16px);
    max-height:calc(100dvh - 16px);
    border-radius:16px;
  }

  .safety-grid{
    grid-template-columns:minmax(0,1fr);
  }

  .safety-actions{
    align-items:stretch;
    flex-direction:column-reverse;
  }

  .safety-actions button{
    width:100%;
  }

  input[type="text"],
  input[type="search"],
  textarea,
  select{
    font-size:16px;
  }
}

@media (orientation:landscape) and (max-height:600px){
  .clinic-shell{
    height:auto;
    min-height:100dvh;
    overflow:visible;
  }

  .topbar{
    position:relative;
    padding:8px 12px;
  }

  .actions-card.tool-open,
  .actions-card.inline-open.tool-open{
    top:0;
    right:0;
    bottom:0;
    max-height:100dvh;
  }
}

@media (pointer:coarse){
  :where(
    .primary-btn,
    .ghost-btn,
    .warn-btn,
    .danger-btn,
    .voice-btn,
    .voice-input-btn,
    .quick-questions button,
    .tool-launch,
    .tab,
    .filter-chip,
    .common-order-chip,
    .order-grid button,
    .exam-grid button,
    .catalog-grid button,
    .rx-info-btn,
    .rx-group-toggle,
    .rx-remove,
    .medication-remove,
    .dose-multipliers button,
    .diagnosis-chip button,
    .suggestion-item,
    .workflow-step
  ){
    min-height:44px;
  }

  .icon-btn{
    width:44px;
    min-width:44px;
    height:44px;
    min-height:44px;
  }

  input,
  select{
    min-height:44px;
  }

  .queue-list,
  .chat-log,
  .rx-table-wrap,
  .suggestions,
  .tabs,
  .workflow-progress,
  .tool-launcher{
    -webkit-overflow-scrolling:touch;
  }
}

@media (prefers-contrast:more){
  button,
  input,
  textarea,
  select{
    border-width:2px;
  }

  .queue-item.active,
  .record-item.active,
  .tab.active{
    outline:2px solid currentColor;
    outline-offset:1px;
  }
}

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

  button:active,
  .queue-item:active,
  .record-item:active{
    transform:none!important;
  }
}

@media (prefers-color-scheme:dark) and (max-width:860px){
  .mobile-panel-nav{
    border-color:var(--glass-border);
    background:rgba(22,33,30,0.92);
  }
}

@media print{
  .mobile-panel-nav,
  .tool-backdrop,
  .safety-backdrop{
    display:none!important;
  }
}

/* Final mobile workspace contract. Keep the header and patient actions in
   stable rows so the conversation remains visible in the first viewport. */
@media (max-width:860px){
  .clinic-shell{
    padding:8px 8px calc(76px + env(safe-area-inset-bottom));
  }

  .topbar{
    position:relative;
    display:grid;
    grid-template-columns:minmax(0,1fr);
    align-items:stretch;
    gap:8px;
    min-height:0;
    margin-bottom:8px;
    padding:10px 12px;
    border-radius:12px;
  }

  .topbar-brand{
    align-items:center;
    gap:9px;
    min-width:0;
    padding-right:68px;
  }

  .topbar-brand-mark{
    width:38px;
    height:38px;
    flex:0 0 38px;
  }

  .topbar-brand .eyebrow{display:none;}

  .topbar h1{
    min-width:0;
    overflow:hidden;
    font-size:20px;
    line-height:1.2;
    text-overflow:ellipsis;
    white-space:nowrap;
  }

  .session-meta{
    display:flex;
    align-items:center;
    justify-content:flex-start;
    flex-wrap:wrap;
    gap:6px;
    width:100%;
    min-width:0;
    overflow:visible;
  }

  .session-meta>.ai-status{
    grid-column:auto;
    flex:1 1 104px;
    min-width:84px;
    max-width:170px;
    min-height:44px;
    padding-inline:10px;
    justify-content:flex-start;
    white-space:nowrap;
  }

  .session-meta>.educator-entry-btn,
  .session-meta>.assignment-context-btn,
  .session-meta>.icon-btn{
    flex:0 0 auto;
  }

  .session-meta>.educator-entry-btn,
  .session-meta>.assignment-context-btn{
    min-height:44px;
    padding-inline:11px;
    white-space:nowrap;
  }

  .session-meta>.icon-btn{
    width:44px;
    min-width:44px;
    height:44px;
    min-height:44px;
  }

  .session-meta>strong{
    position:absolute;
    top:18px;
    right:13px;
    display:block;
    margin:0;
    font-size:13px;
    font-variant-numeric:tabular-nums;
    line-height:1;
    white-space:nowrap;
  }

  .layout{gap:8px;}
  .encounter-panel{padding:6px;}
  .encounter-view{gap:7px;}

  .workflow-progress{
    grid-template-columns:repeat(7,minmax(106px,1fr));
    gap:6px;
    margin-inline:0;
    padding:0 3px 3px;
    scroll-padding-inline:3px;
  }

  .workflow-step{
    min-width:106px;
    min-height:48px;
    padding:6px 7px;
  }
}

@media (max-width:640px){
  .session-meta>#shortcutsBtn{display:none!important;}

  .patient-strip{
    display:grid;
    grid-template-columns:minmax(0,1fr);
    align-items:start;
    gap:10px;
    padding:10px 12px;
  }

  .patient-name-row{align-items:center;gap:7px;}
  .patient-name-row h2{font-size:22px;}
  .patient-facts{gap:5px;}
  #patientMeta{margin-top:5px;font-size:13px;}

  .patient-strip .status-stack{
    display:flex;
    align-items:center;
    justify-content:flex-start;
    flex-direction:row;
    flex-wrap:wrap;
    gap:6px;
    width:100%;
  }

  .patient-strip .status-stack>.pill{
    flex:0 0 auto;
    min-height:34px;
  }

  .status-stack button{flex:0 0 auto;}
  #finishVisitBtn{flex:1 1 76px;min-width:76px;padding-inline:10px;}
  #topSummonBtn:not(.hidden){flex:1 1 170px;}
  #topReturnWithResultsBtn:not(.hidden){order:4;flex:1 0 100%;}

  .chat-card>.card-head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    flex-direction:row;
    gap:8px;
  }

  .chat-card>.card-head .toolbar-actions{width:auto;flex:0 0 auto;}
  .chat-log{min-height:300px;max-height:52dvh;}

  .chat-form{
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:8px;
  }

  .chat-form input{grid-column:1/-1;}

  .quick-questions{
    display:flex;
    grid-template-columns:none;
    gap:7px;
    overflow-x:auto;
    padding:0 12px 10px;
    scroll-padding-inline:12px;
    scrollbar-width:none;
  }

  .quick-questions::-webkit-scrollbar{display:none;}

  .quick-questions button{
    flex:0 0 auto;
    min-width:86px;
    padding-inline:12px;
  }
}

@media (max-width:360px){
  .topbar h1{font-size:18px;}
  .topbar-brand{padding-right:60px;}
  .session-meta>.ai-status{min-width:78px;}
  .patient-strip{padding-inline:10px;}
  .workflow-progress{grid-template-columns:repeat(7,minmax(100px,1fr));}
  .workflow-step{min-width:100px;}
}
