/* NdA — Chats (Instagram/Tinder-style messaging) · Design System v2
   -------------------------------------------------------------------------
   The conversation inbox (avatar + name + last message + time + unread badge)
   and the message thread (left/right bubbles, day separators, sticky input
   bar). Use ONLY the --v2-* tokens from theme-v2.css; never hardcode hex.

   Layout: mobile-first master/detail. On a phone one pane shows at a time —
   `.nda-chats--inbox-open` reveals the inbox, `.nda-chats--thread-open`
   reveals the thread (with a back chevron). At ≥860px both panes sit side by
   side and the open/closed modifiers are ignored.
   ------------------------------------------------------------------------- */

/* The /chats page wrapper uses .nda-page; widen it for the master/detail grid. */
.nda-chats-page {
  max-width: 1040px;
}

.nda-chats__page-head {
  margin-bottom: 16px;
}

/* ── Shell / panes ──────────────────────────────────────────────────────────*/

.nda-chats {
  position: relative;
}

.nda-chats__pane--inbox {
  display: block;
}

.nda-chats__pane--thread {
  display: none;
}

/* Mobile: flip panes. */
.nda-chats--thread-open .nda-chats__pane--inbox {
  display: none;
}

.nda-chats--thread-open .nda-chats__pane--thread {
  display: block;
}

/* ── Inbox list ─────────────────────────────────────────────────────────────*/

.nda-chats__inbox {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nda-chats__row-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 11px 13px;
  text-align: left;
  background: var(--v2-surface);
  border: 1px solid var(--v2-border);
  border-radius: 18px;
  box-shadow: 0 14px 36px -28px var(--v2-shadow);
  cursor: pointer;
  font-family: var(--v2-font-body);
  color: var(--v2-text);
  transition: border-color 150ms ease, transform 120ms ease, background 150ms ease;
}

.nda-chats__row-item:hover {
  border-color: var(--v2-accent-soft);
}

.nda-chats__row-item:active {
  transform: scale(0.992);
}

.nda-chats__row-item:focus-visible {
  outline: 2px solid var(--v2-accent);
  outline-offset: 2px;
}

.nda-chats__row-item--active {
  border-color: var(--v2-accent);
  background: var(--v2-accent-soft);
}

/* Circular monogram avatar. */
.nda-chats__avatar {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--v2-surface2);
  border: 1px solid var(--v2-border);
  color: var(--v2-accent);
  font-family: var(--v2-font-title);
  font-size: 22px;
  line-height: 1;
  user-select: none;
}

/* A subtle accent ring signals an unread thread. */
.nda-chats__avatar--unread {
  border-color: var(--v2-accent);
  box-shadow: 0 0 0 3px var(--v2-accent-soft);
}

.nda-chats__row-main {
  flex: 1 1 auto;
  min-width: 0; /* let the preview ellipsis kick in */
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nda-chats__row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.nda-chats__row-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--v2-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nda-chats__row-time {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--v2-soft);
}

.nda-chats__row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nda-chats__row-preview {
  min-width: 0;
  flex: 1 1 auto;
  font-size: 13.5px;
  color: var(--v2-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nda-chats__row-preview--unread {
  color: var(--v2-text);
  font-weight: 600;
}

/* Unread count pill. */
.nda-chats__badge {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--v2-radius-pill);
  background: var(--v2-accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

/* ── Inbox states (empty / error / skeleton) ────────────────────────────────*/

.nda-chats__inbox-state {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nda-chats__empty {
  margin-top: 8px;
  padding: 40px 24px;
  text-align: center;
  background: var(--v2-surface);
  border: 1px solid var(--v2-border);
  border-radius: 22px;
  box-shadow: 0 14px 36px -28px var(--v2-shadow);
}

.nda-chats__empty-glyph {
  font-size: 44px;
  line-height: 1;
}

.nda-chats__empty-title {
  font-family: var(--v2-font-title);
  font-size: 22px;
  color: var(--v2-text);
  margin: 14px 0 6px;
}

.nda-chats__empty-text {
  font-size: 14px;
  color: var(--v2-soft);
  margin: 0 auto;
  max-width: 320px;
  line-height: 1.5;
}

.nda-chats__error {
  margin-top: 8px;
  padding: 22px 20px;
  text-align: center;
  background: var(--v2-surface);
  border: 1px solid var(--v2-border);
  border-radius: 18px;
}

.nda-chats__error-text {
  margin: 0;
  font-size: 14px;
  color: var(--v2-soft);
}

/* Skeleton rows during first load. */
.nda-chats__row-item--skeleton {
  cursor: default;
  pointer-events: none;
}

.nda-chats__skel-disc,
.nda-chats__skel-line {
  background: var(--v2-surface2);
  border-radius: 8px;
  animation: nda-chats-shimmer 1.3s ease-in-out infinite;
}

.nda-chats__skel-disc {
  border-radius: 50%;
}

.nda-chats__skel-line {
  height: 11px;
}

.nda-chats__skel-line--name {
  width: 42%;
  margin-bottom: 8px;
}

.nda-chats__skel-line--preview {
  width: 72%;
}

@keyframes nda-chats-shimmer {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nda-chats__skel-disc,
  .nda-chats__skel-line {
    animation: none;
  }
}

/* ── Thread ─────────────────────────────────────────────────────────────────
   A flex column that fills the space between the page header and the floating
   nav. The messages area scrolls; the composer is sticky just above the nav. */

/* Height available below the v2 sticky header (~64px) within the viewport. */
.nda-chats__thread,
.nda-chats__placeholder {
  --nda-thread-reserve: calc(
    var(--v2-bottom-nav-h) + var(--v2-bottom-nav-gap) +
    env(safe-area-inset-bottom, 0px) + 150px
  );
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nda-thread-reserve));
  min-height: 320px;
  background: var(--v2-surface);
  border: 1px solid var(--v2-border);
  border-radius: 22px;
  box-shadow: 0 18px 44px -34px var(--v2-shadow);
  overflow: hidden;
}

.nda-chats__thread-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  background: var(--v2-surface);
  border-bottom: 1px solid var(--v2-border);
}

.nda-chats__back {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--v2-surface2);
  border: 1px solid var(--v2-border);
  color: var(--v2-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 150ms ease;
}

.nda-chats__back:hover {
  background: var(--v2-accent-soft);
}

.nda-chats__back:focus-visible {
  outline: 2px solid var(--v2-accent);
  outline-offset: 2px;
}

.nda-chats__thread-avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--v2-surface2);
  border: 1px solid var(--v2-border);
  color: var(--v2-accent);
  font-family: var(--v2-font-title);
  font-size: 19px;
  line-height: 1;
  user-select: none;
}

