/* ==========================================================================
   Zyra chat — professional messaging UI (Phase 2.3 messaging redesign).
   Shared by the portal, vendor and admin messages pages. Loaded from
   templates/footer.php (storefront shell) and templates/admin_header.php
   (admin shell) so header.php / nav.php stay untouched.

   Colours are chat-local --zc-* values defined explicitly for both modes
   (dark scoped under [data-bs-theme="dark"]), following the footer lesson:
   a background never references a text token. Verified contrasts:
   own bubble white/#346d7a 5.81:1 · other light 16.26:1 · other dark
   9.86:1 · meta 4.59:1 / 6.60:1 · avatar initials 5.18:1 / 8.06:1 ·
   day separator 5.34:1 / 7.00:1 · "Seen" 5.51:1 / 8.51:1.
   ========================================================================== */

.zc-shell,
.zc-card {
  --zc-own-bg: #346d7a;
  --zc-own-text: #ffffff;
  --zc-other-bg: #f5f5f4;
  --zc-other-text: #111827;
  --zc-other-border: #e5e7eb;
  --zc-thread-bg: #f9f9f8;
  --zc-meta: #6b7280;
  --zc-seen: #346d7a;
  --zc-avatar-bg: #edf3f4;
  --zc-avatar-text: #346d7a;
  --zc-active-bg: #edf3f4;
  --zc-unread-bg: #e5484d;
  --zc-sep-bg: #f5f5f4;
  --zc-sep-text: #5b6675;
  --zc-time-unread: #346d7a;
  --zc-send-disabled-bg: #f5f5f4;
  --zc-send-disabled-text: #6b7280;
}

[data-bs-theme="dark"] .zc-shell,
[data-bs-theme="dark"] .zc-card {
  --zc-other-bg: #374151;
  --zc-other-text: #f9fafb;
  --zc-other-border: #4b5563;
  --zc-thread-bg: #161e2a;
  --zc-meta: #9ca3af;
  --zc-seen: #8fc1cc;
  --zc-avatar-bg: #172332;
  --zc-avatar-text: #8fc1cc;
  --zc-active-bg: #172332;
  --zc-sep-bg: #374151;
  --zc-sep-text: #d1d5db;
  --zc-time-unread: #8fc1cc;
  --zc-send-disabled-bg: #374151;
  --zc-send-disabled-text: #9ca3af;
}

/* --- Shell: two panes on desktop, one pane at a time on phones ---------- */

.zc-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  background: var(--zyra-paper);
  border: 1px solid var(--zyra-border);
  border-radius: 16px;
  overflow: hidden;
  height: min(740px, max(460px, calc(100dvh - 232px)));
}

.zc-card {
  display: flex;
  flex-direction: column;
  background: var(--zyra-paper);
  border: 1px solid var(--zyra-border);
  border-radius: 16px;
  overflow: hidden;
  height: min(740px, max(460px, calc(100dvh - 264px)));
}

@media (max-width: 991.98px) {
  .zc-shell {
    grid-template-columns: minmax(0, 1fr);
    height: max(420px, calc(100dvh - 208px));
  }
  .zc-card {
    height: max(420px, calc(100dvh - 248px));
  }
  /* One pane at a time: an open thread replaces the list. */
  .zc-shell.has-thread .zc-list-pane { display: none; }
  .zc-shell:not(.has-thread) .zc-thread-pane { display: none; }
}

/* --- Conversation list --------------------------------------------------- */

.zc-list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--zyra-border);
  background: var(--zyra-paper);
}

.zc-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
}

.zc-list-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--zyra-ink);
}

.zc-total-unread {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--zc-unread-bg);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

.zc-search {
  position: relative;
  padding: 0 16px 12px;
}

.zc-search-icon {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-62%);
  color: var(--zyra-muted);
  pointer-events: none;
  display: inline-flex;
}

.zc-search-input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 40px;
  border: 1px solid var(--zyra-border);
  border-radius: 999px;
  background: var(--zyra-surface);
  color: var(--zyra-ink);
  font-size: 14px;
  outline: none;
}

.zc-search-input:focus {
  border-color: var(--zyra-brand);
  box-shadow: 0 0 0 2px var(--zyra-brand-subtle);
  background: var(--zyra-paper);
}

.zc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.zc-conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--zyra-ink);
  min-height: 64px;
}

.zc-conv:hover {
  background: var(--zyra-surface);
  text-decoration: none;
  color: var(--zyra-ink);
}

