/* Desktop/tablet layout; mobile keeps its existing touch navigation. */
@media (min-width: 700px) {
  main, .topbar, main > section { box-sizing: border-box; }
  main > section { margin-left: auto; margin-right: auto; }
  .market-home-search { grid-template-columns: minmax(0, 1fr) minmax(180px, 240px); }
  .home-suppliers-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .home-new-users { max-width: 560px; margin: 20px auto 0; }
  .home-new-users h2 { text-align: center; margin-bottom: 12px; }
  .modal-card, .detail-card:not(.detail-page .detail-card) { max-height: calc(100dvh - 48px); overflow-y: auto; }
  .auth-gate-box { box-sizing: border-box; width: min(100%, 440px); max-height: calc(100dvh - 48px); overflow-y: auto; }
  .tile { min-width: 0; }
  .tile-title { overflow-wrap: anywhere; }
}

@media (min-width: 900px) {
  :root { --desktop-width: 1200px; }
  .topbar { width: 100%; max-width: var(--desktop-width); margin: 0 auto; padding: 20px 28px 0; }
  main { max-width: var(--desktop-width); padding: 16px 28px 112px; }
  .topbar .ad-banner { width: 100%; max-width: none; margin-left: auto; margin-right: auto; }
  .topbar .ad-banner-body { padding: 18px 24px; }
  #homeView { box-sizing: border-box; max-width: var(--desktop-width); padding: 24px 28px 112px; }
  .feed-view, .news-view, .projects-view { max-width: none; padding-left: 0; padding-right: 0; }
  .market-home-head { margin-bottom: 20px; align-items: center; }
  .market-home-brand { font-size: 32px; }
  .market-home-identity .home-stats-bar { font-size: 13px; margin-top: 6px; }
  .market-home-more summary { font-size: 14px; padding: 0 18px; }
  .market-home-search { margin-bottom: 24px; }
  .market-home-section { margin-bottom: 28px; }
  .market-home-section-head h2 { font-size: 23px; }
  .market-home-section-head button { font-size: 14px; }
  .feed-grid, .market-home-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .market-home-grid .tile-photo-wrap { aspect-ratio: 1.25; }
  .market-home-grid .tile-body { padding: 12px; }
  .market-home-grid .tile-title { font-size: 15px; line-height: 1.35; }
  .market-home-grid .tile-line, .market-home-grid .tile-price-line { font-size: 13px; }
  .screen-topbar { max-width: 860px; margin-left: auto; margin-right: auto; }
  .filter-bar { max-width: 860px; margin-left: auto; margin-right: auto; }
  .home-suppliers-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
  .home-supplier-card { min-width: 0; }
  .app-downloads { margin-top: 24px; padding-top: 16px; }
  .app-downloads-title { font-size: 14px; }
  #messagesView { width: 100%; max-width: 760px; }
  #messagesView .messages-title { font-size: 26px; }
  .messages-list .dlg-row { min-height: 64px; padding: 10px 14px; }
  .messages-list .dlg-row-name { font-size: 15px; }
  .messages-list .dlg-row-last { font-size: 13px; }
  #profileView, #productView, #balanceView { width: 100%; max-width: 880px; }
  .profile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .market-dock {
    width: 680px; bottom: 16px; padding: 7px; border: 1px solid var(--border);
    border-radius: 20px; box-shadow: 0 8px 32px rgba(16, 24, 40, .12);
    backdrop-filter: blur(16px);
  }
  .market-dock button, .market-dock button.is-on { height: 58px; min-height: 58px; font-size: 12px; gap: 4px; }
  body.chat-open .chat-view { width: calc(100% - 56px); max-width: 880px; bottom: 104px; padding: 8px 20px 12px; border: 1px solid var(--border); border-radius: 18px; }
  body.chat-open:has(#marketDock.hidden) .chat-view { bottom: 20px; }
  .chat-head, .dlg-head { padding-bottom: 8px; }
  .chat-bubble { max-width: min(78%, 580px); }
  .detail-page .detail-card { max-width: 800px; margin-left: auto; margin-right: auto; }
  .detail-page .detail-photo-wrap { max-width: 520px; margin-left: auto; margin-right: auto; aspect-ratio: 1.25; }
  .detail-page .detail-photo { object-fit: contain; }
  .product-photo-wrap { max-width: 520px; margin-left: auto; margin-right: auto; }
}

@media (min-width: 1200px) {
  .feed-grid, .market-home-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (hover: hover) and (pointer: fine) and (min-width: 900px) {
  .market-home-grid .tile, .home-supplier-card { transition: box-shadow .18s ease, border-color .18s ease; }
  .market-home-grid .tile:hover, .home-supplier-card:hover { border-color: rgba(14, 107, 91, .3); box-shadow: 0 6px 20px rgba(16, 24, 40, .09); }
}
@media (prefers-reduced-motion: reduce) {
  .market-home-grid .tile, .home-supplier-card { transition: none; }
}

/* Detail pages: natural photos and reachable content on narrow/short screens. */
#detailOverlay .detail-card, #productView { box-sizing: border-box; }
#detailOverlay .detail-card { width: 100%; }
#detailOverlay .detail-photo-wrap, #productBody .product-photo-wrap {
  width: 100%; max-width: 100%; aspect-ratio: auto; background: var(--card, #f5f5f7);
  border-radius: 16px; overflow: hidden;
}
#detailOverlay .detail-photo, #productBody .product-photo-wrap img.respond-video {
  display: block; width: 100%; height: auto !important; aspect-ratio: auto !important;
  max-height: clamp(180px, 62dvh, 620px) !important; object-fit: contain; background: transparent;
}
#detailOverlay .product-title-row, #productBody .product-title-row { min-width: 0; flex-wrap: wrap; }
#detailOverlay .product-title-top, #productBody .product-title-top,
#detailOverlay .product-desc, #productBody .product-desc { min-width: 0; overflow-wrap: anywhere; }
#detailOverlay .detail-meta-row { flex-wrap: wrap; }
#detailOverlay .detail-meta-row .product-meta-line { white-space: normal; }
#detailOverlay .detail-card { padding-bottom: calc(var(--dock-h, 92px) + env(safe-area-inset-bottom, 0px) + 36px); }
#productView { padding-bottom: calc(var(--dock-h, 92px) + env(safe-area-inset-bottom, 0px) + 36px); }
@media (min-width: 900px) {
  #detailOverlay .detail-card { max-width: 1120px; padding-left: 28px; padding-right: 28px;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "top top" "actions actions" "photo title" "photo meta" "photo body";
    column-gap: 28px; row-gap: 12px; align-items: start; grid-template-rows: auto auto auto auto minmax(0, 1fr);
  }
  #detailOverlay .product-topbar { grid-area: top; }
  #detailOverlay #detailPostActions { grid-area: actions; }
  #detailOverlay .product-title-row { grid-area: title; }
  #detailOverlay .detail-photo-wrap { grid-area: photo; margin: 0; }
  #detailOverlay .detail-meta-row { grid-area: meta; margin: 0; }
  #detailOverlay .detail-body { grid-area: body; }
  #productView { max-width: 1100px; }
  #productBody { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto auto minmax(0, 1fr); column-gap: 28px; row-gap: 12px; align-items: start; }
  #productBody > .post-owner-actions { grid-column: 1 / -1; grid-row: 1; }
  #productBody > .product-title-row { grid-column: 2; grid-row: 2; }
  #productBody > .product-photo-wrap { grid-column: 1; grid-row: 2 / span 3; margin: 0; }
  #productBody > .product-meta { grid-column: 2; grid-row: 3; }
  #productBody > .product-desc { grid-column: 2; grid-row: 4; }
  #productView:has(.product-photo-wrap) #productContactBox { margin-left: calc(50% + 14px); }
  #productBody:not(:has(.product-photo-wrap)) { display: block; }
  #detailOverlay .detail-photo, #productBody .product-photo-wrap img.respond-video {
    max-height: clamp(220px, calc(100dvh - 240px), 640px) !important;
  }
}

