/* Chat: the Inquire pages (inquire.php, inquiry.php, admin/inquiry.php) and the conversation lists.
   Loads after refine.css, so it uses the same colour tokens and follows light and dark mode. */

/* ---------- The chat panel ---------- */
.chat {
  display: flex; flex-direction: column; overflow: hidden;
  height: clamp(26rem, calc(100vh - 8.5rem), 48rem);
  height: clamp(26rem, calc(100dvh - 8.5rem), 48rem);
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r-card);
}
.is-admin .chat { height: clamp(26rem, calc(100vh - 11rem), 46rem); height: clamp(26rem, calc(100dvh - 11rem), 46rem); }

/* Top bar: back arrow, avatar, name and state, then one action. */
.chat-head { flex: none; display: flex; align-items: center; gap: .7rem; padding: .65rem .85rem; border-bottom: 1px solid var(--edge); background: var(--surface); }
.chat-back { flex: none; display: grid; place-items: center; width: 2.5rem; height: 2.5rem; margin-left: -.25rem; border-radius: 50%; color: var(--violet); }
.chat-back:hover { background: var(--tint); }
.chat-back svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="dark"] .chat-back { color: var(--chip-ink); }
.chat-title { min-width: 0; flex: 1 1 auto; }
.chat-title h1 { margin: 0; font-family: inherit; font-size: 1rem; font-weight: 700; line-height: 1.25; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Conversation state is a text badge, not a dot. A coloured dot reads as "online", and it is not. */
.chat-state, .convo-state {
  display: inline-flex; align-items: center; max-width: 100%; margin-top: .15rem; padding: .1rem .55rem;
  border-radius: 6px; background: var(--tint); color: var(--link);
  font-size: .6875rem; font-weight: 700; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-state i, .convo-state i { display: none; }
.chat-state.is-open, .convo-state.is-open { background: var(--warn-bg); color: var(--warn-ink); }
.chat-state.is-answered, .convo-state.is-answered { background: var(--tint); color: var(--link); }
.chat-state.is-closed, .convo-state.is-closed { background: var(--tint-2); color: var(--ink-soft); }
.chat-link, .chat-info-btn {
  flex: none; padding: .45rem .8rem; border: 0; border-radius: 999px; background: var(--tint); color: var(--link);
  font-family: inherit; font-size: .8125rem; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer;
}
.chat-link:hover, .chat-info-btn:hover { background: var(--tint-2); }
.chat-info-btn { display: none; }

/* ---------- Avatars ---------- */
.chat-avatar { flex: none; display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; overflow: hidden; border-radius: 50%; background: var(--tint-2); color: var(--violet); font-weight: 700; font-size: 1rem; line-height: 1; }
.chat-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-avatar-staff { background: var(--violet); color: #fff; }
.chat-avatar-sm { width: 1.75rem; height: 1.75rem; font-size: .75rem; }
.chat-avatar-lg { width: 4rem; height: 4rem; font-size: 1.5rem; }
.chat-avatar-gap { flex: none; width: 1.75rem; }
:root[data-theme="dark"] .chat-avatar:not(.chat-avatar-staff) { color: var(--chip-ink); }

/* ---------- Messages ---------- */
.chat-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 1rem .9rem;
  display: flex; flex-direction: column; background: var(--bg); scrollbar-width: thin; scrollbar-color: var(--edge-strong) transparent;
}
.chat-intro { display: grid; justify-items: center; gap: .2rem; max-width: 22rem; margin: 0 auto; padding: .75rem .5rem 1.25rem; text-align: center; color: var(--ink-soft); font-size: .875rem; line-height: 1.4; }
.chat-intro strong { color: var(--ink); font-size: 1.0625rem; }
.chat-intro .chat-avatar { margin-bottom: .35rem; }
.chat-day { align-self: center; margin: .9rem 0 .3rem; }
.chat-day span { display: inline-block; padding: .2rem .7rem; border-radius: 999px; background: var(--tint); color: var(--ink-soft); font-size: .6875rem; font-weight: 600; }

.bubble-row { display: flex; align-items: flex-end; gap: .5rem; margin-top: .125rem; }
.bubble-row.grp-start { margin-top: .6rem; }
.bubble-row.is-mine { justify-content: flex-end; }
.bubble-col { display: flex; flex-direction: column; min-width: 0; max-width: min(34rem, 78%); }
.bubble-row.is-mine .bubble-col { align-items: flex-end; }
.bubble-who { margin: 0 0 .15rem .8rem; color: var(--ink-soft); font-size: .6875rem; font-weight: 600; }
.bubble { padding: .5rem .8rem .35rem; border: 1px solid var(--edge); border-radius: 18px; background: var(--surface); color: var(--ink); overflow-wrap: anywhere; }
.bubble p { margin: 0; font-size: .9375rem; line-height: 1.45; white-space: pre-wrap; }
.bubble time { display: block; margin-top: .15rem; text-align: right; color: var(--ink-soft); font-size: .6875rem; }
.bubble-row.is-mine .bubble { border-color: var(--violet); background: var(--violet); color: #fff; }
.bubble-row.is-mine .bubble time { color: rgba(255, 255, 255, .82); }
/* Messages from one person join up: the corner next to the neighbour is squared off. */
.bubble-row.is-other:not(.grp-start) .bubble { border-top-left-radius: 6px; }
.bubble-row.is-other:not(.grp-end) .bubble   { border-bottom-left-radius: 6px; }
.bubble-row.is-mine:not(.grp-start) .bubble  { border-top-right-radius: 6px; }
.bubble-row.is-mine:not(.grp-end) .bubble    { border-bottom-right-radius: 6px; }

/* ---------- Message box ---------- */
.composer { flex: none; padding: .6rem .75rem .5rem; border-top: 1px solid var(--edge); background: var(--surface); }
.composer-row { display: flex; align-items: flex-end; gap: .5rem; }
.composer textarea {
  flex: 1 1 auto; display: block; box-sizing: border-box; width: 100%; min-height: 2.75rem; max-height: 10rem; margin: 0; padding: .7rem 1rem;
  border: 1px solid var(--edge-strong); border-radius: 22px; background: var(--bg); color: var(--ink);
  font: inherit; font-size: 1rem; line-height: 1.35; resize: none; overflow-y: auto;
}
.composer textarea:focus { border-color: var(--violet); outline: 2px solid var(--violet); outline-offset: 1px; }
.composer textarea[aria-invalid="true"] { border-color: var(--danger); }
.send-btn {
  flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%;
  background: var(--violet); color: #fff; cursor: pointer; transition: background-color .15s;
}
.send-btn svg { width: 1.2rem; height: 1.2rem; margin: 0 .1rem .1rem 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.send-btn:hover:not(:disabled) { background: var(--violet-dark); }
.send-btn:disabled { background: var(--tint-2); color: var(--ink-soft); cursor: not-allowed; }
.composer-hint { display: flex; flex-wrap: wrap; gap: .1rem .9rem; margin: .4rem .6rem 0; color: var(--ink-soft); font-size: .75rem; line-height: 1.35; }
.only-keys { display: none; }
@media (hover: hover) and (pointer: fine) { .only-keys { display: inline; } }
@media (hover: none), (pointer: coarse) { .composer-hint.keys-only { display: none; } }
.composer-error { margin: 0 0 .5rem; padding: .45rem .8rem; border-radius: 10px; background: var(--bad-bg); color: var(--bad-ink); font-size: .8125rem; }

/* Suggested questions sit above the box in one row you can swipe. */
.quick-asks { display: flex; gap: .5rem; margin: 0 0 .55rem; padding: 0 0 .15rem; overflow-x: auto; scrollbar-width: none; }
.quick-asks::-webkit-scrollbar { display: none; }
.quick-asks .chip-btn {
  flex: none; min-height: 2.25rem; padding: .4rem .85rem; border: 1px solid var(--edge-strong); border-radius: 999px; background: var(--surface);
  color: var(--violet); font-family: inherit; font-size: .8125rem; font-weight: 500; line-height: 1.2; white-space: nowrap; cursor: pointer;
}
.quick-asks .chip-btn:hover { background: var(--tint); }
:root[data-theme="dark"] .quick-asks .chip-btn { color: var(--chip-ink); }

.chat-closed { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem .75rem; padding: .75rem 1rem; border-top: 1px solid var(--edge); background: var(--tint); font-size: .875rem; }
.chat-closed p { margin: 0; color: var(--ink-soft); }

/* ---------- Admin: chat with a contact panel beside it ---------- */
.chat-layout { display: grid; gap: 1rem; align-items: start; }
.chat-info { display: grid; gap: 1rem; padding: 1rem; }
.chat-info[hidden] { display: none; }
.info-person { display: flex; align-items: center; gap: .75rem; }
.info-person strong { display: block; overflow-wrap: anywhere; }
.info-person div span { display: block; color: var(--ink-soft); font-size: .8125rem; }
.info-list { display: grid; gap: .75rem; margin: 0; }
.info-list > div { display: grid; gap: .2rem; }
.info-list dt { color: var(--ink-soft); font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.info-list dd { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: 0; }
.info-val { min-width: 0; font-size: .9375rem; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
.copy-chip {
  flex: none; min-width: 3.75rem; min-height: 2rem; padding: .3rem .75rem; border: 1px solid var(--edge); border-radius: 999px;
  background: var(--tint); color: var(--violet); font-family: inherit; font-size: .75rem; font-weight: 600; line-height: 1.2; cursor: pointer;
}
.copy-chip:hover { background: var(--tint-2); }
:root[data-theme="dark"] .copy-chip { color: var(--chip-ink); }
.info-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.chat-info .inq-state { display: flex; }
.chat-info .inq-state .btn { width: 100%; }

@media (min-width: 56rem) {
  .chat-layout { grid-template-columns: minmax(0, 1fr) 19rem; }
  .chat-info { position: sticky; top: 5rem; }
}
@media (max-width: 55.99rem) {
  .chat-layout .chat-info { order: -1; }
  html.js .chat-info-btn { display: inline-flex; }
}

/* ---------- Conversation lists (My Inquiries, admin Inquiries) ---------- */
.convo-list { list-style: none; margin: 0 0 1rem; padding: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r-card); }
.convo-list li + li { border-top: 1px solid var(--edge); }
.convo { display: flex; align-items: flex-start; gap: .8rem; padding: .85rem 1rem; color: inherit; text-decoration: none; }
.convo:hover { background: var(--tint); }
.convo .chat-avatar { width: 3rem; height: 3rem; }
.convo-main { display: grid; flex: 1 1 auto; gap: .12rem; min-width: 0; }
.convo-top { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.convo-name { min-width: 0; overflow: hidden; color: var(--ink); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.convo-top time { flex: none; color: var(--ink-soft); font-size: .75rem; }
.convo-snippet { overflow: hidden; color: var(--ink-soft); font-size: .875rem; text-overflow: ellipsis; white-space: nowrap; }
.convo-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .75rem; color: var(--ink-soft); font-size: .75rem; }
.convo-topic { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo.is-unread { box-shadow: inset 3px 0 0 var(--violet); }
.convo.is-unread .convo-name { font-weight: 700; }
.convo.is-unread .convo-snippet { color: var(--ink); font-weight: 600; }
.convo.is-closed { opacity: .78; }

/* ---------- Phones ---------- */
@media (max-width: 39.99rem) {
  .chat { height: clamp(24rem, calc(100vh - 7rem), 48rem); height: clamp(24rem, calc(100dvh - 7rem), 48rem); }
  .is-admin .chat { height: clamp(24rem, calc(100vh - 9rem), 46rem); height: clamp(24rem, calc(100dvh - 9rem), 46rem); }
  .chat-body { padding: .8rem .65rem; }
  .bubble-col { max-width: 84%; }
  .convo { padding: .8rem .85rem; }
}