.nda-chats__thread-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--v2-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Scrollable message area. */
.nda-chats__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 14px 8px;
  background: var(--v2-bg2);
}

.nda-chats__messages-state {
  margin: auto;
  font-size: 14px;
  color: var(--v2-soft);
}

.nda-chats__thread-empty {
  margin: auto;
  max-width: 280px;
  padding: 20px;
  text-align: center;
}

.nda-chats__thread-empty-text {
  margin: 0;
  font-size: 14px;
  color: var(--v2-soft);
  line-height: 1.5;
}

/* Day separator. */
.nda-chats__daysep {
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
}

.nda-chats__daysep-label {
  padding: 3px 12px;
  border-radius: var(--v2-radius-pill);
  background: var(--v2-surface2);
  border: 1px solid var(--v2-border);
  color: var(--v2-soft);
  font-size: 11.5px;
  font-weight: 600;
}

/* Bubble rows. */
.nda-chats__row {
  display: flex;
  justify-content: flex-start;
  padding: 1px 0;
}

.nda-chats__row--mine {
  justify-content: flex-end;
}

.nda-chats__bubble {
  position: relative;
  max-width: 78%;
  padding: 9px 13px 7px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.42;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.nda-chats__bubble--theirs {
  background: var(--v2-surface);
  border: 1px solid var(--v2-border);
  color: var(--v2-text);
  border-bottom-left-radius: 6px;
}

.nda-chats__bubble--mine {
  background: var(--v2-accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.nda-chats__bubble-text {
  display: block;
  white-space: pre-wrap;
}

.nda-chats__bubble-time {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  text-align: right;
  letter-spacing: 0.02em;
}

.nda-chats__bubble--theirs .nda-chats__bubble-time {
  color: var(--v2-soft);
}

.nda-chats__bubble--mine .nda-chats__bubble-time {
  color: rgba(255, 255, 255, 0.78);
}

/* ── Composer (sticky, above the floating nav) ──────────────────────────────*/

.nda-chats__send-error {
  margin: 0;
  padding: 6px 14px;
  font-size: 12.5px;
  color: var(--v2-accent-strong);
  background: var(--v2-accent-soft);
  text-align: center;
}

.nda-chats__composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  background: var(--v2-surface);
  border-top: 1px solid var(--v2-border);
}

.nda-chats__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 42px;
  padding: 0 16px;
  border-radius: var(--v2-radius-pill);
  background: var(--v2-surface2);
  border: 1px solid var(--v2-border);
  color: var(--v2-text);
  font-family: var(--v2-font-body);
  font-size: 14.5px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.nda-chats__input::placeholder {
  color: var(--v2-soft);
}

.nda-chats__input:focus {
  outline: none;
  border-color: var(--v2-accent);
  box-shadow: 0 0 0 3px var(--v2-accent-soft);
}

.nda-chats__send {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--v2-accent);
  border: none;
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 150ms ease, transform 120ms ease, opacity 150ms ease;
}

.nda-chats__send:hover:not(:disabled) {
  background: var(--v2-accent-strong);
}

.nda-chats__send:active:not(:disabled) {
  transform: scale(0.92);
}

.nda-chats__send:focus-visible {
  outline: 2px solid var(--v2-accent);
  outline-offset: 2px;
}

.nda-chats__send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Right-pane placeholder (desktop, no thread selected) ────────────────────*/

.nda-chats__placeholder {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  background: var(--v2-surface);
}

.nda-chats__placeholder-glyph {
  font-size: 40px;
  line-height: 1;
}

.nda-chats__placeholder-text {
  margin: 0;
  font-size: 14.5px;
  color: var(--v2-soft);
}

/* ── Wide screens: side-by-side master/detail ───────────────────────────────*/

@media (min-width: 860px) {
  .nda-chats {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 18px;
    align-items: start;
  }

  /* Both panes always visible; ignore the mobile open/closed flip. */
  .nda-chats__pane--inbox,
  .nda-chats--thread-open .nda-chats__pane--inbox {
    display: block;
  }

  .nda-chats__pane--thread,
  .nda-chats--thread-open .nda-chats__pane--thread {
    display: block;
    position: sticky;
    top: 84px;
  }

  /* The back chevron is mobile-only — both panes are visible here. */
  .nda-chats__back {
    display: none;
  }

  .nda-chats__thread,
  .nda-chats__placeholder {
    --nda-thread-reserve: calc(
      var(--v2-bottom-nav-h) + var(--v2-bottom-nav-gap) +
      env(safe-area-inset-bottom, 0px) + 130px
    );
  }
}
