/* Prevent nav auth flicker on mobile */
@media (max-width: 768px) {
  body.logged-in #nav-auth { display: none !important; }
  body:not(.logged-in) #nav-user { display: none !important; }
}

/* ============================================
   ESC MOBILE - Bottom Tab Navigation & Layout
   Only applies at max-width: 768px
   ============================================ */

@media (max-width: 768px) {

  /* Hide all marketing/explanatory sections on mobile */
  #how,
  #pledge,
  #markets,
  #tracks,
  #advisory-program,
  #structure,
  #exchange-1031,
  .hero,
  .marquee-wrap,
  .how-section,
  .markets-section,
  .tracks-section,
  .advisory-section,
  .structure-section {
    display: none !important;
  }

  /* Hide marketing nav links - keep only functional ones */
  #nav-pub-links li:not(#nav-portal-tab) {
    display: none !important;
  }

  /* Hide desktop nav links (but allow .open to override) */
  #nav-pub-links {
    display: none !important;
  }

  /* When menu opens, only show My Portal link */
  #nav-pub-links.open {
    display: flex !important;
    position: fixed !important;
    top: 52px !important;
    left: 0 !important;
    right: 0 !important;
    background: #111 !important;
    z-index: 999 !important;
    padding: 16px !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  #nav-pub-links.open a {
    color: #fff !important;
    font-size: 15px !important;
    padding: 8px 0 !important;
  }
  .hero-section,
  .marketing-section,
  .public-sections,
  #ip-how {
    display: none !important;
  }

  /* Top bar - compact */
  nav, .nav, header nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 8px 16px;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Main content area - account for top and bottom bars */
  body {
    padding-top: 52px;
    padding-bottom: 64px;
  }

  /* Bottom Tab Bar */
  #mobile-tab-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #111;
    border-top: 1px solid #333;
    z-index: 1000;
    align-items: center;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #888;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    padding: 8px 0;
    border: none;
    background: none;
    transition: color 0.2s;
  }

  .mobile-tab-btn.active {
    color: #C9A962;
  }

  .mobile-tab-btn svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.5;
  }

  /* Mobile tab panels */
  .mobile-panel {
    display: none;
    padding: 16px;
  }

  .mobile-panel.active {
    display: block;
  }

  /* Single column overrides */
  .grid, [class*="grid-"], [class*="-grid"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Cards full width */
  .card, [class*="-card"], [class*="card-"] {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Fix horizontal overflow */
  body, .container, main, section, article {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }

  /* Portal tabs - scrollable horizontal row */
  .portal-tabs, [class*="portal-tab"] {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    gap: 8px !important;
    padding: 8px 0 !important;
    scrollbar-width: none !important;
    white-space: nowrap !important;
  }

  .portal-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Stats bar - 2 column grid */
  .stats-bar, [class*="stats"] {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }

  /* Underwriting calculator - stack inputs */
  #pt-underwriting .calc-grid,
  #pt-underwriting .input-row,
  #pt-underwriting .results-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  #pt-underwriting input,
  #pt-underwriting select {
    width: 100% !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
    padding: 12px !important;
  }

  /* Typography scale down */
  h1 { font-size: 1.8rem !important; }
  h2 { font-size: 1.4rem !important; }
  h3 { font-size: 1.1rem !important; }

  /* Buttons full width */
  .btn-primary, .btn-cta, [class*="btn-"] {
    width: 100% !important;
    padding: 14px !important;
    font-size: 15px !important;
  }

  /* Hide PWA install banner inside Capacitor */
  .pwa-banner, #pwa-banner, [id*="install"], [class*="install-banner"] {
    display: none !important;
  }

  /* Fix mobile nav menu - ensure it displays when open */
  .nav-menu,
  .nav-links,
  .nav-dropdown,
  #nav-menu,
  #mobile-nav,
  [class*="nav-menu"],
  [class*="nav-links"] {
    position: fixed !important;
    top: 52px !important;
    left: 0 !important;
    right: 0 !important;
    background: #111 !important;
    z-index: 999 !important;
    padding: 16px !important;
    flex-direction: column !important;
  }

  /* Fix hamburger/close button */
  .hamburger,
  .menu-toggle,
  [class*="hamburger"],
  [class*="menu-toggle"],
  .nav-toggle {
    display: flex !important;
    visibility: visible !important;
  }

  /* Hide public marketing site on mobile when logged in */
  body.logged-in #public-site {
    display: none !important;
  }

  /* Stack Investment Summary and Deal Allocation cards vertically */
  #pt-overview .section-2col,
  .section-2col {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  #pt-overview .section-2col > div,
  .section-2col > div {
    width: 100% !important;
  }

  /* Fix card backgrounds in My Portal */
  #pt-overview .card,
  #pt-overview > div,
  #ip-main .card,
  #ip-main > div > div {
    background: #ffffff !important;
    color: #111111 !important;
  }

  /* Fix 1031 promo banner overflow */
  #pt-overview .promo-banner,
  [class*="promo"],
  [class*="1031"] {
    width: 100% !important;
    overflow: hidden !important;
  }

  /* Fix nav auth buttons on mobile */
  #nav-auth {
    display: flex !important;
    gap: 8px !important;
    align-items: center !important;
  }

  .btn-nav {
    font-size: 11px !important;
    padding: 6px 10px !important;
    white-space: nowrap !important;
  }

  /* Fix modal staying open when Apply is clicked after Sign In */
  .overlay {
    z-index: 2000 !important;
  }

  .modal {
    z-index: 2001 !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }

  /* Hide Sign In / Apply when logged in */
  body.logged-in #nav-auth {
    display: none !important;
  }

  /* Hide Sign Out when not logged in */
  body:not(.logged-in) #nav-user {
    display: none !important;
  }

  /* Show investor portal immediately on mobile when logged in */
  body.logged-in #investor-portal {
    display: block !important;
  }

  /* Commitment section full width */
  .dd-commit-box {
    width: 100% !important;
    margin: 16px 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .dd-commit-header {
    padding: 28px 20px 20px !important;
  }

  .dd-commit-body {
    padding: 24px 20px !important;
  }

  .dd-commit-form {
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Radio button groups - stack vertically */
  .dd-radio-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .dd-radio-opt {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 16px !important;
    text-align: left !important;
  }

  /* Amount input full width */
  .dd-amount-input {
    width: 100% !important;
    font-size: 16px !important;
    padding: 14px 16px !important;
    box-sizing: border-box !important;
  }

  /* Compact toggle buttons */
  .dd-toggle-group {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
    width: 100% !important;
    margin-bottom: 8px !important;
  }

  .dd-toggle-btn {
    flex: 1 !important;
    padding: 12px 8px !important;
    font-size: 12px !important;
    letter-spacing: 0.5px !important;
    border: 1px solid #111 !important;
    background: #fff !important;
    color: #111 !important;
    cursor: pointer !important;
    text-align: center !important;
    position: relative !important;
  }

  .dd-toggle-btn.active {
    background: #111 !important;
    color: #fff !important;
  }

  .dd-info-btn {
    font-size: 11px !important;
    margin-left: 4px !important;
    opacity: 0.6 !important;
    cursor: pointer !important;
  }

  .dd-info-box {
    background: #f5f5f3 !important;
    padding: 12px !important;
    font-size: 12px !important;
    line-height: 1.6 !important;
    color: #555 !important;
    margin-bottom: 8px !important;
  }

  .dd-field-label {
    font-size: 11px !important;
    letter-spacing: 1.5px !important;
    color: #888 !important;
    margin-bottom: 8px !important;
    text-transform: uppercase !important;
  }

  .dd-commit-btn {
    width: 100% !important;
    padding: 18px !important;
    font-size: 13px !important;
    letter-spacing: 2px !important;
    margin-top: 16px !important;
  }

  /* Stack 2-col sections */
  #pt-overview .section-2col,
  .section-2col {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    width: 100% !important;
  }

  .section-2col > * {
    width: 100% !important;
  }

  /* Ensure investor portal is full width */
  #investor-portal {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    padding: 0 !important;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* iOS zoom fix — inputs under 16px trigger zoom */
  .fi, input, select, textarea {
    font-size: 16px !important;
  }

  /* Smooth section transitions */
  .ip-section {
    animation: mFadeIn 0.15s ease-in;
  }
  @keyframes mFadeIn { from { opacity: 0; } to { opacity: 1; } }

  /* Mobile Calculator */
  #ip-calculator { padding: 16px !important; }

  .mc-field { margin-bottom: 14px; }

  .mc-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--gray-400);
    display: block;
    margin-bottom: 6px;
  }

  .mc-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--white);
    border: 1px solid var(--border);
    margin-bottom: 8px;
  }

  .mc-result-label {
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--gray-400);
  }

  .mc-result-value {
    font-family: 'Playfair Display', serif;
    font-size: 20px;
    color: var(--black);
  }

  .mc-result-value.good { color: #2d7a4f; }
  .mc-result-value.warn { color: #c0392b; }

  /* Modal mobile polish */
  .modal {
    padding: 24px 20px !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }

  .btn-submit {
    padding: 16px !important;
    font-size: 13px !important;
  }

}

/* Hide bottom tab bar and calculator on desktop */
@media (min-width: 769px) {
  #mobile-tab-bar {
    display: none !important;
  }
  #ip-calculator {
    display: none !important;
  }
}
