/* public/css/auth-phone.css
   The screens a person sees before signing in (login, register, the invitation sign-ups, forgot and
   reset password, MFA setup and verify, single sign-on completion, pending, document verification),
   at phone size. Nobody is signed in on these pages, so there is no organization and no
   features.phoneLayout to read: they are responsive for everyone, by window size alone, and do not
   use html.phone-mode or the bottom bar.

   Desktop must not change by a pixel, so every rule sits inside one of exactly two media queries,
   the phone layout's own thresholds (PhoneMode.MAX_WIDTH = 599, SIDE_MAX_HEIGHT = 500):
     (max-width: 599px)                          a phone held upright
     (max-height: 500px) and (pointer: coarse)   a phone on its side
   Nothing else may sit at the top level of this file (tests/authPhoneCss.test.js). Each page links
   it last, after its own <style> block, so at equal specificity these rules win; inline styles on
   the pages are overridden with !important. Colours are theme variables from css/themes.css. */

/* ── A phone held upright ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 599px) {
  /* The page: 16px side gutters clear of the notch and the rounded corners, room above the home
     indicator. Short pages stay centred; tall forms start at the top. */
  body {
    box-sizing: border-box;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  /* Document verification's header and footer run edge to edge; its own blocks keep the gutters. */
  body:has(> .verify-page) {
    padding: 0;
  }
  body:has(#register-form),
  body:has(.mfa-layout) {
    align-items: flex-start;
  }

  /* The "Home" pill scrolls with the page in the top-left corner, below the status bar; the card
     starts under it. */
  .back-home {
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    min-height: 44px;
  }
  body:has(> .back-home) {
    padding-top: calc(max(16px, env(safe-area-inset-top)) + 56px);
  }

  /* The card uses the width, with comfortable inner padding; no inner scroll box (register's card
     scrolled inside itself, a trap with the keyboard up). */
  .auth-container {
    width: auto;
    max-width: none;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 24px 20px;
    max-height: none;
    overflow: visible;
  }
  .auth-container h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
  }

  /* Fields and buttons: at least 44px to tap, and 16px text so iOS does not zoom on focus. */
  .form-group input:not([type="radio"]):not([type="checkbox"]),
  .form-group select {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
  }
  .password-wrapper input:not([type="radio"]):not([type="checkbox"]) {
    padding-right: 52px;
  }
  .password-wrapper .toggle-password {
    right: 2px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
  }
  .auth-container button[type="submit"],
  #sso-microsoft,
  #sso-signup-microsoft {
    min-height: 48px;
  }

  /* Register's role choice: a stacked list that fits, each whole row a tap target. */
  .auth-role-choice {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .auth-role-choice > label {
    margin-top: 0 !important;
    white-space: normal !important;
    gap: 12px !important;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--input-border);
    border-color: color-mix(in srgb, var(--primary-color) 35%, transparent);
    border-radius: 10px;
  }
  .auth-role-choice input[type="radio"] {
    accent-color: var(--primary-color);
  }
  .auth-role-choice > label:has(input:checked) {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    box-shadow: inset 0 0 0 1px var(--primary-color);
  }

  /* "Remember this device": the whole row is the tap target. */
  .form-group .remember-device {
    display: flex;
    min-height: 48px;
    cursor: pointer;
  }
  .remember-device input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex: none;
    accent-color: var(--primary-color);
  }

  /* Footer links: room around each, so two are not hit at once. */
  .auth-footer {
    margin-top: 12px;
  }
  .auth-footer a {
    display: inline-block;
    padding: 12px 4px;
  }

  /* Messages wrap inside the card, long words included, and keep clear of the button above. */
  #forgot-message,
  #reset-message {
    margin-top: 16px;
  }
  #login-error-message,
  #forgot-message,
  #reset-message,
  .password-hint,
  #password-hint,
  #password-mismatch {
    overflow-wrap: anywhere;
  }

  /* The notification: inside both gutters (it is 360px wide on a desktop, off a 360px screen's
     left edge), below the status bar, with a dismiss button big enough to tap. */
  body #__toast-container {
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    width: auto;
  }
  body #__toast-container .__toast .__toast-msg {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body #__toast-container .__toast .__toast-x {
    width: 44px;
    height: 44px;
    margin: -12px -14px -12px 0;
    padding: 0;
  }

  /* MFA verify shows the large mark at 200px, more than a third of a small phone's screen. */
  body:has(#mfa-verify-form) .logo img {
    max-width: 96px;
  }

  /* MFA setup: one column, a smaller logo, the panels closer to the edge. */
  .mfa-header {
    gap: 12px;
    margin-bottom: 20px;
  }
  .mfa-header .logo img {
    max-width: 72px;
  }
  .mfa-heading h2 {
    font-size: 1.6rem;
  }
  .mfa-layout {
    gap: 16px;
  }
  .auth-container:has(.mfa-layout) {
    padding: 20px 16px;
  }
  .mfa-panel {
    padding: 16px;
  }
  .mfa-panel h3 {
    color: inherit;
  }
  .qr-box {
    max-width: 240px;
  }
  .code-box {
    white-space: normal;
    overflow-wrap: anywhere;
    -webkit-user-select: all;
    user-select: all;
  }
  /* The phone's own way in (js/mfa-setup-phone.js builds it only at phone size): the key and the
     app link above the QR. The secret row below the QR would repeat the key, so it steps aside. */
  .mfa-panel:has(.mfa-phone-setup) > .form-group {
    display: none;
  }
  .mfa-phone-setup {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
  }
  .mfa-phone-open {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
  }
  .mfa-panel .mfa-phone-label {
    margin: 4px 0 0;
  }
  .mfa-phone-key {
    padding: 12px 14px;
    border: 1px solid var(--input-border);
    border-color: color-mix(in srgb, var(--primary-color) 35%, transparent);
    border-radius: 10px;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 1.05rem;
    letter-spacing: 0.08em;
    text-align: center;
    overflow-wrap: anywhere;
    -webkit-user-select: all;
    user-select: all;
  }
  .mfa-phone-setup .mfa-phone-copy {
    min-height: 48px;
    margin: 0;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: inherit;
    font-weight: 600;
  }
  .mfa-panel .mfa-phone-status {
    min-height: 1.4em;
    margin: -4px 0 0;
    text-align: center;
  }

  /* Pending: the desktop's 60px/40px padding is too much for a phone. */
  .pending-container {
    padding: 32px 20px;
    border-radius: 16px;
  }
  .pending-container h1 {
    font-size: 1.6rem;
  }
  .pending-container button {
    width: 100%;
    min-height: 48px;
  }
  /* The Report Bug button (when the organization has it) sits above the card, not on it. */
  body:has(.bug-report-btn--no-sidebar) {
    padding-top: calc(max(16px, env(safe-area-inset-top)) + 64px);
  }
  .bug-report-btn--no-sidebar {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    margin: 0;
    min-height: 44px;
  }

  /* Single sign-on completion: the "Back to login" link gets room to tap. */
  #msg a {
    display: inline-block;
    padding: 10px 4px;
    margin: -10px 0;
  }

  /* Document verification: clear of the notch, a 44px "Check another document". */
  .verify-header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .verify-main {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .verify-footer {
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }
  .btn-again {
    min-height: 44px;
  }
}

