/* ============================================
   Pixelius — Mobile overrides (≤ 768px)
   Single-tab thumb-first layout.

   Intent: Customer on a phone between sessions — one-handed,
   sometimes outdoor light. Wants: tap → pick photo → run → save.
   Hide every other tab. Anchor primary CTA to thumb zone.
   ============================================ */

/* ============================================
   Visibility helpers — viewport-conditional content.
   Used to swap copy that references gestures (drag-drop)
   which don't exist on touch. Default: hide .mobile-only.
   ============================================ */
.mobile-only { display: none !important; }

@media (max-width: 768px) {

  /* Flip visibility inside mobile breakpoint */
  .mobile-only { display: block !important; }
  .desktop-only { display: none !important; }
  /* Inline variants for spans inside flowing text */
  span.mobile-only { display: inline !important; }
  span.desktop-only { display: none !important; }


  /* ============================================
     1. Header — compact, drop secondary actions
     ============================================ */
  .app-header {
    height: 2.875rem;
    min-height: 2.875rem;
    padding: 0 0.75rem;
    gap: 0.5rem;
  }

  .app-header .logo {
    font-size: 0.9375rem;
  }
  .app-header .logo-icon {
    width: 1.25rem;
    height: 1.25rem;
  }

  /* On mobile we expose only two tabs (Upscale + Deblur). Show the tab bar
     but hide the buttons that aren't reachable from a phone, so the bar
     doesn't fragment into a row of cramped icons. The router enforces the
     same allowlist so stale URLs/hashes can't reach hidden tabs. */
  .tab-bar {
    padding: 0 0.5rem;
    gap: 0;
    overflow-x: hidden;
  }
  .tab-bar .tab-btn[data-tab="advanced"],
  .tab-bar .tab-btn[data-tab="refine"],
  .tab-bar .tab-btn[data-tab="yearbook"] {
    display: none !important;
  }
  /* Make the visible tabs share the row evenly with comfortable touch targets */
  .tab-bar .tab-btn {
    flex: 1 1 0;
    min-height: 2.5rem;
    padding: 0 0.5rem;
    justify-content: center;
    font-size: 0.8125rem;
  }

  /* Theme follows OS on phones; redeem code is reachable from the points panel */
  .theme-toggle,
  #btn-add-code {
    display: none !important;
  }

  /* Points pill — keep, but tighten so it doesn't crowd the avatar */
  .user-points {
    padding: 0 0.5rem;
    height: 2rem;
    gap: 0.25rem;
  }
  .user-points svg {
    width: 0.875rem;
    height: 0.875rem;
  }
  .user-points span {
    font-size: 0.8125rem;
  }

  .user-avatar {
    width: 2rem;
    height: 2rem;
    font-size: 0.8125rem;
  }

  /* Push points + avatar to the right edge — header has just 3 items now */
  .header-right {
    margin-left: auto;
    gap: 0.5rem;
  }


  /* ============================================
     2. Basic-tab workspace — fill viewport
     ============================================ */
  /* (Removed redundant `.tab-pane { height: calc(100vh - 2.875rem) }` override:
     base.css already gives the pane `position: absolute; inset: 0` which fills
     the parent .tab-content correctly. The 100vh-based override fought against
     dvh sizing on iOS, pushing the bottom toolbar below the fold.) */

  /* Welcome state: shrink so the icon + copy don't crowd small screens */
  #tab-basic .welcome-icon {
    width: 3.5rem;
    height: 3.5rem;
  }
  #tab-basic .welcome-title {
    font-size: 1.0625rem;
    margin-top: 0.875rem;
  }
  #tab-basic .welcome-desc {
    font-size: 0.8125rem;
    max-width: 18rem;
    line-height: 1.5;
  }

  /* Drag-drop overlay is meaningless on touch — hide it */
  .drop-zone-overlay {
    display: none !important;
  }

  /* Bump the preview "X" close button to a 44px tap target */
  .preview-clear-btn {
    width: 2.75rem;
    height: 2.75rem;
    top: 0.75rem;
    right: 0.75rem;
  }


  /* ============================================
     5. Deblur tab — stack queue panel above workspace
     ============================================ */
  #tab-deblur .layout-3col {
    flex-direction: column;
  }
  /* Queue panel collapses to a compact horizontal strip on top */
  #tab-deblur .panel-left {
    width: 100%;
    min-width: 0;
    max-width: none;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.625rem;
    gap: 0.5rem;
  }
  /* Add Files / Folder side-by-side */
  #tab-deblur .panel-left .import-actions {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
  }
  #tab-deblur .panel-left .import-btn {
    flex: 1;
    justify-content: center;
    min-height: 2.5rem;
    font-size: 0.8125rem;
  }
  /* Queue header + list compressed; list scrolls vertically with capped height */
  #tab-deblur .panel-left .queue-header {
    padding: 0.25rem 0;
  }
  #tab-deblur .panel-left .queue-list {
    max-height: 6.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
  }
  #tab-deblur .panel-left .queue-empty {
    padding: 0.625rem;
    font-size: 0.75rem;
  }
  #tab-deblur .panel-left .queue-empty svg {
    width: 1.25rem;
    height: 1.25rem;
  }
  /* Run + Clear in a thumb-friendly row */
  #tab-deblur .panel-left .queue-actions {
    display: flex;
    gap: 0.5rem;
  }
  #tab-deblur .panel-left .queue-actions .btn {
    min-height: 2.75rem;
    font-size: 0.875rem;
  }
  #tab-deblur .panel-left .queue-actions .btn-primary {
    flex: 2;
    box-shadow: 0 0 0 1px rgba(216, 254, 61, 0.18);
  }
  #tab-deblur .panel-left .queue-actions .btn-ghost {
    flex: 1;
  }

  /* Workspace below takes remaining space */
  #tab-deblur .panel-main {
    flex: 1 1 auto;
    min-height: 0;
  }
  /* Welcome state shrink for narrow screens */
  #tab-deblur .welcome-icon {
    width: 3rem;
    height: 3rem;
  }
  #tab-deblur .welcome-title {
    font-size: 1rem;
  }
  #tab-deblur .welcome-desc {
    font-size: 0.8125rem;
    max-width: 18rem;
  }
  /* Hide desktop zoom controls on the deblur viewer (pinch is native via View modal) */
  #tab-deblur .viewer-controls {
    display: none !important;
  }


  /* ============================================
     6. Deblur — Variants viewer (mobile-first compare)
     ============================================
     The 3-column desktop grid becomes a vertical scroll of full-width
     cards on phones, with the original pinned at the top so the user
     never loses the reference while scrolling through variants.
     Tap any card → existing slider comparison viewer (Original vs that variant).
  */
  #tab-deblur #deb-variants .viewer-info-bar {
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
  }
  #tab-deblur #deb-variants .viewer-info-bar #deb-btn-close-variants {
    min-height: 2.25rem;
    padding: 0 0.875rem;
  }

  /* Vertical stack — 1 column, comfortable thumb-scrolling */
  #tab-deblur .variants-grid {
    grid-template-columns: 1fr;
    gap: 0.625rem;
    padding: 0.625rem;
    /* iOS momentum scrolling */
    -webkit-overflow-scrolling: touch;
  }

  /* Each card: header tighter, image area stretches to ~55vh max */
  #tab-deblur .variant-card {
    border-radius: 0.625rem;
    /* Subtle visual lift so cards feel selectable, not a flat list */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  }
  #tab-deblur .variant-card-header {
    padding: 0.625rem 0.875rem;
    background: var(--surface);
  }
  #tab-deblur .variant-card-label {
    font-size: 0.875rem;
    letter-spacing: -0.005em;
  }
  /* "Tap to compare" affordance — a small hint right of the label */
  #tab-deblur .variant-card-label::after {
    content: " · tap to compare";
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0;
    margin-left: 0.25rem;
  }
  /* Bigger download tap target */
  #tab-deblur .variant-card-download {
    width: 2.25rem;
    height: 2.25rem;
  }
  #tab-deblur .variant-card-download svg {
    width: 1rem;
    height: 1rem;
  }

  /* Image area: aspect-driven so portrait phone photos don't get squashed */
  #tab-deblur .variant-card-body {
    min-height: 14rem;
    max-height: 55vh;
    background: var(--bg-tertiary);
  }
  #tab-deblur .variant-card-body img {
    object-fit: contain;
  }
  /* Hover state useless on touch — kill the hover dim that just causes
     a flicker on tap */
  #tab-deblur .variant-card-body:hover {
    opacity: 1;
  }

  /* Spinner rooms — bigger so cards have presence even before output arrives */
  #tab-deblur .variant-spinner {
    min-height: 14rem;
  }


  /* ============================================
     3. Bottom toolbar — 2-row thumb-first grid
        Row 1: resolution pills (4 columns)
        Row 2: Load · Run · Save (3 columns, Run prominent)
     ============================================ */
  #tab-basic .basic-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-auto-rows: auto;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    /* Respect iOS home indicator */
    padding-bottom: max(0.625rem, env(safe-area-inset-bottom));
  }

  /* Resolution pills span all 3 columns on row 1 */
  #tab-basic .basic-toolbar .resolution-pills {
    grid-column: 1 / -1;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
    padding: 0.1875rem;
  }

  #tab-basic .basic-toolbar .res-pill {
    padding: 0.625rem 0.25rem;
    font-size: 0.8125rem;
    min-height: 2.375rem;
    text-align: center;
  }

  /* Active pill more visually pronounced on mobile (no hover affordance) */
  #tab-basic .basic-toolbar .res-pill.active {
    font-weight: 600;
  }

  /* Hide the inline divider <div> between buttons and pills (no longer needed in grid) */
  #tab-basic .basic-toolbar > div[style*="background:var(--border)"],
  #tab-basic .basic-toolbar > div[style*="background: var(--border)"] {
    display: none !important;
  }

  /* Action row: 3 equal-width 44px-tall buttons */
  #tab-basic .basic-toolbar #basic-btn-load,
  #tab-basic .basic-toolbar #basic-btn-run,
  #tab-basic .basic-toolbar #basic-btn-save {
    height: 2.75rem;
    font-size: 0.875rem;
    padding: 0 0.75rem;
    width: 100%;
  }
  /* Place the 3 buttons in row 2 explicitly */
  #tab-basic .basic-toolbar #basic-btn-load { grid-column: 1; }
  #tab-basic .basic-toolbar #basic-btn-run  { grid-column: 2; }
  #tab-basic .basic-toolbar #basic-btn-save { grid-column: 3; }

  /* Ensure Run keeps the lime accent prominence */
  #tab-basic .basic-toolbar .btn-primary {
    box-shadow: 0 0 0 1px rgba(216, 254, 61, 0.18);
  }


  /* ============================================
     4. Viewer (preview / before-after) — touch friendly
     ============================================ */
  /* Top info bar: keep horizontal but shrink + truncate filename */
  #tab-basic .viewer-info-bar {
    padding: 0.5rem 0.625rem;
    gap: 0.375rem;
    font-size: 0.75rem;
  }
  #tab-basic .viewer-filename {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #tab-basic .viewer-actions {
    gap: 0.25rem;
  }
  #tab-basic .viewer-actions .btn-sm {
    padding: 0.375rem 0.625rem;
    height: 2rem;
  }

  /* Hide zoom controls — pinch-zoom is the native mobile gesture */
  #tab-basic .viewer-controls {
    display: none !important;
  }

  /* Slider handle bigger on touch */
  .viewer-slider-handle {
    width: 2rem !important;
    height: 2rem !important;
  }


  /* ============================================
     5. Processing overlay — center, more breathing room
     ============================================ */
  #tab-basic .processing-overlay {
    padding: 1.5rem;
  }
  #tab-basic .progress-percent {
    font-size: 2.25rem;
  }
  #tab-basic .progress-text {
    font-size: 0.8125rem;
  }


  /* ============================================
     6. Modals & toasts — full-bleed cards
     ============================================ */
  .modal-backdrop .modal {
    max-width: calc(100vw - 1.5rem) !important;
    width: calc(100vw - 1.5rem);
    margin: 0.75rem;
  }

  /* Toast: bottom-center on mobile (less likely to overlap thumb) */
  .toast,
  #toast {
    bottom: 4.5rem !important;
    top: auto !important;
    left: 0.75rem !important;
    right: 0.75rem !important;
    max-width: none !important;
  }

  /* User dropdown: full-width pop-down so labels don't truncate */
  .user-dropdown {
    right: 0.75rem !important;
    left: auto !important;
    min-width: 11rem;
  }

}


/* ============================================
   Tighter phone breakpoint (≤ 400px) — extra-small
   ============================================ */
@media (max-width: 400px) {
  .app-header .logo {
    /* On a 360px iPhone SE, the logo word competes with points + avatar.
       Drop the wordmark; the icon alone carries the brand. */
    display: none;
  }

  #tab-basic .basic-toolbar .res-pill {
    font-size: 0.75rem;
    padding: 0.5rem 0.125rem;
  }

  #tab-basic .welcome-title {
    font-size: 1rem;
  }
  #tab-basic .welcome-desc {
    font-size: 0.75rem;
  }
}
