/* ==========================================================================
   Seven Bites — Support chat
   Matches showcase screen "11. Support Chat". Desktop: conversation list on
   the left, chat window on the right (fixed height, messages scroll).
   Phones: conversations as chips above a full-height chat.
   ========================================================================== */

.ch-page {
  padding-block: var(--sp-6) var(--sp-10);
}

.ch {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--sp-5);
  height: min(720px, calc(100vh - var(--header-h) - var(--sp-12)));
  min-height: 520px;
}

/* ---------- Conversations ---------- */

.ch-threads {
  display: flex;
  flex-direction: column;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--sh-card);
  overflow-y: auto;
}

.ch-threads__title {
  margin: 0 var(--sp-2) var(--sp-3);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

.ch-threads__list {
  display: grid;
  gap: var(--sp-2);
}

.ch-thread {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  text-align: left;
  transition: background-color var(--t-base) var(--ease-out), border-color var(--t-base) var(--ease-out);
}

.ch-thread:hover {
  background: var(--c-tile);
}

.ch-thread.is-active {
  background: var(--c-yellow-soft);
  border-color: rgba(252, 210, 6, 0.6);
}

.ch-thread__icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--c-navy);
  color: var(--c-yellow);
}

.ch-thread__icon .icon {
  width: 19px;
  height: 19px;
}

.ch-thread__text {
  display: grid;
  flex: 1;
  min-width: 0;
}

.ch-thread__text strong {
  font-size: var(--fs-sm);
}

.ch-thread__text small {
  color: var(--c-muted);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-thread time {
  align-self: flex-start;
  color: var(--c-muted);
  font-size: 0.625rem;
}

/* ---------- Chat window ---------- */

.ch-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-radius: var(--r-lg);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--sh-card);
  overflow: hidden;
}

.ch-chat__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}

.ch-avatar {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c-navy);
  border: 2px solid var(--c-yellow);
}

.ch-avatar img {
  width: 46%;
  height: auto;
}

.ch-avatar--sm {
  width: 32px;
  height: 32px;
  border-width: 1.5px;
}

.ch-chat__who {
  display: grid;
  flex: 1;
  min-width: 0;
}

.ch-chat__who h2 {
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
}

.ch-chat__who small {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--c-muted);
  font-size: var(--fs-xs);
}

.ch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-green);
  box-shadow: 0 0 0 3px var(--c-green-soft);
}

.ch-head__btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c-tile);
  color: var(--c-navy);
  transition: background-color var(--t-base) var(--ease-out);
}

.ch-head__btn:hover {
  background: var(--c-yellow);
}

.ch-head__btn .icon {
  width: 19px;
  height: 19px;
}

/* messages */
.ch-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin: 0;
  padding: var(--sp-5) var(--sp-4);
  overflow-y: auto;
  list-style: none;
  background:
    radial-gradient(circle at 10% 0%, rgba(252, 210, 6, 0.06), transparent 40%),
    var(--c-surface-2);
  overscroll-behavior: contain;
}

.ch-day {
  align-self: center;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--c-tile);
  color: var(--c-muted);
  font-size: 0.6875rem;
  font-weight: var(--fw-semibold);
}

.ch-msg {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  max-width: 82%;
  animation: ch-in 0.3s var(--ease-out);
}

@keyframes ch-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.ch-msg--me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ch-msg__body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.ch-msg--me .ch-msg__body {
  justify-items: end;
}

.ch-bubble {
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.ch-msg--me .ch-bubble {
  border-radius: 16px 16px 4px 16px;
  border-color: var(--c-yellow);
  background: var(--c-yellow);
  color: var(--c-navy);
}

.ch-msg__time {
  color: var(--c-muted);
  font-size: 0.625rem;
}

.ch-product {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  padding-right: var(--sp-4);
  border-radius: var(--r-md);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  font-size: var(--fs-sm);
}

.ch-product .media {
  width: 52px;
  height: 52px;
  border-radius: var(--r-sm);
}

.ch-product span {
  display: grid;
}

.ch-product small {
  color: var(--c-text-2);
  font-weight: var(--fw-semibold);
}

.ch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.ch-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--c-navy);
  color: var(--c-on-dark);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  transition: transform var(--t-base) var(--ease-out);
}

