/*
 * assets/store/messages.css: conversations on the /products/ store (2026-10-29,
 * SPEC2 section 5). Load with `storeStyles: ["messages.css"]`; it sits after
 * store.css and uses only its tokens, so html.dark flips it with everything
 * else. Two parts:
 *   1. the shared components drawn by assets/store/messages.js (DHS.messages):
 *      the feed (.dhs-msgs), messages (.dhs-msg), system lines (.dhs-msg-sys),
 *      offer cards (.dhs-offer), the composer additions (.dhs-cmp) and the
 *      lightbox (.dhs-lightbox), used by the inbox and the order page;
 *   2. the inbox page (.dhs-inbox): a two pane layout from 900px, one pane
 *      (the list, or one conversation with a back button) on phones.
 * Checked at 360px with no horizontal scroll.
 */

:root {
  --dhs-lb-bg: rgba(14, 15, 16, .97);
  --dhs-lb-fg: #ffffff;
  --dhs-lb-btn: rgba(255, 255, 255, .14);
  --dhs-msg-team: var(--dhs-bg-muted);
  --dhs-msg-you: var(--dhs-accent-soft);
  --dhs-offer-pending-bg: var(--dhs-st-missing-bg);
  --dhs-offer-pending-fg: var(--dhs-st-missing-fg);
}
html.dark {
  --dhs-lb-bg: rgba(0, 0, 0, .97);
  --dhs-msg-team: var(--dhs-bg-muted);
}

/* ── 1. Feed ─────────────────────────────────────────────────────────────── */
.dhs-msgs { display: flex; flex-direction: column; gap: 16px; padding: 16px 0 8px; min-width: 0; }
.dhs-msgs__day { display: flex; align-items: center; gap: 12px; margin-top: 4px; font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--dhs-text-muted); }
.dhs-msgs__day::before, .dhs-msgs__day::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--dhs-border-light); }
.dhs-msgs__day > span { flex: none; }

.dhs-msg { display: flex; align-items: flex-start; gap: 10px; min-width: 0; border-radius: var(--dhs-r); transition: background-color .4s var(--dhs-ease); }
.dhs-msg--you { flex-direction: row-reverse; }
.dhs-msg.is-flash { background: var(--dhs-accent-soft); }
.dhs-msg__avatar { flex: none; margin-top: 20px; }
.dhs-msg__body { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; max-width: min(640px, calc(100% - 42px)); }
.dhs-msg--you .dhs-msg__body { align-items: flex-end; max-width: min(640px, 88%); }
.dhs-msg--offer .dhs-msg__body { width: min(480px, calc(100% - 42px)); }
.dhs-msg__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 13px; line-height: 18px; }
.dhs-msg--you .dhs-msg__head { flex-direction: row-reverse; }
.dhs-msg__name { font-weight: 700; color: var(--dhs-text-strong); }
.dhs-msg__time { font-size: 12px; color: var(--dhs-text-muted); white-space: nowrap; }
.dhs-msg__edited { font-size: 12px; color: var(--dhs-text-muted); font-style: italic; }
.dhs-msg__bubble { max-width: 100%; padding: 10px 14px; border-radius: 4px 16px 16px 16px; background: var(--dhs-msg-team); color: var(--dhs-text-strong); font-size: 15px; line-height: 22px; white-space: pre-line; overflow-wrap: anywhere; word-break: break-word; }
.dhs-msg--you .dhs-msg__bubble { border-radius: 16px 4px 16px 16px; background: var(--dhs-msg-you); }
.dhs-msg__link { color: var(--dhs-accent-text); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
html.dark .dhs-msg__link { color: var(--dhs-accent); }

.dhs-msg__quote { display: flex; flex-direction: column; gap: 1px; max-width: 100%; padding: 6px 10px; border: 0; border-left: 3px solid var(--dhs-accent); border-radius: var(--dhs-r-sm); background: var(--dhs-bg-subtle); text-align: left; font-size: 13px; line-height: 18px; color: var(--dhs-text-body); cursor: pointer; }
.dhs-msg__quote:hover { background: var(--dhs-bg-hover); }
.dhs-msg__quote-who { font-weight: 700; color: var(--dhs-text-heading); }
.dhs-msg__quote-text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }

