.chat-workspace, .chat-sidebar, .chat-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-sidebar, .chat-panel { background: var(--surface); }
.chat-workspace:not(.has-thread) .chat-panel,
.chat-workspace.has-thread .chat-sidebar { display: none; }

.chat-sidebar-head {
  flex: none;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid var(--line);
}

.chat-sidebar-head h1 {
  margin-bottom: 12px;
  font-size: 30px;
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -.04em;
}

.chat-search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  margin: 0;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  box-shadow: none;
}

.chat-search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.chat-search > .ico { flex: none; }
.chat-search input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
}
#device .chat-search input:focus-visible { outline: none; }
.chat-search input::placeholder { color: var(--ink-2); }
.chat-search button { display: grid; place-items: center; flex: none; min-width: 28px; min-height: 28px; border-radius: 6px; }

.chat-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 8px 8px 14px;
}

.chat-list-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding-inline: 8px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 700;
}
.chat-list-heading :is(h2, h3) { font: inherit; }
.chat-list-heading button { padding: 5px 0 5px 5px; color: var(--brand); font-size: 13px; font-weight: 600; }

.chat-list :is(.li, .chat-list-item) {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 66px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 11px;
  text-align: left;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.chat-list .li + .li::before { display: none; }
.chat-list :is(.li, .chat-list-item):is(.on, [aria-current="true"]) {
  border-color: color-mix(in srgb, var(--brand) 19%, transparent);
  background: var(--brand-soft);
}
.chat-list :is(.li-main, .chat-list-main) { flex: 1; min-width: 0; }
.chat-list .seller-name { font-size: 15px; font-weight: 700; }
.chat-list .seller-name .nm { color: var(--ink); font-size: inherit; }
.chat-find-merchant { flex: none; margin: 0 12px calc(10px + env(safe-area-inset-bottom)); }
.chat-list :is(.chat-preview, .li-main > span) {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-list .chat-preview .ico { width: 13px; height: 13px; margin-right: 3px; vertical-align: -.16em; }
.chat-list :is(.chat-list-meta, .li-end) {
  display: flex;
  align-self: stretch;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: none;
  padding-top: 2px;
  color: var(--ink-2);
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}
.chat-list :is(.chat-list-meta, .li-end) :is(time, small) { color: inherit; font-size: inherit; font-variant-numeric: tabular-nums; }
.chat-list .chat-unread {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding-inline: 4px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}
.chat-list [aria-current="true"] .chat-unread { background: var(--surface); }

.chat-list-empty, .chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 22px 14px;
  color: var(--ink-2);
  text-align: center;
}
.chat-empty { flex: 1; min-height: 0; }
.chat-list-empty :is(h2, h3, b), .chat-empty :is(h2, h3, b) { color: var(--ink); font-size: 16px; font-weight: 700; }
.chat-list-empty p, .chat-empty p { max-width: 32ch; font-size: 14px; line-height: 1.45; }
.chat-empty-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  margin-bottom: 6px;
  border-radius: 15px;
  background: var(--brand-soft);
  color: var(--brand);
}

.chat-panel .chat-head {
  flex: none;
  margin: 0;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: none;
  backdrop-filter: none;
}
.chat-head .chat-person { display: flex; align-items: center; flex: 1; gap: 9px; min-width: 0; text-align: left; }
.chat-head .chat-person > :last-child { min-width: 0; }
.chat-person :is(.chat-person-status, .seller-meta) { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.4; }
.chat-person-status.is-typing { color: var(--brand); }
.chat-head .deal-pill { border-radius: 10px; height: 36px; box-shadow: none; }
.chat-head .deal-pill:disabled { background: var(--surface-2); color: var(--ink-2); }

