/*
 * mobile.css — iOS & Mobile Optimisation Layer
 * Loaded last on every page so these rules win.
 * Covers: safe-area insets, 100dvh, font-size zoom, tap highlight,
 *         scroll momentum, touch targets, modal treatment, appearance resets.
 */

/* ─────────────────────────────────────────────
   1. GLOBAL iOS RESETS
────────────────────────────────────────────── */
*,
*::before,
*::after {
  /* Kill the grey flash on tap */
  -webkit-tap-highlight-color: transparent;
  /* Let each element manage its own scroll axis */
  -webkit-touch-callout: none;
}

html {
  /* Smooth momentum scrolling across the whole page on iOS */
  -webkit-overflow-scrolling: touch;
  /* Prevent font inflation on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  /* Ensure body never causes horizontal scroll on narrow screens */
  overflow-x: hidden;
  /* Consistent cursor */
  cursor: default;
}

/* ─────────────────────────────────────────────
   2. INPUT / BUTTON — PREVENT AUTO-ZOOM & SYSTEM STYLING
   iOS zooms into any input with font-size < 16px.
   -webkit-appearance removes default system chrome.
────────────────────────────────────────────── */
input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
textarea,
select {
  font-size: 16px !important;   /* Hard floor — prevents iOS zoom */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;             /* iOS rounds corners by default */
}

/* Restore select arrow on non-iOS */
@supports not (-webkit-touch-callout: none) {
  select {
    -webkit-appearance: auto;
    appearance: auto;
  }
}

