/* =========================================================
   RSBuild Mobile App Shell
   Production mobile stylesheet
   ========================================================= */

/* ---------- Base safety ---------- */

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
}

button,
a {
  touch-action: manipulation;
}

.rs-mobile-bottom-nav,
.rs-mobile-menu,
.rs-mobile-header-avatar {
  display: none;
}

/* =========================================================
   Mobile app frame
   ========================================================= */

@media (max-width: 768px) {
  :root {
    --mobile-topbar-h: 54px;
    --mobile-bottom-nav-h: 68px;
    --mobile-page-gutter: 12px;
  }

  body {
    padding-top: var(--mobile-topbar-h) !important;
    padding-bottom: var(--mobile-bottom-nav-h) !important;
  }

  .rs-top {
    min-height: var(--mobile-topbar-h) !important;
  }

  .rs-top-inner {
    position: relative !important;
    min-height: var(--mobile-topbar-h) !important;
    padding: 8px 12px !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .rs-brand {
    width: auto !important;
    height: 38px !important;
    margin: 0 auto !important;
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .rs-brand-logo {
    height: 30px !important;
    width: auto !important;
    margin: 0 !important;
    display: block !important;
  }

  .rs-top .rs-nav {
    display: none !important;
  }

  .rs-main,
  .container.rs-main {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 8px var(--mobile-page-gutter) 0 !important;
  }

  .rs-page {
    width: 100% !important;
    max-width: none !important;
    padding: 8px 0 18px !important;
  }
}

/* =========================================================
   Mobile header account avatar + dropdown
   ========================================================= */

@media (max-width: 768px) {
  .rs-mobile-header-avatar {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);

    width: 34px;
    height: 34px;
    border-radius: 999px;
    overflow: hidden;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 0;
    border: 1px solid rgba(15,23,42,.16);
    background: #e5e7eb;
    color: #111827;

    font-size: 13px;
    font-weight: 900;
    z-index: 50;
  }

  .rs-mobile-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .rs-mobile-header-avatar span {
    font-size: 13px;
    font-weight: 900;
    color: #111827;
  }

  /* Keep desktop account dropdown available for mobile avatar trigger */
  .rs-top .rs-actions {
    display: block !important;
    position: absolute !important;
    right: 0;
    top: 0;
    width: 0;
    height: 0;
    overflow: visible !important;
  }

  .rs-top .rs-actions > .rs-ico,
  .rs-top .rs-actions > .rs-user-menu > .rs-user-btn {
    display: none !important;
  }

  .rs-user-menu {
    display: block !important;
    position: static !important;
  }

  .rs-user-dd {
    position: fixed !important;
    top: 58px !important;
    right: 12px !important;
    left: auto !important;
    z-index: 3000 !important;
    width: 230px !important;
  }
}

/* =========================================================
   Home page mobile feed layout
   ========================================================= */

@media (max-width: 768px) {
  body.route-home .rs-main,
  body.route-home .container.rs-main {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  body.route-home .dash {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.route-home .dash-center {
    order: 1;
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
  }

  body.route-home .dash-left {
    order: 2;
    width: 100% !important;
    max-width: none !important;
    padding: 0 12px !important;
  }

  body.route-home .dash-right {
    order: 3;
    width: 100% !important;
    max-width: none !important;
    padding: 0 12px !important;
  }

  body.route-home .home-feed-shell,
  body.route-home .home-feed-list {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.route-home .feedcard {
    width: 100% !important;
    max-width: none !important;
    margin: 0 0 10px !important;
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    overflow: hidden;
  }

  body.route-home .dash-left .box,
  body.route-home .dash-right .box {
    border-radius: 14px !important;
  }
}

/* =========================================================
   Feed header compact mobile styling
   ========================================================= */

@media (max-width: 768px) {
  body.route-home .feed-h {
    position: relative !important;
    z-index: 30 !important;
    overflow: visible !important;

    padding: 8px 10px !important;
    min-height: 42px !important;
    gap: 8px !important;
  }

  body.route-home .feed-h,
  body.route-home .feed-stats,
  body.route-home .comment-preview {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .feed-h .avatar,
  .feed-h .rs-avatar {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    min-height: 30px !important;
    flex: 0 0 30px !important;
    aspect-ratio: 1 / 1 !important;

    border-radius: 50% !important;
    overflow: hidden !important;
    font-size: 12px !important;
  }

  .feed-h .avatar img,
  .feed-h .rs-avatar img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 50% !important;
    display: block;
  }

  .feed-h .user,
  .feed-h .username,
  .feed-h .uname {
    font-size: 13px !important;
    line-height: 1.2 !important;
  }

  .feed-h .meta,
  .feed-h .ago,
  .feed-h .fhs {
    font-size: 11px !important;
  }

  .feed-h .post-menu-trigger {
    width: 34px !important;
    height: 34px !important;
  }
}

/* =========================================================
   Feed photos and mobile image behaviour
   ========================================================= */

@media (max-width: 768px) {
  img,
  a,
  button,
  .photos,
  .photos a,
  .photos img,
  .feedcard,
  .feedcard * {
    -webkit-tap-highlight-color: transparent;
  }

  .photos img,
  .feedcard img {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  body.route-home .photos {
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.route-home .photos img {
    width: 100% !important;
    display: block;
  }

  body.route-home .photos .psmall {
    display: none !important;
  }

  body.route-home .photos .pbig {
    position: relative !important;
    display: block !important;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  body.route-home .photos .pbig img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Remove rounding from post images */
  .feedcard img,
  .photos img,
  .photos .pbig,
  .photos a {
    border-radius: 0 !important;
  }

  /* Image tap feedback */
  body.route-home .photos a,
  body.route-home .pbig {
    position: relative;
    overflow: hidden;
  }

  body.route-home .photos a:active::after,
  body.route-home .pbig:active::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,0.08);
  }

  .photos .pbig[data-post-href] {
    cursor: pointer;
  }
}

/* Mobile multi-image count pill */
@media (max-width: 768px) {
  body.route-home .pcount--mobile {
    position: absolute !important;
    top: auto !important;
    left: auto !important;
    right: 10px !important;
    bottom: 10px !important;
    transform: none !important;

    min-width: 40px !important;
    height: 30px !important;
    padding: 0 10px !important;

    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;

    border-radius: 10px !important;
    background: rgba(15, 23, 42, .85) !important;
    color: #fff !important;

    font-size: 13px !important;
    font-weight: 900 !important;
    line-height: 1 !important;

    border: 1px solid rgba(255,255,255,.25) !important;
    box-shadow: 0 6px 16px rgba(0,0,0,.25) !important;

    pointer-events: none !important;
    z-index: 5 !important;
  }
}

@media (min-width: 769px) {
  .pcount--mobile {
    display: none !important;
  }
}

/* =========================================================
   Mobile double-tap like heart animation
   ========================================================= */

@media (max-width: 768px) {
  .mobile-long-like-heart {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 20;

    transform: translate(-50%, -50%) scale(.7);
    animation: mobileLongLikePop .7s ease forwards;

    color: #ff2d55;
    font-size: 92px;
    line-height: 1;
    text-shadow: 0 8px 26px rgba(0,0,0,.35);

    pointer-events: none;
  }
}

@keyframes mobileLongLikePop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.6);
  }

  25% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.12);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -58%) scale(1);
  }
}

