/* Conversations & Editorial Messaging Studio */
.conversations {
  --thread-coral: var(--coral-soft);
  --thread-light: var(--white);
  --thread-muted: var(--muted);
  --thread-rule: var(--line);
}

.conversations .subhead {
  margin-bottom: 18px;
}

.conversations .subhead h1 {
  letter-spacing: -0.04em;
}

.conversations .chat-layout {
  display: grid;
  grid-template-columns: minmax(225px, 0.58fr) minmax(0, 1.6fr);
  gap: clamp(14px, 2.2vw, 24px);
  align-items: start;
}

.conversations .thread-sidebar,
.conversations .chat-panel {
  min-width: 0;
  border: 1px solid var(--thread-rule);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--sheen);
}

.conversations .thread-sidebar {
  padding: 16px 12px;
}

.thread-list-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 6px 14px;
}

.thread-list-title h2 {
  font-size: 1.02rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.thread-list-title > span {
  min-width: 24px;
  padding: 2px 8px;
  border: 1px solid rgba(207, 169, 114, 0.34);
  border-radius: 99px;
  text-align: center;
  color: var(--iris-soft);
  background: rgba(207, 169, 114, 0.14);
  font-size: 0.74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.conversations .chat-matches {
  display: grid;
  gap: 4px;
  max-height: min(630px, 65vh);
  overflow: auto;
}

.conversations .match-row {
  position: relative;
  min-width: 0;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  background: transparent;
  box-shadow: none;
  border-radius: 12px;
}

.conversations .match-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.conversations .match-row.sel {
  border-color: rgba(236, 78, 48, 0.5);
  background: rgba(236, 78, 48, 0.13);
}

.conversations .match-row .avatar {
  width: 42px;
  height: 42px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.conversations .match-row > span {
  flex: 1;
  min-width: 0;
}

.conversations .match-row strong,
.conversations .match-row small {
  max-width: none;
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversations .match-row strong {
  font-size: 0.95rem;
  color: var(--thread-light);
}

.conversations .match-row small {
  margin-top: 2px;
  font-size: 0.79rem;
  color: var(--thread-muted);
}

.conversations .chat-panel {
  display: block;
  padding: 0;
  overflow: hidden;
}

.thread-stage {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 104px;
  padding: 16px clamp(16px, 2.4vw, 26px);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.thread-stage-image {
  position: absolute;
  inset: 0 0 0 auto;
  z-index: -2;
  width: 56%;
  height: 100%;
  object-fit: cover;
  object-position: center 47%;
  opacity: 0.55;
  filter: saturate(0.88);
}

.thread-stage::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background: linear-gradient(
    96deg,
    rgba(20, 20, 23, 0.98) 0%,
    rgba(20, 20, 23, 0.92) 44%,
    rgba(14, 14, 17, 0.64) 70%,
    rgba(9, 9, 11, 0.38) 100%
  );
}

.conversations .message-head {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.conversations .message-head > div {
  min-width: 0;
}

.conversations .message-head .avatar {
  flex: none;
  width: clamp(46px, 4.4vw, 60px);
  height: clamp(46px, 4.4vw, 60px);
  padding: 2px;
  border: 1.5px solid rgba(230, 207, 168, 0.52);
  border-radius: 50%;
  background: var(--well);
}

.conversations .message-head h2 {
  margin: 0;
  color: var(--white);
  font-size: clamp(1.22rem, 2.2vw, 1.75rem);
  letter-spacing: -0.035em;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.conversations .message-head p {
  font-size: 0.82rem;
  margin: 4px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.thread-options {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  background: rgba(14, 14, 17, 0.88);
  color: var(--white);
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.thread-options:hover {
  background: var(--raised);
}

.thread-options .ic {
  width: 1rem;
  height: 1rem;
}

.thread-interior {
  padding: 0 clamp(14px, 2.2vw, 26px) 16px;
  background: var(--well);
}

.conversations .message-list {
  display: grid;
  align-content: start;
  gap: 8px;
  height: clamp(230px, 34vh, 430px);
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 18px 4px 16px;
  border: 0;
  border-radius: 0;
  background: none;
  scrollbar-width: thin;
  scrollbar-color: var(--raised) var(--well);
}

.thread-day {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 8px;
}

.thread-day::before,
.thread-day::after {
  content: "";
  height: 1px;
  background: var(--line);
  width: 34px;
}

.thread-day span {
  font-size: 0.74rem;
  font-weight: 650;
  color: var(--dim);
}

.conversations .bubble {
  justify-self: start;
  max-width: min(82%, 530px);
  padding: 10px 14px 7px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
  background: var(--surface-2);
  color: var(--white);
  white-space: normal;
  overflow-wrap: anywhere;
}

.conversations .bubble.mine {
  justify-self: end;
  border-color: rgba(255, 210, 195, 0.28);
  border-radius: 16px 16px 4px 16px;
  background: linear-gradient(135deg, #b82c1d 0%, #ec4e30 100%);
  color: #ffffff;
  box-shadow: 0 8px 22px -12px rgba(236, 78, 48, 0.52);
}

.thread-text {
  display: block;
  white-space: pre-wrap;
  line-height: 1.48;
}

.conversations .bubble time {
  display: block;
  text-align: end;
  color: var(--muted);
  font-size: 0.69rem;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.conversations .bubble.mine time {
  color: rgba(255, 245, 238, 0.8);
}

.thread-first {
  align-self: center;
  text-align: center;
  margin: 40px auto 14px;
  color: var(--thread-muted);
}

.thread-first > span,
.thread-empty-icon {
  display: inline-grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  width: 48px;
  height: 48px;
  background: var(--surface-2);
  color: var(--iris-soft);
}

.thread-first p {
  margin: 10px 0 0;
}

.conversations .compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
}

.conversations .compose:focus-within {
  border-color: var(--iris-soft);
}

.conversations .compose input {
  width: 100%;
  min-width: 0;
  background: none;
  border: 0;
  padding: 8px 10px;
  box-shadow: none;
  outline: 0;
  color: var(--white);
}

.conversations .compose input::placeholder {
  color: var(--dim);
}

.conversations .compose .form-error {
  grid-column: 1 / -1;
  margin: 0 8px;
}

.conversations .compose .form-error:empty {
  display: none;
}

.thread-send {
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 42px;
  min-height: 42px;
  border: 1px solid rgba(255, 212, 196, 0.36);
  border-radius: 10px;
  background: var(--brand-grad);
  color: #ffffff;
}

.thread-send:hover {
  filter: brightness(1.08);
}

.thread-send .ic {
  width: 18px;
  height: 18px;
}

.thread-tools {
  padding: 16px clamp(14px, 2.2vw, 26px) 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.thread-tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.thread-tool-grid > div {
  min-width: 0;
}

.thread-tool {
  height: 100%;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--well);
  border-radius: 12px;
}

.thread-tool-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.thread-tool-heading i {
  color: var(--iris-soft);
  display: flex;
  align-items: center;
}

.thread-tool-heading .ic {
  width: 18px;
  height: 18px;
}

.thread-tool strong {
  font-size: 0.94rem;
  overflow-wrap: anywhere;
  color: var(--white);
}

.thread-tool p {
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0;
  color: var(--muted);
}

.thread-tool .helper {
  font-size: 0.77rem;
  color: var(--dim);
}

.thread-tool .btn {
  justify-self: start;
  min-height: 36px;
  padding: 6px 11px;
}

.thread-tools .chat-tools {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding: 10px 0 0;
}

.thread-tools .chat-tools > summary,
.thread-context > summary {
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--iris-soft);
  padding: 8px 2px;
  font-weight: 650;
}

.thread-tools [data-date-editor] {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--well);
}

.thread-context {
  padding: 0 clamp(14px, 2.2vw, 26px);
  border-bottom: 1px solid var(--line);
  background: var(--well);
}

.thread-context[open] {
  padding-bottom: 12px;
}

.thread-empty {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(200px, 0.9fr);
  border: 1px solid var(--line);
  overflow: hidden;
  border-radius: 20px;
  background: var(--surface);
  color: var(--white);
}

.thread-empty > div {
  align-self: center;
  padding: clamp(25px, 5vw, 56px);
}

.thread-empty h2 {
  max-width: 15ch;
  margin: 18px 0 10px;
  font-size: clamp(1.75rem, 3.4vw, 2.8rem);
  line-height: 1.05;
}

.thread-empty p {
  max-width: 39ch;
  color: var(--muted);
  margin: 0 0 22px;
}

.thread-empty img {
  width: 100%;
  height: 100%;
  min-height: 290px;
  object-fit: cover;
}

@media (max-width: 780px) {
  .conversations .chat-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  .conversations .thread-sidebar {
    padding: 10px 12px;
  }
  .thread-list-title {
    margin: 0 2px 8px;
  }
  .thread-list-title h2 {
    font-size: 0.9rem;
  }
  .conversations .chat-matches {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    max-height: none;
    scrollbar-width: thin;
  }
  .conversations .chat-matches .match-row {
    min-width: 0;
    max-width: 200px;
    flex: 0 0 auto;
    width: auto;
    padding: 7px 10px;
  }
  .conversations .match-row .avatar {
    width: 32px;
    height: 32px;
  }
  .conversations .match-row > span {
    max-width: 120px;
  }
  .conversations .match-row strong {
    font-size: 0.85rem;
  }
  .conversations .match-row small {
    font-size: 0.72rem;
  }
  .conversations .subhead {
    margin-bottom: 10px;
  }
  .thread-stage {
    min-height: 84px;
    padding: 12px;
    gap: 8px;
  }
  .conversations .message-head {
    gap: 10px;
  }
  .conversations .message-head .avatar {
    width: 44px;
    height: 44px;
  }
  .thread-options {
    padding: 6px 10px;
    min-width: 40px;
    min-height: 40px;
    font-size: 0.74rem;
  }
  .conversations .message-list {
    height: clamp(180px, calc(48svh - var(--member-dock-space, 74px)), 330px);
  }
  .thread-stage-image {
    width: 65%;
  }
}

@media (max-width: 600px) {
  .conversations .chat-panel,
  .conversations .thread-sidebar {
    border-radius: 16px;
  }
  .thread-tool-grid {
    grid-template-columns: 1fr;
  }
  .thread-empty {
    grid-template-columns: minmax(0, 1fr);
  }
  .thread-empty img {
    height: 140px;
    min-height: 0;
    object-position: center 58%;
  }
}

.thread-workspace {
  display: flex;
  flex-direction: column;
  height: max(360px, calc(100dvh - 116px));
}
.thread-workspace > .subhead {
  margin: 0 0 12px;
  padding-bottom: 12px;
}
.thread-workspace > .subhead h1 {
  font-size: clamp(1.55rem, 2.5vw, 2.1rem);
  line-height: 1.15;
}
.thread-workspace .chat-layout {
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
.thread-workspace .thread-sidebar,
.thread-workspace .chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.thread-workspace .chat-matches {
  display: grid;
  align-content: start;
  grid-template-columns: minmax(0, 1fr);
  overflow-y: auto;
  max-height: none;
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.thread-workspace .thread-stage {
  min-height: 66px;
  padding: 10px 16px;
}
.thread-workspace .message-head {
  flex: 1;
  gap: 10px;
}
.thread-workspace .message-head .avatar {
  width: 44px;
  height: 44px;
}
.thread-workspace .message-head h2 {
  font-size: clamp(1.1rem, 1.6vw, 1.45rem);
}
.thread-workspace .thread-interior {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-bottom: 10px;
}
.thread-workspace .message-list {
  flex: 1;
  height: auto;
  overscroll-behavior: contain;
}
.thread-workspace .compose {
  flex: none;
}
.thread-workspace .thread-send {
  width: auto;
  min-width: 44px;
  display: inline-flex;
  gap: 7px;
  justify-content: center;
  align-items: center;
  padding-inline: 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
}
.thread-workspace .thread-send:disabled {
  opacity: 0.65;
  cursor: wait;
}
.thread-back {
  display: none;
}
.thread-drawer {
  flex: none;
  min-height: 0;
  max-height: 48%;
  overflow: auto;
  border-top: 1px solid var(--line);
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.thread-drawer > summary {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px clamp(14px, 2.2vw, 26px);
  background: var(--surface);
  color: var(--iris-soft);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.thread-drawer .thread-tools {
  padding-top: 10px;
}
.thread-drawer .thread-context {
  margin-bottom: 10px;
}
.thread-workspace :is(button, summary, a):focus-visible,
.thread-workspace #messages:focus-visible {
  outline: 2px solid var(--iris-soft);
  outline-offset: -3px;
}
.thread-workspace .compose:focus-within {
  box-shadow: 0 0 0 2px rgba(230, 207, 168, 0.24);
}
.thread-workspace .compose .form-error {
  margin: 0;
}
.thread-feedback {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 4px;
}
.thread-feedback[hidden] {
  display: none;
}
.thread-retry {
  flex: none;
  min-height: 36px;
  padding: 4px 10px;
  color: var(--white);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
}

@media (max-width: 780px) {
  .thread-workspace {
    height: max(240px, calc(var(--thread-viewport, 100dvh) - 104px - var(--member-dock-space, 0px)));
  }
  .thread-workspace .chat-layout {
    grid-template-rows: minmax(0, 1fr);
  }
  .thread-workspace.room-open .thread-sidebar,
  .thread-workspace.inbox-open .chat-panel {
    display: none;
  }
  .thread-workspace .chat-matches {
    overflow-x: hidden;
  }
  .thread-workspace .chat-matches .match-row {
    width: 100%;
    max-width: none;
    padding: 10px;
  }
  .thread-workspace .match-row > span {
    max-width: none;
  }
  .thread-workspace .match-row .avatar {
    width: 42px;
    height: 42px;
  }
  .thread-workspace .match-row strong {
    font-size: 0.96rem;
  }
  .thread-workspace .match-row small {
    font-size: 0.8rem;
  }
  .thread-workspace .thread-stage {
    padding: 8px;
  }
  .thread-back {
    display: grid;
    place-items: center;
    flex: none;
    min-width: 42px;
    min-height: 44px;
    border-radius: 10px;
    color: var(--thread-light);
    background: var(--well);
    border: 1px solid var(--line-strong);
  }
  .thread-back .ic {
    width: 20px;
    height: 20px;
  }
  .thread-workspace .compose input {
    font-size: 16px;
  }
  .thread-workspace .thread-send {
    min-height: 44px;
    padding-inline: 10px;
  }
  .thread-workspace .thread-send span {
    display: none;
  }
  .thread-workspace .compose[data-busy="true"] .thread-send .ic {
    display: none;
  }
  .thread-workspace .compose[data-busy="true"] .thread-send::before {
    content: "";
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: white;
    border-radius: 50%;
    animation: thread-sending 0.8s linear infinite;
  }
}
@keyframes thread-sending {
  to {
    transform: rotate(1turn);
  }
}
@media (prefers-reduced-motion: reduce) {
  .thread-workspace .compose[data-busy="true"] .thread-send::before {
    animation: none;
  }
}
