/* mobile-auth.css — sign-in / register screens on phones and tablets
   Desktop / laptop (fine pointer, wider than 640 px) is untouched: every rule
   below sits inside a phone-layout or coarse-pointer media query.

   1. Touch screens (phones, all tablets): 16 px inputs (no iOS focus zoom),
      44 px+ fields, buttons and links, a 40 px eye button, and room below the
      card so a field near the bottom can scroll above the on-screen keyboard.
   2. Phone layout: card fits the width, compact logo and heading, even field
      spacing, safe-area insets.
   3. Narrow phones (≤ 420 px): the two-column register rows stack. */

/* ── 1. Touch: target sizes and keyboard room ───────────────── */
@media (max-width: 640px), (pointer: coarse) {
  #auth-overlay {
    height: 100%;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    /* Bottom reserve ≈ the on-screen keyboard. .auth-screen keeps its
       margin: auto, so a short card is centred in the space above the
       reserve (it sits high, clear of the keyboard), and a tall one starts
       at the top and scrolls, ending with enough room that the last field
       and buttons can be scrolled up above the keyboard. The reserve is
       fixed, not tied to :focus, so nothing jumps when a field gains or
       loses focus (a jump between tap-down and tap-up loses the click). */
    padding:
      max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      calc(max(16px, env(safe-area-inset-bottom)) + 35dvh)
      max(16px, env(safe-area-inset-left));
    scroll-padding: 16px 0 calc(16px + env(safe-area-inset-bottom));
  }

  .auth-input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px;               /* < 16 px makes iOS Safari zoom on focus */
    line-height: 1.4;
    border-radius: 8px;
    /* when focus scrolls a field into view, keep it clear of the keyboard */
    scroll-margin-top: 24px;
    scroll-margin-bottom: 30dvh;
  }
  .pw-wrap .auth-input { padding-right: 50px; }
  .pw-toggle { width: 40px; height: 40px; right: 2px; border-radius: 8px; }
  .pw-toggle svg { width: 20px; height: 20px; }

  .auth-btn {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 15px;
    border-radius: 9px;
    touch-action: manipulation;    /* no double-tap-zoom delay */
  }
  .auth-btn.secondary { margin-top: 10px; }

  .auth-footer {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    column-gap: 2px;
    margin-top: 10px;
    font-size: 14px;
  }
  .auth-link {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; min-width: 44px;
    padding: 0 8px;
    font-size: 14px;
    touch-action: manipulation;
  }

  .auth-error { font-size: 13px; }

  /* Forgot / reset password: the 44 px "Forgot password?" link sits close
     under the password field, and the hint and notes are easy to read */
  .auth-forgot { margin-top: 2px; }
  .auth-forgot + .auth-btn { margin-top: 6px; }
  .auth-hint, .auth-ok, .auth-req { font-size: 13px; }
  .auth-req { margin-top: 0; }

  /* Even 12 px between fields. In styles.css ":first-of-type" also hits the
     Organization label and the labels inside the two-column rows, which left
     those fields with no gap above them. */
  #auth-overlay .auth-box > .auth-label,
  #auth-overlay .auth-box > .auth-row { margin-top: 12px; }
  #auth-overlay .auth-box > .auth-row .auth-label { margin-top: 0; }
  #auth-overlay .auth-box > .auth-error:not(.visible) + .auth-label,
  #auth-overlay .auth-box > .auth-error:not(.visible) + .auth-row { margin-top: 0; }
}

/* ── 2. Phone layout: fit the width, compact header ─────────── */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  .auth-screen { max-width: 440px; }
  .auth-box {
    max-width: none;
    padding: 1.25rem 1.25rem 1.375rem;
  }
  .auth-logo { height: 24px; margin-bottom: .75rem; }
  .auth-box h1 { font-size: 1.125rem; margin-bottom: 1rem; }
  .auth-box .auth-label { font-size: 11px; margin-bottom: 5px; }

  .auth-box .auth-row { gap: 10px; }
  .auth-box .auth-row > div { min-width: 0; }   /* never push the card wider */

  .auth-btn { margin-top: 16px; }
  .auth-info { font-size: 14px; padding: 12px 14px; overflow-wrap: anywhere; }
}

/* small phones: a little less chrome around the form */
@media (max-width: 380px) {
  #auth-overlay {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .auth-box { padding: 1rem 1rem 1.125rem; }
}

/* ── 3. Narrow phones: register rows become one column ──────── */
@media (max-width: 420px) {
  .auth-box .auth-row { flex-direction: column; gap: 12px; }
}