/* =========================================================
   Mobile comment preview
   ========================================================= */

@media (max-width: 768px) {
  body.route-home .comment-preview {
    opacity: 0.85;
    padding: 6px 12px 10px !important;
  }

  body.route-home .comment-preview .cmt:nth-child(n+2) {
    display: none !important;
  }

  body.route-home .comment-preview .cmt {
    pointer-events: none;
  }
}

/* =========================================================
   Mobile post menu safety
   ========================================================= */

.post-menu-wrap {
  position: relative;
  z-index: 50;
}

.post-menu-dropdown {
  position: absolute;
  z-index: 9999 !important;
}

@media (max-width: 768px) {
  body.route-home .post-menu-wrap {
    position: relative !important;
    z-index: 1000 !important;
  }

  body.route-home .post-menu-trigger {
    position: relative !important;
    z-index: 1001 !important;
    width: 42px !important;
    height: 42px !important;
  }

  body.route-home .post-menu-dropdown {
    position: absolute !important;
    z-index: 1002 !important;
    top: 42px !important;
    right: 0 !important;
    min-width: 170px !important;

    background: #fff !important;
    box-shadow: 0 18px 45px rgba(15,23,42,.22) !important;
  }

  body.route-home .photos,
  body.route-home .photos a,
  body.route-home .photos img {
    position: relative !important;
    z-index: 1 !important;
  }

  body.route-home .post-menu-item {
    min-height: 46px !important;
    padding: 13px 15px !important;
    font-size: 14px !important;
  }
}

/* =========================================================
   Mobile post composer
   Opens from bottom-nav create button
   ========================================================= */