button,
[role="button"],
.btn,
.tab-btn,
.pg-btn,
.push-btn {
  -webkit-appearance: none;
  appearance: none;
  /* Prevent double-tap zoom on buttons */
  touch-action: manipulation;
  /* Minimum Apple HIG touch target */
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

/* ─────────────────────────────────────────────
   3. 100VH FIX
   iOS Safari shrinks/grows the viewport as the browser
   chrome appears/disappears.  100dvh tracks the *current*
   visible height; the 100vh fallback is for older browsers.
────────────────────────────────────────────── */
.dashboard-container {
  height: 100vh;                        /* fallback */
  height: 100dvh;
}

.main-content,
.screens-content,
.earnings-container,
.payouts-container {
  min-height: calc(100vh - 70px);       /* fallback */
  min-height: calc(100dvh - 70px);
}

.sidebar {
  height: 100vh;                        /* fallback */
  height: 100dvh;
}

/* Login / Signup full-page containers */
.login-container,
.signup-container,
.login-page,
.auth-page {
  min-height: 100vh;                    /* fallback */
  min-height: 100dvh;
}

/* Mobile nav overlay */
.mobile-nav {
  height: 100vh;                        /* fallback */
  height: 100dvh;
}

/* ─────────────────────────────────────────────
   4. SAFE-AREA INSETS
   env() variables give the exact pixel values for the
   notch, Dynamic Island, and home indicator on iPhones.
   Requires viewport-fit=cover in the meta tag.
────────────────────────────────────────────── */

/* Top bar — sits below the status bar / Dynamic Island */
.topbar {
  top: 0;
  top: env(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
}

/* Sidebar — respect left notch in landscape.
   max() keeps the original 30px top padding on non-notch devices;
   on iPhone with Dynamic Island the safe-area value takes over. */
.sidebar {
  padding-top: max(30px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  left: 0;
  left: env(safe-area-inset-left);
}

/* Any fixed element near the bottom (FABs, push button) */
.contact-icon,
.push-btn-fixed {
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: calc(20px + env(safe-area-inset-right));
}

/* Modals — content must clear the notch and home indicator */
.modal,
.modal-overlay {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ─────────────────────────────────────────────
   5. MODAL — iOS SCROLL LOCK & POSITIONING
────────────────────────────────────────────── */
.modal,
.modal-overlay {
  position: fixed;
  inset: 0;
  /* Crisp rendering on retina + GPU compositing */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  /* Momentum scroll inside the modal */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-content {
  /* Keep within safe area */
  margin: max(20px, env(safe-area-inset-top)) auto 20px;
  /* Prevent modal being too close to the home indicator */
  margin-bottom: max(20px, env(safe-area-inset-bottom));
  /* Smooth GPU compositing */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
  /* Never taller than the visible area */
  max-height: calc(100dvh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─────────────────────────────────────────────
   6. SCROLL CONTAINERS
────────────────────────────────────────────── */
.modal-body,
.modal-content,
[class*="scroll"],
.notifications-list,
.campaign-cards-container,
.table-section table {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Prevent the whole page bouncing on iOS when content is scrollable */
body.modal-open {
  position: fixed;
  width: 100%;
  /* preserves scroll position */
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   7. TOUCH TARGETS — minimum 44×44 per Apple HIG
────────────────────────────────────────────── */
/* Inline/button elements — 44px touch target */
.tab-btn,
.btn,
.hamburger-btn,
.modal-close,
.notif-bell,
.vypa-dark-toggle,
.page-link,
.pg-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

/* Nav links are block-level flex — must NOT use inline-flex or they
   lose full-width layout and misalign inside the sidebar */
.nav-links a,
.sidebar a,
.dropdown-item {
  min-height: 44px;
  display: flex;
  width: 100%;
  align-items: center;
  touch-action: manipulation;
}

/* Nav links need a bit more breathing room on mobile */
@media (max-width: 1023px) {
  .nav-links a {
    padding: 14px 20px;
    /* Preserve original 22px — accessibility requirement for elderly/visually-impaired users */
    font-size: 22px;
  }

  .hamburger-btn {
    padding: 10px;
    font-size: 22px;
  }
}

/* ─────────────────────────────────────────────
   8. TOPBAR — MOBILE LAYOUT FIXES
────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .topbar {
    height: auto;
    min-height: 60px;
    padding: env(safe-area-inset-top) 12px 0;
    flex-wrap: wrap;
    gap: 8px;
    /* Backdrop blur is expensive on iOS; simplify */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(255, 255, 255, 0.97);
  }

  /* Topbar title */
  .topbar h1 {
    font-size: 18px;
    flex: 1;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    gap: 10px;
  }
}

/* ─────────────────────────────────────────────
   9. SIDEBAR OVERLAY — SMOOTH ON iOS
────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    /* GPU layer */
    will-change: transform;
    -webkit-transform: translateX(-100%);
    /* Momentum scroll inside sidebar */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.open {
    transform: translateX(0);
    -webkit-transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 199;
    display: none;
    opacity: 0;
    transition: opacity 0.28s ease;
    -webkit-backdrop-filter: none;
  }

  .sidebar.open ~ .sidebar-backdrop,
  .sidebar-backdrop.visible {
    display: block;
    opacity: 1;
  }
}

/* ─────────────────────────────────────────────
   10. MAIN-CONTENT — FULL WIDTH + SAFE PADDING
────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .main-content {
    margin-left: 0 !important;
    /* Push content below topbar + notch */
    margin-top: calc(60px + env(safe-area-inset-top));
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    width: 100%;
    box-sizing: border-box;
  }
}

/* ─────────────────────────────────────────────
   11. TABLES — HORIZONTAL SCROLL ON SMALL SCREENS
────────────────────────────────────────────── */
@media (max-width: 768px) {
  .table-section {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-section table,
  #earningsTable {
    min-width: 560px;   /* enough to keep columns readable */
  }

  /* Campaign cards stack nicely */
  .campaign-details {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px;
  }

  .campaign-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .campaign-actions .btn {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
    font-size: 13px;
  }
}

/* ─────────────────────────────────────────────
   12. STATS / SUMMARY CARDS
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .campaign-stats-bar,
  .summary-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .campaign-stat-card,
  .summary-card {
    padding: 14px 12px;
  }

  .stat-value,
  .summary-card .value {
    font-size: 20px !important;
  }
}

@media (max-width: 390px) {
  .campaign-stats-bar,
  .summary-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ─────────────────────────────────────────────
   13. FORMS — SPACING & SIZING
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .form-group {
    margin-bottom: 16px;
  }

  .form-textarea {
    font-size: 16px !important;
    min-height: 100px;
  }

  .form-select {
    font-size: 16px !important;
    height: 48px;
  }

  .modal-actions {
    flex-direction: column;
    gap: 10px;
  }

  .modal-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ─────────────────────────────────────────────
   14. PAGINATION
────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* The "Showing X–Y of Z" text + buttons row */
  div:has(> .pg-btn) {
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }

  .pg-btn {
    min-width: 40px;
    min-height: 40px;
    font-size: 14px;
  }
}

/* ─────────────────────────────────────────────
   15. EARNINGS / PAYOUTS PAGE
────────────────────────────────────────────── */
@media (max-width: 768px) {
  .earnings-container,
  .payouts-container {
    padding: 16px;
    box-sizing: border-box;
  }

  .earnings-title,
  .payouts-title {
    font-size: 22px !important;
  }

  /* Per-screen table horizontal scroll */
  .table-section > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 480px;
  }
}

/* ─────────────────────────────────────────────
   16. SCREENS PAGE CARDS
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .screens-grid,
  .screen-cards {
    grid-template-columns: 1fr !important;
  }
}

/* ─────────────────────────────────────────────
   17. NOTIFICATIONS PAGE
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .notifications-list .notif-item {
    padding: 14px 12px;
  }
}

/* ─────────────────────────────────────────────
   18. LOGIN / SIGNUP — FULL-SCREEN TREATMENT
────────────────────────────────────────────── */
@media (max-width: 768px) {
  .login-container,
  .signup-container {
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* The brand panel can collapse on mobile */
  .login-brand-panel,
  .auth-panel-left {
    display: none;
  }

  .login-form-panel,
  .auth-panel-right {
    width: 100% !important;
    padding: 32px 20px;
    box-sizing: border-box;
    /* Ensure content scrolls if keyboard pushes it up */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ─────────────────────────────────────────────
   19. GALLERY PAGE
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .media-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }
}

/* ─────────────────────────────────────────────
   20. PROFILE PAGE TABS
────────────────────────────────────────────── */
@media (max-width: 768px) {
  .profile-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    display: flex;
    gap: 4px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .profile-tabs::-webkit-scrollbar {
    display: none;
  }

  .profile-tab-btn {
    flex-shrink: 0;
  }
}

/* ─────────────────────────────────────────────
   21. DARK-MODE TOGGLE — visible on mobile
────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .vypa-dark-toggle {
    display: inline-flex !important;
    font-size: 13px;
    padding: 6px 10px;
    gap: 4px;
  }
}

/* ─────────────────────────────────────────────
   22. PUSH BUTTON — ALWAYS VISIBLE
────────────────────────────────────────────── */
@media (max-width: 426px) {
  .no-mobile {
    display: none !important;
  }

  .mobile-logo {
    display: block !important;
  }

  .push-btn {
    font-size: 14px !important;
    padding: 8px 14px !important;
    min-height: 44px;
  }
}

/* ─────────────────────────────────────────────
   23. ADVERT REQUESTS PAGE SPECIFICS
────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Tab bar — horizontally scrollable, no wrap */
  .tabs-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    display: flex;
    padding-bottom: 4px;
    gap: 6px;
    scrollbar-width: none;
  }

  .tabs-container::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex-shrink: 0;
    font-size: 12px;
    padding: 8px 12px;
    white-space: nowrap;
  }

  /* Campaign card responsive adjustments */
  .campaign-card {
    padding: 16px;
  }

  .campaign-header {
    flex-direction: column;
    gap: 8px;
  }

  .detail-label {
    font-size: 11px;
  }

  .detail-value {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .campaign-details {
    grid-template-columns: 1fr 1fr !important;
  }

  .campaign-actions {
    flex-direction: column;
  }

  .campaign-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ─────────────────────────────────────────────
   24. TOUR TOOLTIP — SAFE ON SMALL SCREENS
────────────────────────────────────────────── */
@media (max-width: 640px) {
  .shepherd-element {
    max-width: calc(100vw - 32px) !important;
    left: 16px !important;
    right: 16px !important;
  }
}

/* ─────────────────────────────────────────────
   25. FOCUS STYLES — ACCESSIBLE BUT NOT DISTRACTING
────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--brand, #10b981);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─────────────────────────────────────────────
   26. PREVENT LAYOUT SHIFT FROM SCROLLBAR APPEARING
────────────────────────────────────────────── */
html {
  scrollbar-gutter: stable;
}

/* ─────────────────────────────────────────────
   27. SMOOTH SCROLLING — RESPECTS REDUCED MOTION
────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* ─────────────────────────────────────────────
   28. DARK MODE — ensure mobile dark areas are correct
────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .dark-mode .topbar {
    background: rgba(20, 20, 30, 0.97) !important;
    border-bottom-color: rgba(255, 255, 255, 0.06);
  }

  .dark-mode .sidebar {
    background: var(--dark-bg, #1a1a2e);
  }
}