.ch-action:hover {
  transform: translateY(-1px);
}

.ch-action .icon {
  width: 15px;
  height: 15px;
  color: var(--c-yellow);
}

/* typing dots */
.ch-typing .ch-bubble {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}

.ch-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-muted);
  animation: ch-dot 1s ease-in-out infinite;
}

.ch-typing i:nth-child(2) { animation-delay: 0.15s; }
.ch-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes ch-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* quick replies */
.ch-quick {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.ch-quick::-webkit-scrollbar {
  display: none;
}

.ch-chip {
  flex-shrink: 0;
  min-height: 34px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  border: 1.5px solid var(--c-border-strong);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition: border-color var(--t-base) var(--ease-out), background-color var(--t-base) var(--ease-out);
}

.ch-chip:hover {
  border-color: var(--c-yellow);
  background: var(--c-yellow-tint);
}

/* message box */
.ch-send {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  margin: var(--sp-3) var(--sp-4) var(--sp-4);
  padding: 6px 6px 6px var(--sp-4);
  border-radius: 24px;
  background: var(--c-surface-2);
  border: 1.5px solid var(--c-border);
  transition: border-color var(--t-base) var(--ease-out);
}

.ch-send:focus-within {
  border-color: var(--c-yellow);
}

.ch-send textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 9px 0;
  border: 0;
  background: transparent;
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-base);
  line-height: 1.4;
  resize: none;
  outline: none;
}

.ch-send button {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--c-navy);
  color: var(--c-yellow);
  transition: transform var(--t-base) var(--ease-out);
}

.ch-send button:hover {
  transform: scale(1.06);
}

.ch-send .icon {
  width: 19px;
  height: 19px;
}

/* ---------- Phones ---------- */

@media (max-width: 767.98px) {
  .ch-page {
    padding-block: var(--sp-3) 0;
  }
  .ch {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    height: calc(100dvh - 67px - var(--tabbar-h) - var(--sp-3) - env(safe-area-inset-bottom, 0px));
    min-height: 420px;
  }
  .ch-threads {
    flex-shrink: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    overflow: visible;
  }
  .ch-threads__title {
    display: none;
  }
  .ch-threads__list {
    display: flex;
    gap: var(--sp-2);
    overflow-x: auto;
    margin: 0 calc(var(--gutter) * -1);
    padding: 0 var(--gutter) 2px;
    scrollbar-width: none;
  }
  .ch-threads__list::-webkit-scrollbar {
    display: none;
  }
  .ch-thread {
    flex-shrink: 0;
    width: auto;
    gap: 6px;
    padding: 6px 14px 6px 6px;
    border-radius: var(--r-pill);
    background: var(--c-surface);
    border-color: var(--c-border);
  }
  .ch-thread.is-active {
    background: var(--c-yellow);
    border-color: var(--c-yellow);
  }
  .ch-thread__icon {
    width: 28px;
    height: 28px;
  }
  .ch-thread__icon .icon {
    width: 14px;
    height: 14px;
  }
  .ch-thread__text small,
  .ch-thread time {
    display: none;
  }
  .ch-chat {
    flex: 1;
    margin: 0 calc(var(--gutter) * -1);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0;
  }
  .ch-msg {
    max-width: 90%;
  }
  .site-footer {
    display: none;
  }
}

/* a reply from a real person on the team (staff inbox) */
.ch-msg__who {
  color: var(--c-text-2);
  font-size: 0.6875rem;
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
}

.ch-msg--staff .ch-bubble {
  border-color: var(--c-navy);
  background: var(--c-navy);
  color: var(--c-on-dark);
}