@media (max-width: 768px) {
  body.route-home .mobile-composer {
    display: none !important;
  }

  body.route-home .mobile-composer.is-mobile-open {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 12px 10px !important;
    padding: 0 !important;
    border-radius: 14px !important;
    overflow: hidden !important;
  }

  body.route-home .mobile-composer.is-mobile-open .box-b {
    padding: 12px !important;
  }

  body.route-home .mobile-composer.is-mobile-open .composer-row,
  body.route-home .mobile-composer.is-mobile-open .composer-form {
    width: 100% !important;
    max-width: none !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  body.route-home .mobile-composer.is-mobile-open .composer-select,
  body.route-home .mobile-composer.is-mobile-open .btn,
  body.route-home .mobile-composer.is-mobile-open button {
    width: 100% !important;
    max-width: none !important;
  }
}

/* =========================================================
   Bottom navigation
   ========================================================= */

@media (max-width: 768px) {
  .rs-mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;

    height: calc(var(--mobile-bottom-nav-h) + env(safe-area-inset-bottom));
    padding: 8px 10px env(safe-area-inset-bottom);

    display: grid;
    grid-template-columns: 1fr 1fr auto 1fr 1fr !important;
    align-items: center;
    gap: 4px;

    background: #fff;
    border-top: 1px solid rgba(15,23,42,.12);
    box-shadow: 0 -10px 30px rgba(15,23,42,.12);

    margin-bottom: 0 !important;
  }

  .rs-mobile-nav-item {
    position: relative;
    width: 100%;
    height: 46px;
    border: 0;
    border-radius: 16px;

    background: transparent;
    color: #64748b;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .rs-mobile-nav-item svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.15;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .rs-mobile-nav-item.active {
    color: #111827;
    background: rgba(15,23,42,.06);
  }

  .rs-mobile-nav-item.active::after {
    content: "";
    position: absolute;
    bottom: 5px;
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: currentColor;
  }

  .rs-mobile-badge {
    position: absolute;
    top: 5px;
    right: 13px;

    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 999px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: #e11d48;
    color: #fff;

    font-size: 10px;
    font-weight: 900;
    border: 2px solid #fff;
  }

  .rs-mobile-create-btn {
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 999px;

    background: #111827;
    color: #fff;

    font-size: 32px;
    line-height: 1;
    font-weight: 400;

    display: flex;
    align-items: center;
    justify-content: center;

    transform: translateY(-6px);
    box-shadow: 0 5px 14px rgba(15,23,42,.22);

    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .rs-mobile-create-btn:active {
    transform: translateY(-12px) scale(.94);
  }
}

/* =========================================================
   Mobile footer
   ========================================================= */

@media (max-width: 768px) {
  .footer {
    display: block !important;
    margin: 14px 0 calc(var(--mobile-bottom-nav-h, 68px) + 14px) !important;
    padding: 18px 12px 20px !important;

    background: #fff;
    border-top: 1px solid rgba(15,23,42,.08);
  }

  .footer-inner {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;

    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;

    text-align: center !important;
  }

  .footer-left {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
  }

  .footer-brand {
    text-decoration: none !important;
  }

  .footer-brand-text {
    font-size: 11px !important;
    font-weight: 900 !important;
    color: #64748b !important;
  }

  .footer-links {
    width: 100% !important;

    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 10px 12px !important;
  }

  .footer-links a,
  .footer-cookie-link {
    width: auto !important;
    min-height: auto !important;
    padding: 0 !important;

    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;

    color: #334155 !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    line-height: 1.4 !important;
    text-decoration: none !important;

    appearance: none !important;
    cursor: pointer;
  }

  .footer-links a:hover,
  .footer-cookie-link:hover {
    text-decoration: underline !important;
  }
}

/* =========================================================
   Mobile page safety
   ========================================================= */

@media (max-width: 768px) {
  #pvFsEnter,
  .pv-fs-enter {
    display: none !important;
  }

  .dm-page,
  .dm-card,
  .dm-list,
  .dm-item {
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* =========================================================
   iOS / iPadOS PWA safe-area status bar
   ========================================================= */

@supports (-webkit-touch-callout: none) {
  html,
  body {
    background: #111827;
  }

  body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    height: env(safe-area-inset-top);
    background: #111827;

    z-index: 9999;
    pointer-events: none;
  }

  body {
    padding-top: calc(env(safe-area-inset-top) + 54px) !important;
  }

  .rs-top {
    padding-top: env(safe-area-inset-top);
  }

  .rs-main {
    background: #f5f6f8;
  }
}

@media (max-width: 768px) {
  body.route-home .mobile-composer.is-mobile-open {
    scroll-margin-top: 70px; /* pushes it below header */
  }
}