/*
 * mobile-cross-platform.css
 * Normalises rendering differences between iOS Safari, Android Chrome/WebView,
 * and desktop browsers. Loaded globally. Does NOT change any layout logic —
 * only browser-quirk overrides.
 */

/* ─── 1. RESET BROWSER-SPECIFIC FORM QUIRKS ─────────────────────────────── */

/*
 * iOS Safari auto-zooms into inputs whose font-size < 16px.
 * Android renders inputs with a system-default background gradient.
 * Fix both by enforcing 16px minimum and removing native appearance.
 */
input,
textarea,
select,
button {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.4;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0; /* removes iOS's rounded-rectangle default */
}

/* Restore border-radius where our design sets it */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="date"],
textarea,
select {
  border-radius: 10px;
}

/* Checkboxes and radios: don't strip appearance — only strip on other inputs */
input[type="checkbox"],
input[type="radio"] {
  -webkit-appearance: auto;
  -moz-appearance: auto;
  appearance: auto;
  font-size: inherit;
  border-radius: 0;
  width: auto;
  height: auto;
}

/* File inputs */
input[type="file"] {
  -webkit-appearance: none;
  appearance: none;
  font-size: 14px; /* file inputs don't trigger zoom */
  border-radius: 10px;
}

/* Prevent iOS Safari from adding a blue tint to tapped elements */
a,
button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent iOS auto-styling of telephone links */
a[href^="tel"] {
  color: inherit;
  text-decoration: none;
}

/* ─── 2. TOUCH TARGET SIZES ──────────────────────────────────────────────── */

/*
 * Apple HIG and Google Material both recommend 44×44pt minimum.
 * Apply to all interactive elements at mobile breakpoints.
 */
