/* =============================================================================
   MyApollo v3 — Chat UI (master/detail), PLOT visual language in v3 tokens.
   Drop-in: used by /account #messages and (later) /plot/#chats.
   Depends on v3-tokens.css + v3-components.css.
   ============================================================================= */

/* ── Master/detail shell ────────────────────────────────────────────────── */
.v3-chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  height: clamp(540px, calc(100dvh - 220px), 820px);
  background:
    linear-gradient(180deg, rgba(245,240,230,0.03) 0%, rgba(245,240,230,0.01) 100%),
    var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
}
.v3-chat > * { min-width: 0; }

@media (min-width: 900px) {
  .v3-chat {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  }
}

/* ── Left pane: conversation list ──────────────────────────────────────── */
.v3-chat__list {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  min-height: 0;
}
.v3-chat__list-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.v3-chat__list-head h2 {
  font: var(--font-display-md);
  display: flex; align-items: center; gap: 8px;
}
.v3-chat__list-head .v3-mono {
  margin-left: auto;
  font-size: 0.6875rem;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Search box (optional — search the list) */
.v3-chat__search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  margin: 10px 12px 6px;
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--line-2);
  color: var(--ink);
}
.v3-chat__search i { color: var(--ink-faint); font-size: 0.85rem; }
.v3-chat__search input {
  flex: 1; min-width: 0;
  background: transparent;
  border: 0; outline: 0;
  color: var(--ink);
  font: var(--font-body-sm);
}
.v3-chat__search input::placeholder { color: var(--ink-faint); }

.v3-chat__list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 12px;
  scrollbar-width: thin;
}
.v3-chat__list-scroll::-webkit-scrollbar { width: 6px; }
.v3-chat__list-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

/* Empty state */
.v3-chat__empty {
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  color: var(--ink-dim);
}
.v3-chat__empty i {
  font-size: 2.2rem;
  color: var(--gold-soft);
  margin-bottom: var(--sp-3);
  display: inline-block;
}
.v3-chat__empty p { font: var(--font-body-sm); max-width: 28ch; margin: 0 auto; }

/* Single conversation card */
.v3-chat__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    background var(--t-base) var(--ease),
    border-color var(--t-base) var(--ease);
  border: 1px solid transparent;
}
.v3-chat__item:hover {
  background: var(--glass-bg);
  border-color: var(--line);
}
.v3-chat__item[aria-selected="true"] {
  background: var(--gold-soft);
  border-color: rgba(201, 168, 76, 0.28);
}
.v3-chat__thumb {
  width: 44px; height: 44px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,0.16), transparent 55%),
    linear-gradient(135deg, var(--gold) 0%, var(--rose) 100%);
  flex-shrink: 0;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #1a1814;
  font: 700 0.95rem/1 var(--font-body);
  letter-spacing: 0.02em;
}
.v3-chat__thumb i { font-size: 1rem; }
.v3-chat__thumb--booking {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
}
.v3-chat__thumb--support {
  background: linear-gradient(135deg, var(--rose) 0%, var(--gold) 100%);
}
.v3-chat__thumb--plot {
  background: linear-gradient(135deg, #ff3ea5 0%, #2ee5ff 100%);
}
.v3-chat__thumb-dot {
  position: absolute;
  top: -2px; right: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #4ec27b;
  border: 2px solid var(--surface-2);
  box-shadow: 0 0 6px rgba(78, 194, 123, 0.6);
}

.v3-chat__item-body {
  flex: 1; min-width: 0;
}
.v3-chat__item-top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 2px;
}
.v3-chat__item-name {
  font: 600 0.9375rem/1.2 var(--font-body);
  color: var(--cream);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: -0.01em;
}
.v3-chat__item-time {
  font: 500 0.6875rem/1 var(--font-body);
  color: var(--ink-faint);
  flex-shrink: 0;
}
.v3-chat__item-preview {
  display: flex; align-items: center; gap: 6px;
  font: var(--font-body-sm);
  color: var(--ink-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.v3-chat__item-preview .who {
  color: var(--ink-faint); font-weight: 600;
}
.v3-chat__item-unread {
  margin-left: auto;
  flex-shrink: 0;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  color: #1a1814;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 0.6875rem/1 var(--font-body);
}

/* ── Right pane: thread view ────────────────────────────────────────────── */
.v3-chat__thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(201,168,76,0.05) 0%, transparent 60%),
    var(--bg);
}

