/* YOOR mobile portals layer. Loaded LAST. Desktop (>900px) untouched. Navy + gold. */
:root{--ym-navy:#0b2361;--ym-gold:#b38a4c;--ym-gold-soft:#f1e5cc;--ym-paper:#faf7f1;--ym-line:#e2dccf;--ym-sb:env(safe-area-inset-bottom,0px)}

/* Table scroll containers (added by mobile-portals.js) — harmless on desktop */
.ym-scroll{position:relative;max-width:100%}
.ym-scroll>.ym-scroll-in{overflow-x:auto;-webkit-overflow-scrolling:touch;overscroll-behavior-x:contain}
.ym-scroll-hint{display:none}
.ym-drawer-close{display:none}
.ym-drawer-close svg{width:18px;height:18px;flex:none}

@media (max-width:900px){
  html,body{overflow-x:hidden;max-width:100%}
  #app,.workspace,.main,.page,.content{min-width:0;max-width:100%}
  .main{overflow-x:clip}
  img,video,iframe,canvas,svg{max-width:100%}
  pre,code,.op-code{white-space:pre-wrap;overflow-wrap:anywhere}
  /* any table: never push page width */
  .main table{min-width:0}
  .table-scroll,.bt-table-scroll,.ci-table-scroll,.ym-scroll>.ym-scroll-in{overflow-x:auto;-webkit-overflow-scrolling:touch;max-width:100%}
  .ym-scroll{margin:0 0 4px;border-radius:14px}
  .ym-scroll-hint{display:flex;align-items:center;gap:8px;font-size:11.5px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--ym-gold);padding:2px 2px 8px}
  .ym-scroll-hint:after{content:"";flex:1;height:1px;background:linear-gradient(90deg,var(--ym-gold-soft),transparent)}
  .ym-scroll[data-fits="true"] .ym-scroll-hint{display:none}
  .ym-scroll>.ym-scroll-in>table{min-width:640px}
  .ym-scroll>.ym-scroll-in>table td,.ym-scroll>.ym-scroll-in>table th{white-space:nowrap}
  .ym-scroll>.ym-scroll-in>table td .cell-sub,.ym-scroll>.ym-scroll-in>table td small{white-space:normal}

  /* Tablet: metrics two-up, multi-col grids relax */
  .pro-metrics,.metrics,.stats,.kpis{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  .pro-dash-grid{grid-template-columns:minmax(0,1fr)!important}
}

/* ---------- Phone drawer + shell ---------- */
@media (max-width:700px){
  .workspace{display:block!important}
  .main{margin-left:0!important;padding:18px 14px calc(110px + var(--ym-sb))!important;width:auto!important}
  .sidebar{position:fixed!important;left:0!important;transform:translateX(-105%);transition:transform .26s cubic-bezier(.2,.8,.2,1)!important;width:min(300px,86vw)!important;z-index:70!important;top:var(--toolbar)!important;height:calc(100dvh - var(--toolbar))!important;overflow-y:auto;overscroll-behavior:contain;padding-bottom:calc(18px + var(--ym-sb))!important;box-shadow:18px 0 50px #0b236140!important;border-radius:0 18px 18px 0}
  .sidebar.open{transform:none}
  .sidebar-shade{z-index:69!important;background:#0b2361a6!important;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px)}
  .sidebar .nav-item{min-height:46px;padding:11px 12px!important;border-radius:12px;font-size:15px}
  .sidebar .nav-item span{display:inline!important}
  .ym-drawer-close{display:flex;position:sticky;top:0;margin:-8px -6px 8px auto;width:44px;height:44px;border-radius:12px;border:1px solid #ffffff2b;background:#ffffff14;color:#f3ede1;align-items:center;justify-content:center;cursor:pointer;z-index:2}
  .ym-drawer-close svg{width:18px;height:18px}

  /* Topbar */
  .topbar{position:sticky;top:var(--toolbar);z-index:30;height:auto!important;min-height:60px;padding:8px 12px!important;gap:8px!important;background:#fffdf9f2!important;backdrop-filter:saturate(1.2) blur(8px);-webkit-backdrop-filter:saturate(1.2) blur(8px);box-shadow:0 1px 0 var(--ym-line)}
  .topbar>.row{min-width:0;flex:1 1 auto;gap:8px}
  .mobile-menu{display:inline-flex!important;align-items:center;justify-content:center;width:44px!important;height:44px!important;flex:none;border-radius:12px!important;background:var(--ym-navy)!important;color:#f6f1e7!important;border:0!important}
  .mobile-menu .icon,.mobile-menu svg{width:20px;height:20px;color:#f6f1e7;stroke:currentColor}
  .breadcrumb{min-width:0;overflow:hidden}
  .breadcrumb b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:15px;color:var(--ym-navy)}
  .top-actions{flex:none;min-width:0;gap:6px!important}
  .top-actions .btn,.top-actions button,.top-actions select,.x-search-hint{min-height:40px}
  .top-search{display:none!important}
  .profile-select{max-width:118px!important;font-size:13px!important;min-height:40px;border-radius:10px}
  .ya-account{margin-left:4px;gap:6px}
  .ya-account button{min-height:36px;padding:6px 12px;font-size:12px}
  .ya-account-name{display:none}

  /* Demo / role preview bar */
  .demo-bar{padding:6px 10px!important}
  .role-switch{gap:4px}
  .role-switch button{min-height:32px;font-size:11.5px!important;border-radius:999px}

  /* Headings, cards */
  .page-heading{flex-direction:column;align-items:stretch!important;gap:12px!important}
  .page-heading h1{font-size:24px!important;color:var(--ym-navy)}
  .page-heading p{font-size:13.5px!important;line-height:1.6!important}
  .page-heading .row,.page-heading>div:last-child{flex-wrap:wrap;gap:8px}
  .page-heading .btn{flex:1 1 auto;justify-content:center}
  .card,.panel,.yx-card,.pro-card{border-radius:16px!important}
  .card,.panel,.pro-card{padding:16px!important}

  /* Metrics: stacked two-up, then single */
  .pro-metric{padding:14px!important;border-radius:14px}
  .pro-metric-value{font-size:24px!important}

  /* Any multi-column grids collapse */
  [class*="grid-2"],[class*="grid-3"],[class*="grid-4"],[class*="-grid"]:not(.pro-metrics):not(.op-coverage):not(.x-language-grid),.form-grid,.yx-grid,.yx-setup-head,.op-checks,.split,.two-col,.cols{grid-template-columns:minmax(0,1fr)!important}
  .row.wrap,.toolbar,.filters,.filter-bar,.tabs{flex-wrap:wrap}
  .tabs,.segmented,.pill-tabs{overflow-x:auto;scrollbar-width:none;max-width:100%}
  .tabs::-webkit-scrollbar{display:none}

  /* Controls: 44px tap, 16px input (prevents iOS zoom) */
  .main .btn,dialog .btn,.yx-actions .btn{min-height:44px}
  .main input:not([type=checkbox]):not([type=radio]):not([type=range]),.main select,.main textarea,dialog input:not([type=checkbox]):not([type=radio]),dialog select,dialog textarea,.yc-compose textarea,.yc-search input,.yd-call input,.cl-formFieldInput{font-size:16px!important;min-height:44px}
  .main label,dialog label,.field>span,.yx-field>span{font-size:14px}
  .main input,.main select,.main textarea,dialog input,dialog select,dialog textarea{max-width:100%;border-radius:12px}
  .icon-btn,.notification-button{min-width:40px;min-height:40px}

  /* Settings / toggles / accounts approvals */
  .op-toggle-row,.setting-row,.settings-row,.acc-row,.approval-row{flex-wrap:wrap;gap:10px}
  .op-toggle-row>*:first-child{flex:1 1 200px;min-width:0}
  .op-list-row{flex-wrap:wrap}
  .yx-actions{flex-direction:column;align-items:stretch}
  .yx-actions .btn{justify-content:center}

  /* Modal: screen-safe, scrolling body, actions always visible */
  dialog#modal{width:calc(100vw - 16px)!important;max-width:calc(100vw - 16px)!important;max-height:calc(100dvh - 24px - env(safe-area-inset-top,0px) - var(--ym-sb))!important;margin:auto!important;border-radius:20px!important;display:none;overflow:hidden!important}
  dialog#modal[open]{display:flex!important;flex-direction:column}
  dialog#modal>*{min-width:0}
  dialog#modal .modal-head{padding:16px!important;flex:none}
  dialog#modal .modal-head h2{font-size:19px}
  dialog#modal .modal-body{padding:16px!important;overflow-y:auto;flex:1 1 auto;min-height:0;-webkit-overflow-scrolling:touch}
  dialog#modal .modal-foot{padding:12px 16px calc(12px + var(--ym-sb))!important;flex:none;position:sticky;bottom:0;gap:8px}
  dialog#modal .modal-foot .btn{flex:1 1 140px;justify-content:center}
  dialog#modal form{display:contents}
  dialog::backdrop{background:#0b236199}

  /* Toasts above launchers */
  .toast-stack{left:12px!important;right:12px!important;bottom:calc(84px + var(--ym-sb))!important;width:auto!important}

  /* ---------- Floating chat + Dialpad ---------- */
  .yc-root{right:12px!important;bottom:calc(12px + var(--ym-sb))!important}
  .yd-root{left:12px!important;bottom:calc(12px + var(--ym-sb))!important}
  .yc-launch,.yd-launch{width:52px;height:52px;padding:0!important;justify-content:center;box-shadow:0 10px 26px #0b236140}
  .yd-launch{border-color:var(--ym-gold)!important}
  .yc-launch-label,.yd-launch-label{display:none!important}
  .yc-panel{position:fixed;left:8px;right:8px;width:auto!important;bottom:calc(76px + var(--ym-sb));height:calc(100dvh - 96px - var(--toolbar,0px) - var(--ym-sb))!important;max-height:620px;border-radius:20px}
  .yd-root.open .yd-panel{position:fixed;left:8px;right:8px;width:auto!important;bottom:calc(76px + var(--ym-sb));max-height:calc(100dvh - 96px - var(--toolbar,0px) - var(--ym-sb))!important}
  .yd-frame iframe{height:min(460px,calc(100dvh - 330px))!important;min-height:260px}
  .yc-head .yc-ico,.yd-ico{width:40px!important;height:40px!important}
  .yc-tabs button{min-height:36px;padding:8px 12px}
  .yd-btn{min-height:44px}
  .yd-call button{flex:none}
  /* While a modal or the drawer is open, launchers step aside (iframe stays mounted) */
  html.ym-modal .yc-root,html.ym-modal .yd-root,html.ym-drawer .yc-root,html.ym-drawer .yd-root{opacity:0;pointer-events:none;transform:translateY(12px);transition:opacity .2s,transform .2s}
  html.ym-modal .yd-root *,html.ym-drawer .yd-root *{pointer-events:none}
}

@media (max-width:430px){
  .pro-metrics,.metrics,.stats,.kpis{gap:10px!important}
  .breadcrumb>span,.breadcrumb>.icon,.pro-breadcrumb-org{display:none!important}
  .top-actions .btn.primary{padding:0 12px!important;font-size:12px!important}
  .profile-select{max-width:96px!important}
}
@media (max-width:360px){
  .pro-metrics,.metrics,.stats,.kpis{grid-template-columns:minmax(0,1fr)!important}
  .main{padding-left:10px!important;padding-right:10px!important}
  .top-actions .btn.primary .icon~*{display:none}
  .profile-select{max-width:80px!important}
  .page-heading h1{font-size:21px!important}
}

/* ---------- Public site + auth ---------- */
@media (max-width:700px){
  .site-nav{padding:0 14px!important;gap:10px!important;min-height:62px;max-width:100vw}
  body .public .site-nav>a:first-of-type{flex:1 1 auto;min-width:0}
  body .public .site-nav .official-brand{
    width:clamp(140px,calc(100vw - 180px),240px)!important;
    max-width:100%!important;padding:0!important;
  }
  body .public .site-nav .official-brand img{
    display:block;width:100%!important;height:auto!important;
    max-height:none!important;object-fit:contain;
  }
  .site-links{max-width:100%;overflow-x:auto;scrollbar-width:none}
  .pe-login summary,.ya-login-btn{min-height:44px;display:inline-flex;align-items:center}
  .pe-login-options,.ya-menu{width:min(280px,calc(100vw - 24px))!important;right:0}
  .ya-menu button{min-height:44px}
  .ya-gate-card,.ya-auth-main{text-align:left}
  .ya-auth-main{padding:24px 12px calc(24px + var(--ym-sb))}
  .ya-auth-side{align-items:center;text-align:center}
  .ya-auth-side .ya-brand,.ya-gate-brand .ya-brand{justify-content:center;margin:0 auto}
  .cl-rootBox,.cl-card,.cl-cardBox{max-width:calc(100vw - 24px)!important;width:100%!important}
  .cl-logoBox{justify-content:center!important;margin-inline:auto}
  .ya-tabs button{min-height:40px}
  .ya-btn{min-height:44px}
}
@media (prefers-reduced-motion:reduce){.sidebar{transition:none!important}}

/* Override legacy per-role header grids on both phones and tablets. */
@media(max-width:900px){
 html body:has(#app .workspace){--toolbar:118px!important}
 html body:has(#app .workspace)>.demo-bar{
  display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;
  grid-template-rows:54px 48px!important;gap:4px 8px!important;
  height:118px!important;min-height:118px!important;padding:6px 10px!important;
 }
 html body:has(#app .workspace) .demo-label{
  grid-column:1!important;grid-row:1!important;position:static!important;
  display:flex!important;justify-content:flex-start!important;min-width:0!important;
 }
 html body:has(#app .workspace) .demo-label .official-brand{
  width:156px!important;max-width:100%!important;min-width:0!important;padding:4px!important;
  background:#fff!important;border-radius:9px!important;
 }
 html body:has(#app .workspace) .demo-tools{
  grid-column:2!important;grid-row:1!important;position:static!important;
  display:flex!important;width:auto!important;min-width:0!important;max-width:125px;gap:4px!important;
 }
 html body:has(#app .workspace) .demo-tools .ya-account{margin:0!important;gap:4px!important}
 html body:has(#app .workspace) .demo-tools .ya-av{display:none}
 html body:has(#app .workspace) .demo-tools button{min-height:44px!important}
 html body:has(#app .workspace) .role-switch{
  grid-column:1/-1!important;grid-row:2!important;position:static!important;
  display:flex!important;width:100%!important;max-width:100%!important;min-width:0!important;gap:2px!important;
 }
 html body:has(#app .workspace) .role-switch button{
  flex:1 1 0!important;min-width:0!important;min-height:44px!important;
  padding:4px 2px!important;font-size:10px!important;white-space:normal!important;line-height:1.2;
 }
 html body #app .workspace .main{padding-bottom:calc(120px + var(--ym-sb))!important}
}

/* Reserve a clear bottom strip rather than floating controls over form fields. */
@media(max-width:700px){
 html body:has(#app .workspace) #app{
  height:calc(100dvh - var(--toolbar) - 76px - var(--ym-sb));
  overflow-y:auto;overscroll-behavior-y:contain;scroll-padding-bottom:24px;
 }
 html body:has(#app .workspace)::after{
  content:"";position:fixed;bottom:0;left:0;right:0;height:calc(76px + var(--ym-sb));
  background:#faf7f1;border-top:1px solid var(--ym-line);z-index:48;pointer-events:none;
 }
}
