:root {
  --swiss-tg-safe-top: 0px;
  --swiss-tg-safe-right: 0px;
  --swiss-tg-safe-bottom: 0px;
  --swiss-tg-safe-left: 0px;
  --swiss-tg-content-safe-top: 0px;
  --swiss-tg-content-safe-right: 0px;
  --swiss-tg-content-safe-bottom: 0px;
  --swiss-tg-content-safe-left: 0px;
  --swiss-safe-top: max(
    env(safe-area-inset-top, 0px),
    var(--tg-safe-area-inset-top, 0px),
    var(--tg-content-safe-area-inset-top, 0px),
    var(--swiss-tg-safe-top),
    var(--swiss-tg-content-safe-top)
  );
  --swiss-safe-right: max(
    env(safe-area-inset-right, 0px),
    var(--tg-safe-area-inset-right, 0px),
    var(--tg-content-safe-area-inset-right, 0px),
    var(--swiss-tg-safe-right),
    var(--swiss-tg-content-safe-right)
  );
  --swiss-safe-bottom: max(
    env(safe-area-inset-bottom, 0px),
    var(--tg-safe-area-inset-bottom, 0px),
    var(--tg-content-safe-area-inset-bottom, 0px),
    var(--swiss-tg-safe-bottom),
    var(--swiss-tg-content-safe-bottom)
  );
  --swiss-safe-left: max(
    env(safe-area-inset-left, 0px),
    var(--tg-safe-area-inset-left, 0px),
    var(--tg-content-safe-area-inset-left, 0px),
    var(--swiss-tg-safe-left),
    var(--swiss-tg-content-safe-left)
  );
}

html.swiss-interaction-guard,
html.swiss-interaction-guard body {
  -webkit-text-size-adjust: 100%;
  touch-action: pan-x pan-y;
  overscroll-behavior-x: none;
}

html.swiss-interaction-guard body,
html.swiss-interaction-guard body *:not(input):not(textarea):not(select):not([contenteditable="true"]):not([contenteditable=""]) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html.swiss-interaction-guard input,
html.swiss-interaction-guard textarea,
html.swiss-interaction-guard select,
html.swiss-interaction-guard [contenteditable="true"],
html.swiss-interaction-guard [contenteditable=""] {
  -webkit-user-select: text;
  user-select: text;
}

html.swiss-interaction-guard img,
html.swiss-interaction-guard svg {
  -webkit-user-drag: none;
  user-drag: none;
}

html.swiss-interaction-guard button,
html.swiss-interaction-guard a,
html.swiss-interaction-guard [role="button"],
html.swiss-interaction-guard [data-action] {
  -webkit-tap-highlight-color: transparent;
}

html.telegram-mini-app,
html.telegram-mini-app body {
  width: 100%;
  height: var(--swiss-tg-viewport-height, var(--tg-viewport-stable-height, 100dvh));
  min-height: var(--swiss-tg-viewport-height, var(--tg-viewport-stable-height, 100dvh));
  margin: 0;
  background: #050505;
}

html.telegram-mini-app body {
  overflow-x: clip;
  overscroll-behavior-y: none;
}

/* Telegram overlays its own close/minimize controls above the Web App. Keep the
   site's header below that chrome, but do not add this space in a normal browser. */
html.telegram-mini-app {
  --swiss-tg-header-clearance: max(108px, calc(var(--swiss-safe-top) + 10px));
}

html.telegram-mini-app .site-shell {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--swiss-tg-viewport-height, var(--tg-viewport-stable-height, 100dvh));
  padding-top: 0;
  padding-right: var(--swiss-safe-right);
  padding-bottom: calc(var(--swiss-safe-bottom) + 14px);
  padding-left: var(--swiss-safe-left);
}

html.telegram-mini-app .telegram-miniapp-top-safe {
  position: sticky;
  z-index: 61;
  top: 0;
  width: 100%;
  height: var(--swiss-tg-header-clearance);
  pointer-events: none;
  background: #050505;
}

html.telegram-mini-app .header {
  top: var(--swiss-tg-header-clearance);
  z-index: 60;
}

html.telegram-mini-app .mobile-drawer {
  top: var(--swiss-tg-header-clearance);
  height: calc(100% - var(--swiss-tg-header-clearance));
}

/* Every fixed layer starts below Telegram's native controls. */
html.telegram-mini-app .mobile-menu-panel {
  padding-top: calc(var(--swiss-tg-header-clearance) + 18px);
  padding-right: calc(var(--swiss-safe-right) + 16px);
  padding-bottom: calc(var(--swiss-safe-bottom) + 20px);
  padding-left: calc(var(--swiss-safe-left) + 16px);
}

html.telegram-mini-app .modal-root {
  place-items: start center;
  overflow: auto;
  padding:
    calc(var(--swiss-tg-header-clearance) + 12px)
    calc(var(--swiss-safe-right) + 12px)
    calc(var(--swiss-safe-bottom) + 12px)
    calc(var(--swiss-safe-left) + 12px);
}

html.telegram-mini-app .modal-card {
  max-height: calc(
    var(--swiss-tg-viewport-height, var(--tg-viewport-stable-height, 100dvh))
    - var(--swiss-tg-header-clearance)
    - var(--swiss-safe-bottom)
    - 24px
  );
}

