/*
 * EZPZ Texting — shared mobile UI enhancements.
 *
 * Goals (per PRD "Enhance mobile UI for better consistency across pages"):
 *  1. Visual consistency across pages (nav, buttons, cards, inputs, safe-area).
 *  2. Interactive elements meet 44px touch-target guidance on small screens.
 *  3. Lightweight perf hints: font smoothing, text-size-adjust lock, image defaults.
 *
 * Intentionally additive: this stylesheet is loaded AFTER each page's inline
 * <style>, so `:root` variable fallbacks and narrow media queries tighten
 * the existing look rather than rewriting it. Desktop is untouched.
 */

:root {
  --ezpz-mobile-safe-top: env(safe-area-inset-top, 0px);
  --ezpz-mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ezpz-mobile-safe-left: env(safe-area-inset-left, 0px);
  --ezpz-mobile-safe-right: env(safe-area-inset-right, 0px);
  --ezpz-mobile-tap-min: 44px;
}

/* Global text rendering hardening — applies at every width so copy matches across pages. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Prevent long unbreakable strings (tokens, URLs) from blowing out narrow layouts. */
.card,
.panel,
.auth-card,
.hero,
.inbox-masthead,
.admin-collapsible,
.integ-step-card,
.integ-callout {
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* Images: don't let a stray huge image break narrow layouts. */
img {
  max-width: 100%;
  height: auto;
}

/* ===========================================================
 * Mobile (≤ 900px): consolidates nav, spacing, and tap sizing
 * so every page collapses the same way on phones/tablets.
 * =========================================================== */
@media (max-width: 900px) {
  /* Respect notches + rounded corners on iOS/Android. */
  body {
    padding-left: var(--ezpz-mobile-safe-left);
    padding-right: var(--ezpz-mobile-safe-right);
  }

  .topbar {
    padding-top: var(--ezpz-mobile-safe-top);
  }

  .nav-wrap {
    padding: 9px 12px;
    gap: 10px;
  }

  .brand {
    font-size: 14px;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
  }
  .brand img {
    height: 30px;
  }
  .brand > div,
  .brand > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Hamburger becomes a proper 44px tap target on every page. */
  .menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: var(--ezpz-mobile-tap-min);
    min-height: var(--ezpz-mobile-tap-min);
    padding: 0 10px;
    border-radius: 10px;
    font-size: 22px;
    line-height: 1;
    background: rgba(255, 217, 77, 0.08);
  }
  .menu-toggle:active {
    background: rgba(255, 217, 77, 0.18);
  }

  /* Collapsed menu: consistent look whether inline style was defined or not. */
  .nav-links a {
    min-height: var(--ezpz-mobile-tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    font-size: 15px;
  }

  /* Larger, thumb-friendly primary controls across pages. */
  .btn,
  .primary-btn,
  .toggle-btn,
  .action-btn,
  button.small-btn,
  .signup-btn {
    min-height: var(--ezpz-mobile-tap-min);
  }

  /* Anchors styled as buttons (e.g. .badge links, .plan-card-actions .btn) match. */
  a.btn,
  a.primary-btn {
    min-height: var(--ezpz-mobile-tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Inputs: 16px min font-size prevents iOS zoom-on-focus; larger tap area. */
  .field,
  input.field,
  textarea.field,
  select.field,
  .search,
  .date-input,
  .filter-select {
    font-size: 16px;
    min-height: var(--ezpz-mobile-tap-min);
  }

  /* Cards/hero: tighten padding and radius so the mobile viewport feels consistent. */
  .card,
  .auth-card,
  .panel {
    padding: 16px;
    border-radius: 16px;
  }
  .hero,
  .inbox-masthead {
    padding: 16px;
    border-radius: 18px;
  }
  .hero h1,
  .inbox-masthead-title {
    font-size: 22px;
    line-height: 1.2;
  }
  .hero p,
  .inbox-masthead-desc {
    font-size: 14px;
  }

  /* Consistent page gutter so all pages align to the same safe content width. */
  .page {
    width: calc(100% - 12px);
    padding-left: 0;
    padding-right: 0;
  }

  /* Bottom safe-area breathing room — prevents controls sitting under the iOS home bar. */
  main.page,
  body > main {
    padding-bottom: calc(24px + var(--ezpz-mobile-safe-bottom));
  }
}

/* ===========================================================
 * Small phones (≤ 520px): tighten typography & gutter further
 * =========================================================== */
@media (max-width: 520px) {
  .hero h1,
  .inbox-masthead-title,
  .auth-title {
    font-size: 20px;
  }
  .card h2,
  .panel-title {
    font-size: 18px;
  }

  /* Tables/grid rows gain horizontal scroll nicety on phones. */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent tap-highlight flash from obscuring our yellow buttons. */
  a,
  button {
    -webkit-tap-highlight-color: rgba(15, 35, 104, 0.12);
  }
}

/* ===========================================================
 * Reduced motion — honour the OS setting across all pages.
 * =========================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