.zc-conv.is-active {
  background: var(--zc-active-bg);
  box-shadow: inset 3px 0 0 var(--zyra-brand);
}

.zc-conv:focus-visible {
  outline: 2px solid var(--zyra-brand);
  outline-offset: 1px;
}

.zc-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--zc-avatar-bg);
  color: var(--zc-avatar-text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
  flex-shrink: 0;
  user-select: none;
}

.zc-avatar--sm {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.zc-conv-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.zc-conv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.zc-conv-name {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zc-conv-name .zc-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.zc-conv-time {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--zyra-muted);
}

.zc-conv.is-unread .zc-conv-time {
  color: var(--zc-time-unread);
  font-weight: 600;
}

.zc-conv-preview {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--zyra-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zc-conv.is-unread .zc-conv-preview {
  color: var(--zyra-ink);
  font-weight: 600;
}

.zc-unread {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--zc-unread-bg);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.zc-role-pill {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--zyra-brand-subtle);
  color: var(--zc-avatar-text);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

.zc-list-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--zyra-muted);
  font-size: 14px;
}

/* --- Thread pane --------------------------------------------------------- */

.zc-thread-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.zc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--zyra-border);
  background: var(--zyra-paper);
}

.zc-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border-radius: 50%;
  color: var(--zyra-ink);
  flex-shrink: 0;
  text-decoration: none;
}

.zc-back:hover {
  background: var(--zyra-surface);
  color: var(--zyra-ink);
}

@media (max-width: 991.98px) {
  .zc-back { display: inline-flex; }
}

.zc-head-id {
  flex: 1;
  min-width: 0;
}

.zc-head-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--zyra-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zc-head-sub {
  font-size: 13px;
  line-height: 1.35;
  color: var(--zyra-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zc-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--zc-thread-bg);
  padding: 8px 16px 16px;
  overscroll-behavior: contain;
}

.zc-day {
  display: flex;
  justify-content: center;
  margin: 16px 0 8px;
}

.zc-day span {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--zc-sep-bg);
  color: var(--zc-sep-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.zc-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
}

.zc-group.is-me { align-items: flex-end; }
.zc-group.is-other { align-items: flex-start; }

.zc-bubble {
  max-width: min(78%, 560px);
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.zc-group.is-me .zc-bubble {
  background: var(--zc-own-bg);
  color: var(--zc-own-text);
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.zc-group.is-me .zc-bubble--first { border-top-right-radius: 18px; }

.zc-group.is-other .zc-bubble {
  background: var(--zc-other-bg);
  color: var(--zc-other-text);
  border: 1px solid var(--zc-other-border);
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.zc-group.is-other .zc-bubble--first { border-top-left-radius: 18px; }

.zc-meta {
  margin-top: 3px;
  padding: 0 4px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--zc-meta);
}

.zc-receipt {
  color: var(--zc-seen);
  font-weight: 600;
}

.zc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  min-height: 100%;
}

.zc-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--zyra-surface);
  color: var(--zyra-muted);
  margin-bottom: 14px;
}

.zc-empty-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--zyra-ink);
}

.zc-empty-text {
  margin: 0;
  max-width: 340px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--zyra-muted);
}

.zc-error {
  padding: 28px 16px;
  text-align: center;
  color: var(--zyra-danger);
  font-size: 14px;
}

.zc-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  background: var(--zc-thread-bg);
}

/* --- Composer ------------------------------------------------------------ */

.zc-composer {
  border-top: 1px solid var(--zyra-border);
  background: var(--zyra-paper);
  padding: 12px;
}

.zc-composer form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
}

.zc-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 132px;
  padding: 11px 16px;
  border: 1px solid var(--zyra-border);
  border-radius: 22px;
  background: var(--zyra-surface);
  color: var(--zyra-ink);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  overflow-y: auto;
}

.zc-input:focus {
  border-color: var(--zyra-brand);
  box-shadow: 0 0 0 2px var(--zyra-brand-subtle);
  background: var(--zyra-paper);
}

.zc-input::placeholder { color: var(--zyra-muted); }

.zc-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--zc-own-bg);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color .15s ease, opacity .15s ease;
}

.zc-send:hover:not(:disabled) { background: var(--zyra-brand); }

.zc-send:disabled {
  background: var(--zc-send-disabled-bg);
  color: var(--zc-send-disabled-text);
  cursor: default;
}

.zc-send:focus-visible {
  outline: 2px solid var(--zyra-brand);
  outline-offset: 2px;
}

.zc-send .spinner-border {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .zc-send { transition: none; }
}