html.telegram-mini-app .cart-root::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  left: 0;
  height: var(--swiss-tg-header-clearance);
  pointer-events: none;
  background: #050505;
}

html.telegram-mini-app .cart-backdrop { z-index: 1; }

html.telegram-mini-app .cart-panel {
  z-index: 3;
  top: var(--swiss-tg-header-clearance);
  height: calc(100% - var(--swiss-tg-header-clearance));
}

html.telegram-mini-app .site-shell > main,
html.telegram-mini-app .site-shell > section {
  min-width: 0;
}

html.telegram-mini-app .cart-panel-head {
  padding-top: 16px;
  padding-right: calc(var(--swiss-safe-right) + 20px);
  padding-left: calc(var(--swiss-safe-left) + 20px);
}

html.telegram-mini-app .cart-scroll {
  padding-right: calc(var(--swiss-safe-right) + 18px);
  padding-bottom: calc(var(--swiss-safe-bottom) + 34px);
  padding-left: calc(var(--swiss-safe-left) + 18px);
}

html.telegram-mini-app .floating-cart {
  right: calc(var(--swiss-safe-right) + 13px);
  bottom: calc(var(--swiss-safe-bottom) + 13px);
}

html.telegram-mini-app .cart-toast,
html.telegram-mini-app .account-toast {
  right: calc(var(--swiss-safe-right) + 12px);
  bottom: calc(var(--swiss-safe-bottom) + 72px);
  left: calc(var(--swiss-safe-left) + 12px);
}

/* Internal screens keep the Telegram chrome clear without adding a second frame. */
html.telegram-mini-app .account-shell-v2 {
  min-height: calc(var(--swiss-tg-viewport-height, 100dvh) - var(--swiss-safe-top) - var(--swiss-safe-bottom));
}

html.telegram-mini-app .cabinet-v2 {
  min-height: calc(var(--swiss-tg-viewport-height, 100dvh) - var(--swiss-safe-top) - var(--swiss-safe-bottom));
  padding-top: 0;
  padding-bottom: calc(78px + var(--swiss-safe-bottom));
}

html.telegram-mini-app .cabinet-topbar {
  min-height: calc(63px + var(--swiss-safe-top));
  padding-top: calc(10px + var(--swiss-safe-top));
}

html.telegram-mini-app .cabinet-bottom-nav {
  min-height: calc(63px + var(--swiss-safe-bottom));
  padding-bottom: var(--swiss-safe-bottom);
}

html.telegram-mini-app .cabinet-address-editor {
  inset: calc(8px + var(--swiss-safe-top)) calc(10px + var(--swiss-safe-right)) calc(8px + var(--swiss-safe-bottom)) calc(10px + var(--swiss-safe-left));
}

html.telegram-mini-app .admin-app {
  min-height: calc(var(--swiss-tg-viewport-height, 100dvh) - var(--swiss-safe-top) - var(--swiss-safe-bottom));
}

.swiss-orientation-lock {
  display: none;
}

@media (orientation: landscape) and (max-height: 650px) and (pointer: coarse) {
  html.swiss-portrait-required body {
    overflow: hidden;
  }

  html.swiss-portrait-required .site-shell {
    filter: blur(8px);
    pointer-events: none;
  }

  html.swiss-portrait-required .swiss-orientation-lock,
  html.swiss-portrait-required .portrait-lock {
    position: fixed;
    z-index: 10000;
    inset: 0;
    display: grid;
    place-items: center;
    padding:
      max(24px, env(safe-area-inset-top, 0px))
      max(24px, env(safe-area-inset-right, 0px))
      max(24px, env(safe-area-inset-bottom, 0px))
      max(24px, env(safe-area-inset-left, 0px));
    color: #f4ead6;
    text-align: center;
    background:
      radial-gradient(circle at 50% 30%, rgba(240, 180, 55, .16), transparent 34%),
      rgba(0, 0, 0, .97);
  }

  .swiss-orientation-lock-card,
  .portrait-lock-card {
    display: grid;
    justify-items: center;
    width: min(420px, 100%);
    padding: 30px 26px;
    border: 1px solid rgba(219, 161, 51, .35);
    border-radius: 24px;
    background: rgba(12, 12, 11, .96);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
  }

  .swiss-orientation-lock-card strong,
  .portrait-lock-card strong {
    margin: 18px 0 8px;
    color: #fff;
    font-size: 21px;
  }

  .swiss-orientation-lock-card > span:last-child,
  .portrait-lock-card > span:last-child {
    color: #a9a49a;
    line-height: 1.55;
  }

  .swiss-orientation-lock-icon,
  .portrait-lock-icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border: 1px solid rgba(219, 161, 51, .45);
    border-radius: 50%;
    color: #efb343;
    font-size: 34px;
  }
}

@media (max-width: 560px) {
  html.telegram-mini-app .site-shell {
    padding-top: 0;
  }

  html.telegram-mini-app .cart-panel-head {
    min-height: 78px;
    padding-top: 12px;
    padding-right: calc(var(--swiss-safe-right) + 16px);
    padding-left: calc(var(--swiss-safe-left) + 16px);
  }

  html.telegram-mini-app .cart-scroll {
    padding-right: calc(var(--swiss-safe-right) + 14px);
    padding-bottom: calc(var(--swiss-safe-bottom) + 92px);
    padding-left: calc(var(--swiss-safe-left) + 14px);
  }
}