.dhs-msg__media { display: grid; grid-template-columns: repeat(2, minmax(0, 150px)); gap: 6px; max-width: 100%; }
.dhs-msg__media--one { grid-template-columns: minmax(0, 280px); }
.dhs-msg__thumb { display: block; width: 100%; padding: 0; border: 1px solid var(--dhs-border-light); border-radius: var(--dhs-r); overflow: hidden; background: var(--dhs-bg-media); aspect-ratio: 4 / 3; cursor: zoom-in; }
.dhs-msg__thumb img { width: 100%; height: 100%; object-fit: cover; }
.dhs-msg__thumb:hover img { opacity: .92; }
.dhs-msg__video { max-width: 100%; }
.dhs-msg__video video { display: block; width: 320px; max-width: 100%; border-radius: var(--dhs-r); background: var(--dhs-bg-media); }
.dhs-msg__audio audio { display: block; width: 280px; max-width: 100%; }
.dhs-msg__downloads { display: flex; flex-wrap: wrap; gap: 4px 12px; max-width: 100%; }
.dhs-msg__download { display: inline-flex; align-items: center; gap: 4px; max-width: 240px; min-width: 0; font-size: 12px; line-height: 18px; color: var(--dhs-text-body); }
.dhs-msg__download:hover { color: var(--dhs-text-strong); text-decoration: underline; text-underline-offset: 2px; }
.dhs-msg__size { flex: none; color: var(--dhs-text-muted); }
.dhs-msg__files { width: min(360px, 100%); }

.dhs-msg__tools { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.dhs-msg:hover .dhs-msg__tools, .dhs-msg:focus-within .dhs-msg__tools { opacity: 1; }
@media (hover: none) { .dhs-msg__tools { opacity: 1; } }
.dhs-msg__tool { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 2px 8px; border-radius: var(--dhs-r-sm); font-size: 12px; font-weight: 600; color: var(--dhs-text-muted); }
.dhs-msg__tool:hover { background: var(--dhs-bg-hover); color: var(--dhs-text-strong); }

.dhs-msg-sys { display: flex; align-items: flex-start; gap: 8px; width: fit-content; max-width: min(560px, 100%); margin: 0 auto; padding: 8px 12px; border: 1px solid var(--dhs-border-faint); border-radius: var(--dhs-r); background: var(--dhs-bg-subtle); font-size: 13px; line-height: 19px; color: var(--dhs-text-body); }
.dhs-msg-sys__icon { flex: none; display: inline-flex; margin-top: 2px; color: var(--dhs-text-heading); }
.dhs-msg-sys__text { min-width: 0; overflow-wrap: anywhere; white-space: pre-line; }
.dhs-msg-sys .dhs-msg__time { flex: none; margin-left: 4px; line-height: 19px; }

/* ── Offer card ──────────────────────────────────────────────────────────── */
.dhs-offer { width: 100%; border: 1px solid var(--dhs-border); border-radius: var(--dhs-r-lg); background: var(--dhs-bg); box-shadow: var(--dhs-shadow-1); overflow: hidden; }
.dhs-offer__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--dhs-border-light); background: var(--dhs-bg-subtle); }
.dhs-offer__label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--dhs-text-heading); }
.dhs-offer__status { display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: var(--dhs-r-pill); font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--dhs-bg-muted); color: var(--dhs-text-heading); }
.dhs-offer__status--pending { background: var(--dhs-offer-pending-bg); color: var(--dhs-offer-pending-fg); }
.dhs-offer__status--accepted { background: var(--dhs-accent-soft); color: var(--dhs-accent-text); }
.dhs-offer__status--declined { background: var(--dhs-danger-soft); color: var(--dhs-danger-text); }
.dhs-offer__body { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.dhs-offer__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dhs-offer__title { min-width: 0; font-size: 17px; line-height: 24px; font-weight: 700; color: var(--dhs-text-strong); overflow-wrap: anywhere; }
.dhs-offer__price { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 20px; line-height: 26px; font-weight: 700; color: var(--dhs-text-strong); font-variant-numeric: tabular-nums; }
.dhs-offer__was { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--dhs-text-muted); }
.dhs-offer__discount { margin-top: -6px; font-size: 13px; font-weight: 600; color: var(--dhs-accent-text); }
.dhs-offer__desc { font-size: 14px; line-height: 21px; color: var(--dhs-text-body); white-space: pre-line; overflow-wrap: anywhere; }
.dhs-offer__facts { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; line-height: 18px; color: var(--dhs-text-heading); }
.dhs-offer__facts li { display: inline-flex; align-items: center; gap: 6px; }
.dhs-offer__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dhs-offer__actions .dhs-btn { white-space: normal; }
.dhs-offer__note { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; line-height: 19px; color: var(--dhs-text-body); }
.dhs-offer__note .dhs-icon { flex: none; margin-top: 1px; }
.dhs-offer__note--ok { color: var(--dhs-accent-text); font-weight: 600; }
.dhs-offer__reason { padding: 8px 12px; border-radius: var(--dhs-r); background: var(--dhs-bg-subtle); font-size: 13px; line-height: 19px; white-space: pre-line; overflow-wrap: anywhere; color: var(--dhs-text-heading); }
.dhs-offer--declined .dhs-offer__price, .dhs-offer--expired .dhs-offer__price, .dhs-offer--withdrawn .dhs-offer__price { color: var(--dhs-text-muted); }
@media (max-width: 599px) {
  .dhs-offer__top { flex-direction: column; gap: 4px; }
  .dhs-offer__price { align-items: flex-start; }
  .dhs-offer__actions .dhs-btn { flex: 1 1 100%; }
}

