/* Trybely phone — iOS/Android taps, PWA standalone, locked desktop frame.
   Loaded after the app CSS. Uses !important only where React inline styles
   would otherwise win (desktop frame dimensions). */

/* ── Touch: every phone control responds on the first tap ─────────────── */
button, [role="button"], [role="switch"], .tkp button, .tb-phone-key, .tb-phone-call,
.tb-phone-icon-btn, .tb-phone-pill, .tb-phone-tool, .tcs-act, .tcs-pill, .tcs-chip,
.tcs-pad button, [data-testid^="phone-"], [data-testid="softphone-online"],
[data-testid="incoming-call-answer"], [data-testid="incoming-call-decline"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(217, 162, 124, 0.18);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
@media (hover: none) {
  .tkp button:hover { background: var(--tb-surface, #fff); }
  .tcs-menu button:hover { background: transparent; }
}

/* ── Safe area + full-screen standalone (installed PWA / Home Screen) ─── */
html.tb-standalone,
html.tb-standalone body {
  overscroll-behavior: none;
  height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}
@media (display-mode: standalone), (display-mode: fullscreen) {
  html, body {
    height: 100%;
    overscroll-behavior: none;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
  }
  /* No leftover browser-chrome padding; the OS already insets the webview. */
  html.tb-standalone body { margin: 0; }
}

/* ── Mobile: keep Call / keypad clear of floating chrome ──────────────── */
@media (max-width: 767px) {
  /* Swipe-screen dots sat at bottom: calc(safe-area + 76px) — right on the Call button. */
  [data-testid="tier-swipe-dots"] {
    bottom: auto !important;
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 50;
  }
  /* Quick Guide launcher: lift above the tab bar and Call button. */
  .tqg-root {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 104px) !important;
  }
  /* Home button already lifts itself; keep it off the keypad column. */
  .trybely-home-btn--bottom-left {
    left: max(12px, env(safe-area-inset-left, 0px));
  }
  .tb-phone-shell, .tb-phone-home-pane, [data-testid="phone-panel"][data-layout="pane"] {
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }
  [data-testid="phone-panel"],
  [data-testid="phone-screen"],
  [data-testid="phone-keypad"],
  .tb-phone-shell,
  .tb-phone-keypad,
  #trybely-call-screen,
  [data-call-screen-slot],
  [data-testid="softphone-keypad"],
  .tkp,
  #padCard,
  [data-testid="incoming-call-alert"] {
    touch-action: manipulation;
  }
}

/* ── Desktop: LOCKED phone-shaped frame (iPhone 14 logical 390×844) ───── */
@media (min-width: 768px) {
  /* Swipe-dots are a phone gesture; hide on desktop so they don't sit on the frame. */
  [data-testid="tier-swipe-dots"] { display: none !important; }
  [data-testid="phone-screen"],
  [data-testid="tb-phone-frame"] {
    width: 390px !important;
    min-width: 390px !important;
    max-width: 390px !important;
    height: 844px !important;
    min-height: 844px !important;
    max-height: 844px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    margin: 24px auto !important;
    box-sizing: border-box !important;
    border-radius: 44px !important;
    flex-shrink: 0 !important;
    position: relative !important;
  }
  [data-testid="phone-screen"] > [data-testid="phone-topbar"] {
    flex: 0 0 auto;
  }
  [data-testid="phone-screen"] > *:not([data-testid="phone-topbar"]):not([data-call-screen-slot]):not(#trybely-call-screen) {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  /* In-place call screen fills the same frame — never a second, different size. */
  [data-testid="phone-screen"] [data-call-screen-slot],
  [data-testid="phone-screen"] #trybely-call-screen,
  [data-testid="tb-phone-frame"] #trybely-call-screen {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    padding: max(12px, env(safe-area-inset-top, 0px)) 14px 16px !important;
    border-radius: 44px !important;
    overflow: auto !important;
    box-sizing: border-box !important;
  }
  /* Call screen that mounted on document.body (no phone view on screen):
     dock it to the same 390×844 frame so the page does not reflow. */
  body > #trybely-call-screen:not([data-compact="true"]) {
    inset: auto !important;
    width: 390px !important;
    min-width: 390px !important;
    max-width: 390px !important;
    height: 844px !important;
    min-height: 844px !important;
    max-height: 844px !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    border-radius: 44px !important;
    overflow: auto !important;
    padding: 16px !important;
    box-sizing: border-box !important;
  }
  body > #trybely-call-screen[data-compact="true"] {
    transform: none !important;
    width: 390px !important;
    max-width: 390px !important;
    left: 50% !important;
    margin-left: -195px;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }
  /* Standalone softphone page: same locked frame. */
  body.tb-desktop-phone-page:not(.embed) .ps-main,
  body.tb-desktop-phone-page:not(.embed) #padCard {
    width: 390px;
    max-width: 390px;
    margin-left: auto;
    margin-right: auto;
  }
  body.tb-desktop-phone-page:not(.embed) .ps-main {
    height: 844px;
    max-height: 844px;
    overflow: auto;
    border-radius: 44px;
    box-sizing: border-box;
    border: 1px solid rgba(217, 162, 124, 0.28);
    background: #0D0E10;
  }
}

/* ── PWA “Add to Home Screen” hint ────────────────────────────────────── */
.tb-pwa-hint {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: max(12px, env(safe-area-inset-left, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  max-width: 420px;
  margin: 0 auto;
  z-index: 80;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 16px;
  background: #111827;
  color: #F7F5F0;
  border: 1px solid #C8A24A;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.35);
  font: 500 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.tb-pwa-hint h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: #F7F5F0;
}
.tb-pwa-hint p { margin: 0; font-size: 13px; color: #E5E7EB; line-height: 1.45; }
.tb-pwa-hint-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tb-pwa-hint-actions button, .tb-pwa-hint-dismiss {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 0;
  font: 650 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
.tb-pwa-hint-install { background: #C8A24A; color: #111827; }
.tb-pwa-hint-dismiss {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: #F7F5F0;
  font-size: 20px;
  line-height: 1;
}
html.tb-standalone .tb-pwa-hint,
@media (display-mode: standalone), (display-mode: fullscreen) {
  .tb-pwa-hint { display: none !important; }
}

/* Keypad shared widget — 44px targets, no sticky hover on touch */
.tkp button {
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
