/**
 * iPhone 12+ / narrow viewports: text controls ≥16px to prevent Safari zoom on focus.
 * Loaded AFTER other app CSS. Beats most inline font-size on inputs.
 *
 * Dense data tables: keep 16px text but allow shorter rows (no 44px min-height).
 * Textareas: 16px font only — do not force min-height (pages set their own).
 *
 * Body-level overlays often use their own backdrop class (not `.backdrop`).
 */

@media (max-width: 767px) {
  .app-shell input[type="text"],
  .app-shell input[type="email"],
  .app-shell input[type="tel"],
  .app-shell input[type="url"],
  .app-shell input[type="search"],
  .app-shell input[type="password"],
  .app-shell input[type="number"],
  .app-shell input[type="date"],
  .app-shell input[type="time"],
  .app-shell input[type="datetime-local"],
  .app-shell textarea,
  .app-shell select,
  .backdrop input[type="text"],
  .backdrop input[type="email"],
  .backdrop input[type="tel"],
  .backdrop input[type="url"],
  .backdrop input[type="search"],
  .backdrop input[type="password"],
  .backdrop input[type="number"],
  .backdrop input[type="date"],
  .backdrop input[type="time"],
  .backdrop input[type="datetime-local"],
  .backdrop textarea,
  .backdrop select,
  #composerModal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  #composerModal textarea,
  #composerModal select,
  .composer-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .composer-modal textarea,
  .composer-modal select,
  .sched-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .sched-modal textarea,
  .sched-modal select,
  #emailComposerContent input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  #emailComposerContent textarea,
  #emailComposerContent select,
  .email-composer-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .email-composer-modal textarea,
  .email-composer-modal select,
  .form-builder-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .form-builder-modal textarea,
  .form-builder-modal select,
  .fb-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .fb-modal textarea,
  .fb-modal select,
  #portal-app input[type="text"],
  #portal-app input[type="email"],
  #portal-app input[type="tel"],
  #portal-app input[type="url"],
  #portal-app input[type="search"],
  #portal-app input[type="password"],
  #portal-app input[type="number"],
  #portal-app input[type="date"],
  #portal-app input[type="time"],
  #portal-app input[type="datetime-local"],
  #portal-app textarea,
  #portal-app select,
  .pay-public-shell input[type="text"],
  .pay-public-shell input[type="email"],
  .pay-public-shell input[type="tel"],
  .pay-public-shell input[type="url"],
  .pay-public-shell input[type="search"],
  .pay-public-shell input[type="password"],
  .pay-public-shell input[type="number"],
  .pay-public-shell textarea,
  .pay-public-shell select,
  .book-page input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .book-page textarea,
  .book-page select,
  .container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .container textarea,
  .container select,
  .authPage input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .authPage textarea,
  .authPage select,
  .signup-right input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .signup-right textarea,
  .signup-right select,
  .form-container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .form-container textarea,
  .form-container select,
  .pay-link-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .pay-link-modal textarea,
  .pay-link-modal select,
  .deal-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .deal-modal-backdrop textarea,
  .deal-modal-backdrop select,
  .deal-doctor-modal-panel input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .deal-doctor-modal-panel textarea,
  .deal-doctor-modal-panel select,
  .td-qs-settings-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .td-qs-settings-backdrop textarea,
  .td-qs-settings-backdrop select,
  .ai-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .ai-modal-backdrop textarea,
  .ai-modal-backdrop select,
  .td-event-reminder-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .td-event-reminder-modal-backdrop textarea,
  .td-event-reminder-modal-backdrop select,
  .detail-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .detail-modal-backdrop textarea,
  .detail-modal-backdrop select,
  .fb-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .fb-modal-backdrop textarea,
  .fb-modal-backdrop select,
  .cmd-palette-overlay input[type="text"],
  .cmd-palette-input {
    font-size: 16px !important;
  }

  /* Rich text / contenteditable — same iOS zoom rule as inputs */
  .app-shell .ql-editor,
  .backdrop .ql-editor,
  #composerModal .ql-editor,
  .composer-modal .ql-editor,
  #emailComposerContent .ql-editor,
  .email-composer-modal .ql-editor,
  .app-shell [contenteditable="true"],
  .backdrop [contenteditable="true"],
  #composerModal [contenteditable="true"],
  .composer-modal [contenteditable="true"],
  #emailComposerContent [contenteditable="true"],
  .email-composer-modal [contenteditable="true"] {
    font-size: 16px !important;
  }

  /* Comfortable tap targets — inputs & selects only (not textarea) */
  .app-shell input[type="text"],
  .app-shell input[type="email"],
  .app-shell input[type="tel"],
  .app-shell input[type="url"],
  .app-shell input[type="search"],
  .app-shell input[type="password"],
  .app-shell input[type="number"],
  .app-shell input[type="date"],
  .app-shell input[type="time"],
  .app-shell input[type="datetime-local"],
  .app-shell select,
  .backdrop input[type="text"],
  .backdrop input[type="email"],
  .backdrop input[type="tel"],
  .backdrop input[type="url"],
  .backdrop input[type="search"],
  .backdrop input[type="password"],
  .backdrop input[type="number"],
  .backdrop input[type="date"],
  .backdrop input[type="time"],
  .backdrop input[type="datetime-local"],
  .backdrop select,
  #composerModal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  #composerModal select,
  .composer-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .composer-modal select,
  .sched-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .sched-modal select,
  #emailComposerContent input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  #emailComposerContent select,
  .email-composer-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .email-composer-modal select,
  .form-builder-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .form-builder-modal select,
  .fb-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .fb-modal select,
  #portal-app input[type="text"],
  #portal-app input[type="email"],
  #portal-app input[type="tel"],
  #portal-app input[type="url"],
  #portal-app input[type="search"],
  #portal-app input[type="password"],
  #portal-app input[type="number"],
  #portal-app input[type="date"],
  #portal-app input[type="time"],
  #portal-app input[type="datetime-local"],
  #portal-app select,
  .pay-public-shell input[type="text"],
  .pay-public-shell input[type="email"],
  .pay-public-shell input[type="tel"],
  .pay-public-shell input[type="url"],
  .pay-public-shell input[type="search"],
  .pay-public-shell input[type="password"],
  .pay-public-shell input[type="number"],
  .pay-public-shell select,
  .book-page input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .book-page select,
  .container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .container select,
  .authPage input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .authPage select,
  .signup-right input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .signup-right select,
  .form-container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .form-container select,
  .pay-link-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .pay-link-modal select,
  .deal-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .deal-modal-backdrop select,
  .deal-doctor-modal-panel input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .deal-doctor-modal-panel select,
  .td-qs-settings-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .td-qs-settings-backdrop select,
  .ai-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .ai-modal-backdrop select,
  .td-event-reminder-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .td-event-reminder-modal-backdrop select,
  .detail-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .detail-modal-backdrop select,
  .fb-modal-backdrop input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
  .fb-modal-backdrop select,
  .cmd-palette-overlay input[type="text"],
  .cmd-palette-input {
    min-height: 44px !important;
    box-sizing: border-box !important;
  }

  /*
   * Horizontal containment: stops accidental full-page sideways scroll on long
   * unbroken strings / legacy fixed widths. Intentional scrollers use dedicated
   * overflow-x: auto regions (see check-mobile-overflow.mjs allowlist).
   */
  html {
    overflow-x: hidden;
  }
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Deal workspace modal (not line-item sheet): safe-area inset + cap width */
  .deal-modal-backdrop:not(.dli-modal-backdrop) {
    box-sizing: border-box;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
      max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }

  .deal-modal-backdrop:not(.dli-modal-backdrop) .deal-modal {
    width: 100%;
    max-width: min(600px, 100%);
    box-sizing: border-box;
  }

  /* Tables: 16px font, do not force tall rows */
  .app-shell .pipe-list-table input,
  .app-shell .pipe-list-table textarea,
  .app-shell .pipe-list-table select,
  .app-shell .contact-list-table input,
  .app-shell .contact-list-table textarea,
  .app-shell .contact-list-table select,
  .backdrop .pipe-list-table input,
  .backdrop .pipe-list-table textarea,
  .backdrop .pipe-list-table select,
  #portal-app .pipe-list-table input,
  #portal-app .pipe-list-table textarea,
  #portal-app .pipe-list-table select,
  .deal-modal-backdrop .pipe-list-table input,
  .deal-modal-backdrop .pipe-list-table textarea,
  .deal-modal-backdrop .pipe-list-table select,
  .fb-modal-backdrop .pipe-list-table input,
  .fb-modal-backdrop .pipe-list-table textarea,
  .fb-modal-backdrop .pipe-list-table select {
    min-height: unset !important;
    font-size: 16px !important;
  }
}
