/* ============================================================================
   Desktop layout (>= 1024px)

   Everything in this file lives inside a min-width media query, so the mobile
   experience is byte-for-byte unchanged. Below 1024px the site keeps its
   430px app shell and bottom tab bar exactly as before.

   The shell becomes a three-column grid:  [ nav | feed | aside ]  (RTL order,
   so nav sits on the right where the thumb/eye expects it in Arabic).
   ========================================================================== */

/* Hidden by default; only the desktop grid reveals it. */
.acf-desktop-aside { display: none; }

@media (min-width: 1024px) {

  :root {
    --acf-d-nav: 232px;
    --acf-d-aside: 288px;
    --acf-d-gap: 20px;
    --acf-d-max: 1300px;
    /* Header is 60px tall and fixed; 74 clears it and matches the shell's
       padding-top so the rails start level with the feed. */
    --acf-d-stick: 74px;
  }

  /* scrollbar-cleanup.css sets overflow-x:hidden !important on html AND body.
     html's value propagates to the viewport, but body keeps its own and so
     becomes a scroll container that never scrolls - which silently kills every
     position:sticky descendant. Desktop has no horizontal overflow to hide. */
  html, body {
    background: #05070d;
    overflow-x: visible !important;
    overflow-y: visible !important;
  }

  /* The phone-width frame and its drop shadow are what made desktop look
     unfinished. Widen it and drop the framing. */
  .mobile-shell {
    width: min(100vw, var(--acf-d-max));
    max-width: var(--acf-d-max);
    background: transparent;
    box-shadow: none;
    /* scrollbar-cleanup.css sets overflow-x:hidden !important here. That makes
       overflow-y compute to auto, turning the shell into a scroll container, and
       a sticky child then sticks to a container that never scrolls. Both axes
       must be visible or the rails do not stick at all. */
    overflow: visible !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
    display: grid;
    grid-template-columns: var(--acf-d-nav) minmax(0, 1fr) var(--acf-d-aside);
    /* No "head" row: the topbar is fixed and out of flow. */
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "menu menu menu"
      "nav  main aside";
    column-gap: var(--acf-d-gap);
    align-items: start;
  }

  /* Every direct child needs an explicit area, or grid auto-places it into a
     cell it does not belong in. The header dropdown is position:sticky, so it
     is a real grid item, not an overlay. */
  .mobile-shell > .acf-header-menu {
    grid-area: menu;
    margin-bottom: 12px;
    border-radius: 14px;
    border-bottom: 0;
  }

  /* Flash messages float instead of competing for a grid cell; three is the
     maximum the layout can emit (success, notice, error). */
  .mobile-shell > .toast {
    position: fixed;
    top: 76px;
    left: 26px;
    right: auto;
    z-index: 300;
    width: min(360px, 32vw);
    margin: 0;
  }
  .mobile-shell > .toast:nth-of-type(2) { top: 142px; }
  .mobile-shell > .toast:nth-of-type(3) { top: 208px; }

  /* header-svg.css sets height/padding with !important, but drives them from
     these variables. Setting the variables works with that design instead of
     escalating an !important war. */
  .app-topbar,
  .app-topbar.acf-svg-topbar {
    --acf-header-height: 60px;
    --acf-header-padding-x: 4px;
  }

  /* A sticky grid item can only travel inside its own grid area, so the header
     would scroll away with row 1. Taking it out of flow is what actually pins
     it; the shell then reserves the space with padding-top. Matches
     header-svg.css specificity because that rule is !important. */
  .app-topbar.acf-svg-topbar,
  .app-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 50% !important;
    transform: translateX(-50%);
    width: min(100vw, var(--acf-d-max));
    z-index: 200 !important;
    border-radius: 0 0 16px 16px;
  }

  .mobile-shell { padding-top: calc(60px + 14px); }

  /* header-svg.css pins the brand, the toggle and the actions with
     position:absolute so they sit at the two edges and dead centre of a 430px
     bar. Stretched to 1300px that reads as three items floating in a void.
     Put them back in flow and lay the bar out as a real flex row. */
  .app-topbar.acf-svg-topbar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding-inline: 20px !important;
  }

  .acf-svg-topbar .acf-header-brand,
  .acf-svg-topbar .acf-header-actions,
  .acf-svg-topbar .top-actions,
  .acf-svg-topbar .acf-header-menu-toggle {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    height: auto !important;
    width: auto !important;
    max-width: none !important;
    flex: 0 0 auto;
  }

  /* Brand first in the RTL row, actions last, toggle beside the brand. */
  .acf-svg-topbar .acf-header-brand { order: 1 !important; display: flex; align-items: center; gap: 10px; }
  .acf-svg-topbar .acf-header-menu-toggle { order: 2 !important; margin-inline-start: 4px; }
  .acf-svg-topbar .acf-header-actions,
  .acf-svg-topbar .top-actions { order: 3 !important; display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }

  .brand-copy b { font-size: 16px; max-width: none; }
  .brand-copy small { font-size: 11.5px; max-width: none; }
  .brand-compact { max-width: none; }
  .acf-svg-topbar .acf-header-login,
  .acf-svg-topbar .mini-login,
  .acf-svg-topbar .mini-register { height: 36px; padding: 0 14px; font-size: 13px; }

  /* ---- Column 1: the tab bar becomes a real sidebar ----------------------
     navigation.css targets .tabbar.acf-svg-tabbar.acf-navigation-bar, so these
     overrides match that specificity or they simply lose, regardless of load
     order. The plain .tabbar fallbacks cover pages rendered without the SVG
     navigation classes. */
  .tabbar,
  .tabbar.acf-svg-tabbar,
  .tabbar.acf-svg-tabbar.acf-navigation-bar {
    grid-area: nav;
    position: sticky;
    top: var(--acf-d-stick);
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    width: 100%;
    max-width: none;
    height: auto;
    /* Both rails must stay reachable no matter how tall they get: cap them to
       the viewport and let the column scroll inside itself. Without this a tall
       rail simply runs off the bottom and the sticking feels broken. */
    /* Floor it: on a short window calc() goes negative, max-height clamps to
       0 and the whole rail disappears. */
    max-height: max(280px, calc(100dvh - var(--acf-d-stick) - 16px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    border-radius: 18px;
    background: rgba(13, 19, 33, .72);
    border: 1px solid rgba(255, 255, 255, .07);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .tabbar::-webkit-scrollbar,
  .acf-desktop-aside::-webkit-scrollbar { width: 0; height: 0; }

  .tabbar a,
  .tabbar.acf-svg-tabbar a,
  .tabbar.acf-svg-tabbar.is-mode-icon a,
  .tabbar.acf-svg-tabbar.is-mode-text a {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    padding: 11px 13px;
    border-radius: 14px;
    font-size: 14.5px;
    transition: background .14s ease, color .14s ease;
  }

  .tabbar.acf-svg-tabbar a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
  .tabbar.acf-svg-tabbar a.active,
  .tabbar.acf-svg-tabbar.acf-navigation-bar a.active {
    background: rgba(124, 58, 237, .20);
    color: #fff;
    box-shadow: none;
  }

  .tabbar b,
  .tabbar.acf-svg-tabbar b,
  .tabbar.acf-svg-tabbar.acf-navigation-bar b {
    font-size: 14.5px;
    max-width: none;
    font-weight: 700;
    overflow: visible;
  }

  .tabbar span,
  .tabbar.acf-svg-tabbar span,
  .tabbar .acf-tab-icon,
  .tabbar.acf-svg-tabbar .acf-tab-icon { flex: 0 0 auto; }

  /* The write action is the primary CTA; make it read like one. */
  .tabbar .write-tab,
  .tabbar.acf-svg-tabbar .write-tab,
  .tabbar.acf-svg-tabbar.acf-navigation-bar .write-tab {
    order: -1;
    justify-content: center;
    margin-bottom: 6px;
    padding: 13px;
    border-radius: 15px;
  }

  .tabbar i { position: static; margin-inline-start: auto; }

  /* ---- Column 2: the feed ------------------------------------------------ */
  .app-content {
    grid-area: main;
    min-height: 0;
    padding: 0 0 60px;
  }

  /* Cards were tuned for a 406px column; give them desktop proportions. */
  .card-text { font-size: 16.5px; }
  .post-content { font-size: 19px; line-height: 2.05; }
  .panel, .post-view, .reaction-panel, .comments-panel, .profile-header, .anon-card {
    padding: 20px;
  }
  .confession-card, .acf-feed-card { padding: 18px; }

  /* ---- Column 3: the aside ---------------------------------------------- */
  /* Mirrors the nav rail exactly — same sticky offset, same cap, same internal
     scroll — so the two rails read as a matched pair framing the feed. */
  .acf-desktop-aside {
    grid-area: aside;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: sticky;
    top: var(--acf-d-stick);
    /* Floor it: on a short window calc() goes negative, max-height clamps to
       0 and the whole rail disappears. */
    max-height: max(280px, calc(100dvh - var(--acf-d-stick) - 16px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }

  .acf-aside-card {
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 18px;
    background: rgba(13, 19, 33, .72);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: none;
  }

  .acf-aside-cta {
    background: linear-gradient(150deg, rgba(124, 58, 237, .26), rgba(6, 182, 212, .13));
    border-color: rgba(124, 58, 237, .34);
  }

  .acf-aside-title {
    margin: 0;
    font-size: 14.5px;
    font-weight: 800;
    color: #fff;
  }

  .acf-aside-text {
    margin: 0;
    font-size: 13px;
    line-height: 1.75;
    color: #aab5c8;
  }

  .acf-aside-question {
    margin: 0;
    font-size: 14.5px;
    line-height: 1.85;
    color: #e8edf7;
  }

  .acf-aside-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 13px;
    font-size: 13.5px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
  }

  .acf-aside-btn.soft {
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .12);
  }

  .acf-aside-btn:hover { filter: brightness(1.09); }

  .acf-aside-link {
    font-size: 12.5px;
    color: #9aa7bd;
    text-align: center;
  }
  .acf-aside-link:hover { color: #cbd5e1; }

  .acf-aside-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .acf-aside-item a {
    display: flex;
    gap: 10px;
    padding: 8px;
    border-radius: 12px;
    transition: background .14s ease;
  }
  .acf-aside-item a:hover { background: rgba(255, 255, 255, .055); }

  .acf-aside-rank {
    flex: 0 0 20px;
    font-size: 15px;
    font-weight: 900;
    color: rgba(255, 255, 255, .26);
    line-height: 1.5;
  }

  .acf-aside-body { display: grid; gap: 3px; min-width: 0; }

  .acf-aside-snippet {
    font-size: 12.8px;
    line-height: 1.65;
    color: #d5dced;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .acf-aside-meta { font-size: 11px; color: #7f8ca3; }

  .acf-aside-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 4px 6px 20px;
    font-size: 12px;
  }
  .acf-aside-foot a { color: #7f8ca3; }
  .acf-aside-foot a:hover { color: #cbd5e1; text-decoration: underline; }

  /* Mobile-only affordances that make no sense with a mouse. */
  .acf-body:before { background: none; }
}

/* Wider screens: let the feed breathe rather than stretching it forever. */
@media (min-width: 1500px) {
  :root { --acf-d-max: 1420px; --acf-d-aside: 348px; }
}

@media (prefers-reduced-motion: reduce) {
  .tabbar a, .acf-aside-item a, .acf-aside-btn { transition: none; }
}

@media (min-width: 1024px) {
  .acf-aside-blog-item a { align-items: center; }
  .acf-aside-blog-thumb {
    flex: 0 0 52px;
    width: 52px;
    height: 40px;
    border-radius: 9px;
    overflow: hidden;
    background: rgba(255, 255, 255, .05);
  }
  .acf-aside-blog-thumb img { width: 100%; height: 100%; object-fit: cover; }
}
