/* Drawer controls exist in the DOM but never affect desktop navigation. */
html.aic-layout-refactor .app-sidebar__mobile-close,
html.aic-layout-refactor .dashboard-mini-sidebar__mobile-close { display: none; }

/* A.I.C. R77: mobile / tablet overlay contract.
 * A modal root (not its inner dialog) is above both fixed bottom navigations.
 * Existing desktop, toast and native <dialog> layers remain unchanged.
 */
@media (max-width: 1024px) {
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav) :is(
    .my-driver-hazards-page .filter-modal,
    .my-place-index-page .filter-modal,
    .waybills-page .modal,
    .group-form-page .office-modal,
    .hz-modal,
    .group-dispatch-page .group-dispatch-modal,
    .plan-board-legend-modal,
    .plan-board-group-modal,
    .waybill-office-transfer-modal
  ) { z-index: 2000; }

  html.aic-layout-refactor body.aic-management-mobile-nav
  .admin-user-form-page :is(
    #role-modal, #status-modal, #office-modal,
    #office-switch-modal, #office-scope-modal, #assignment-modal
  ) { z-index: 2000; }

  html.aic-layout-refactor body.aic-management-mobile-nav
  turbo-frame#admin-office-modal:not(:empty) { z-index: 2000; }

  /* Photo viewer and nested dispatch dialogs must retain their relative order. */
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav)
  .hz-modal.hz-modal--photo { z-index: 2020; }
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav)
  .foot-waybill-modal { z-index: 2030; }
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav)
  .foot-waybill-other-routes-modal { z-index: 2040; }
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav)
  .split-relay-modal { z-index: 2050; }
  html.aic-layout-refactor body:is(.aic-driver-mobile-nav, .aic-management-mobile-nav)
  .place-picker-modal { z-index: 2070; }

  /* A drawer or modal owns the complete display, including the bottom safe area.
   * The Stimulus guard owns the matching nav inert state; this is a pointer fallback.
   */
  html.aic-layout-refactor body.aic-mobile-overlay-active :is(
    .management-mobile-nav, .driver-mobile-nav
  ) { pointer-events: none; }

  /* Explicit close controls replace re-tapping a nav button behind the overlay. */
  html.aic-layout-refactor body.aic-management-mobile-nav .app-sidebar__mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    margin-left: auto;
    margin-bottom: 8px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    color: var(--ui-color-text, #293749);
    background: transparent;
    font-size: 19px;
    cursor: pointer;
  }
  html.aic-layout-refactor body.aic-management-mobile-nav .app-sidebar__mobile-close:focus-visible {
    outline: 2px solid var(--ui-color-focus, #2563eb);
    outline-offset: 2px;
  }
  /* R78: PC-equivalent mobile drawer, no visible X. Keep an accessible
   * close action as last focusable item in the menu for keyboard users. */
  html.aic-layout-refactor body.aic-driver-mobile-nav .dashboard-mini-sidebar__mobile-close {
    display: block;
    position: absolute;
    width: 1px;
    min-width: 1px;
    height: 1px;
    min-height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    white-space: nowrap;
    clip-path: inset(50%);
    border: 0;
  }
  html.aic-layout-refactor body.aic-driver-mobile-nav .dashboard-mini-sidebar__mobile-close:focus-visible {
    position: relative;
    width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    margin: 8px 0 0;
    padding: 8px 10px;
    overflow: visible;
    white-space: normal;
    clip-path: none;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    outline: 2px solid var(--ui-color-focus, #2563eb);
    outline-offset: 2px;
    color: #111827;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
  }
}

/* The workflow is sticky at 901-1024px; only its fixed-sheet mode is layered. */
@media (max-width: 900px) {
  html.aic-layout-refactor body.aic-management-mobile-nav
  .system-error-workflow-backdrop:not([hidden]) { z-index: 2000; }
  html.aic-layout-refactor body.aic-management-mobile-nav
  .system-error-workflow.is-open { z-index: 2001; }
}

/* Error filters become a backdrop / bottom sheet at <=720px only. */
@media (max-width: 720px) {
  html.aic-layout-refactor body.aic-management-mobile-nav
  .system-error-filter-backdrop:not([hidden]) { z-index: 2000; }
  html.aic-layout-refactor body.aic-management-mobile-nav
  .system-error-filter-panel:not([hidden]) { z-index: 2001; }
}
