@media (max-width: 850px) {

    body.ims-auth {
        display: block;
    }

    .ims-auth-brand {
        width: 100%;
        min-height: auto;

        padding: 30px 24px;
    }

    .ims-auth-message {
        margin: 60px 0;
    }

    .ims-auth-message h1 {
        font-size: 42px;
    }

    .ims-auth-panel {
        width: 100%;
        min-height: auto;

        padding: 48px 24px;
    }

    .ims-sidebar {
        display: none;
    }

    .ims-workspace {
        width: 100%;

        margin-left: 0;
    }

    .ims-topbar {
        padding: 0 18px;
    }

    .ims-topbar-context {
        display: none;
    }

    .ims-content {
        padding: 22px 18px;
    }
}
/* At laptop widths, preserve all controls: search above Agenda / Mail,
   without pushing language and the user menu off-screen. */
@media (max-width: 1480px){
  .ims-topbar{height:auto;min-height:var(--ims-topbar-height);padding:8px 18px;flex-direction:column;align-items:stretch;justify-content:center;gap:7px}
  .ims-topbar-context{display:none}
  .ims-topbar-search{order:0;min-width:0;width:100%;padding:0}
  .ims-global-search-form{max-width:none}
  .ims-topbar-user{order:1;width:100%;justify-content:flex-end;flex-wrap:wrap;gap:8px 14px;min-height:28px}
}
@media (max-width: 920px){
  .ims-global-search-form{max-width:none}
  .ims-global-search-select{max-width:180px}
  .ims-search-sections{grid-template-columns:1fr}
}
@media (max-width: 640px){
  .ims-global-search-form{flex-wrap:wrap;border-radius:18px}
  .ims-global-search-input{min-width:180px}
  .ims-global-search-select,.ims-global-search-button{width:100%}
  .ims-search-page-input-wrap,.ims-search-page-select{min-width:100%}
  .ims-search-pagination{justify-content:center}
}


/* IMS 31 — Responsive navigation and reading layer.
 * Intentionally scoped to the authenticated IMS shell and small viewports.
 * All existing desktop layouts and business logic remain unchanged.
 */
.ims-mobile-menu-button { display: none; }
.ims-nav-children:not(.is-expanded) { display: none; }