/* Compact tools share the Back toolbar; desktop gives the actual photo more width. */
#detailOverlay .product-topbar, #productView .product-topbar { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
#detailOverlay .product-topbar .post-owner-actions, #productView .product-topbar .post-owner-actions {
  margin: 0; gap: 6px; flex-wrap: nowrap;
}
#detailOverlay .product-topbar .post-owner-actions button, #productView .product-topbar .post-owner-actions button {
  min-height: 36px; padding: 7px 10px; font-size: 13px; line-height: 1.25; white-space: nowrap;
}
#detailOverlay .product-topstats:empty, #productView .product-topstats:empty { display: none; }
@media (max-width: 359px) {
  #detailOverlay .product-topbar .back-btn, #productView .product-topbar .back-btn { padding: 8px 10px; font-size: 13px; }
  #detailOverlay .product-topbar .post-owner-actions, #productView .product-topbar .post-owner-actions { gap: 4px; }
  #detailOverlay .product-topbar .post-owner-actions button, #productView .product-topbar .post-owner-actions button { padding: 7px 6px; font-size: 12px; }
}
@media (min-width: 900px) {
  #detailOverlay .detail-card, #productView { width: 100%; max-width: 1440px; }
  #detailOverlay .detail-card { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); grid-template-areas: "top top" "photo title" "photo meta" "photo body"; grid-template-rows: auto auto auto minmax(0, 1fr); }
  #productBody { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  #productBody > .product-title-row { grid-row: 1; }
  #productBody > .product-photo-wrap { grid-row: 1 / span 3; }
  #productBody > .product-meta { grid-row: 2; }
  #productBody > .product-desc { grid-row: 3; }
  #productView:has(.product-photo-wrap) #productContactBox { margin-left: calc((100% - 28px) * .6153846154 + 28px); }
  #detailOverlay .detail-photo, #productBody .product-photo-wrap img.respond-video { max-height: none !important; }
  #detailOverlay .detail-photo-wrap .detail-nav, #productBody .product-photo-wrap .product-nav { top: min(50%, 40dvh); }
}