/* Mobile: master/detail behaves like push navigation.
   Add data-view="thread" to the .v3-chat root to slide to the thread pane. */
@media (max-width: 899px) {
  .v3-chat .v3-chat__list,
  .v3-chat .v3-chat__thread {
    grid-column: 1;
    grid-row: 1;
  }
  .v3-chat[data-view="thread"] .v3-chat__list { display: none; }
  .v3-chat[data-view="list"]   .v3-chat__thread { display: none; }
}

/* Empty thread state — shown when nothing is selected (desktop) */
.v3-chat__thread-empty {
  margin: auto;
  padding: var(--sp-6);
  text-align: center;
  color: var(--ink-dim);
}
.v3-chat__thread-empty i {
  font-size: 3rem;
  color: var(--gold-soft);
  margin-bottom: var(--sp-3);
  display: inline-block;
}
.v3-chat__thread-empty h3 {
  font: var(--font-display-md);
  color: var(--cream);
  margin-bottom: var(--sp-2);
}
.v3-chat__thread-empty p { font: var(--font-body-sm); max-width: 32ch; margin: 0 auto; }

/* Thread head — sticky avatar + name */
.v3-thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface-2) 92%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  position: sticky; top: 0; z-index: 2;
  flex-shrink: 0;
}
.v3-thread-back {
  display: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--glass-bg);
  border: 1px solid var(--line-2);
  color: var(--ink);
  align-items: center; justify-content: center;
  cursor: pointer;
}
@media (max-width: 899px) {
  .v3-thread-back { display: inline-flex; }
}
.v3-thread-head__info {
  flex: 1; min-width: 0;
}
.v3-thread-head__name {
  font: 700 1rem/1.1 var(--font-display);
  letter-spacing: -0.005em;
  color: var(--cream);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.v3-thread-head__meta {
  font: var(--font-body-sm);
  color: var(--ink-dim);
  margin-top: 2px;
  display: flex; align-items: center; gap: 6px;
}
.v3-thread-head__meta .live-dot {
  display: inline-flex; align-items: center; gap: 4px;
  color: #4ec27b;
  font-weight: 600;
}
.v3-thread-head__meta .live-dot::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: #4ec27b;
  animation: v3-thread-dot 1.5s ease-in-out infinite;
}
@keyframes v3-thread-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .v3-thread-head__meta .live-dot::before { animation: none; }
}

/* Pinned banner — booking-context card */
.v3-thread-banner {
  margin: 14px 16px 0;
  padding: 14px;
  border-radius: var(--r-md);
  background:
    radial-gradient(ellipse at 100% 0%, rgba(201,168,76,0.18), transparent 60%),
    linear-gradient(135deg, rgba(201,168,76,0.10), rgba(184,92,92,0.06)),
    var(--surface-2);
  border: 1px solid rgba(201,168,76,0.32);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  backdrop-filter: blur(10px);
}
.v3-thread-banner__meta {
  font: var(--font-body-sm);
  color: var(--ink-dim);
  line-height: 1.4;
  min-width: 0;
}
.v3-thread-banner__meta strong { color: var(--cream); display: block; margin-bottom: 2px; }
.v3-thread-banner__meta .v3-mono { color: var(--gold-light); }
.v3-thread-banner__cta {
  background: var(--ink);
  color: #1a1814;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  font: 700 0.6875rem/1 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  border: 0;
}

/* Message scroll */
.v3-thread-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.v3-thread-scroll::-webkit-scrollbar { width: 6px; }
.v3-thread-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.v3-thread-day {
  align-self: center;
  font: 700 0.6875rem/1 var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 6px 12px;
  background: var(--glass-bg);
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
}

/* Single message */
.v3-thread-msg {
  display: flex; align-items: flex-start;
  gap: 10px;
  max-width: 82%;
  animation: v3-msg-pop 280ms var(--spring) both;
}
.v3-thread-msg--me {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 78%;
}
@keyframes v3-msg-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .v3-thread-msg { animation: none; }
}