@media (max-width: 850px) {
  body.ims-app { min-width: 0; }
  body.ims-app .ims-shell { display: block; min-width: 0; }
  body.ims-app .ims-workspace {
    width: 100%; max-width: 100%; min-width: 0; margin-left: 0;
  }
  body.ims-app .ims-sidebar {
    display: block; position: fixed; inset: 0 auto 0 0;
    width: min(86vw, 330px); max-width: 100%;
    height: 100vh; height: 100dvh;
    overflow-y: auto; overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 2201; transform: translateX(-105%);
    visibility: hidden; transition: transform .2s ease, visibility .2s ease;
    box-shadow: none;
  }
  body.ims-app.ims-mobile-nav-open .ims-sidebar {
    transform: translateX(0); visibility: visible;
    box-shadow: 8px 0 30px rgba(8, 19, 33, .27);
  }
  body.ims-app.ims-mobile-nav-open { overflow: hidden; }
  .ims-mobile-menu-backdrop {
    position: fixed; inset: 0; z-index: 2200;
    background: rgba(8, 18, 30, .57);
  }
  .ims-mobile-menu-backdrop[hidden] { display: none !important; }
  .ims-mobile-menu-button {
    display: inline-flex; align-items: center; justify-content: center;
    align-self: start; gap: 8px; min-height: 42px;
    padding: 7px 12px; border: 1px solid #d6dce5;
    border-radius: 9px; background: #fff; color: var(--ims-text);
    font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
    grid-area: menu;
  }
  .ims-mobile-menu-button:focus-visible,
  .ims-sidebar a:focus-visible { outline: 3px solid #7bbdff; outline-offset: 2px; }
  .ims-mobile-menu-icon { font-size: 21px; line-height: 1; }
  body.ims-app .ims-sidebar-brand { position: sticky; top: 0; z-index: 1; background: var(--ims-primary); }
  body.ims-app .ims-navigation { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  body.ims-app .ims-navigation .ims-nav-item { min-height: 42px; display: flex; align-items: center; }
  body.ims-app .ims-topbar {
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: 'menu user' 'search search';
    height: auto; min-height: 0; padding: 10px 12px;
    align-items: start; gap: 9px; position: relative;
  }
  body.ims-app .ims-topbar-context { display: none; }
  body.ims-app .ims-topbar-search {
    grid-area: search; width: 100%; min-width: 0; padding: 0;
    order: initial; justify-content: stretch;
  }
  body.ims-app .ims-topbar-user {
    grid-area: user; display: flex; flex-wrap: wrap; min-width: 0;
    width: 100%; align-items: center; justify-content: flex-end;
    gap: 6px 10px; order: initial; font-size: 12px;
  }
  body.ims-app .ims-topbar-user .ims-user-menu { min-width: 0; }
  body.ims-app .ims-user-menu-trigger { max-width: min(52vw, 220px); padding: 8px 5px; }
  body.ims-app .ims-user-menu-trigger > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.ims-app .ims-user-menu-dropdown { right: 0; max-width: calc(100vw - 24px); }
  body.ims-app .ims-global-search-form { max-width: none; min-width: 0; width: 100%; }
  body.ims-app .ims-content {
    min-width: 0; width: 100%; max-width: 100%;
    padding: 16px 12px 45px; overflow-x: clip;
  }
  body.ims-app .ims-content :is(.ims-page,.ims-card,.ims-subcard,.ims-panel) { min-width: 0; max-width: 100%; }
  body.ims-app .ims-content .ims-card { padding: 15px 12px; }
  body.ims-app .ims-content .ims-page-header { margin-bottom: 16px; }
  body.ims-app .ims-content .ims-page-header h1 { font-size: clamp(21px, 5.6vw, 28px); overflow-wrap: anywhere; }
  body.ims-app .ims-content :is(.ims-page-header-actions,.ims-header-actions,.ims-filter-bar,.ims-form-actions,.ims-card-header-row) {
    flex-wrap: wrap; min-width: 0; gap: 8px 10px;
  }
  body.ims-app .ims-content :is(.ims-form-grid,.ims-profile-grid,.ims-mini-form,.ims-two-columns,.ims-catalog-grid,.ims-grid-2,.ims-grid-3,.ims-grid-4) {
    min-width: 0;
  }
  body.ims-app .ims-content :is(input:not([type=checkbox]):not([type=radio]), select, textarea) {
    max-width: 100%; min-width: 0;
  }
  body.ims-app .ims-content :is(img,video,iframe) { max-width: 100%; }
  body.ims-app .ims-content :is(pre,.ims-document-audit-value) { max-width: 100%; overflow-x: auto; }
  body.ims-app .ims-content :is(.ims-table-wrap,.ims-leads-table-wrap,.ims-mail-table-wrap,.hr-table-wrap,.ims-mobile-table-scroll) {
    max-width: 100%; width: 100%; overflow-x: auto;
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  }
  body.ims-app .ims-content :is(.ims-table-wrap,.ims-leads-table-wrap,.ims-mail-table-wrap,.ims-mobile-table-scroll) > table {
    width: max-content; min-width: 100%;
  }
  body.ims-app .ims-content .ims-mobile-table-scroll { display: block; }
  body.ims-app .ims-content :is(.ims-table-wrap,.ims-mobile-table-scroll):focus-visible {
    outline: 2px solid #3678cb; outline-offset: 2px;
  }
  body.ims-app .ims-content :is(.ims-table-wrap,.ims-mobile-table-scroll) :is(th,td) { white-space: normal; }
  body.ims-app .ims-content :is(.ims-table-wrap,.ims-mobile-table-scroll) :is(th,td) :is(input,select,textarea) { max-width: none; }
  body.ims-app .ims-content .ims-leads-table :is(th,td) { white-space: nowrap; }
  body.ims-app .ims-content :is(.ims21-tabs,.ims-layout-static-tabs,.ims-tabs) {
    max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  body.ims-app .ims-content :is(.ims-layout-canvas-wrap,.ims-layout-a4-canvas) { max-width: 100%; }
  body.ims-app .ims-content :is(.ims-view-picker-panel,.ims-user-menu-dropdown) { max-width: calc(100vw - 24px); }
  body.ims-app dialog:not([open]) { display: none; }
  body.ims-app dialog[open] { max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  body.ims-app .wa-app {
    display: flex; flex-direction: column; height: auto; min-height: 0;
    max-width: 100%;
  }
  body.ims-app .wa-side {
    flex: none; width: 100%; max-width: 100%; min-width: 0;
    height: clamp(215px, 32dvh, 310px); border-right: 0; border-bottom: 1px solid #e1e7e4;
  }
  body.ims-app .wa-chat { flex: none; min-width: 0; width: 100%; height: clamp(370px, 66dvh, 680px); }
  body.ims-app .wa-messages { min-height: 120px; }
  body.ims-app .wa-bubble { max-width: 94%; }
  body.ims-app .wa-chat-head { flex-wrap: wrap; }
  /* The standalone live-chat view hides the desktop sidebar intentionally.
     On mobile its navigation remains available through the drawer only. */
  body.ims-app:has(#vi-conversation) .ims-sidebar { display: block !important; }
  body.ims-app .vi-board { max-width: 100%; overflow-x: auto; }
  body.ims-app .vi-toolbar .vi-field { min-width: min(140px,100%); }
}
@media (max-width: 560px) {
  body.ims-app .ims-topbar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'menu' 'user' 'search';
  }
  body.ims-app .ims-topbar-user { justify-content: flex-start; }
  body.ims-app .ims-topbar-search .ims-global-search-form {
    display: grid; grid-template-columns: 1fr auto;
    border-radius: 14px; gap: 7px;
  }
  body.ims-app .ims-global-search-icon { display: none; }
  body.ims-app .ims-global-search-input {
    grid-column: 1 / -1; width: 100%; min-width: 0; min-height: 39px; padding: 0 8px;
  }
  body.ims-app .ims-global-search-select { width: 100%; max-width: none; min-width: 0; }
  body.ims-app .ims-global-search-button { width: auto; padding-inline: 14px; }
  body.ims-app .ims-content { padding-inline: 10px; }
  body.ims-app .ims-content .ims-card { padding: 13px 10px; }
  body.ims-app .ims-content .ims-page-header-actions > * { min-width: 0; }
  body.ims-app .ims-content .ims-search-page-form :is(.ims-search-page-input-wrap,.ims-search-page-select) { min-width: 0; width: 100%; }
  body.ims-app .ims-content .ims-form-actions > .ims-button { max-width: 100%; }
  body.ims-app .ims-content .vi-topstats { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  body.ims-app .ims-sidebar { transition: none; }
}

/* Multi-monitor workspace must also override the mobile drawer and chat-specific sidebar rules. */
html.ims-workspace-mode body.ims-app .ims-sidebar,
html.ims-workspace-mode body.ims-app:has(#vi-conversation) .ims-sidebar{display:none!important;visibility:hidden!important;transform:none!important}
html.ims-workspace-mode body.ims-app .ims-workspace{width:100%!important;max-width:100%!important;margin-left:0!important}
html.ims-workspace-mode body.ims-app .ims-mobile-menu-button{display:none!important}
@media (max-width:850px){
  html.ims-workspace-mode body.ims-app .ims-workspace-exit{display:inline-flex;grid-area:menu;align-self:start;min-height:42px}
}