/* Detail border follows the same desktop content edges as the advertising banner. */
@media (min-width: 900px) {
  #detailOverlay .detail-card {
    width: calc(100% - 56px);
    max-width: calc(var(--desktop-width, 1200px) - 56px);
    margin-left: auto; margin-right: auto;
  }
}

/* Keep the complete main photo within the visible desktop card, not a tall poster. */
@media (min-width: 900px) {
  #detailOverlay .detail-card, #productBody { grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); }
  #detailOverlay .detail-photo-wrap, #productBody .product-photo-wrap {
    display: flex; align-items: center; justify-content: center;
    width: 100%; max-width: 100%; background: transparent;
  }
  #detailOverlay .detail-photo, #productBody .product-photo-wrap img.respond-video {
    width: auto !important; height: auto !important; max-width: 100%;
    max-height: clamp(180px, calc(100dvh - 260px), 520px) !important;
    object-fit: contain; margin: 0 auto;
  }
  #detailOverlay .detail-photo-wrap .detail-nav, #productBody .product-photo-wrap .product-nav { top: 50%; }
  #productView:has(.product-photo-wrap) #productContactBox { margin-left: calc((100% - 28px) * .475 + 28px); }
}

/* A single quiet white surface, including the side gutters around the detail card. */
#detailOverlay.detail-overlay.detail-page {
  background: #fff; background-image: none;
}
#detailOverlay .detail-card {
  background: #fff; border-color: transparent; box-shadow: none;
}

/* Shared white page surface; card colours, status accents and modal scrims stay distinct. */
html, body, #app, main, main > section,
.home-view, .feed-view, .news-view, .projects-view, .balance-view,
body .chat-view, body .detail-overlay.detail-page {
  background-color: #fff; background-image: none;
}

