/* AAC Pro Estimator - iOS Mobile Shell v110
   Activates at <= 820px; desktop layout is untouched above that breakpoint.
   v110 adds: 6-tab bar, Home panel, virtual scan tiles, Review grouping, Back FAB.
*/

/* Shell is hidden by default (desktop sees nothing) */
#iosShell {
  display: none;
}

/* Tool cards inside the tools panel are hidden until a tile is tapped */
.ios-tool-card-hidden {
  display: none !important;
}

/* ========================================================
   MOBILE SHELL  (only applies at phone / tablet widths)
   ======================================================== */
@media (max-width: 820px) {

  /* Prevent the desktop content from scrolling behind the fixed shell.
     overflow:hidden alone does not stop iOS Safari rubber-band overscroll,
     which peeks through the fixed overlay and reveals the full 3876px
     multi-view document (the "roller deck"). position:fixed freezes the
     viewport scroll anchor entirely — the proven iOS Safari scroll-lock. */
  body.ios-shell-active {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /* Hide ALL desktop chrome behind the shell — belt-and-suspenders so
     nothing bleeds through even on overscroll edge frames. */
  body.ios-shell-active .app-shell__nav,
  body.ios-shell-active .aac-mode-nav,
  body.ios-shell-active .app-shell__header,
  body.ios-shell-active .credentials-bar,
  body.ios-shell-active .results-box-mobile-sticky-totals,
  body.ios-shell-active .aac-rd-fab,
  body.ios-shell-active #aacBuildStamp {
    display: none !important;
  }

  /* Full-viewport shell sits on top of everything */
  #iosShell {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #f4f4f8;
    -webkit-overflow-scrolling: touch;
  }

  /* --------------------------------------------------
     PINNED HEADER  -  project name + running total
     -------------------------------------------------- */
  #iosShellHeader {
    background: #19195F;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top, 0px);
    min-height: calc(52px + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
  }

  #iosShellProjectName {
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 52%;
  }

  #iosShellTotal {
    font-family: 'Playfair Display', serif;
    font-size: 22px;
    font-weight: 700;
    color: #C9A84C;
    letter-spacing: 0.2px;
    white-space: nowrap;
  }

  /* --------------------------------------------------
     PANELS CONTAINER
     -------------------------------------------------- */
  #iosShellPanels {
    flex: 1;
    overflow: hidden;
    position: relative;
  }

  /* Each panel fills the container and scrolls independently.
     overscroll-behavior:contain stops the panel's momentum from
     propagating to the document and triggering iOS rubber-band. */
  .ios-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px 16px 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

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

  /* Cards inside panels get a clean elevated look */
  #iosShell .card {
    border-radius: 14px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
    background: #fff;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
  }

  /* --------------------------------------------------
     TOOLS PANEL  -  2-column tile grid
     -------------------------------------------------- */
  .ios-tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }

  .ios-tool-tile {
    background: #fff;
    border: 1.5px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px 10px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
    font-family: 'Montserrat', sans-serif;
    font-size: inherit;
    color: inherit;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
  }

  .ios-tool-tile:active {
    transform: scale(0.95);
  }

  .ios-tool-tile.active {
    border-color: #19195F;
    box-shadow: 0 0 0 2px rgba(25, 25, 95, 0.12);
    background: rgba(25, 25, 95, 0.03);
  }

  .ios-tool-tile svg {
    width: 26px;
    height: 26px;
    color: #19195F;
    flex-shrink: 0;
    display: block;
  }

  .ios-tool-tile.active svg {
    color: #C9A84C;
  }

  .ios-tile-label {
    font-size: 11px;
    font-weight: 600;
    color: #374151;
    line-height: 1.3;
  }

  .ios-tool-tile.active .ios-tile-label {
    color: #19195F;
  }

  /* Expanded tool card is visible */
  .ios-tool-card-active {
    display: block !important;
  }

  /* --------------------------------------------------
     MORE PANEL  -  sync status line
     -------------------------------------------------- */
  #iosShellSync {
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    color: #9ca3af;
    padding: 4px 0 12px;
  }

  /* --------------------------------------------------
     BOTTOM TAB BAR
     -------------------------------------------------- */
  #iosTabBar {
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    position: relative;
    z-index: 10;
  }

  .ios-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    min-height: 52px;
    touch-action: manipulation;
  }

  .ios-tab-btn svg {
    width: 22px;
    height: 22px;
    color: #9ca3af;
    transition: color 0.15s ease;
    flex-shrink: 0;
    display: block;
  }

  .ios-tab-btn .ios-tab-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 500;
    color: #9ca3af;
    transition: color 0.15s ease;
    line-height: 1;
    white-space: nowrap;
  }

  .ios-tab-btn.active svg {
    color: #C9A84C;
  }

  .ios-tab-btn.active .ios-tab-label {
    color: #C9A84C;
    font-weight: 700;
  }


  /* --------------------------------------------------
     HOME PANEL
     -------------------------------------------------- */
  .ios-home-hero {
    text-align: center;
    padding: 20px 0 12px;
  }

  .ios-home-greeting {
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 4px;
  }

  .ios-home-brand {
    font-family: 'Playfair Display', serif;
    font-size: 22px;
    font-weight: 700;
    color: #19195F;
  }

  .ios-home-new-estimate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px;
    background: #19195F;
    color: #fff;
    border: none;
    border-radius: 14px;
    font-family: 'Montserrat', sans-serif;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.3px;
    margin: 4px 0 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s ease, transform 0.1s ease;
    box-shadow: 0 4px 16px rgba(25, 25, 95, 0.22);
  }

  .ios-home-new-estimate:active {
    opacity: 0.88;
    transform: scale(0.98);
  }

  .ios-home-new-estimate svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  /* 2D / 3D Scan card */
  .ios-home-scan-card {
    background: linear-gradient(135deg, #19195F 0%, #0d0a3e 100%);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 16px;
  }

  .ios-home-scan-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
  }

  .ios-home-scan-icon {
    width: 28px;
    height: 28px;
    color: #C9A84C;
    flex-shrink: 0;
  }

  .ios-home-scan-title {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
  }

  .ios-home-scan-sub {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 2px;
  }

  .ios-home-scan-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .ios-home-scan-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    background: #C9A84C;
    color: #19195F;
    border: none;
    border-radius: 10px;
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s ease;
  }

  .ios-home-scan-primary:active { opacity: 0.85; }

  .ios-home-scan-primary svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .ios-home-scan-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s ease;
  }

  .ios-home-scan-secondary:active { opacity: 0.75; }

  .ios-home-scan-secondary svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  /* Section labels */
  .ios-home-section-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 10px;
    margin-top: 4px;
  }

  /* Recent estimates list */
  .ios-home-recent-section {
    margin-bottom: 20px;
  }

  .ios-home-recent-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .ios-home-recent-empty {
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    color: #9ca3af;
    padding: 14px 0;
    text-align: center;
  }

  .ios-home-recent-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #fff;
    border-radius: 12px;
    padding: 13px 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  }

  .ios-home-recent-row:active { opacity: 0.75; }

  .ios-home-recent-info {
    flex: 1;
    min-width: 0;
  }

  .ios-home-recent-name {
    font-family: 'Montserrat', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #19195F;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ios-home-recent-code {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
  }

  .ios-home-recent-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
  }

  .ios-home-recent-total {
    font-family: 'Playfair Display', serif;
    font-size: 14px;
    font-weight: 700;
    color: #C9A84C;
  }

  .ios-home-status {
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .ios-status-draft {
    background: #f3f4f6;
    color: #6b7280;
  }

  .ios-status-sent,
  .ios-status-approved {
    background: #dcfce7;
    color: #15803d;
  }

  .ios-status-pending {
    background: #fef9c3;
    color: #854d0e;
  }

  /* Quick access grid */
  .ios-home-quick-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 24px;
  }

  .ios-home-quick-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 10px;
    background: #fff;
    border: 1.5px solid #e5e7eb;
    border-radius: 14px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #19195F;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s ease, transform 0.1s ease;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  }

  .ios-home-quick-tile:active {
    transform: scale(0.95);
    border-color: #19195F;
  }

  .ios-home-quick-tile svg {
    width: 22px;
    height: 22px;
    color: #C9A84C;
    flex-shrink: 0;
  }

  /* --------------------------------------------------
     VIRTUAL SCAN TILES  (Tools tab — gold accent)
     -------------------------------------------------- */
  .ios-tool-tile-scan {
    border-color: #C9A84C;
    background: linear-gradient(135deg, rgba(201, 168, 76, 0.07), rgba(201, 168, 76, 0.02));
  }

  .ios-tool-tile-scan svg {
    color: #C9A84C;
  }

  .ios-tool-tile-scan .ios-tile-label {
    color: #19195F;
  }

  .ios-tool-tile-scan:active {
    transform: scale(0.95);
    background: rgba(201, 168, 76, 0.14);
  }

  /* --------------------------------------------------
     REVIEW TAB  -  grouped action sections
     Groups are injected by reviewGroupPass() in mobile-shell.js.
     -------------------------------------------------- */
  .ios-review-group {
    margin-bottom: 8px;
  }

  .ios-review-group-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 10px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin: 16px 0 8px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
  }

  .ios-review-group-label:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }

  .ios-review-btn-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
  }

  .ios-review-btn-row > * {
    flex: 1;
  }

  /* Compact vertical stack inside a group */
  .ios-review-group > button,
  .ios-review-group > div > button {
    margin-bottom: 8px !important;
    margin-top: 0 !important;
  }

  /* --------------------------------------------------
     BACK FAB  (shown when tempShowDesktopMode is active)
     -------------------------------------------------- */
  .ios-shell-back-fab {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    background: #19195F;
    color: #fff;
    border: none;
    border-radius: 24px;
    padding: 13px 24px;
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
    box-shadow: 0 6px 20px rgba(25, 25, 95, 0.35);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
  }

}
/* end @media (max-width: 820px) */
