/* ==========================================================================
   Mobile-first layer — loaded last on every page (index, map, admin).
   Base rules below apply at every width (touch + small-screen friendly
   defaults); only the phone/tablet corrections live in max-width blocks.
   ========================================================================== */

/* ---------- Global base (all widths) ---------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow-wrap: break-word; }
img, svg, video { max-width: 100%; }
a, button, [role="button"], label, select, summary { touch-action: manipulation; }
:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }


/* Mobile nav menu: readable on the dark theme, anchored to the header */
.nav { position: relative; z-index: 900; }
.menu-toggle { min-width: 44px; min-height: 44px; display: none; align-items: center; justify-content: center; border-radius: 12px; }
.menu-toggle[aria-expanded="true"] { background: #ffffff14; }

/* ---------- Phones & small tablets ---------- */
@media (max-width: 767px) {
  /* iOS zooms into any field under 16px — keep every input at 16px */
  input, select, textarea { font-size: 16px !important; }

  /* Comfortable touch targets */
  .button, .text-link, .nav-cta, .role-card, .map-back, .logout-button,
  .admin-tabs button, .map-style-toggle button, .home-map-style button,
  .full-map-layer-toggle button { min-height: 44px; }
  .partner-region-chips button,
  .home-map-chips button,
  .full-map-region-chips button { min-height: 34px; }
  .text-link { display: inline-flex; align-items: center; }

  /* Leave room for the notch / rounded corners in landscape */
  .nav.wrap, .map-header, .admin-top {
    padding-left: max(var(--safe-pad), env(safe-area-inset-left)) !important;
    padding-right: max(var(--safe-pad), env(safe-area-inset-right)) !important;
  }

  /* --- Header + hamburger menu --- */
  .nav.wrap { --safe-pad: 16px; }
  .menu-toggle { display: inline-flex !important; }
  .nav nav {
    position: absolute !important;
    top: 100% !important;
    right: 12px !important;
    left: 12px !important;
    display: none;
    flex-direction: column;
    gap: 4px !important;
    padding: 8px !important;
    border: 1px solid #aeeaff33 !important;
    border-radius: 16px;
    background: #061a2cf2 !important;
    backdrop-filter: blur(16px);
    box-shadow: 0 18px 40px #02101f99;
    z-index: 1000;
  }
  .nav nav.open { display: flex; }
  .nav nav a {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 10px;
    color: #effaff !important;
    font-size: 16px !important;
  }
  .nav nav a:active, .nav nav a:hover { background: #ffffff14; }

  /* --- Hero --- */
  .hero { overflow-x: clip; }
  .hero-actions { flex-wrap: wrap; gap: 12px 18px; }
  .hero-actions .button { flex: 1 1 100%; justify-content: center; }
  .hero-actions .text-link { margin-inline: auto; }

  /* --- Join banner: gift image in flow, drop the decorative vertical text --- */
  .join-vertical { display: none !important; }
  .join-banner { flex-direction: column; align-items: stretch !important; min-height: 0 !important; padding: 28px 20px !important; }
  .join-banner > div:first-child { max-width: none !important; }
  .join-banner h2 { font-size: 30px !important; line-height: 1.45; }
  .join-banner p { max-width: none !important; font-size: 14px !important; }
  .join-banner .button { width: 100%; justify-content: center; }
  .gift-art {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    margin: 28px auto 0;
    width: 190px !important;
    height: 190px !important;
  }
  .gift-product-image { width: 150px !important; height: 150px !important; }

  /* --- App launch CTA: keep it one tidy pill --- */
  .app-launch-note {
    width: 100%;
    min-height: 54px;
    padding: 10px 18px !important;
    font-size: 15px !important;
    text-align: center;
  }
  .app-launch-note #mobileLaunchNote { font-size: 15px !important; line-height: 1.5; }
  .app-store-badges { gap: 10px; }
  .app-store-badge { flex: 1 1 0; min-width: 0 !important; }

  /* --- Home partners map --- */
  .home-map-search { min-height: 48px; }
  .home-map-top { flex-wrap: wrap; justify-content: flex-start; }
  .home-map-top > span { display: none; }
  .home-map-top > * { white-space: nowrap; }
  #homeLocateMe { width: 44px; height: 44px; }
  .home-map-explore { min-height: 48px; }
  .leaflet-control-zoom .leaflet-control-zoom-indicator .zoom-lbl { font-size: 10px !important; }
  .leaflet-control-zoom a { width: 40px !important; height: 40px !important; }
  .leaflet-control-zoom .leaflet-control-zoom-indicator { width: 40px !important; }

  /* --- Lead form & Location UX --- */
  .location-mode-cards {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .loc-mode-card {
    padding: 12px 14px !important;
  }
  .loc-card-icon {
    font-size: 26px !important;
  }
  .btn-primary-gps {
    min-height: 56px !important;
    padding: 12px 14px !important;
  }
  .gps-btn-text strong {
    font-size: 15px !important;
  }
  .gps-btn-text small {
    font-size: 12px !important;
  }
  .map-search-input-shell input {
    font-size: 13.5px !important;
  }
  .btn-search-go {
    padding: 9px 14px !important;
    font-size: 13px !important;
  }
  .map-picker {
    height: 245px !important;
    min-height: 245px !important;
  }
  .form-map-wrapper {
    border-radius: 12px !important;
  }
  .location-choice-sub-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px !important;
  }
  .btn-expand-pill {
    padding: 4px 12px !important;
    font-size: 12px !important;
  }
  .map-hint-banner {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .btn-map-expand-banner {
    justify-content: center !important;
    min-height: 38px !important;
  }
  .map-on-canvas-controls {
    top: 10px !important;
    right: 10px !important;
    gap: 6px !important;
  }
  .map-on-canvas-btn {
    padding: 7px 11px !important;
    font-size: 11.5px !important;
  }
  .map-fs-top-bar {
    padding: max(10px, env(safe-area-inset-top)) 12px 10px !important;
    gap: 8px !important;
  }
  .map-fs-bar-row {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }
  .map-fs-title-box {
    font-size: 13px !important;
  }
  .map-fs-title-text {
    font-size: 13px !important;
  }
  .btn-fs-close {
    padding: 6px 11px !important;
    font-size: 11.5px !important;
  }
  .form-map-wrapper.is-fullscreen .map-on-canvas-controls {
    top: max(116px, calc(env(safe-area-inset-top) + 106px)) !important;
    right: 10px !important;
  }
  .form-map-wrapper.is-fullscreen #formMap .leaflet-bottom.leaflet-left {
    bottom: max(168px, calc(env(safe-area-inset-bottom) + 158px)) !important;
    left: 12px !important;
    z-index: 1005 !important;
  }
  .form-map-wrapper.is-fullscreen #formMap .leaflet-control-zoom {
    z-index: 1005 !important;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35) !important;
  }
  .map-fs-bottom-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px 14px max(14px, env(safe-area-inset-bottom)) !important;
  }
  .btn-fs-confirm {
    width: 100% !important;
    justify-content: center !important;
    min-height: 52px !important;
    font-size: 15px !important;
  }
  .loc-selected-card {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .manual-fields-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  /* Compact Image Upload on Mobile */
  .image-upload-box.compact {
    padding: 6px 10px !important;
  }
  .image-compact-bar {
    gap: 8px !important;
  }
  .image-compact-thumb {
    width: 38px !important;
    height: 38px !important;
  }
  .image-compact-icon {
    font-size: 18px !important;
  }
  .image-compact-title {
    font-size: 12.5px !important;
  }
  .image-compact-sub {
    font-size: 10.5px !important;
  }
  .btn-compact-upload {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
  .image-preview-wrap.compact {
    padding: 5px 8px !important;
    gap: 8px !important;
  }
  .image-preview-wrap.compact img {
    width: 38px !important;
    height: 38px !important;
  }
  .preview-filename {
    font-size: 11.5px !important;
  }
  .btn-compact-remove {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  .form-map-toggle-btn { flex-direction: column; align-items: stretch !important; gap: 12px; text-align: right; }
  .map-toggle-info { align-items: flex-start; }
  .map-toggle-badge { justify-content: center; min-height: 44px; }
  .btn-map-search, .map-locate-btn { min-height: 48px; font-size: 15px !important; }
  .btn-map-search *, .map-locate-btn * { font-size: inherit !important; }
  .map-drawer-footer { flex-direction: column; align-items: stretch !important; gap: 10px; }
  .map-confirm-btn { min-height: 48px; justify-content: center; font-size: 14px !important; }
  .map-interactive-banner, .map-help { font-size: 13px !important; }
  .form-gift-box { flex-direction: column; align-items: flex-start !important; gap: 10px; }
  .form-gift-box .gift-box-copy b { font-size: 16px; line-height: 1.6; }
  .form-gift-box .gift-box-copy p { font-size: 14px; }
  .submit-button { width: 100%; min-height: 56px; justify-content: center; }
  .submit-button .submit-text { font-size: 16px !important; line-height: 1.4; }

  /* --- Full-screen map dialog: compact toolbar, map first, sheet below --- */
  .full-map-header { padding: max(8px, env(safe-area-inset-top)) 12px 8px !important; gap: 8px !important; }
  .full-map-subtitle, .full-map-title small { display: none; }
  .full-map-brand .brand-icon { width: 32px; height: 32px; }
  .full-map-header-actions { gap: 6px; }
  .full-map-header-actions button { min-height: 40px; padding: 6px 12px !important; font-size: 13px !important; }
  .full-map-center-controls {
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .full-map-center-controls::-webkit-scrollbar { display: none; }
  .full-map-center-controls:focus-visible { outline: none; }
  .full-map-close-btn > span:not(.close-x), .full-map-locate-btn .locate-label { display: none; }
  .full-map-close-btn, .full-map-locate-btn { min-width: 40px; justify-content: center; }
  .full-map-header-actions { margin-inline-start: auto; }
  .full-map-center-controls > * { flex: none; white-space: nowrap; }
  .full-map-center-controls button, .full-map-counter-badge { min-height: 40px; }
  .full-map-sidebar { height: 46dvh !important; padding-bottom: env(safe-area-inset-bottom); }
  .map-filter-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .map-autocomplete-shell { height: 38px; }
  .map-autocomplete-input { font-size: 13.5px !important; }
  .map-autocomplete-dropdown { max-height: 170px; z-index: 1080; }
  .home-map-chips, .full-map-region-chips { max-height: 56px; }

  /* --- Standalone /map page --- */
  .map-header { --safe-pad: 16px; height: 64px !important; }
  .map-header .brand-icon { width: 38px; height: 38px; }
  .map-header .brand-name { font-size: 18px !important; }
  .map-back { padding: 0 14px !important; font-size: 13px !important; white-space: nowrap; }
  .map-intro h1 { font-size: 30px !important; }
  .partner-explorer { grid-template-areas: "map" "side" !important; }
  #partnerMap, .map-page-fallback { height: 56dvh !important; min-height: 340px !important; }
  .map-page-top > span, .map-page-attribution { display: none; }
  .map-page-top { justify-content: space-between; }
  .locate-button { width: 48px; height: 48px; }
  .partner-sidebar { grid-template-rows: auto auto auto auto auto !important; }
  .partner-map-list { max-height: none; overflow: visible; }
  .partner-map-card { min-height: 64px; }
  .map-page-cta { width: 100%; justify-content: center; font-size: 15px; text-align: center; }

  /* --- Admin --- */
  .admin-top { --safe-pad: 16px; height: 64px !important; }
  .admin-top-label { display: none; }
  .admin-view { display: inline-flex; align-items: center; min-height: 44px; font-size: 13px !important; }
  .admin-wrap { width: calc(100% - 24px) !important; margin-top: 20px !important; }
  .login-box { margin: 28px auto !important; padding: 26px 20px !important; }
  .login-box .button { width: 100%; justify-content: center; }
  .dashboard-heading { flex-direction: column; align-items: stretch !important; gap: 14px; }
  .dashboard-heading h1 { font-size: 26px !important; line-height: 1.4; }
  .logout-button { align-self: flex-start; white-space: nowrap; }
  .admin-stats { gap: 10px !important; }
  .stat-card-label { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; line-height: 1.4; }
  .admin-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tabs button { flex: none; scroll-snap-align: start; }
  .admin-panel { padding: 16px !important; }
  .panel-heading { flex-direction: column; align-items: stretch !important; gap: 12px; }
  .panel-heading .button { width: 100%; justify-content: center; }
  .partner-admin-form, .edit-grid { grid-template-columns: minmax(0, 1fr) !important; padding: 16px !important; }
  .partner-admin-form label, .edit-grid label { min-width: 0; }
  .partner-admin-form input, .edit-grid input { width: 100%; min-width: 0; }
  .partner-admin-form button { width: 100%; justify-self: stretch !important; justify-content: center; }
  .lead-card { grid-template-columns: minmax(0, 1fr) !important; }
  .lead-actions button, .partner-admin-card button { min-height: 40px; padding: 0 14px; }
  .partner-edit-dialog { width: calc(100% - 16px) !important; max-width: none !important; max-height: calc(100dvh - 16px); margin: auto; overflow-y: auto !important; overscroll-behavior: contain; }
  .modal-dialog-content { padding: 20px 18px 0 !important; }
  .modal-dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    gap: 10px !important;
    margin: 20px -18px 0 !important;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom)) !important;
    background: #fff;
    box-shadow: 0 -8px 20px -12px #07598555;
  }
  .modal-dialog-actions .button { flex: 1 1 0; justify-content: center; padding: 0 12px !important; white-space: nowrap; }
}

/* Very small phones (≤ 360px, e.g. Galaxy S8 / iPhone SE 1st gen) */
@media (max-width: 360px) {
  .wrap { width: calc(100% - 28px) !important; }
  .nav.wrap { --safe-pad: 12px; }
  .brand-name { font-size: 18px !important; }
  .app-store-badges { flex-direction: column; }
  .hero-product-image { width: 100% !important; max-width: 100% !important; }
  .full-map-header-actions .sidebar-toggle-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
