/**
 * Customer chat — client UI
 */

body.chat-page {
  margin: 0;
  background: var(--page-bg, #f1f5f9);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1000px;
  margin: 0 auto;
  background: var(--page-bg, #f1f5f9);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, var(--brand, #2f6fed) 0%, var(--brand-dark, #1d4fc2) 100%);
  color: #ffffff;
  box-shadow: 0 4px 18px var(--brand-shadow-strong, rgba(29, 79, 194, 0.28));
  position: sticky;
  top: 0;
  z-index: 10;
}

.chat-header__back {
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-header__info {
  flex: 1;
  min-width: 0;
}

.chat-header__info h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.chat-header__info p {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  opacity: 0.88;
}

.chat-header__badge {
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #ef4444;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-guest-notice {
  padding: 0.7rem 1rem;
  background: #fff8e6;
  border-bottom: 1px solid #f2e2b8;
  color: #7a5c11;
  font-size: 0.82rem;
  line-height: 1.4;
  text-align: center;
}

.chat-guest-notice a {
  color: var(--brand, #2f6fed);
  font-weight: 600;
  text-decoration: none;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: #64748b;
  font-size: 0.9rem;
  padding: 2rem 1rem;
}

.chat-empty.is-hidden {
  display: none;
}

.chat-bubble-row {
  display: flex;
  width: 100%;
}

.chat-bubble-row.is-user {
  justify-content: flex-end;
}

.chat-bubble-row.is-team {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: min(82%, 20rem);
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  word-break: break-word;
}

.chat-bubble-row.is-user .chat-bubble {
  background: linear-gradient(135deg, var(--brand, #2f6fed) 0%, var(--brand-dark, #1d4fc2) 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chat-bubble-row.is-team .chat-bubble {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chat-bubble__sender {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand, #2f6fed);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-bubble__text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-bubble__image {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  cursor: pointer;
}

.chat-bubble__meta {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.68rem;
  opacity: 0.75;
}

.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem calc(0.85rem + env(safe-area-inset-bottom));
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  position: sticky;
  bottom: 0;
}

.chat-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
}

.chat-reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.chat-reply-preview[hidden] {
  display: none !important;
}

.chat-reply-preview__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.chat-reply-preview__label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--brand, #2f6fed);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-reply-preview__text {
  font-size: 0.8rem;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-reply-preview__cancel {
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-bubble__reply {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.45rem;
  padding: 0.45rem 0.55rem;
  border-left: 3px solid var(--brand, #2f6fed);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.06);
}

.chat-bubble-row.is-user .chat-bubble__reply {
  background: rgba(255, 255, 255, 0.14);
  border-left-color: rgba(255, 255, 255, 0.85);
}

.chat-bubble__reply-label {
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.85;
}

.chat-bubble__reply-text {
  font-size: 0.78rem;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-bubble__text--deleted {
  font-style: italic;
  opacity: 0.75;
}

.chat-bubble__actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.chat-bubble__action {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.85;
}

.chat-bubble-row.is-user .chat-bubble__action {
  color: #ffffff;
}

.chat-bubble-row.is-team .chat-bubble__action {
  color: var(--brand, #2f6fed);
}

.chat-bubble__action--danger {
  color: #fecaca !important;
}

.chat-bubble-row.is-team .chat-bubble__action--danger {
  color: #dc2626 !important;
}

.chat-composer__attach {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-composer__input {
  flex: 1;
  min-height: 2.5rem;
  max-height: 7rem;
  resize: none;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font: inherit;
  line-height: 1.4;
  background: #f8fafc;
}

.chat-composer__input:focus {
  outline: none;
  border-color: var(--brand, #2f6fed);
  box-shadow: 0 0 0 3px var(--brand-shadow-soft, rgba(47, 111, 237, 0.15));
}

.chat-composer__send {
  min-width: 4.2rem;
  height: 2.5rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand, #2f6fed) 0%, var(--brand-dark, #1d4fc2) 100%);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-composer__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100002;
  background: rgba(15, 23, 42, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.chat-image-lightbox.is-open {
  display: flex;
}

.chat-image-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}
