/* Phone layout. Desktop styles remain in their existing modules. */
#mobile-navigation,#mobile-new-chat{display:none}
@media(max-width:800px){
  :root{--mobile-nav-height:64px;--mobile-safe-bottom:env(safe-area-inset-bottom,0px);font-size:16px}
  html,body{width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
  .app-shell{position:fixed;inset:0;height:var(--mobile-app-height,100dvh);min-height:0;max-width:100%}
  main{height:100%;min-height:0;padding-bottom:calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));overflow:hidden}
  header{height:calc(60px + env(safe-area-inset-top,0px));min-height:calc(60px + env(safe-area-inset-top,0px));padding:env(safe-area-inset-top,0px) 12px 0;gap:8px;flex:none}
  .page-heading{flex:1;min-width:0}
  #page-title{font-size:18px;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;letter-spacing:-.4px}
  .header-right{gap:4px;margin-left:0}
  .header-right :is(#workspace-save,#mode-badge,#balance-button){display:none}
  #mobile-new-chat{display:inline-grid}
  header :is(.icon,#mobile-new-chat),#menu{width:44px;height:44px;min-width:44px;padding:10px}
  #sidebar-collapse{display:none}
  #mobile-navigation{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:4px;position:fixed;z-index:50;bottom:0;left:0;right:0;height:calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));margin:0;padding:6px max(8px,env(safe-area-inset-right,0px)) var(--mobile-safe-bottom) max(8px,env(safe-area-inset-left,0px));border-top:1px solid var(--line);background:var(--panel)}
  #mobile-navigation button{min-width:0;min-height:48px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;border:0;background:transparent;color:var(--muted);padding:5px 2px;border-radius:12px;font-size:11px;line-height:1.2;font-weight:550}
  #mobile-navigation button.active{background:var(--green-dark);color:var(--accent)}
  #mobile-navigation .ui-icon{width:22px;height:22px}
  .mobile-keyboard-open #mobile-navigation{display:none}
  .mobile-keyboard-open main{padding-bottom:0}
  #sidebar{width:min(340px,calc(100vw - 32px));max-width:calc(100vw - 32px);height:var(--mobile-app-height,100dvh);padding:calc(12px + env(safe-area-inset-top,0px)) 16px max(16px,var(--mobile-safe-bottom));z-index:90;overscroll-behavior:contain}
  #sidebar-overlay{z-index:80;inset:0}
  #sidebar .sidebar-top{gap:8px}
  #sidebar .brand{margin:0 0 16px;font-size:23px}
  #sidebar .brand small{font-size:11px;white-space:normal}
  #close-sidebar{width:44px;height:44px;min-width:44px;align-self:flex-start}
  #sidebar :is(.nav,.new-chat){min-height:48px;font-size:15px;padding:11px 12px;margin:3px 0}
  #sidebar .nav-caption{font-size:11px;margin:20px 12px 8px}
  #sidebar .nav-tag{font-size:10px}
  #sidebar :is(#chat-search,.history-filters select){font-size:16px;min-height:44px}
  #sidebar :is(.chat-item,.history-chat-menu,.profile-button,.history-filters .icon){min-height:44px;font-size:14px}
  #sidebar .history-chat-menu{min-width:44px;font-size:22px}
  #sidebar .profile-button small,#sidebar .about-button{font-size:12px}
  #sidebar .chat-list{flex:1 0 110px}
  .notice{flex:none;margin:10px 14px 0;padding:9px 11px;font-size:12px;line-height:1.5}
  .page{min-width:0;min-height:0}
  .content-page{overflow-y:auto;overscroll-behavior:contain;padding:22px 16px 28px;-webkit-overflow-scrolling:touch}
  .content-page h2{font-size:27px;line-height:1.25}
  .content-page .lead{font-size:15px;line-height:1.65}
  .content-page button{min-height:44px;max-width:100%;font-size:14px}
  .content-page :is(input,select,textarea){font-size:16px;max-width:100%;min-width:0}
  .content-page :is(input:not([type=checkbox]):not([type=radio]),select){min-height:44px}
  .content-page :is(.small,.card>p){font-size:14px;line-height:1.65}
  .chat-page{overflow:hidden}
  .chat-toolbar{flex:none;padding:10px 14px 0;gap:8px;min-width:0}
  .chat-toolbar .experience-label{min-width:0;flex:1 1 0;width:0}
  .chat-toolbar .experience-label select{width:100%;min-width:0;min-height:44px;font-size:15px;max-width:100%;padding:9px 25px 9px 10px}
  #experience-description{display:none}
  #chat-options{width:44px;min-width:44px;height:44px;flex:0 0 44px;margin-left:0}
  #assistant-switch{min-height:44px;font-size:14px}
  .messages{min-height:0;padding:14px 16px;overscroll-behavior:contain;scroll-padding-bottom:16px}
  .welcome{margin:16px auto 14px;max-width:440px}
  .welcome-orbit{display:none}
  .welcome-kicker{font-size:10px;line-height:1.5;letter-spacing:1.4px}
  .welcome h2,.welcome h2 span{font-size:29px;line-height:1.2;letter-spacing:-1px}
  .welcome h2{margin:12px 0}
  .welcome>p{font-size:14px;line-height:1.6}
  .prompt-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:9px;margin-top:20px}
  .prompt-grid button{min-height:76px;padding:12px;border-radius:13px;display:flex;align-items:center;gap:9px;transform:none}
  .prompt-grid .prompt-icon{height:30px;width:30px;min-width:30px;margin:0;float:none}
  .prompt-grid strong{white-space:normal;font-size:13px;line-height:1.45}
  .prompt-grid small{display:none}
  .composer-wrap{flex:none;padding:4px 12px 8px;max-width:100%;min-width:0}
  .composer-context-bar{gap:6px;margin:0}
  .composer-context-bar :is(.scope-line,.context-review-button){font-size:12px;min-height:36px;line-height:1.4;padding:7px 4px}
  .composer-context-bar .scope-line{max-width:50%}
  .context-review-button{max-width:50%;white-space:normal;text-align:right}
  .composer{border-radius:20px;padding:10px 8px 8px;min-width:0}
  .composer #prompt{font-size:16px;line-height:1.5;padding:4px 6px 8px;min-height:48px;max-height:min(160px,25dvh)}
  .composer-controls{flex-wrap:nowrap;gap:4px}
  .composer-controls :is(.icon,.tool-button,.attach-button,.send-button){display:inline-grid;place-items:center;min-width:44px;width:44px;height:44px;flex:0 0 44px;padding:10px}
  .composer-controls .tool-label,.composer-controls #research-toggle{display:none}
  .composer-controls .ui-icon{width:21px;height:21px}
  .composer-controls #dictate{min-width:44px;width:44px;flex:0 0 44px;padding:10px}
  .composer-controls .grow{min-width:0;flex:1}
  .composer-controls #send{padding:0;font-size:28px;border-radius:13px}
  .composer-controls #stop{min-height:44px;min-width:108px;padding:8px 12px;font-size:14px}
  .composer-controls:has(#stop:not([hidden])) :is(#composer-settings,#tools-menu,#dictate,#conversation-open){display:none}
  .composer-note{font-size:11px;line-height:1.4;margin:7px 0 0}
  .attachment-chips{gap:6px;max-height:80px;overflow:auto}
  .attachment-chip{min-height:36px;font-size:13px}
  .attachment-chip button{min-width:32px;min-height:32px}
  .bubble{margin:14px auto 25px;max-width:100%}
  .bubble .body{font-size:16px;line-height:1.75;min-width:0}
  .bubble .speaker{font-size:13px}
  .bubble.user .body{max-width:94%;padding:12px 15px}
  .bubble :is(.bubble-tools,.turn-actions){gap:4px 12px;flex-wrap:wrap}
  .bubble :is(.bubble-tools,.turn-actions) button{min-height:44px;font-size:13px;padding:8px 2px}
  .bubble pre{max-width:100%;overflow:auto;font-size:13px}
  :is(.markdown-table,.rich-table){max-width:100%;overflow:auto;overscroll-behavior-x:contain}
  :is(.markdown-table,.rich-table) :is(th,td){font-size:14px;line-height:1.6}
  .source-link{min-height:44px;font-size:13px;max-width:100%}
  .task-status{flex:none;font-size:13px;line-height:1.5;gap:8px}
  .action-bar{flex-wrap:wrap;font-size:14px;gap:8px}
  #modal,dialog#modal:has(.settings-hub),dialog#modal:has(.canvas-shell){width:100%;max-width:100%;max-height:calc(var(--mobile-app-height,100dvh) - 12px);margin:auto 0 0;inset:auto 0 0;padding:0;border-radius:22px 22px 0 0;overflow:auto;overscroll-behavior:contain}
  #modal>.row{position:sticky;top:0;z-index:3;margin:0!important;padding:14px 16px;background:var(--panel);border-bottom:1px solid var(--line);gap:12px;align-items:center}
  #modal-title{font-size:20px;line-height:1.35;min-width:0;overflow-wrap:anywhere}
  #modal #close-modal{flex:none;width:44px;min-width:44px;height:44px}
  #modal-body{padding:16px 16px max(24px,var(--mobile-safe-bottom));min-width:0}
  #modal-body :is(button,a.primary,a.secondary){min-height:44px;font-size:14px;line-height:1.5}
  #modal-body :is(input,select,textarea){font-size:16px;min-width:0;max-width:100%}
  #modal-body :is(input:not([type=checkbox]):not([type=radio]),select){min-height:46px}
  #modal-body textarea{line-height:1.6}
  #modal-body :is(label,.lead){font-size:14px;line-height:1.6}
  #modal-body :is(.small,.settings-hint,.context-description,.context-notice,.context-footnote){font-size:13px;line-height:1.65}
  #modal-body :is(.dialog-actions,.form-actions){display:flex;flex-wrap:wrap;gap:10px}
  #modal-body .settings-grid{grid-template-columns:1fr;gap:16px}
  .settings-hub{grid-template-columns:minmax(0,1fr);gap:20px;min-height:0}
  .settings-tabs{flex-direction:row;overflow-x:auto;min-width:0;padding:0 0 10px;border:0;border-bottom:1px solid var(--line);gap:5px}
  .settings-tab{flex:none;font-size:14px;min-height:44px;white-space:nowrap;padding:9px 12px}
  .settings-title{font-size:24px}
  .settings-description,.settings-panel .settings-note p{font-size:14px!important}
  .preference-grid{grid-template-columns:1fr}
  .settings-panel .form-stack>button{align-self:stretch}
  .menu-action{padding:14px;min-height:64px;gap:12px}
  .menu-action strong{font-size:15px;line-height:1.45}
  .menu-action small,.profile-popover .menu-action small{font-size:13px;line-height:1.55}
  .tool-template-grid,.template-library .tool-template-grid{grid-template-columns:1fr}
  .profile-popover{max-height:calc(var(--mobile-app-height,100dvh) - 24px);z-index:100}
  .canvas-document-bar,.canvas-library-head{flex-wrap:wrap}
  .canvas-document-bar input{flex-basis:100%}
  .canvas-toolbar{gap:6px}
  .canvas-editor,.canvas-preview{min-height:220px;height:42dvh;padding:16px;font-size:16px}
  .canvas-preview-open .canvas-panels{grid-template-columns:minmax(0,1fr)}
  .canvas-preview{border-left:0;border-top:1px solid var(--line)}
  .canvas-footer{font-size:12px;flex-wrap:wrap;gap:6px}
  .canvas-card-actions{flex-wrap:wrap}
  .detail-pane{position:fixed;z-index:70;inset:auto 0 0;width:100%;max-width:100%;height:min(90dvh,var(--mobile-app-height,100dvh));border-radius:22px 22px 0 0;padding:20px 16px max(24px,var(--mobile-safe-bottom));overflow:auto}
  #toast{bottom:calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 12px);max-width:calc(100% - 28px);font-size:14px}
  .mobile-keyboard-open #toast{bottom:12px}
  .context-actions{grid-template-columns:1fr}
}
@media(max-width:359px){
  header{padding-left:8px;padding-right:8px;gap:4px}
  #page-title{font-size:16px}
  .composer-wrap{padding-left:8px;padding-right:8px}
  .composer-controls{gap:1px}
  .composer-controls :is(.icon,.tool-button,.attach-button,.send-button){min-width:44px;width:44px;flex-basis:44px}
  .messages{padding-left:12px;padding-right:12px}
  .prompt-grid{gap:7px}
  .prompt-grid button{padding:10px 8px;gap:6px}
}