/* ── Composer additions (on top of .dhs-composer in store.css) ───────────── */
.dhs-cmp.is-drag { border-color: var(--dhs-accent); box-shadow: 0 0 0 2px var(--dhs-accent-soft); }
.dhs-cmp__input { min-height: 46px; max-height: 220px; resize: none; overflow-y: auto; }
.dhs-cmp .dhs-composer__files { padding-top: 4px; padding-bottom: 8px; }
.dhs-cmp__reply { display: flex; align-items: center; gap: 8px; margin: 8px 8px 0; padding: 6px 6px 6px 10px; border-left: 3px solid var(--dhs-accent); border-radius: var(--dhs-r-sm); background: var(--dhs-bg-subtle); }
.dhs-cmp__reply-icon { flex: none; display: inline-flex; color: var(--dhs-accent-text); }
.dhs-cmp__reply-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; font-size: 13px; line-height: 18px; }
.dhs-cmp__reply-who { font-weight: 700; color: var(--dhs-text-heading); }
.dhs-cmp__reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dhs-text-body); }
.dhs-cmp__count { font-size: 12px; color: var(--dhs-text-muted); white-space: nowrap; }
.dhs-cmp__count.is-over { color: var(--dhs-danger-text); font-weight: 700; }
@media (max-width: 599px) { .dhs-cmp .dhs-composer__hint { display: none; } }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
.dhs-lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--dhs-lb-bg); color: var(--dhs-lb-fg); display: flex; flex-direction: column; }
.dhs-lightbox:not([open]) { display: none; }
.dhs-lightbox::backdrop { background: var(--dhs-overlay); }
.dhs-lightbox__bar { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; }
.dhs-lightbox__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; line-height: 20px; }
.dhs-lightbox .dhs-iconbtn, .dhs-lightbox__nav { color: var(--dhs-lb-fg); }
.dhs-lightbox .dhs-iconbtn:hover { background: var(--dhs-lb-btn); }
.dhs-lightbox__stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 64px 32px; }
.dhs-lightbox__img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--dhs-r-sm); }
.dhs-lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; background: var(--dhs-lb-btn); }
.dhs-lightbox__nav--prev { left: 8px; }
.dhs-lightbox__nav--next { right: 8px; }
@media (max-width: 599px) {
  .dhs-lightbox__stage { padding: 8px 8px 88px; }
  .dhs-lightbox__nav { top: auto; bottom: 20px; transform: none; }
  .dhs-lightbox__nav--prev { left: calc(50% - 60px); }
  .dhs-lightbox__nav--next { right: calc(50% - 60px); }
}

/* ── 2. The inbox page ───────────────────────────────────────────────────── */
.dhs-inbox-page .dhs-pagehead { margin-bottom: 20px; }
.dhs-inbox { display: grid; grid-template-columns: minmax(0, 1fr); border: 1px solid var(--dhs-border-light); border-radius: var(--dhs-r-lg); background: var(--dhs-bg); overflow: hidden; }
.dhs-inbox__list { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.dhs-inbox__listhead { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-bottom: 1px solid var(--dhs-border-light); }
.dhs-inbox__tools { display: flex; align-items: center; gap: 8px; }
.dhs-inbox__count { flex: 1 1 auto; font-size: 14px; font-weight: 700; color: var(--dhs-text-strong); }
.dhs-inbox__search { position: relative; }
.dhs-inbox__search .dhs-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--dhs-text-muted); pointer-events: none; }
.dhs-inbox__search .dhs-input { height: 40px; padding-left: 38px; }
.dhs-tlist { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.dhs-tlist__empty { padding: 32px 16px; text-align: center; font-size: 14px; color: var(--dhs-text-body); }

.dhs-trow { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--dhs-border-faint); color: inherit; text-decoration: none; }
.dhs-trow:hover { background: var(--dhs-bg-hover); }
.dhs-trow.is-active { background: var(--dhs-bg-muted); }
.dhs-trow.is-active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--dhs-accent); }
.dhs-trow__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dhs-trow__line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dhs-trow__title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; line-height: 21px; font-weight: 600; color: var(--dhs-text-strong); }
.dhs-trow__time { flex: none; font-size: 12px; line-height: 18px; color: var(--dhs-text-muted); white-space: nowrap; }
.dhs-trow__preview { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; line-height: 20px; color: var(--dhs-text-body); }
.dhs-trow.is-unread .dhs-trow__title { font-weight: 800; }
.dhs-trow.is-unread .dhs-trow__preview { font-weight: 600; color: var(--dhs-text-strong); }
.dhs-trow__badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--dhs-accent); color: var(--dhs-on-accent); font-size: 12px; line-height: 20px; font-weight: 700; text-align: center; }
.dhs-trow__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dhs-tchip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--dhs-r-sm); border: 1px solid var(--dhs-border); font-size: 12px; line-height: 18px; font-weight: 600; color: var(--dhs-text-heading); white-space: nowrap; }
.dhs-tchip--offer { border-color: transparent; background: var(--dhs-offer-pending-bg); color: var(--dhs-offer-pending-fg); }
.dhs-tchip--muted { border-color: transparent; background: var(--dhs-bg-muted); }
.dhs-trow .dhs-pill { height: 22px; font-size: 12px; }