#device .chat-panel .chat-wrap {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: var(--surface);
}
.chat-panel .chat-body {
  min-height: 0;
  gap: 7px;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 14px 12px;
  background: var(--surface-2);
}
.chat-panel .chat-body > * { flex-shrink: 0; }
.chat-panel .chat-body > .chat-empty { flex: 1 0 auto; }
.chat-panel .chat-banner {
  align-self: center;
  max-width: 100%;
  margin: 0 0 4px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: none;
}
.chat-panel .chat-banner .ico { flex: none; }
.chat-panel .chat-status-banner {
  flex: none;
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
}
.chat-panel .chat-load-older { align-self: center; min-height: 36px; margin-block-end: 6px; }
.support-entry-badge {
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
}
.chat-panel .day { margin: 3px 0; padding: 3px 9px; color: var(--ink-2); }
.chat-panel .msg {
  max-width: min(86%, 34rem);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-wrap: anywhere;
  box-shadow: none;
}
.chat-panel .msg.in { border-bottom-left-radius: 5px; }
.chat-panel .msg.out {
  border-color: color-mix(in srgb, var(--brand) 15%, var(--line));
  border-bottom-right-radius: 5px;
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  color: var(--ink);
}
.chat-panel .msg time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chat-panel .msg-text { white-space: pre-wrap; }
.chat-panel .msg-meta {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  float: right;
  margin: 5px 0 0 8px;
  padding: 1px 0;
  color: var(--ink-2);
  white-space: nowrap;
}
.chat-panel .msg-meta time { float: none; margin: 0; }
.chat-panel .chat-delivery { display: inline-grid; place-items: center; }
.chat-panel .chat-delivery .ico { width: 13px; height: 13px; }
.chat-panel .chat-delivery:is(.is-read, [data-status="read"]) { color: var(--brand); }
.chat-panel .chat-delivery:is(.is-failed, [data-status="failed"]) { color: var(--danger); }
.chat-panel .sys-card { align-self: center; width: min(100%, 360px); margin-inline: 0; border: 1px solid var(--line); border-radius: 14px; box-shadow: none; }
.chat-panel .typing { box-shadow: none; }
.chat-panel .quick-row {
  flex: none;
  width: 100%;
  padding: 9px 12px 0;
  background: var(--surface);
}
.chat-panel .quick-row .chip {
  height: 32px;
  padding-inline: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  box-shadow: none;
}
.chat-panel .composer {
  flex: none;
  width: 100%;
  margin: 0;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: var(--surface);
}

@media (hover: hover) {
  .chat-list :is(.li, .chat-list-item):not(.on, [aria-current="true"]):hover { background: var(--surface-2); }
  .chat-head button.chat-person:hover .seller-name { color: var(--brand); }
  .chat-panel .quick-row .chip:hover { background: var(--brand-soft); }
}

@media (min-width: 860px) {
  #device[data-view="account"]:is([data-route="chat"], [data-route="chats"]) > .scr { animation: none; }
  #device[data-view="support"] > .scr { animation: none; }
  .chat-workspace {
    display: grid;
    grid-template-columns: minmax(222px, 30%) minmax(0, 1fr);
    width: calc(100% - clamp(40px, 5vw, 92px));
    max-width: 1228px;
    margin: clamp(16px, 3.2vh, 30px) auto;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--sh-1);
  }
  .chat-workspace.has-thread .chat-sidebar,
  .chat-workspace:not(.has-thread) .chat-panel { display: flex; }
  .chat-workspace.support-only { grid-template-columns: minmax(0, 1fr); max-width: 850px; }
  .chat-sidebar { border-right: 1px solid var(--line); }
  .chat-sidebar-head { padding: 17px 15px 13px; }
  .chat-sidebar-head h1 { margin-bottom: 11px; font-size: 25px; }
  .chat-list { padding-inline: 7px; }
  .chat-list :is(.li, .chat-list-item):focus-visible { outline-offset: -2px; }
  .chat-search input { font-size: 14px; }
  .chat-panel > .chat-empty { background: var(--surface-2); }
  .chat-panel > .chat-empty .chat-empty-icon { width: 58px; height: 58px; border-radius: 17px; }
  .chat-panel > .chat-empty :is(h2, h3, b) { font-size: 19px; }
  #device[data-view="account"] .chat-panel .chat-head { min-height: 69px; padding: 12px clamp(14px, 1.8vw, 24px); }
  .chat-head :is(.chat-back, [data-act="back"]) { display: none; }
  .support-chat-head .chat-back { display: grid; flex: none; }
  #device .chat-panel .chat-body { padding: 16px max(16px, calc((100% - 760px) / 2)); }
  #device .chat-panel .msg { max-width: min(82%, 34rem); }
  .chat-panel .quick-row { padding-inline: clamp(14px, 1.8vw, 24px); }
  #device .chat-panel .composer { padding: 10px clamp(14px, 1.8vw, 24px) 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel :is(.msg.new, .sys-card, .typing, .typing i) { animation: none; }
}
.chat-chat-actions { display: flex; flex: none; align-items: center; gap: 6px; margin-inline-start: auto; }
.chat-chat-actions .chat-open-dispute { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: var(--ink-2); }
.chat-chat-actions .chat-open-dispute:is(:hover, :focus-visible) { background: var(--brand-soft); color: var(--brand); }
@media (max-width: 380px) { .chat-chat-actions { gap: 2px; } }