/* White content surfaces as well as white pages. Keep action/status colours distinct. */
:root { --bg: #fff; --bg-page: #fff; --card: #fff; }
.tile, .earn-card, .news-card, .news-tile, .news-tile-wide, .project-link,
.balance-card, .home-tile, .profile-head, .offer-card, .product-card, .comment-card,
.admin-card, .modal-card, .detail-card, .sheet, .ask-card, .sndpk-sheet,
.home-supplier-card, .dlg-row, .news-modal-card {
  background-color: #fff; background-image: none;
}

/* Keep the identity, login, VPN and menu in a single compact header row. */
.market-home-head { grid-template-columns: auto auto auto minmax(0, 1fr); gap: 8px; align-items: center; }
.market-home-head .market-home-identity, .market-home-brand-row { display: contents; }
.market-home-head .market-home-brand { grid-column: 1; grid-row: 1; white-space: nowrap; }
.market-home-head .market-home-login { grid-column: 2; grid-row: 1; height: 38px; white-space: nowrap; }
.market-home-head .market-home-login-label { white-space: nowrap; max-width: none; }
.market-home-head .market-home-vpn { grid-column: 3; grid-row: 1; display: inline-flex; align-items: center; justify-content: center; height: 38px; box-sizing: border-box; padding: 0 12px; border-radius: 11px; background: #e9444b; color: #fff; font-size: 13px; font-weight: 650; text-decoration: none; white-space: nowrap; }
.market-home-head .market-home-more { grid-column: 4; grid-row: 1; justify-self: end; }
.market-home-head .market-home-more summary { box-sizing: border-box; min-height: 38px; padding: 0 12px; white-space: nowrap; }
.market-home-head .home-stats-bar { grid-column: 1 / -1; grid-row: 2; min-width: 0; width: 100%; margin-top: 0; }
.market-home-head:has(.market-home-login.hidden) .market-home-vpn { grid-column: 2; }
@media (max-width: 560px) {
 .market-home-head { gap: 5px; }
 .market-home-head .market-home-brand { font-size: 19px; }
 .market-home-head .market-home-login { padding: 0 8px; gap: 4px; }
 .market-home-head .market-home-login-label { font-size: 12px; }
 .market-home-head .market-home-vpn { padding: 0 8px; font-size: 12px; }
 .market-home-head .market-home-more summary { padding: 0 8px; font-size: 12px; }
}
@media (max-width: 350px) {
 .market-home-head { gap: 4px; }
 .market-home-head .market-home-brand { font-size: 16px; }
 .market-home-head .market-home-login { padding: 0 6px; }
 .market-home-head .market-home-vpn { padding: 0 6px; }
 .market-home-head .market-home-more summary { padding: 0 6px; }
}

/* Always-visible market chat entries, following new products on the homepage. */
.home-market-chats-note { margin: -4px 0 12px; color: var(--fg-dim, #777); font-size: 13px; line-height: 1.5; }
.home-market-chats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.home-market-chat { display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0; box-sizing: border-box; padding: 18px; border: 1px solid var(--border, #e5e7eb); border-radius: 16px; background: #fff; color: var(--fg, #17181a); font-family: inherit; text-align: left; cursor: pointer; }
.home-market-chat-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 40px; height: 40px; border-radius: 12px; background: #edf4ff; font-size: 22px; }
.home-market-chat-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.home-market-chat-body strong { font-size: 15px; line-height: 1.25; }
.home-market-chat-body > span { color: var(--accent, #327bf0); font-size: 13px; }
.home-market-chat-arrow { margin-left: auto; color: var(--accent, #327bf0); font-size: 22px; }
.home-market-chat:hover { border-color: #b9d3fb; }
.home-market-chat:focus-visible { outline: 2px solid var(--accent, #327bf0); outline-offset: 3px; }
@media (max-width: 699px) {
 .home-market-chats-grid { grid-template-columns: 1fr; gap: 8px; }
 .home-market-chat { padding: 12px 14px; }
 .home-market-chat-body { flex: 1; }
}

/* Comment totals remain visible even before the first comment. */
.tile-photo-wrap .tile-badge-comments { top: auto; left: auto; bottom: 6px; right: 6px; display: inline-flex; align-items: center; gap: 4px; }
.tile-photo-wrap .tile-rfq-offers { bottom: 40px; }
