/**
 * App shell — behaviours + device density.
 *
 * Does NOT restyle phone/tablet public or desk visuals (those live in
 * marketplace.css, desk.css, pwa.css). This layer adds:
 *   - pull-to-refresh chrome
 *   - horizontal swipe-friendly scroll strips
 *   - laptop/desktop density only
 *   - friendly press / focus polish that inherits tokens
 */

/* ---- pull to refresh ---------------------------------------------- */

.app-ptr {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    z-index: 60;
    display: flex;
    justify-content: center;
    pointer-events: none;
    height: 0;
    overflow: visible;
}

.app-ptr-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    margin-top: calc(8px + var(--gnd-safe-t));
    padding: 0 14px;
    border: 1px solid var(--gnd-line-strong);
    border-radius: 999px;
    background: var(--gnd-paper);
    box-shadow: var(--gnd-shadow-sm);
    color: var(--gnd-mute);
    font-family: var(--gnd-sans);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -.01em;
    opacity: 0;
    transform: translateY(-12px) scale(.96);
    transition: opacity var(--gnd-dur) var(--gnd-ease), transform var(--gnd-dur) var(--gnd-ease);
}

.app-ptr.is-pulling .app-ptr-pill,
.app-ptr.is-ready .app-ptr-pill,
.app-ptr.is-refreshing .app-ptr-pill {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.app-ptr.is-ready .app-ptr-pill {
    color: var(--gnd-brand);
    border-color: #BFDBFE;
    background: var(--gnd-brand-soft);
}

.app-ptr-spin {
    width: 16px;
    height: 16px;
    border: 2px solid #D0D5DD;
    border-top-color: var(--gnd-brand);
    border-radius: 50%;
    flex: none;
}

.app-ptr.is-refreshing .app-ptr-spin {
    animation: app-ptr-spin .7s linear infinite;
}

@keyframes app-ptr-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .app-ptr-pill { transition: none; }
    .app-ptr.is-refreshing .app-ptr-spin { animation: none; }
}

/* ---- horizontal swipe strips (additive) --------------------------- */

.app-hscroll {
    display: flex;
    gap: var(--gnd-space-3);
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    touch-action: pan-x;
    scrollbar-width: none;
}

.app-hscroll::-webkit-scrollbar { display: none; }

.app-hscroll > * {
    scroll-snap-align: start;
    flex: none;
}

/* Marketplace category row + desk segment chips stay swipeable on touch. */
html.has-touch body.mp .mp-cats,
html.has-touch body.desk .tools,
html.has-touch body.desk .seg {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
}

html.has-touch body.mp .mp-cats {
    scroll-snap-type: x proximity;
}

html.has-touch body.mp .mp-cats > * {
    scroll-snap-align: start;
}

/* ---- desk scroll frame for PTR ------------------------------------ */

body.desk .app-scroll {
    position: relative;
    overscroll-behavior-y: contain;
}

html.is-standalone body.desk .app-scroll,
html.has-touch body.desk .app-scroll {
    overscroll-behavior-y: none;
}

html.is-standalone body.mp,
html.has-touch body.mp {
    overscroll-behavior-y: contain;
}

/* Edge affordance: soft hint that menu opens from the left on phone/tablet. */
html.has-touch body.desk .app-edge-glow {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 10px;
    z-index: 35;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(36, 91, 244, .08), transparent);
    opacity: 0;
    transition: opacity .2s var(--gnd-ease);
}

html.has-touch body.desk.bp-phone .app-edge-glow,
html.has-touch body.desk.bp-tablet .app-edge-glow {
    opacity: 1;
}

@media (min-width: 1024px) {
    body.desk .app-edge-glow { display: none; }
}

/* ---- laptop / desktop content width only — phone/tablet untouched -- */

@media (min-width: 1024px) {
    body.desk main > .mx-auto {
        max-width: var(--gnd-content-max);
    }
}

@media (min-width: 1024px) and (max-width: 1279px) {
    body.mp .mp-wrap {
        max-width: min(1120px, 100%);
    }
}

@media (min-width: 1280px) and (max-width: 1535px) {
    body.mp .mp-wrap {
        max-width: min(1240px, 100%);
    }
}

@media (min-width: 1536px) {
    body.mp .mp-wrap {
        max-width: min(1320px, 100%);
    }
}

/* ---- friendly press feedback (all devices, subtle) ---------------- */

html.has-touch body.mp .mp-btn:active,
html.has-touch body.mp .mp-card:active,
html.has-touch body.desk .btn:active,
html.has-touch body.desk .actile:active,
html.has-touch body.desk .mcard:active,
html.has-touch body.desk .rowcard:active {
    transform: scale(.985);
}

@media (prefers-reduced-motion: reduce) {
    html.has-touch body.mp .mp-btn:active,
    html.has-touch body.mp .mp-card:active,
    html.has-touch body.desk .btn:active,
    html.has-touch body.desk .actile:active,
    html.has-touch body.desk .mcard:active,
    html.has-touch body.desk .rowcard:active {
        transform: none;
    }
}