.v3-thread-msg__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, var(--rose) 100%);
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 0.75rem/1 var(--font-body);
  color: #1a1814;
  flex-shrink: 0;
  margin-top: 2px;
}
.v3-thread-msg--me .v3-thread-msg__avatar {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 100%);
}

.v3-thread-msg__body { min-width: 0; }
.v3-thread-msg__meta {
  font: 500 0.625rem/1 var(--font-body);
  color: var(--ink-faint);
  margin-bottom: 4px;
  display: flex; gap: 6px; align-items: baseline;
  letter-spacing: 0.04em;
}
.v3-thread-msg__meta .name { color: var(--ink-dim); font-weight: 600; }
.v3-thread-msg--me .v3-thread-msg__meta { justify-content: flex-end; }
.v3-thread-msg__meta .read { color: var(--gold); font-weight: 600; }

.v3-thread-msg__bubble {
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  font: var(--font-body-md);
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  color: var(--ink);
  border-top-left-radius: 6px;
}
.v3-thread-msg--me .v3-thread-msg__bubble {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  color: #1a1814;
  border-color: transparent;
  border-top-right-radius: 6px;
  border-top-left-radius: 18px;
  box-shadow: 0 6px 18px rgba(201,168,76,0.22);
}

/* System / host announcement message */
.v3-thread-system {
  align-self: center;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--line);
  font: var(--font-body-sm);
  color: var(--ink-faint);
  display: flex; align-items: center; gap: 6px;
}
.v3-thread-system i { font-size: 0.75rem; color: var(--gold); }

/* Typing indicator */
.v3-thread-typing {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 18px;
  border-top-left-radius: 6px;
  width: fit-content;
}
.v3-thread-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: v3-typing 1s ease-in-out infinite;
}
.v3-thread-typing span:nth-child(2) { animation-delay: 150ms; }
.v3-thread-typing span:nth-child(3) { animation-delay: 300ms; }
@keyframes v3-typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30%           { opacity: 1;   transform: scale(1.05); }
}

/* Input bar */
.v3-thread-input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface-2) 92%, transparent);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}
.v3-thread-input-wrap {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 6px 6px 16px;
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--line-2);
  transition: border-color var(--t-base) var(--ease);
}
.v3-thread-input-wrap:focus-within {
  border-color: var(--gold);
}
.v3-thread-input-wrap textarea {
  flex: 1; min-width: 0;
  background: transparent;
  border: 0; outline: 0;
  resize: none;
  font: var(--font-body-md);
  color: var(--ink);
  line-height: 1.4;
  padding: 8px 0;
  max-height: 100px;
}
.v3-thread-input-wrap textarea::placeholder { color: var(--ink-faint); }
.v3-thread-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--grad-warm);
  color: #1a1814;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), opacity var(--t-base) var(--ease);
  flex-shrink: 0;
}
.v3-thread-send:hover { transform: scale(1.06); }
.v3-thread-send:active { transform: scale(0.95); }
.v3-thread-send[disabled] {
  opacity: 0.4; cursor: not-allowed; transform: none;
}

/* Quick-action chips (above input) */
.v3-thread-quick {
  display: flex; flex-wrap: nowrap; gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-top: 1px solid var(--line);
}
.v3-thread-quick::-webkit-scrollbar { display: none; }
.v3-thread-quick button {
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--line-2);
  color: var(--ink-dim);
  font: 500 0.75rem/1 var(--font-body);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--t-base) var(--ease), color var(--t-base) var(--ease);
}
.v3-thread-quick button:hover {
  border-color: var(--gold);
  color: var(--ink);
}

/* Loading skeleton for thread */
.v3-thread-skel {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px;
}
.v3-thread-skel .skel-bubble {
  height: 38px;
  border-radius: 18px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: v3-skel-shimmer 1.4s linear infinite;
}
.v3-thread-skel .skel-bubble:nth-child(2) { width: 60%; align-self: flex-end; }
.v3-thread-skel .skel-bubble:nth-child(3) { width: 80%; }
.v3-thread-skel .skel-bubble:nth-child(4) { width: 45%; align-self: flex-end; }
@keyframes v3-skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