.dhs-inbox__conv { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--dhs-bg); }
.dhs-conv__head { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 10px 16px; border-bottom: 1px solid var(--dhs-border-light); }
.dhs-conv__who { flex: 1 1 auto; min-width: 0; }
.dhs-conv__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; line-height: 22px; font-weight: 700; color: var(--dhs-text-strong); }
.dhs-conv__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--dhs-text-muted); }
.dhs-conv__subitem { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.dhs-conv__subitem + .dhs-conv__subitem::before { content: ""; flex: none; width: 4px; height: 4px; margin-right: 2px; border-radius: 50%; background: var(--dhs-border); }
.dhs-conv__sub a { color: var(--dhs-accent-text); font-weight: 600; }
html.dark .dhs-conv__sub a { color: var(--dhs-accent); }
.dhs-conv__actions { flex: none; display: flex; gap: 8px; }
.dhs-conv__banner:empty { display: none; }
.dhs-conv__banner { padding: 12px 16px 0; }
.dhs-conv__scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px; }
.dhs-conv__more { display: flex; justify-content: center; padding-top: 16px; }
.dhs-conv__composer { padding: 12px 16px 16px; border-top: 1px solid var(--dhs-border-faint); }
.dhs-conv__closed { margin-bottom: 8px; font-size: 13px; line-height: 19px; color: var(--dhs-text-muted); }
.dhs-conv__empty { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 24px; }
.dhs-conv__loading { display: flex; flex-direction: column; gap: 16px; padding: 24px 16px; }

@media (min-width: 900px) {
  .dhs-inbox { grid-template-columns: 340px minmax(0, 1fr); height: clamp(560px, calc(100dvh - var(--dhs-header-h) - 260px), 920px); }
  .dhs-inbox__list { border-right: 1px solid var(--dhs-border-light); }
  .dhs-conv__back { display: none; }
}
@media (min-width: 1160px) {
  .dhs-inbox { grid-template-columns: 380px minmax(0, 1fr); }
  .dhs-conv__scroll { padding: 0 24px; }
  .dhs-conv__composer { padding: 12px 24px 20px; }
}
@media (max-width: 899px) {
  .dhs-inbox:not(.is-conv) .dhs-inbox__conv { display: none; }
  .dhs-inbox.is-conv .dhs-inbox__list { display: none; }
  /* --dhs-bnav-offset: the phone bottom nav's height while it shows (store.css). */
  .dhs-inbox.is-conv .dhs-inbox__conv { height: calc(100dvh - var(--dhs-bnav-offset, 0px) - 16px); min-height: 440px; }
  .dhs-inbox-page.is-conv .dhs-pagehead, .dhs-inbox-page.is-conv .dhs-crumbs, .dhs-inbox-page.is-conv [data-inbox-scope] { display: none; }
  .dhs-inbox-page.is-conv { padding-top: 8px; }
  .dhs-tlist { overflow: visible; }
  .dhs-conv__head { gap: 8px; padding: 8px 12px; min-height: 60px; }
  .dhs-conv__scroll { padding: 0 12px; }
  .dhs-conv__composer { padding: 10px 12px 12px; }
}
@media (max-width: 599px) {
  .dhs-conv__actions .dhs-btn__label { display: none; }
  /* One line under the title on a phone: the order or service link alone. */
  .dhs-conv__subitem:first-child:not(:only-child) { display: none; }
  .dhs-conv__subitem + .dhs-conv__subitem::before { display: none; }
  .dhs-msg__body { max-width: calc(100% - 42px); }
  .dhs-msg--you .dhs-msg__body { max-width: 92%; }
  .dhs-msg__media { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dhs-msg__media--one { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .dhs-msg, .dhs-msg__tools { transition: none; }
}
@media print {
  .dhs-inbox__list, .dhs-conv__composer, .dhs-msg__tools { display: none !important; }
  .dhs-inbox { display: block; height: auto; border: 0; }
  .dhs-conv__scroll { overflow: visible; }
}