/* ── A phone on its side ──────────────────────────────────────────────────────────────────────────
   The desktop card (at most 500px) already fits the width; what changes is touch: 44px targets,
   16px input text, the notch on one side and the home indicator below. */
@media (max-height: 500px) and (pointer: coarse) {
  body {
    box-sizing: border-box;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  body:has(> .verify-page) {
    padding: 0;
  }
  body:has(#register-form),
  body:has(.mfa-layout) {
    align-items: flex-start;
  }
  .back-home {
    left: max(16px, env(safe-area-inset-left));
    min-height: 44px;
  }
  .auth-container {
    max-height: none;
    overflow: visible;
  }

  .form-group input:not([type="radio"]):not([type="checkbox"]),
  .form-group select {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
  }
  .password-wrapper input:not([type="radio"]):not([type="checkbox"]) {
    padding-right: 52px;
  }
  .password-wrapper .toggle-password {
    right: 2px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
  }
  .auth-container button[type="submit"],
  #sso-microsoft,
  #sso-signup-microsoft {
    min-height: 48px;
  }

  .auth-role-choice {
    flex-wrap: wrap;
    gap: 8px !important;
  }
  .auth-role-choice > label {
    flex: 1 1 auto;
    justify-content: center;
    margin-top: 0 !important;
    gap: 10px !important;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--input-border);
    border-color: color-mix(in srgb, var(--primary-color) 35%, transparent);
    border-radius: 10px;
  }
  .auth-role-choice input[type="radio"] {
    accent-color: var(--primary-color);
  }
  .auth-role-choice > label:has(input:checked) {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 12%, transparent);
    box-shadow: inset 0 0 0 1px var(--primary-color);
  }

  .form-group .remember-device {
    display: flex;
    min-height: 48px;
    cursor: pointer;
  }
  .remember-device input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex: none;
    accent-color: var(--primary-color);
  }

  .auth-footer {
    margin-top: 12px;
  }
  .auth-footer a {
    display: inline-block;
    padding: 12px 4px;
  }

  body #__toast-container {
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
  }
  body #__toast-container .__toast .__toast-msg {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body #__toast-container .__toast .__toast-x {
    width: 44px;
    height: 44px;
    margin: -12px -14px -12px 0;
    padding: 0;
  }

  /* The large marks on MFA verify and setup would push the form below a sideways phone's fold. */
  body:has(#mfa-verify-form) .logo img,
  .mfa-header .logo img {
    max-width: 72px;
  }
  .mfa-panel h3 {
    color: inherit;
  }
  .mfa-panel:has(.mfa-phone-setup) > .form-group {
    display: none;
  }
  .mfa-phone-setup {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
  }
  .mfa-phone-open {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
  }
  .mfa-panel .mfa-phone-label {
    margin: 4px 0 0;
  }
  .mfa-phone-key {
    padding: 12px 14px;
    border: 1px solid var(--input-border);
    border-color: color-mix(in srgb, var(--primary-color) 35%, transparent);
    border-radius: 10px;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 1.05rem;
    letter-spacing: 0.08em;
    text-align: center;
    overflow-wrap: anywhere;
    -webkit-user-select: all;
    user-select: all;
  }
  .mfa-phone-setup .mfa-phone-copy {
    min-height: 48px;
    margin: 0;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: inherit;
    font-weight: 600;
  }
  .mfa-panel .mfa-phone-status {
    min-height: 1.4em;
    margin: -4px 0 0;
    text-align: center;
  }

  .pending-container button {
    min-height: 48px;
  }
  body:has(.bug-report-btn--no-sidebar) {
    padding-top: calc(max(16px, env(safe-area-inset-top)) + 64px);
  }
  .bug-report-btn--no-sidebar {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    margin: 0;
    min-height: 44px;
  }

  #msg a {
    display: inline-block;
    padding: 10px 4px;
    margin: -10px 0;
  }

  .verify-header,
  .verify-main {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }
  .verify-footer {
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }
  .btn-again {
    min-height: 44px;
  }
}
