/* CR-2026-11-25-0103: fixed app shell on desktop/tablet (>=768px). The shell is exactly the viewport
   (minus the "Powered by" strip); the sidebar and the top header never scroll away; only the active
   page scrolls, inside its own box. html/body never scroll, so the old sticky sidebar/header (broken by
   the root overflow-x rule) is no longer needed. Visitors/Chats keep their inner scrollers (list,
   messages) with the composer pinned at the bottom. Phones (<768px) keep the drawer/bottom-nav layout. */
@media (min-width:768px){
  html:has(#app-shell:not(.hidden)),
  body:has(#app-shell:not(.hidden)){height:100%;overflow:hidden;overscroll-behavior:none}
  body:has(#app-shell:not(.hidden)){padding-bottom:0}
  body:has(#app-shell:not(.hidden)) #app-shell{height:calc(100dvh - var(--app-strip-h) - env(safe-area-inset-bottom));min-height:0;overflow:hidden;grid-template-rows:minmax(0,1fr)}
  /* Sidebar: full shell height; if its content is taller than the screen it scrolls on its own. */
  body:has(#app-shell:not(.hidden)) #app-shell>aside{position:relative;top:auto;height:100%;max-height:none;min-height:0;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}
  /* Main column: header (and the sound banner when shown) stay put; the active page fills the rest. */
  body:has(#app-shell:not(.hidden)) #app-shell>main{display:flex;flex-direction:column;height:100%;min-height:0;overflow:hidden}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header{position:relative;top:auto;flex:0 0 auto}
  body:has(#app-shell:not(.hidden)) #app-shell>main>.sound-unlock-banner{flex:0 0 auto}
  /* The header keeps one row on every page (status text changes must not change its height or move the page). */
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .status{flex-wrap:nowrap;min-width:0;flex:0 1 auto}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .status>*{flex:0 0 auto;white-space:nowrap}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .status>#realtime-state{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header :is(h1,.eyebrow,.header-site){white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
  /* The active page is the only scroller. Its right margin becomes padding so the scrollbar sits at the edge. */
  body:has(#app-shell:not(.hidden)) #app-shell>main>.page.active{flex:1 1 auto;height:auto;min-height:0;margin-top:0;margin-bottom:0;margin-right:0;padding-right:20px;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}
  /* Visitors/Chats: the page itself does not scroll; list and messages scroll inside and fill the height. */
  body:has(#app-shell:not(.hidden)) #app-shell>main>#inbox.active{overflow:hidden}
  /* Visitors list (board): the list scrolls inside its own box (position:relative also contains the visually
     hidden table labels, which otherwise escape every clip and scroll the whole page); open-chat tabs stay below. */
  body:has(#app-shell:not(.hidden)) #app-shell>main>#inbox.active.board-view:not(.docked){grid-template-rows:minmax(0,1fr) auto}
  body:has(#app-shell:not(.hidden)) #app-shell>main>#inbox.active.board-view:not(.docked)>.visitor-board{position:relative;min-height:0;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}
  /* Chats: the chat Actions open from the "More actions" button (as in the docked chat) instead of filling
     the chat header, so the message pane keeps the height and the composer stays at the bottom. */
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu{position:relative;display:block}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu:not(:has(.head-menu-items>*)){display:none}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu-toggle{display:inline-flex;align-items:center;justify-content:center;gap:6px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu-items{display:none;position:absolute;right:0;top:44px;z-index:40;flex-direction:column;gap:2px;min-width:250px;max-height:min(70vh,520px);overflow-y:auto;padding:6px;background:#fff;border:1px solid #e2e8f0;border-radius:12px;box-shadow:0 18px 40px rgba(15,22,41,.16)}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu.open .head-menu-items{display:flex}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu-items button{width:100%;min-height:38px;text-align:left}
  /* The toggle keeps its width and shows its label (it was squeezed to an empty 22px box). */
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu{flex:0 0 auto}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu-toggle{width:auto;min-width:0;height:40px;padding:0 12px;border:1px solid var(--vb-violet);border-radius:10px;background:var(--vb-violet-50);color:var(--vb-violet);font-weight:600;white-space:nowrap}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .agent-head .head-menu-toggle .dk-actions-label{display:inline}
  /* Chats contact strip: the "Notes, tags & visitor path" button became the first child, so the Contact title lost
     its column and overlapped the Name field. Explicit areas: button, title and save state on one row, fields below. */
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor{grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"profile title save" "fields fields fields";align-items:center;gap:6px 12px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.dk-open-profile{grid-area:profile;white-space:nowrap}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>div:has(>#contact-editor-title){grid-area:title;display:flex;align-items:baseline;gap:8px;min-width:0}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>div:has(>#contact-editor-title) p{margin:0;font-size:12px;color:var(--signal-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid{grid-area:fields}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-save-state{grid-area:save}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>:is(.contact-selector,.contact-resolution,.contact-retry){grid-column:1/-1}
  /* History: the legacy fixed height of the History grid (100vh - 290px) is dropped, so the grid is as tall as
     its list; the page scrolls and the open transcript can stick beside the list. */
  body:has(#app-shell:not(.hidden)) #conversations .history-layout{height:auto}
  /* History/Leads: the open transcript / lead detail stays in view while the list scrolls. */
  body:has(#app-shell:not(.hidden)) #conversation-detail.history-transcript,
  body:has(#app-shell:not(.hidden)) #leads .hl-lead-detail{position:sticky;top:12px;max-height:calc(100dvh - var(--app-strip-h) - 180px);overflow:auto}
}
/* Leads with the detail open: the Page column moves out (the detail shows the page), so Name, Contact, Inquiry and
   Captured fit the narrower list instead of being clipped at the right edge. */
@media (min-width:901px){
  #leads.show-lead .hl-row.lead{grid-template-columns:minmax(110px,1fr) minmax(130px,1.2fr) minmax(0,1.6fr) 96px}
  #leads.show-lead .hl-row.lead>:nth-child(4){display:none}
}
@media (min-width:768px) and (max-width:1050px){
  body:has(#app-shell:not(.hidden)) #app-shell>main>.page.active{padding-right:12px}
}
/* Tablet and narrow desktop (768-1160px, incl. iPad landscape 1024): the one-row header does not fit (at 1024-1049 and
   again at 1101-1132 "Enable sound" ran into the theme toggle on Visitors, where the site name sits beside the title),
   so it becomes two fixed rows: logo, page title, theme,
   bell and avatar on top; presence, live-updates state, Available and Enable sound below (the live-updates text
   truncates, so a longer "Offline..." message never changes the header height). Header buttons are 44px touch targets. */
@media (min-width:768px) and (max-width:1160px){
  body:has(#app-shell:not(.hidden)) #app-shell>main>header{display:grid;grid-template-columns:auto minmax(0,1fr) auto auto;grid-template-areas:"logo title tools user" "status status status status";align-items:center;gap:6px 12px;min-height:0;padding:8px 16px}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-lockup{grid-area:logo}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-mark{display:none}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title{grid-area:title;margin-right:0}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-tools{grid-area:tools}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.user-menu{grid-area:user}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.status{grid-area:status;display:flex;flex-wrap:nowrap;align-items:center;gap:8px;min-width:0;margin:0;padding:0 0 0 2px;border:0;border-radius:0;background:transparent;box-shadow:none}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.status>#availability-toggle{margin-left:auto}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.status>button{min-height:44px;min-width:44px}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .hdr-icon,
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .user-menu-button{width:44px;height:44px;min-height:44px}
}
/* Sidebar footer (tablet / narrow desktop sidebar is 176px): the signed-in name and role stay on one line each and
   truncate, instead of breaking one word per line; up to 1100px Log out moves to its own row
   under the name so the name gets the full width. */
@media (min-width:768px){
  body:has(#app-shell:not(.hidden)) #app-shell>aside .account :is(strong,small){white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
}
@media (min-width:768px) and (max-width:1100px){
  body:has(#app-shell:not(.hidden)) #app-shell>aside .account>.logout{margin-left:44px}
  body:has(#app-shell:not(.hidden)) #app-shell>aside .account>div{flex:1 1 calc(100% - 44px)}
}
/* One-row desktop header (1161px+): the space is shared by priority, so the status buttons and the header tools never
   shrink into each other. The page title always stays whole; the eyebrow and the site name take the space left and
   truncate (contain:inline-size keeps their text out of the title's minimum width) but the site name keeps at least
   48px, then the live-updates text truncates. */
@media (min-width:1160.02px){
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title{flex:1 1 0;min-width:min-content;margin-right:0}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title :is(.eyebrow,.header-site){contain:inline-size}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title .header-site{flex:1 1 0;min-width:48px}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title .header-titleline{min-width:0}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.header-title h1{flex:0 0 auto;overflow:visible;text-overflow:clip}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.status{flex:0 1 auto}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>:is(.header-lockup,.header-tools,.user-menu){flex:0 0 auto}
}
/* One-row desktop header up to 1279px: header controls are 44px touch targets too (the header row is 63px tall). */
@media (min-width:1160.02px) and (max-width:1279.98px){
  body:has(#app-shell:not(.hidden)) #app-shell>main>header>.status>button{min-height:44px;min-width:44px}
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .hdr-icon,
  body:has(#app-shell:not(.hidden)) #app-shell>main>header .user-menu-button{width:44px;height:44px;min-height:44px}
}
@media (min-width:768px) and (max-width:1023.98px){
  /* Chats contact strip: the chat column is ~300-450px wide here, so title and save state share the first row, the
     "Notes, tags & visitor path" button gets its own row and the fields stay inside the panel (two equal columns). */
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor{grid-template-columns:minmax(0,1fr) auto;grid-template-areas:"title save" "profile profile" "fields fields"}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.dk-open-profile{width:100%;min-width:0;margin:0}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid{grid-template-columns:repeat(2,minmax(0,1fr));min-width:0}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid :is(label,input){min-width:0;max-width:100%}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid input{width:100%}
}
/* Short desktop windows (1024px+ wide, up to 820px tall, e.g. 1280x720, 1024x768): the Chats message pane was only
   ~150-190px. The contact fields keep one row (four columns), and the past-sessions bar and field spacing are tighter. */
@media (min-width:1024px) and (max-height:820px){
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor{padding-top:6px;padding-bottom:6px;row-gap:4px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid{grid-template-columns:repeat(4,minmax(0,1fr));align-items:end;gap:4px 8px;padding-bottom:2px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid label{display:grid;gap:2px;line-height:14px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.contact-editor>.contact-editor-grid input{min-height:34px;height:34px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.previous-sessions{padding-top:2px;padding-bottom:2px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .previous-sessions-toggle{min-height:36px;padding-top:6px;padding-bottom:6px}
}
/* History transcript / Lead detail: the sticky panel may be as tall as the page box (header 63px + strip + 12px top
   and bottom gaps), so at 1280x720 / 1024x768 the lead detail no longer needs its own scrollbar beside the page's. */
@media (min-width:1024px){
  body:has(#app-shell:not(.hidden)) #conversation-detail.history-transcript,
  body:has(#app-shell:not(.hidden)) #leads .hl-lead-detail{max-height:calc(100dvh - var(--app-strip-h) - 96px)}
}
/* 1024-1160px uses the two-row header (111px, 48px taller), so the sticky panel is 48px shorter to stay inside the page box. */
@media (min-width:1024px) and (max-width:1160px){
  body:has(#app-shell:not(.hidden)) #conversation-detail.history-transcript,
  body:has(#app-shell:not(.hidden)) #leads .hl-lead-detail{max-height:calc(100dvh - var(--app-strip-h) - 144px)}
}
/* 1024-1160px short windows (e.g. iPad landscape 1024x768): the two-row header is 48px taller than the one-row desktop
   header, so Chats wins it back: attach/voice sit left of the reply box and Send to its right on one row, the AI
   suggestion row gets the row below, the keyboard hint stays for screen readers only (as on phones), and the
   past-sessions bar is slimmer. */
@media (min-width:1024px) and (max-width:1160px) and (max-height:820px){
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply{grid-template-columns:auto minmax(0,1fr) auto;align-items:center;row-gap:4px}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>.composer-tools{grid-column:1;grid-row:1}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>textarea{grid-column:2;grid-row:1}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>button.primary{grid-column:3;grid-row:1}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>.ai-suggestion-row{grid-column:1/-1;grid-row:2;min-height:0;padding-bottom:0}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>#reply-help{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation>.agent-reply>:is(.voice-bar,.attachment-upload-status){grid-column:1/-1;grid-row:3}
  body:has(#app-shell:not(.hidden)) #inbox:not(.docked) #agent-conversation .previous-sessions-toggle{min-height:32px;padding-top:4px;padding-bottom:4px}
}
/* Chats composer (desktop/tablet): attach and voice are 44px touch targets like the header controls. */
@media (min-width:768px){
  body:has(#app-shell:not(.hidden)) #agent-conversation .agent-reply .composer-tools :is(.attach-button,.voice-button){width:44px;min-width:44px;height:44px;min-height:44px}
}
/* CR-0028 (1): sidebar groups open and close independently. Brand, workspace and the account card stay fixed;
   when every group is open and taller than the window, only the nav area between them scrolls (thin, dark).
   position:relative keeps the visually hidden status labels inside the scroller instead of the sidebar. */
@media (min-width:768px){
  body:has(#app-shell:not(.hidden)) #app-shell>aside{overflow:hidden}
  body:has(#app-shell:not(.hidden)) #app-shell>aside>:is(.brand,.workspace-context,.account){flex:0 0 auto}
  #app-shell>aside>.sidebar-scroll{position:relative;flex:1 1 auto;min-height:0;display:flex;flex-direction:column;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:#334155 transparent}
  #app-shell>aside>.sidebar-scroll::-webkit-scrollbar{width:6px}
  #app-shell>aside>.sidebar-scroll::-webkit-scrollbar-thumb{background:#334155;border-radius:3px}
  #app-shell>aside>.sidebar-scroll>nav{flex:0 0 auto;overflow:visible;min-height:auto}
}
