/* ==========================================================================
   Sketch3D-Art Studio Pro — Responsive layer (Phase N, v2.20.0)
   Loaded LAST so these rules win over app.css/brand.css on small screens.
   Targets the defects measured at 390px width:
   1) the header ad slot flex-basis (320px) became a 320px-tall empty void
      when the mobile header switched to a column layout;
   2) in design mode the portal header pushed the studio ~1000px down-page;
   3) chip/tool strips clipped instead of scrolling, and small tap targets.
   ========================================================================== */

/* ---------- Tablets and below ---------- */
@media (max-width: 900px) {
  /* Wide data tables scroll inside their card instead of stretching the page */
  .s3a-portal-body-wrapper table,
  .s3a-page-tab-home table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---------- Phones ---------- */
@media (max-width: 768px) {

  /* 1) Header ad slot: flex-basis was a WIDTH on desktop; in the column
        mobile header it turned into a 320px height. Pin it to content. */
  .s3a-portal-top-header .s3a-ads-header-wrap {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 56px !important;
    overflow: hidden !important;
  }
  .s3a-portal-top-header .s3a-ads-container,
  .s3a-portal-top-header .s3a-ads-header {
    height: auto !important;
    min-height: 0 !important;
    max-height: 56px !important;
  }
  /* When no ad is actually loaded the placeholder collapses entirely */
  .s3a-portal-top-header .s3a-ads-header-wrap:empty {
    display: none !important;
  }

  /* Compact portal header: brand row + meta row, no dead space */
  .s3a-portal-top-header {
    padding: 10px 12px !important;
  }
  .s3a-portal-top-header > div {
    gap: 8px !important;
  }

  /* 2) Design mode owns the screen: hide the portal top header, let the
        studio fill the viewport under the 48px navbar */
  .s3a-design-active .s3a-portal-top-header {
    display: none !important;
  }
  .s3a-design-active .s3a-portal-body-wrapper {
    padding: 0 !important;
    margin: 0 !important;
  }
  .s3a-design-active .s3at,
  .s3a-design-active .s3at .group {
    height: calc(100dvh - 48px) !important;
    max-height: calc(100dvh - 48px) !important;
  }

  /* 3) The view-switcher bar floating over the canvas is 628px wide on
        desktop; on phones it clipped on BOTH sides. Fit it to the screen
        and let its chip groups scroll horizontally instead. */
  .s3as-canvas > div:has(> .s3a-dsw) {
    left: 8px !important;
    right: auto !important;
    width: auto !important;
    max-width: calc(100vw - 16px) !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .s3as-canvas > div:has(> .s3a-dsw) > * {
    flex: 0 0 auto;
  }

  /* Comfortable touch targets in the portal chrome (F27: 44px minimum,
     WCAG 2.5.8 / Apple HIG — was 40px) */
  .s3a-nav-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* F27: 44px minimum touch targets on phones. The tools FAB, chips and
     view-switcher buttons grow to 44px; dense 28px icon buttons keep
     their visual size but get an invisible 44px hit area via ::after so
     sheet rows and toolbars don't break. */
  .s3a-mobile-tools-fab {
    min-height: 44px;
    padding: 10px 16px;
  }
  .seg .chip,
  button.chip {
    min-height: 44px;
  }
  .s3a-dsw button {
    min-height: 44px;
  }
  .icon-btn {
    position: relative;
  }
  .icon-btn::after {
    content: "";
    position: absolute;
    inset: -8px;
  }

  /* Phase O-3 (M-2): on phones the Sign In / Register buttons sat past
     the right edge of the horizontally-scrolling navbar. Let the navbar
     wrap to two rows instead — but ONLY outside design mode, where the
     studio canvas height is computed as 100dvh - 48px. Both button
     groups wrap internally so nothing overflows the screen.
     NOTE: app.css (same breakpoint) forces the strip layout with
     `width: max-content !important` + `flex-wrap: nowrap !important` on
     the inner div plus the M-9 edge-fade mask — all three must be
     overridden here (higher specificity + later file wins). */
  .s3a-global-app-root:not(.s3a-design-active) .s3a-portal-main-navbar {
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
  }
  .s3a-global-app-root:not(.s3a-design-active) .s3a-portal-main-navbar > div {
    flex-wrap: wrap !important;
    height: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: visible !important;
    row-gap: 6px !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
  }
  .s3a-global-app-root:not(.s3a-design-active) .s3a-portal-main-navbar > div > div {
    flex-wrap: wrap !important;
    flex-shrink: 1 !important;
  }

  /* iOS Safari: inputs under 16px trigger an automatic page zoom on focus */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Media never exceeds the screen */
  img, video, iframe, svg {
    max-width: 100%;
  }

  /* Dialogs/modals fit the phone screen */
  .modal, .s3a-modal, [role="dialog"] {
    max-width: calc(100vw - 20px) !important;
  }
}

/* ---------- Small phones ---------- */
@media (max-width: 480px) {
  .s3a-portal-top-header .brand-sub {
    display: none !important; /* tagline is decorative; save the row */
  }
  .s3a-portal-main-navbar {
    height: 46px;
  }
}
