/* T320 — one overlay grammar and one global layer law. */
.interaction-scrim {
  position: fixed;
  z-index: var(--cc-z-modal-scrim);
  top: var(--cc-visual-viewport-top, 0px);
  right: 0;
  left: 0;
  display: none;
  height: var(--cc-visual-viewport-height, 100dvh);
  background: var(--overlay-bg);
}

.interaction-scrim.open,
body[data-overlay-depth]:not([data-overlay-depth="0"]) > .interaction-scrim {
  display: block;
}
.interaction-scrim[data-layer="drawer"] { z-index: var(--cc-z-drawer-scrim); }
body:has([data-navigation-drawer].open) > .interaction-scrim {
  z-index: var(--cc-z-drawer-scrim);
}

.overlay {
  z-index: calc(var(--cc-z-modal) + var(--cc-overlay-depth, 0));
  background: transparent;
}

.settings-drawer[data-sheet-type] {
  z-index: calc(var(--cc-z-modal) + var(--cc-overlay-depth, 0));
}

[data-navigation-drawer] { z-index: var(--cc-z-drawer); }
.cc-sheet-thumb-close { display: none; }

@media (max-width: 820px) {
  body[data-overlay-depth]:not([data-overlay-depth="0"]) { overflow: hidden; }

  .tab-bar,
  [data-mobile-bottom-bar] {
    position: relative;
    z-index: var(--cc-z-bar);
  }

  .overlay[data-sheet-type] { box-sizing: border-box; padding: 0 !important; }
  .overlay[data-sheet-type="full"] { align-items: stretch; justify-content: stretch; }

  .overlay[data-sheet-type="full"] > [role="dialog"],
  .settings-drawer[data-sheet-type="full"] {
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    height: var(--cc-visual-viewport-height, 100dvh) !important;
    max-height: none !important;
    margin: 0 !important;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: hidden;
  }

  .overlay[data-sheet-thumb-close="true"] > [role="dialog"],
  .settings-drawer[data-sheet-thumb-close="true"] {
    padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
  }

  .overlay[data-sheet-type="full"] > [role="dialog"] > .panel-header,
  .settings-drawer[data-sheet-type="full"] > .panel-header { flex: 0 0 auto; }

  .overlay[data-sheet-type="full"] > [role="dialog"] > :not(.panel-header):not(.cc-sheet-thumb-close),
  .settings-drawer[data-sheet-type="full"] > :not(.panel-header):not(.cc-sheet-thumb-close) {
    min-height: 0;
  }

  .cc-sheet-thumb-close {
    position: absolute;
    z-index: var(--cc-z-popover);
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    bottom: max(0.7rem, env(safe-area-inset-bottom, 0px));
    display: inline-flex;
    min-width: 5.5rem;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    border-color: var(--ui-line-strong);
    background: var(--ui-raised);
    box-shadow: var(--ui-shadow-sm);
  }

  .overlay[data-sheet-type="full"] [data-sheet-dismiss],
  .overlay[data-sheet-type="full"] [id$="-cancel"],
  .overlay[data-sheet-type="full"] .close,
  .settings-drawer[data-sheet-type="full"] .close {
    min-width: 44px;
    min-height: 44px;
  }

  .overlay[data-sheet-type="bottom"] { align-items: flex-end; justify-content: center; }

  .overlay[data-sheet-type="bottom"] > [role="dialog"] {
    box-sizing: border-box;
    width: 100vw !important;
    max-width: none !important;
    height: auto !important;
    max-height: min(78dvh, calc(var(--cc-visual-viewport-height, 100dvh) - 3rem));
    margin: 0 !important;
    padding: 1.6rem max(1.1rem, env(safe-area-inset-right, 0px))
      max(1.25rem, env(safe-area-inset-bottom, 0px))
      max(1.1rem, env(safe-area-inset-left, 0px));
    border-width: 1px 0 0 !important;
    border-radius: 1.15rem 1.15rem 0 0 !important;
    box-shadow: 0 -1.5rem 4rem var(--ui-shadow-color) !important;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .overlay[data-sheet-type="bottom"] > [role="dialog"]::before {
    content: "";
    display: block;
    width: 2.8rem;
    height: 0.25rem;
    margin: -0.85rem auto 1rem;
    border-radius: 999px;
    background: var(--ui-line-strong);
  }

  .overlay[data-sheet-type="bottom"] button { min-width: 44px; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay[data-sheet-type] > [role="dialog"] { scroll-behavior: auto; }
}
