/* Phone interaction refinements. Keep native dialog and [hidden] visibility
   under the control of the browser and the existing workspace scripts. */
@media (max-width:700px) {
  html body.dashboard-canvas.auth-ready:has(.shell) {
    --phone-top:max(12px,env(safe-area-inset-top,0px));
    --phone-right:max(12px,env(safe-area-inset-right,0px));
    --phone-bottom:max(12px,env(safe-area-inset-bottom,0px));
    --phone-left:max(12px,env(safe-area-inset-left,0px));
  }

  /* The open phone drawer always uses labelled rows, regardless of the
     desktop rail preference saved on this device. Native details still own
     the visibility of each destination group. */
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar {
    inset:var(--phone-top) auto var(--phone-bottom) var(--phone-left);
    width:min(320px,calc(100vw - var(--phone-left) - var(--phone-right) - 36px));
    height:calc(100dvh - var(--phone-top) - var(--phone-bottom));
    padding:16px 14px;
    align-items:stretch;
    overflow:hidden;
    box-sizing:border-box;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .sidebar-top {
    flex-direction:row;
    justify-content:space-between;
    flex:none;
    gap:8px;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .brand {
    width:auto;
    min-height:44px;
    justify-content:flex-start;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar :is(.brand > span,.nav-group-label,.sidebar-support span,.sidebar-themes span) {
    display:inline;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .nav-chevron {
    display:flex;
    margin-left:auto;
    flex:none;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .workspace {
    display:flex;
    flex:none;
    margin:16px 0;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar nav.organized-navigation {
    flex:1 1 auto;
    min-height:0;
    margin-top:0;
    overflow-x:hidden;
    overflow-y:auto;
    overscroll-behavior:contain;
    scrollbar-width:thin;
    scroll-padding-block:8px;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar summary {
    width:100%;
    min-height:44px;
    margin:0;
    padding:10px 12px;
    justify-content:flex-start;
    border-radius:12px;
    white-space:normal;
    line-height:1.4;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .nav-children {
    position:relative;
    inset:auto;
    width:auto;
    margin:8px 4px 14px 20px;
    padding:0 0 0 12px;
    border:0;
    border-left:1px solid var(--canvas-line);
    border-radius:0;
    box-shadow:none;
    background:transparent;
    z-index:auto;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar nav .nav-children button {
    width:100%;
    min-height:44px;
    padding:10px;
    justify-content:flex-start;
    font-size:13px;
    white-space:normal;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .nav-flyout-title {
    display:none;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .sidebar-bottom {
    display:flex;
    flex:none;
    gap:10px;
    padding:12px 0 0;
    margin-top:12px;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .sidebar-support {
    min-height:44px;
    padding:10px;
    justify-content:flex-start;
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .sidebar-themes {
    flex-direction:row;
    padding:4px;
    border:1px solid var(--canvas-line);
    background:var(--canvas-soft);
  }
  html body.dashboard-canvas.auth-ready.nav-mobile-open:has(.shell) .organized-sidebar .sidebar-themes button {
    flex:1 1 0;
    min-height:44px;
    padding:8px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) :is(.mobile-sidebar-toggle,#sidebar-toggle) {
    width:44px;
    height:44px;
    min-height:44px;
    min-width:44px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .shell > main {
    padding-bottom:calc(160px + env(safe-area-inset-bottom,0px))!important;
  }
  html body.dashboard-canvas.auth-ready .topbar :is(.workspace-guide-help,.workspace-primary-tabs button,.sx-language select) {
    min-width:44px;
    min-height:44px;
  }
  html body.dashboard-canvas.auth-ready .topbar .workspace-primary-tabs {
    overscroll-behavior-inline:contain;
  }
  html body.dashboard-canvas.auth-ready #content .dashboard-targets > header {
    flex-wrap:wrap;
    row-gap:12px;
  }
  html body.dashboard-canvas.auth-ready #content .dashboard-targets > header > div {
    min-width:0;
  }

  /* A table keeps its columns; only its own wrapper scrolls horizontally. */
  html body.dashboard-canvas.auth-ready:has(.shell) #content,
  html body.dashboard-canvas.auth-ready:has(.shell) #content > *,
  html body.dashboard-canvas.auth-ready:has(.shell) #content .card {
    min-width:0;
    max-width:100%;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) :is(#content,#inventory-dialog,.native-booking-dialog,#stock-plan-dialog) .table-wrap {
    position:relative;
    min-width:0;
    max-width:100%;
    overflow:auto;
    overscroll-behavior-inline:contain;
    scrollbar-color:var(--canvas-line) transparent;
    scrollbar-width:thin;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #content :is(button,summary),
  html body.dashboard-canvas.auth-ready:has(.shell) :is(.heading-controls,.demo-banner) button {
    min-height:44px;
    min-width:44px;
  }
  /* Preserve all seven weekday hit areas inside narrow cards. */
  html body.dashboard-canvas.auth-ready:has(.shell) #content .insight-heat > button {
    min-width:0;
    width:100%;
  }
  html body.dashboard-canvas.auth-ready #content .sales-map header {
    flex-wrap:wrap;
  }
  html body.dashboard-canvas.auth-ready #content .sales-map header [role=group] {
    display:flex;
    gap:6px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #content :is(a.button,a.section-link,.inventory-backup > label),
  html body.dashboard-canvas.auth-ready:has(.shell) .demo-banner a {
    display:inline-flex;
    align-items:center;
    min-height:44px;
    padding-block:10px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #content :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea),
  html body.dashboard-canvas.auth-ready:has(.shell) :is(.heading-controls,.targets-context) select {
    min-height:44px;
    font-size:16px!important;
    max-width:100%;
    min-width:0;
    box-sizing:border-box;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #content .table-tools {
    flex-wrap:wrap;
    min-width:0;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #content .table-tools > :is(input,select) {
    flex:1 1 150px;
    min-width:0;
  }

  /* Search and period choices remain in the phone's usable viewport. */
  html body.dashboard-canvas.auth-ready:has(.shell) #dashboard-search .dashboard-search-clear {
    width:44px;
    height:44px;
    flex:0 0 44px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #dashboard-search .dashboard-search-panel {
    max-width:100%;
    box-sizing:border-box;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #dashboard-search [role=listbox] {
    max-height:min(420px,50dvh);
    scroll-padding-block:8px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .dashboard-period-menu {
    max-height:min(460px,55dvh);
    max-width:calc(100vw - var(--phone-left) - var(--phone-right));
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .dashboard-period-trigger {
    max-width:100%;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .dashboard-period-trigger strong {
    white-space:normal;
  }

  /* Exact dashboard overlays: dimensions never force a closed dialog open. */
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(#connection-dialog,.workspace-guide-dialog,.metric-editor,.targets-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options,.channel-sync-confirm,.fulfill-confirm)[open] {
    box-sizing:border-box;
    width:calc(100vw - var(--phone-left) - var(--phone-right));
    max-width:calc(100vw - var(--phone-left) - var(--phone-right));
    max-height:calc(100dvh - var(--phone-top) - var(--phone-bottom));
    overflow:auto;
    overscroll-behavior:contain;
    scroll-padding-block:76px 24px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(#connection-dialog,.workspace-guide-dialog,.metric-editor,.targets-dialog,.channel-api-options,.channel-sync-confirm,.fulfill-confirm)[open] {
    --bg:var(--canvas-bg);
    --panel:var(--canvas-panel);
    --panel2:var(--canvas-soft);
    --text:var(--canvas-text);
    --muted:var(--canvas-muted);
    --line:var(--canvas-line);
    background:var(--canvas-panel);
    color:var(--canvas-text);
    border-color:var(--canvas-line);
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(#connection-dialog,.workspace-guide-dialog,.metric-editor,.targets-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options,.channel-sync-confirm,.fulfill-confirm)[open] :is(button,summary) {
    min-width:44px!important;
    min-height:44px!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(#connection-dialog,.workspace-guide-dialog,.metric-editor,.targets-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options,.channel-sync-confirm,.fulfill-confirm)[open] :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea) {
    min-width:0;
    max-width:100%;
    min-height:44px;
    font-size:16px!important;
    box-sizing:border-box;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(.workspace-guide-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options)[open] > header {
    position:sticky;
    top:0;
    z-index:4;
    background:var(--canvas-panel)!important;
    gap:12px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(.workspace-guide-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options)[open] > header > :first-child {
    min-width:0;
    overflow-wrap:anywhere;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) dialog:is(.workspace-guide-dialog,#inventory-dialog,.price-test-dialog,.native-booking-dialog,#stock-plan-dialog,.channel-api-options)[open] > header > button {
    width:44px;
    height:44px;
    flex:0 0 44px;
    padding:0;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #connection-dialog[open] > form[method=dialog] {
    position:sticky;
    top:0;
    z-index:4;
    min-height:44px;
    background:var(--canvas-panel);
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #connection-dialog .close {
    width:44px;
    height:44px;
  }

  /* Wrapping keeps every guide action and metric ordering control reachable. */
  html body.dashboard-canvas.auth-ready:has(.shell) .workspace-guide-dialog .workspace-guide-layout > nav {
    overscroll-behavior-inline:contain;
    scroll-padding-inline:12px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .workspace-guide-dialog footer {
    flex-wrap:wrap;
    gap:12px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .workspace-guide-dialog :is(a.button,.guide-secondary,.guide-import-shortcuts button) {
    min-height:44px;
    padding-block:10px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .metric-editor {
    padding:20px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) :is(.metric-editor,.targets-dialog)[open] form > header {
    position:sticky;
    top:0;
    z-index:4;
    padding-block:8px;
    background:var(--canvas-panel);
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .metric-editor .metric-option {
    gap:6px;
    padding-block:6px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .metric-editor .metric-option label {
    min-width:0;
    min-height:44px;
    gap:8px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .metric-editor .metric-option label input {
    flex:none;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .metric-editor :is(header > button,.metric-option button) {
    flex:0 0 44px;
    width:44px;
    padding:6px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .targets-dialog[open] {
    inset:var(--phone-top) var(--phone-right) var(--phone-bottom) var(--phone-left);
    width:auto;
    height:auto;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .targets-dialog .targets-editor-scope {
    flex-wrap:wrap;
    gap:12px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .targets-dialog .targets-editor-scope > [data-target-period] {
    white-space:normal;
    padding-bottom:0;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) :is(#inventory-dialog,.native-booking-dialog,#stock-plan-dialog,.price-test-dialog) label:has(> input[type=checkbox]) {
    min-height:44px;
    align-items:center;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .price-test-dialog .price-test-fields {
    grid-template-columns:minmax(0,1fr);
  }

  /* Assistant tools scroll in one row so the conversation retains room. */
  html body.dashboard-canvas.auth-ready:has(.shell) .assistant-launcher {
    bottom:var(--phone-bottom)!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .assistant-launcher input {
    min-height:44px!important;
    font-size:16px!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .assistant-launcher :is(.ask-fab.assistant-launcher-icon,.assistant-launcher-send) {
    width:44px!important;
    height:44px!important;
    min-height:44px!important;
    min-width:44px!important;
    flex-basis:44px!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) .assistant-launcher-suggestions button {
    min-height:44px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] {
    --ask-bg:var(--canvas-panel);
    --ask-panel:var(--canvas-soft);
    --ask-text:var(--canvas-text);
    --ask-muted:var(--canvas-muted);
    --ask-line:var(--canvas-line);
    inset:auto!important;
    left:50%!important;
    bottom:var(--phone-bottom)!important;
    transform:translateX(-50%)!important;
    width:calc(100vw - var(--phone-left) - var(--phone-right))!important;
    max-width:calc(100vw - var(--phone-left) - var(--phone-right))!important;
    height:min(700px,calc(100dvh - var(--phone-top) - var(--phone-bottom)))!important;
    max-height:calc(100dvh - var(--phone-top) - var(--phone-bottom))!important;
    background:var(--canvas-panel)!important;
    color:var(--canvas-text)!important;
    border-color:var(--canvas-line)!important;
    overflow:hidden;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] #ask-close {
    top:12px;
    right:12px;
    width:44px;
    height:44px;
    z-index:5;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-heading {
    padding-right:72px!important;
    background:var(--canvas-soft)!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-tools {
    flex-wrap:nowrap;
    overflow-x:auto;
    overscroll-behavior-inline:contain;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-tools button {
    flex:none;
    white-space:nowrap;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] :is(button,summary) {
    min-height:44px;
    min-width:44px;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-composer {
    background:var(--canvas-panel)!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] #dashboard-question {
    font-size:16px!important;
    color:var(--canvas-text)!important;
    background:var(--canvas-bg)!important;
  }
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-result,
  html body.dashboard-canvas.auth-ready:has(.shell) #ask-dialog[open] .ask-result :is(p,h3,.ask-lead) {
    color:var(--canvas-text)!important;
  }
}
