/* TCHAHIT V116 — keyboard, visible viewport and safe areas: the shared rules.
 * Loaded once by <KeyboardViewport /> (root layout); the variables and the
 * data-kb-* marks are written by lib/keyboard-viewport.ts.
 *
 *   --tc-safe-top / -bottom / -left / -right   status bar, home indicator, cut-outs.
 *       env() on iPhone and recent Android; the --safe-area-inset-* variables
 *       are the same values injected by the Android app on older WebViews.
 *   --kb-inset   px hidden behind the keyboard (0 when the page itself is resized)
 *   --vvh        visible height while the keyboard is open (use var(--vvh, 100dvh))
 *   html[data-kb="open"]   a field is focused and the keyboard is up
 */
:root {
  --tc-safe-top: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
  --tc-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
  --tc-safe-left: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
  --tc-safe-right: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
  --kb-inset: 0px;
  --vv-top: 0px;
}

/* 1. Floating bars step aside while typing: they would ride on top of the
      keyboard and cover the field or the conversation (fixed boxes: no reflow).
      A bar that holds the focused field stays. */
html[data-kb="open"] :is(.tc-tabbar, .tc-netbar, .mobile-nav, .admin-tabbar, .cm-tabbar, .mm-tabbar, .assistant-launcher, .pos-helper-launcher, .sound-unlock, .store-mobile-action, .app-download-sticky, .pos-cart-jump, .qr-checkout, .public-map-locate, .pwa-toast, .tc-webtabs, .cf-dock):not(:focus-within) {
  visibility: hidden !important;
  pointer-events: none !important;
}

/* 2. The window that holds the focused field always fits the visible height;
      what does not fit scrolls inside it, the field stays above the keyboard. */
html[data-kb="open"] [data-kb-card] {
  max-height: calc(var(--vvh, 100dvh) - var(--kb-pad, 0px) - var(--tc-safe-top) - 8px) !important;
  max-block-size: calc(var(--vvh, 100dvh) - var(--kb-pad, 0px) - var(--tc-safe-top) - 8px) !important;
  min-height: 0 !important;
  min-block-size: 0 !important;
  scroll-padding-block: 12px;
}
html[data-kb="open"] [data-kb-card][data-kb-scroll] {
  overflow-y: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
html[data-kb="open"] [data-kb-layer="scrim"] { overscroll-behavior: contain; }

/* 3. Keyboards that cover the page instead of resizing it (iPhone): the
      backdrop / drawer shrinks to the visible area, a floating box is lifted. */
html[data-kb-overlay] [data-kb-layer="scrim"],
html[data-kb-overlay] [data-kb-layer="panel"] {
  top: var(--vv-top, 0px) !important;
  bottom: auto !important;
  inset-block: var(--vv-top, 0px) auto !important;
  height: var(--vvh) !important;
  block-size: var(--vvh) !important;
  min-height: 0 !important;
  max-height: var(--vvh) !important;
}
html[data-kb="open"] [data-kb-layer="float"] { translate: 0 calc(-1 * var(--kb-shift, 0px)); }
@media (prefers-reduced-motion: no-preference) {
  html[data-kb="open"] [data-kb-layer="float"] { transition: translate 160ms ease-out; }
}

/* 4. Fields inside scroll areas keep a margin when the browser reveals them. */
:where(input, textarea, select, [contenteditable="true"]) { scroll-margin-block: 16px; }
