/* ══════════════════════════════════════════════════════════════════
   EHB Dialer — phone layout (Stage 1 of the "basic app").
   Everything here is scoped to max-width 640px so desktop/tablet CSS in
   widget.css is completely untouched. Loaded AFTER widget.css.
   ══════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* 100dvh tracks the iOS Safari collapsing URL bar; 100vh leaves the
     bottom tab bar hidden behind it. */
  body { height: 100dvh; }

  /* ── No sideways panning ──
     .tab-content.active centers its children, so a single too-wide child
     (the 4 focus chips don't wrap) let the whole page pan horizontally
     and cut every card off at the left edge. Clamp it at the container
     and fix the known wide children. */
  .tab-content { overflow-x: hidden; padding: 12px 10px; }
  .card { min-width: 0; }
  .focus-chips { flex-wrap: wrap; }
  .tab-content img, .tab-content table { max-width: 100%; }

  /* ── Bottom tab bar ──
     body is a flex column, so order:10 moves .tabs below the tab content
     without any position:fixed overlap headaches. */
  .tabs {
    order: 10;
    border-bottom: none;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    padding: 2px 2px calc(2px + env(safe-area-inset-bottom));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 12px 3px 10px;
    font-size: 10.5px;
    border-bottom: none;
    border-top: 2px solid transparent;
    flex: 1 0 auto;
    min-width: 52px;
    white-space: nowrap;
  }
  .tab.active { border-top-color: var(--accent); background: var(--accent-soft); }

  /* ── Status bar: compact, wraps to two short rows ── */
  #status-bar { flex-wrap: wrap; gap: 6px; row-gap: 6px; padding: 7px 10px; }
  #status-text { flex: 0 1 auto; font-size: 11px; }
  #live-call-badge { margin-left: 0; }
  #sip-badge { margin-left: 0; }
  /* Discovery checklist is a desktop coaching panel — off the phone.
     (!important: the button carries an inline display:inline-flex) */
  #btn-discovery-pill { display: none !important; }

  /* ── Call controls ──
     The full 9-button row buried the page under dead buttons. On the
     phone, a button you can't press right now doesn't exist: disabled
     controls vanish and pop in when a call makes them live. Idle screen
     keeps just Transcript + Log out in one slim row. */
  #call-controls-bar { gap: 7px; padding: 7px 10px; }
  #call-controls-bar .btn { padding: 10px 12px; font-size: 13px; min-height: 44px; flex: 1 1 auto; }
  #call-controls-bar .btn:disabled { display: none; }
  #call-controls-bar .btn:not(:disabled) { opacity: 1; }
  .ccb-label { display: none; }
  #call-controls-bar .tabs-clock { display: none; }
  #btn-logout { margin-left: 0 !important; flex: 0 1 auto; }
  /* Keyboard hints are pointless on touch. (widget.css's own hide-under-1100px
     rule loses to the later `.shortcuts { display:flex }` — needs the extra
     specificity of the #id prefix to actually win.) */
  #call-controls-bar .ccb-shortcuts { display: none; }

  /* ── Dialer tab ──
     #tab-dialer IS the flex-grown .tab-content, so as a GRID its height is
     pinned to the leftover viewport (~400px) and the three auto rows get
     squeezed into equal thirds — each column then paints over the row below
     it. display:block restores normal stacking; .tab-content still scrolls. */
  #tab-dialer.active { display: block; height: auto; }
  #tab-dialer.active > .dialer-col { max-height: none; overflow: visible; }
  #tab-dialer.active > .dialer-col + .dialer-col { margin-top: 14px; }

  /* 16px stops iOS Safari from auto-zooming the page on input focus */
  input, select, textarea { font-size: 16px !important; }

  /* Outcome buttons are the most-tapped thing on a call */
  .dispositions { gap: 8px; }
  .dispositions .btn, .dispositions button { min-height: 48px; font-size: 13px; }

  /* Drawers become full-screen sheets */
  .lead-drawer { width: 100vw; max-width: 100vw; right: -100vw; }
  .lead-drawer.open { right: 0; }
  .transcript-drawer { width: 100vw; right: -100vw; }
  .transcript-drawer.open { right: 0; }

  /* Inbound-call pop: keep clear of the notch */
  #screen-pop { top: calc(8px + env(safe-area-inset-top)); }

  /* Login screen */
  .login-card { width: calc(100vw - 32px); }

  /* The Keypad tab has its own embedded Mute / End Call, so the global
     control bar up top is pure duplication there — hide it (switchTab
     toggles the body class). Other tabs keep the bar during calls. */
  body.kp-tab-active #call-controls-bar { display: none; }

  /* ── Keypad tab (phone-only manual dialer) ──
     The tab button ships with an inline display:none so desktop never sees
     it; !important flips it on here. */
  .tabs .kp-mobile-only { display: block !important; }
  #tab-keypad.active {
    display: flex; flex-direction: column; align-items: center;
    justify-content: flex-end; gap: 0; padding: 10px 16px 14px;
  }
  #tab-keypad.active > * { width: 100%; max-width: 330px; }

  .kp-match { text-align: center; min-height: 40px; }
  .kp-match-name { font-size: 17px; font-weight: 600; }
  .kp-match-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .kp-number {
    text-align: center; font-family: var(--mono); font-size: 32px;
    letter-spacing: 0.5px; min-height: 46px; line-height: 46px;
    white-space: nowrap; overflow: hidden;
  }
  .kp-cid-row {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin: 2px 0 14px;
  }
  .kp-cid-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
  .kp-cid-row select {
    flex: 0 1 auto; max-width: 220px; background: var(--surface);
    border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: 6px 8px;
  }

  .kp-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 12px; justify-items: center;
  }
  .kp-key {
    width: 100%; max-width: 74px; aspect-ratio: 1; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); font-size: 26px; font-weight: 500; line-height: 1;
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
    user-select: none; -webkit-user-select: none;
  }
  .kp-key small { font-size: 9px; letter-spacing: 1.5px; color: var(--muted); font-weight: 600; }
  .kp-key:active { background: var(--surface-2); transform: scale(0.94); }

  .kp-actions {
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    align-items: center; justify-items: center; margin-top: 14px;
  }
  #kp-call {
    grid-column: 2; width: 68px; height: 68px; border-radius: 50%;
    background: var(--success); border: none; font-size: 28px; color: #fff;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }
  #kp-call:disabled { opacity: 0.35; }
  #kp-call:active { transform: scale(0.94); }
  #kp-back {
    grid-column: 3; background: none; border: none; color: var(--muted);
    font-size: 24px; padding: 14px; visibility: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  /* in-call header + actions (pad stays visible: keys send DTMF for IVRs) */
  .kp-ic-head { text-align: center; margin-bottom: 10px; }
  .kp-ic-state { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
  .kp-ic-name { font-size: 24px; font-weight: 700; margin-top: 4px; }
  .kp-ic-sub { font-size: 13px; color: var(--muted); margin-top: 2px; min-height: 16px; }
  .kp-ic-number { font-family: var(--mono); font-size: 14px; color: var(--muted); margin-top: 4px; }
  .kp-ic-timer { font-family: var(--mono); font-size: 16px; color: var(--success); margin-top: 4px; min-height: 20px; }
  .kp-dtmf-sent {
    font-family: var(--mono); font-size: 13px; color: var(--accent);
    min-height: 18px; letter-spacing: 2px; margin-top: 2px;
  }
  .kp-ic-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
  .kp-ic-btn {
    min-height: 54px; border-radius: 14px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 15px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    -webkit-tap-highlight-color: transparent;
  }
  .kp-ic-btn.kp-on { background: var(--warning); border-color: transparent; color: #000; }
  .kp-ic-hangup { background: var(--danger); border-color: transparent; color: #fff; font-weight: 600; }
}
