/* ═══════════════════════════════════════════════════════════════════════════
   ABODE v6 — DESKTOP LAYER
   ───────────────────────────────────────────────────────────────────────────
   Phase 1 desktop shell: sidebar navigation, framed content, two-pane
   master/detail, centered modals.

   THE ONE RULE FOR THIS FILE: it is ADDITIVE ONLY.
   Every layout rule below lives inside @media (min-width:1024px). A browser
   under 1024px never parses those blocks, so the mobile app cannot regress
   from anything in here — not by care, but by structure. app.css is never
   edited; this file is loaded after it and overrides only above the
   breakpoint.

   The handful of rules OUTSIDE the media query target classes that exist
   nowhere else in the app (.dk-*), so they match no mobile element either.

   Loaded from index.html immediately after styles/app.css.
   ═══════════════════════════════════════════════════════════════════════════ */


/* ───────────────────────────────────────────────────────────────────────────
   1. DESKTOP-ONLY ELEMENTS — hidden by default, revealed at the breakpoint.
      New class names: nothing on mobile matches these.
   ─────────────────────────────────────────────────────────────────────────── */
.dk-only{display:none !important}
.dk-nav-head{display:none}
.dk-nav-spacer{display:none}


@media (min-width:1024px){

  /* ─────────────────────────────────────────────────────────────────────────
     2. TOKENS
     ───────────────────────────────────────────────────────────────────────── */
  :root{
    --dk-nav:236px;        /* sidebar width */
    --dk-max:1180px;       /* reading measure for list + form content */
    --dk-max-wide:1560px;  /* card grids get more room */
    --dk-drawer:min(940px, calc(100vw - var(--dk-nav) - 320px));
    --dk-gut:28px;
  }

  /* The app is no longer a phone in a browser: give it a real cursor,
     real scrollbars and real focus rings. */
  html,body{overscroll-behavior:none}

  .dk-only{display:flex !important}


  /* ─────────────────────────────────────────────────────────────────────────
     3. SHELL — bottom tab bar becomes a left sidebar.

     No JS change: initTabs() delegates clicks on #tabsNav to any .tab-btn and
     calls switchTab(b.dataset.tab). Rotating the same nav into a column keeps
     that contract intact, which is why the sidebar is CSS and not a rewrite.
     ───────────────────────────────────────────────────────────────────────── */
  .tabs-nav{
    top:0; bottom:0; left:0; right:auto;
    width:var(--dk-nav);
    flex-direction:column;
    justify-content:flex-start;
    align-items:stretch;
    gap:2px;
    padding:0 12px 18px;
    background:var(--navy,#1B2A4A);
    border-top:none;
    border-right:1px solid rgba(255,255,255,.07);
    overflow-y:auto;
    overflow-x:hidden;
  }
  /* The safe-area filler strip under the mobile tab bar has no job here. */
  .tabs-nav::after{display:none}

  .dk-nav-head{
    display:flex; align-items:center; gap:11px;
    padding:22px 12px 20px;
    flex-shrink:0;
  }
  .dk-nav-head svg{width:26px;height:26px;display:block;flex-shrink:0}
  .dk-nav-wordmark{
    font-size:17px; font-weight:600; letter-spacing:.4px;
    color:#fff; line-height:1;
  }
  .dk-nav-sub{
    font-size:11px; font-weight:500; letter-spacing:.6px;
    color:rgba(255,255,255,.42); text-transform:uppercase;
    margin-top:3px; line-height:1;
  }
  .dk-nav-spacer{display:block;flex:1;min-height:8px}

  .tab-btn{
    flex:0 0 auto;
    flex-direction:row;
    justify-content:flex-start;
    align-items:center;
    gap:12px;
    width:100%;
    padding:10px 12px;
    border-radius:10px;
    font-size:14px;
    font-weight:500;
    letter-spacing:.1px;
    color:rgba(255,255,255,.64);
    text-align:left;
    position:relative;
    transition:background .16s ease, color .16s ease;
  }
  .tab-btn > span:last-child{white-space:nowrap}
  .tab-btn .tab-icon{width:20px;height:20px}
  .tab-btn .tab-icon svg{width:19px;height:19px}
  .tab-btn:hover{background:rgba(255,255,255,.07);color:#fff}
  .tab-btn.active{
    background:rgba(209,194,146,.15);
    color:#D1C292;
    font-weight:600;
  }
  .tab-btn.active .tab-icon svg{stroke-width:2}
  .tab-btn:focus-visible{
    outline:2px solid #D1C292; outline-offset:2px;
  }
  /* Unread pill sits at the trailing edge of the row, not over the icon. */
  .tab-btn .tab-badge-sms{
    position:absolute; top:50%; right:10px; left:auto;
    transform:translateY(-50%);
    margin:0;
  }

  /* Content area slides out from under the sidebar and reclaims the
     bottom strip the tab bar used to occupy. */
  .tab-content{
    left:var(--dk-nav);
    bottom:0;
  }


  /* ─────────────────────────────────────────────────────────────────────────
     4. CONTENT FRAMING — the actual fix for "it stretches too far".

     Each screen stays full-bleed (navy headers still run edge to edge) while
     its CONTENTS are held to a reading measure and centred. This is the same
     max()-padding pattern app.css already uses on the listing detail screen
     at >=1000px, applied to the rest of the app.
     ───────────────────────────────────────────────────────────────────────── */
  .leads-header,
  .leads-nav,
  .leads-list,
  .deals-header,
  .deals-nav,
  .deals-list,
  .tours-header,
  .tours-nav,
  .conv-header,
  .sms-conv-list,
  .dash-header,
  .dash-tabs,
  .more-view,
  .msg-section-label{
    padding-left:max(var(--dk-gut), calc((100% - var(--dk-max)) / 2)) !important;
    padding-right:max(var(--dk-gut), calc((100% - var(--dk-max)) / 2)) !important;
  }

  /* Cards inside padded lists carry their own margins on mobile — zero them
     so the centred measure is the real edge. */
  .msg-card{margin-left:0;margin-right:0}

  /* Tours + dashboard panels centre their own scroll content. */
  #tourTodayScroll > *,
  #dashCommissionContent,
  #dashPortfolioContent,
  #dashToursContent,
  #dashSharesContent{
    max-width:var(--dk-max);
    margin-left:auto;
    margin-right:auto;
    width:100%;
  }


  /* ─────────────────────────────────────────────────────────────────────────
     5. CARD GRIDS — width becomes columns instead of stretch.
        app.css already steps 1 -> 2 -> 3 at 400/640; carry it further.
     ───────────────────────────────────────────────────────────────────────── */
  .listings-grid,
  .full-list-grid{
    grid-template-columns:repeat(4,1fr);
    gap:14px;
    max-width:var(--dk-max-wide);
    margin-left:auto;
    margin-right:auto;
  }
  .fl-grid{grid-template-columns:repeat(4,1fr)}

  /* Hover was already designed for (.listing-card:hover lifts) — it finally
     has a pointer to fire on. */
  .listing-card{cursor:pointer}


  /* ─────────────────────────────────────────────────────────────────────────
     6. DETAIL VIEWS — full-screen takeover becomes a true right-hand pane.

     .detail-view keeps its translateX(100%) -> translateX(0) transition, so
     open/close JS is untouched; it simply slides a 940px pane in from the
     right instead of covering the screen. Where :has() is supported the list
     behind it narrows to fill the remainder, giving real master/detail —
     the list stays live and clickable while a record is open.
     ───────────────────────────────────────────────────────────────────────── */
  .detail-view{
    left:auto;
    width:var(--dk-drawer);
    border-left:1px solid var(--g200);
    box-shadow:-24px 0 70px rgba(0,0,0,.14);
  }

  @supports selector(:has(*)){
    body:has(#leadDetail.open) #leadsTab,
    body:has(#listingDetail.open) #listingsTab{
      right:var(--dk-drawer);
    }
    /* With both panes live, a dimming scrim would only block the list.
       Close is the back button (or Esc). */
    body:has(#leadDetail.open) .lead-detail-scrim{
      background:transparent !important;
      pointer-events:none !important;
      backdrop-filter:none !important;
      -webkit-backdrop-filter:none !important;
    }
  }


  /* ─────────────────────────────────────────────────────────────────────────
     7. SHEETS AND MODALS — bottom-anchored sheets become centred panels.

     Every sheet here closes with translateY(100%), i.e. "down by my own
     height". That only clears the screen while the sheet is still anchored to
     the bottom edge, so these rules change WIDTH and CORNERS but never move
     an element off `bottom:0`. Breaking that leaves a strip of the sheet
     visible in its closed state.
     ───────────────────────────────────────────────────────────────────────── */

  /* Deal record — floats as a centred document, not a full-screen takeover.
     It is inset on all four sides, so height must yield to top/bottom. */
  .deal-detail{
    top:32px; bottom:32px; height:auto;
    left:calc(var(--dk-nav) + max(28px, (100vw - var(--dk-nav) - 1120px) / 2));
    right:max(28px, (100vw - var(--dk-nav) - 1120px) / 2);
    border-radius:20px;
    box-shadow:0 32px 90px rgba(0,0,0,.30);
  }
  .dd-drag-handle{display:none}   /* drag-to-dismiss is a touch affordance */

  /* Flow sheets stay bottom-anchored (see note above) but stop spanning
     the monitor. */
  .flow-sheet{
    left:calc(var(--dk-nav) + max(28px, (100vw - var(--dk-nav) - 720px) / 2));
    right:max(28px, (100vw - var(--dk-nav) - 720px) / 2);
    max-height:82vh;
    border-radius:20px 20px 0 0;
    box-shadow:0 -12px 60px rgba(0,0,0,.20);
  }
  .flow-sheet-handle{display:none}

  /* Map results sheet becomes a docked panel beside the map, Zillow-style. */
  #listingsTab .bottom-sheet{
    left:20px; right:auto;
    width:min(440px, 34vw);
    border-radius:16px 16px 0 0;
    box-shadow:0 -4px 40px rgba(0,0,0,.16);
  }

  /* Centred overlay sheets — horizontal cap only; vertical anchoring and any
     transform on these is left exactly as-is. */
  .compose-sheet,
  .mkt-picker-sheet{
    max-width:600px;
    margin-left:auto;
    margin-right:auto;
  }
  #searchDefault,
  #searchResults{
    max-width:var(--dk-max);
    margin-left:auto;
    margin-right:auto;
  }
  .thread-menu{right:auto;left:auto}


  /* ─────────────────────────────────────────────────────────────────────────
     8. MAP SCREEN
     ───────────────────────────────────────────────────────────────────────── */
  .map-search-bar{
    left:20px;
    right:auto;
    width:min(520px, 42vw);
  }
  .layers-panel{right:24px}


  /* ─────────────────────────────────────────────────────────────────────────
     9. DESKTOP AFFORDANCES — the small things that say "native app"
        rather than "website on a phone".
     ───────────────────────────────────────────────────────────────────────── */

  /* Real scrollbars, styled to the palette. */
  *::-webkit-scrollbar{width:11px;height:11px}
  *::-webkit-scrollbar-track{background:transparent}
  *::-webkit-scrollbar-thumb{
    background:rgba(27,42,74,.18);
    border-radius:8px;
    border:3px solid transparent;
    background-clip:content-box;
  }
  *::-webkit-scrollbar-thumb:hover{background:rgba(27,42,74,.32);background-clip:content-box}

  /* Keyboard focus is visible for the first time. */
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  [data-act]:focus-visible{
    outline:2px solid #D1C292;
    outline-offset:2px;
    border-radius:6px;
  }

  /* Rows that were tap targets read as clickable rows. */
  .msg-card:hover,
  .thread-menu-item:hover,
  .mls-ac-item:hover{background:rgba(27,42,74,.05)}

  /* Touch-sized hit areas can relax slightly at pointer precision. */
  @media (pointer:fine){
    .leads-header-btn,
    .deals-header-btn,
    .tours-header-btn{transition:background .15s ease}
    .leads-header-btn:hover,
    .deals-header-btn:hover,
    .tours-header-btn:hover{background:rgba(255,255,255,.14)}
  }


  /* ─────────────────────────────────────────────────────────────────────────
     10. DARK MODE PARITY
     ───────────────────────────────────────────────────────────────────────── */
  body.dark-mode .tabs-nav{
    background:#0a0f18;
    border-right-color:rgba(255,255,255,.07);
  }
  body.dark-mode .detail-view{
    border-left-color:var(--g200);
    box-shadow:-24px 0 70px rgba(0,0,0,.45);
  }
  body.dark-mode *::-webkit-scrollbar-thumb{
    background:rgba(255,255,255,.16);background-clip:content-box;
  }
  body.dark-mode *::-webkit-scrollbar-thumb:hover{
    background:rgba(255,255,255,.28);background-clip:content-box;
  }
  body.dark-mode .msg-card:hover{background:rgba(255,255,255,.05)}
}


/* ───────────────────────────────────────────────────────────────────────────
   11. LARGE DISPLAYS — a 27" monitor gets more columns, not more stretch.
   ─────────────────────────────────────────────────────────────────────────── */
@media (min-width:1600px){
  .listings-grid,
  .full-list-grid{grid-template-columns:repeat(5,1fr)}
  .fl-grid{grid-template-columns:repeat(5,1fr)}
}

/* ── Abode Desk entry (desktop only; invisible to mobile) ─────────────── */
.dk-desk-link{display:none}
@media (min-width:1024px){
  .dk-desk-link{display:flex;align-items:center;gap:9px;margin:6px 12px 14px;padding:9px 12px;border-radius:9px;color:rgba(255,255,255,.78);text-decoration:none;font-size:12.5px;font-weight:700;letter-spacing:.2px;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.05)}
  .dk-desk-link:hover{background:rgba(255,255,255,.11);color:#fff}
}
