/**
 * Overlay fit 7.8.7 — every leftover window, phone + desktop.
 * Phone: bottom sheet, safe-area, 48px actions.
 * Desktop: centered or side drawer, one scroll, sticky foot.
 */

:root {
  --bu-z-overlay: 20100;
  --bu-z-overlay-hi: 20140;
}

body.bu-mobile-detail-open,
body.bu-cal-open,
body.bu-notes-open,
body.bu-fleet-open,
body:has(#bu-tool-info:not([hidden])),
body:has(#bu-assign-sheet:not([hidden])),
body:has(#bu-fleet-modal:not([hidden])),
body:has(.bu-map-layers-dialog[open]),
body:has(.bu-cmd-dialog[open]) {
  overflow: hidden !important;
}
body.bu-notes-open::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 20135;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/* —— Calendar dimmer —— */
.bu-cal-scrim {
  position: fixed;
  inset: 0;
  z-index: 20130;
  border: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.bu-cal-scrim[hidden] {
  display: none !important;
}

/* —— Chat: phone bottom sheet, desktop side drawer —— */
.bu-chat-drawer-wrap {
  z-index: var(--bu-z-overlay-hi) !important;
}
@media (max-width: 899px) {
  .bu-chat-drawer-wrap {
    align-items: flex-end !important;
    justify-content: stretch !important;
  }
  .bu-chat-drawer {
    width: 100% !important;
    max-width: none !important;
    height: min(94dvh, 860px) !important;
    max-height: 94dvh !important;
    border-radius: 20px 20px 0 0 !important;
    border-left: 0 !important;
    animation: bu-sheet-up 0.22s ease;
  }
  .bu-chat-form input,
  .bu-chat-form .bu-btn {
    min-height: 46px;
  }
}
@keyframes bu-sheet-up {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

/* —— Objavi chooser —— */
#bu-post.bu-chat.is-open:not([hidden]) {
  z-index: var(--bu-z-overlay-hi) !important;
}

/* —— Notes —— */
.bu-notes {
  z-index: var(--bu-z-overlay-hi) !important;
}
@media (max-width: 899px) {
  .bu-notes {
    inset: auto 0 0 !important;
    top: auto !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-height: min(78dvh, 560px);
    border-radius: 20px 20px 0 0 !important;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .bu-notes-list {
    max-height: min(52dvh, 380px);
  }
}

/* —— Calendar —— */
.bu-cal {
  position: fixed !important;
  z-index: 20150 !important;
  width: min(320px, calc(100vw - 16px));
}
.bu-cal[hidden] { display: none !important; }
@media (max-width: 899px) {
  .bu-cal {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-height: min(82dvh, 560px);
    border-radius: 20px 20px 0 0 !important;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    box-shadow: 0 -16px 48px rgba(15, 23, 42, 0.22) !important;
  }
  .bu-cal-day {
    height: 42px !important;
    font-size: 15px;
  }
  .bu-cal-foot {
    display: flex;
    gap: 8px;
  }
  .bu-cal-foot .bu-btn {
    min-height: 46px;
    flex: 1;
  }
}

/* —— Geo / dropdowns —— */
.bu-geo-list {
  z-index: 20110 !important;
  max-height: min(48dvh, 320px);
}

/* —— Fleet (keeps inner backdrop) —— */
.bu-fleet-modal {
  z-index: var(--bu-z-overlay) !important;
}
@media (max-width: 899px) {
  .bu-fleet-modal:not([hidden]) {
    display: flex !important;
    align-items: flex-end;
    justify-content: center;
    padding: 0 !important;
  }
  .bu-fleet-modal-sheet {
    width: 100%;
    max-height: min(92dvh, 820px);
    border-radius: 20px 20px 0 0 !important;
  }
}

/* —— Tool info —— */
.bu-tool-info-backdrop {
  z-index: var(--bu-z-overlay) !important;
}
@media (max-width: 899px) {
  .bu-tool-info-backdrop:not([hidden]) {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .bu-tool-info-sheet {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 720px);
    border-radius: 20px 20px 0 0;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .bu-tool-info-actions .bu-btn {
    min-height: 46px;
  }
}

/* —— Native dialogs: map layers + command catalog —— */
.bu-map-layers-dialog[open],
.bu-cmd-dialog[open] {
  position: fixed;
  z-index: var(--bu-z-overlay);
  border: 0;
  padding: 0;
  background: transparent;
}
.bu-map-layers-dialog::backdrop,
.bu-cmd-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}
@media (max-width: 899px) {
  .bu-map-layers-dialog[open],
  .bu-cmd-dialog[open] {
    inset: auto 0 0 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: 0;
  }
  .bu-map-layers-card,
  .bu-cmd-card {
    width: 100%;
    max-height: 92dvh;
    overflow: auto;
    border-radius: 20px 20px 0 0 !important;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .bu-cmd-card {
    min-height: 0 !important;
  }
}
@media (min-width: 900px) {
  .bu-map-layers-dialog[open],
  .bu-cmd-dialog[open] {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(480px, 94vw);
    max-height: min(86dvh, 720px);
    margin: 0;
  }
  .bu-map-layers-card,
  .bu-cmd-card {
    border-radius: 20px !important;
    max-height: min(86dvh, 720px);
    overflow: auto;
  }
}

/* —— Assign driver sheet —— */
.bu-assign-sheet {
  position: fixed !important;
  z-index: var(--bu-z-overlay-hi) !important;
}
.bu-assign-sheet[hidden] { display: none !important; }
@media (max-width: 899px) {
  .bu-assign-sheet {
    inset: auto 0 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }
}
@media (min-width: 900px) {
  .bu-assign-sheet {
    inset: auto !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    width: min(420px, calc(100vw - 32px)) !important;
    border-radius: 18px !important;
    padding: 20px !important;
  }
}

/* —— Phone detail / fleet sheets —— */
.bu-mobile-detail-sheet,
.bu-mobile-backdrop,
.bu-mobile-fleet-sheet {
  z-index: var(--bu-z-overlay) !important;
}
.bu-mobile-detail-sheet {
  max-height: min(92dvh, 820px) !important;
}
.bu-mobile-detail-sheet footer .bu-btn,
.bu-mobile-detail-sheet footer a.bu-btn {
  min-height: 48px;
  width: 100%;
  justify-content: center;
}
.bu-mobile-detail-sheet footer .bu-dpro-contact-grid {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 899px) {
  .bu-mshell-drawer-bg { z-index: 20080 !important; }
  .bu-mshell-drawer { z-index: 20090 !important; }
}

.bu-veh-drop-menu,
.bu-live-menu {
  z-index: 20105 !important;
}
.bu-live-pop {
  z-index: 20120 !important;
}
.bu-lemon-lock {
  z-index: 40000 !important;
}

@media (max-width: 899px) {
  .bu-dpro-profile-actions.bu-dpro-contact-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .bu-dpro-profile-actions .bu-btn {
    min-height: 48px;
    justify-content: center;
    font-size: 13px;
  }
  .bu-detail-modal-head .bu-detail-x,
  .bu-post-confirm-x,
  .bu-vip-x,
  .bu-fleet-modal-x {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bu-chat-drawer,
  .bu-notes,
  .bu-cal {
    animation: none !important;
  }
}