@media (max-width: 768px) {
  button,
  .tc-btn,
  .btn,
  .cta-button,
  input[type="submit"],
  input[type="button"],
  input[type="reset"],
  a.nav-link,
  .nav-links a,
  .dropdown-item {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ─── 3. FONT RENDERING ──────────────────────────────────────────────────── */

/*
 * Android Chrome renders fonts thinner than iOS Safari.
 * -webkit-font-smoothing + text-rendering bring them closer together.
 */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%; /* prevents iOS landscape font scaling */
}

/* ─── 4. SCROLL & OVERFLOW ───────────────────────────────────────────────── */

/*
 * iOS Safari can clip position:fixed elements inside overflow:hidden containers.
 * The body scroll fix prevents double-scroll-bar artefacts on Android WebView.
 */
html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  /* Smooth momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* Scrollable containers get momentum scrolling on iOS */
.scroll-x,
.carousel-track,
.chat-messages,
.messages-list,
[data-scroll] {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ─── 5. SAFE-AREA INSETS (notch / home-bar / dynamic island) ────────────── */

/*
 * On iPhone X+ and newer Android devices with notches, content can be hidden
 * behind the system chrome. `env(safe-area-inset-*)` pushes it clear.
 */
.tc-nav {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

@media (max-width: 768px) {
  .tc-nav {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Footer / bottom bars get bottom safe-area padding */
footer,
.bottom-nav,
.chat-input-area,
.fixed-bottom {
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* ─── 6. IMAGE RENDERING ─────────────────────────────────────────────────── */

img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Profile/avatar images — consistent circular rendering across platforms */
.nav-user-avatar img,
.profile-avatar img,
.profile-avatar-large img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* ─── 7. FLEXBOX / GRID GAPS (Android 4.x WebView compat) ───────────────── */

/*
 * Old Android WebViews don't support `gap` in flexbox.
 * We leave modern gap usage intact for modern browsers but add margin fallbacks
 * scoped to the specific components that use gap.
 */
@supports not (gap: 1rem) {
  .nav-links li + li { margin-left: 1.75rem; }
  .nav-actions > * + * { margin-left: 0.75rem; }
  .profile-skills .skill-tag + .skill-tag { margin-left: 0.5rem; margin-bottom: 0.5rem; }
}

/* ─── 8. BUTTON / CARD SHADOWS ──────────────────────────────────────────── */

/*
 * Android renders box-shadow differently from iOS when combined with
 * border-radius. Normalise by ensuring backface-visibility is consistent.
 */
.profile-card,
.job-card,
.category-card,
.card,
.tc-btn,
.btn {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* ─── 9. SELECT DROPDOWN ARROW ───────────────────────────────────────────── */

/*
 * After stripping -webkit-appearance, selects lose their arrow on Android.
 * Add a cross-platform SVG arrow back.
 */
select:not([multiple]):not([size]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%232A3563' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 2.5rem;
}

/* ─── 10. MOBILE TYPOGRAPHY SCALE ───────────────────────────────────────── */

/*
 * iOS and Android have different default font metrics. These clamps keep
 * headings readable without overflowing on small screens.
 */
@media (max-width: 480px) {
  h1 { font-size: clamp(1.5rem, 6vw, 2rem); }
  h2 { font-size: clamp(1.25rem, 5vw, 1.6rem); }
  h3 { font-size: clamp(1rem, 4vw, 1.3rem); }

  .hero h1 { font-size: clamp(1.6rem, 7vw, 2.2rem); }
  .section-title { font-size: clamp(1.3rem, 5.5vw, 1.8rem); }

  /* Prevent text overflow on very narrow screens — exclude chat bubbles */
  p, li, a,
  span:not(.msg-bubble *) {
    word-break: normal;
    overflow-wrap: break-word;
  }
}

@media (max-width: 768px) {
  h1 { font-size: clamp(1.6rem, 6vw, 2.5rem); }
  h2 { font-size: clamp(1.3rem, 5vw, 2rem); }
}

/* ─── 11. CARD / GRID RESPONSIVE FIXES ──────────────────────────────────── */

@media (max-width: 480px) {
  /* Prevent cards from overflowing their container on very narrow screens */
  .profile-card,
  .job-card,
  .category-card {
    min-width: unset;
    width: 100%;
  }

  /* Full-width grids on small screens */
  .categories-grid,
  .jobs-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── 12. FORM LAYOUT ON MOBILE ─────────────────────────────────────────── */

@media (max-width: 600px) {
  /* Prevent input labels from getting clipped */
  .form-group label,
  .form-label {
    font-size: 0.9rem;
    display: block;
    margin-bottom: 0.35rem;
  }

  /* Full-width inputs */
  .form-group input,
  .form-group textarea,
  .form-group select,
  .form-control {
    width: 100%;
    font-size: 16px; /* critical: prevents iOS zoom */
    padding: 0.75rem 1rem;
  }

  /* Stack form rows vertically */
  .form-row {
    flex-direction: column;
    gap: 1rem;
  }
}

/* ─── 13. NAVBAR MOBILE REFINEMENTS ─────────────────────────────────────── */

@media (max-width: 768px) {
  /* Prevent nav overflow on phones with narrow screens */
  .tc-nav {
    height: auto;
    min-height: 60px;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .nav-logo-text {
    font-size: 1rem;
  }
}

/* ─── 14. MODAL / OVERLAY ON MOBILE ─────────────────────────────────────── */

/*
 * iOS Safari's position:fixed is relative to the viewport, but when the
 * keyboard is open the viewport shrinks. Modals need explicit handling.
 */
.modal,
.overlay,
[role="dialog"] {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

@media (max-width: 600px) {
  .modal-content,
  .dialog-content {
    margin: 0;
    border-radius: 20px 20px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ─── 15. CHAT / MESSAGES PAGE ───────────────────────────────────────────── */

@media (max-width: 768px) {
  /* Chat input stays above iOS keyboard */
  .chat-input-area {
    position: sticky;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: white;
  }

  /* Prevent message bubbles from overflowing */
  .message-bubble,
  .msg-bubble {
    max-width: 85%;
    word-break: normal;
    overflow-wrap: anywhere;
    hyphens: none;
    -webkit-hyphens: none;
  }
}

/* ─── 16. PORTFOLIO / FILE UPLOAD ────────────────────────────────────────── */

@media (max-width: 600px) {
  /* File input styling consistent on both platforms */
  input[type="file"] {
    padding: 0.5rem;
    font-size: 14px;
    width: 100%;
  }

  /* Portfolio action buttons full width on mobile */
  .form-actions,
  .form-actions-row {
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-actions .submit-btn,
  .form-actions-row .submit-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ─── 17. CONTRAST & FOCUS STATES (accessibility + visual parity) ────────── */

/*
 * Android Chrome shows a different focus ring style from iOS Safari.
 * Unify with a consistent outline that works across both.
 */
:focus-visible {
  outline: 2px solid #00C9DE;
  outline-offset: 2px;
}

/* Suppress the default outline on touch-only interactions */
:focus:not(:focus-visible) {
  outline: none;
}

/* ─── 18. PREVENT CONTENT FLASH ON IOS (FOUC) ───────────────────────────── */

/*
 * Some CSS transitions flicker on iOS due to GPU compositing.
 * The translate3d hack forces GPU layers on animated elements.
 */
.tc-btn,
.nav-links,
.profile-card,
.carousel-track {
  will-change: transform;
}
