/* ============================================================
   MIRA HOME — Chat Styles
   Customer Widget + Admin Chat Rooms
   ============================================================ */


/* ------------------------------------------------------------
   1. CUSTOMER CHAT — FLOATING OPEN BUTTON
   ------------------------------------------------------------ */
.chat-open-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  background: var(--color-charcoal);
  color: #fff !important;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(44, 36, 24, 0.20);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  font-family: var(--font-body);
}


.chat-open-btn i {
  font-size: 1.1rem;
}

.chat-open-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(44, 36, 24, 0.30);
}

.chat-open-btn:active {
  transform: scale(0.96);
}

/* Unread badge on open button — FIX (bug report: "the number thing, I
   can't even see it properly") — this was originally a plain dot with no
   room for text; the number now actually gets a sized, centered pill. */
.chat-open-btn .chat-unread-dot {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background-color: var(--color-danger);
  border: 2px solid #fff;
  border-radius: 999px;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.chat-open-btn .chat-unread-dot.visible {
  display: flex;
}


/* ------------------------------------------------------------
   2. CUSTOMER CHAT — WIDGET
   ------------------------------------------------------------ */
.customer-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 340px;
  background-color: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(44, 36, 24, 0.12);
  z-index: 1040;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatWidgetIn 0.25s ease forwards;
  max-height: 520px;
}

.customer-chat-widget.open {
  display: flex;
}

@keyframes chatWidgetIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Widget Header ── */
.chat-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: #fff;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.chat-widget-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-widget-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.chat-widget-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--color-primary-xlight);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--color-primary-dark);
  flex-shrink: 0;
}

.chat-widget-header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-widget-title {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--color-charcoal);
  line-height: 1.2;
}

.chat-widget-status {
  font-family: var(--font-body);
  font-size: 0.65rem;
  color: var(--color-brown-light);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.chat-widget-status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: #a8a29e; /* grey = connecting / active a while ago; green only for "Active now" */
  flex-shrink: 0;
}
.chat-widget-status[data-state="online"]::before { background-color: #6fcf97; }
/* Nobody who answers the chat was ever active: no text, so no dot either (never "Last seen" or "Offline"). */
.chat-widget-status[data-state="none"] { display: none; }

/* FIX (bug report: mute/close buttons "not aligned" and "don't look
   pressable") — both are now one shared rule so they're pixel-identical in
   size/line-height (the old close button used a raw "&times;" glyph at a
   different font-size than the mute button's icon-font glyph, which is why
   they never quite lined up), plus a visible resting background/circular
   shape/pressed state so they read as real buttons even before hovering. */
.chat-widget-close,
.chat-widget-mute {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--bg-section-alt);
  border: none;
  color: var(--color-brown-light);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  outline: none;
}
.chat-widget-close:hover,
.chat-widget-mute:hover {
  color: var(--color-charcoal);
  background: var(--border-light);
}
.chat-widget-close:active,
.chat-widget-mute:active {
  transform: scale(0.9);
}
.chat-widget-mute.is-muted { color: var(--color-primary-dark); }

/* ── Chat Messages Box ── */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background-color: var(--bg-page);
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
  min-height: 200px;
  max-height: 340px;
}

.chat-box::-webkit-scrollbar       { width: 4px; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-full); }

/* Empty state */
.chat-box-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--color-brown-light);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  flex: 1;
}

.chat-box-empty i {
  font-size: 1.8rem;
  color: var(--color-stone);
  opacity: 0.5;
}

/* ── Message Bubbles ── */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.chat-message--customer {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message--admin {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  word-break: break-word;
}

.chat-message--customer .chat-bubble {
  background: var(--color-charcoal);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-message--admin .chat-bubble {
  background-color: var(--bg-section-alt);
  color: var(--color-charcoal);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-bubble-time {
  font-family: var(--font-body);
  font-size: 0.6rem;
  color: var(--color-brown-light);
  margin-top: 2px;
  padding: 0 var(--space-1);
}

/* ── Chat Form ── */
.chat-form {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-light);
  background-color: #fff;
  flex-shrink: 0;
}

.chat-message-input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--color-charcoal);
  background-color: var(--bg-page);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  outline: none;
  transition: border-color 0.2s ease;
  min-width: 0;
}

.chat-message-input:focus {
  border-color: var(--color-charcoal);
}

.chat-message-input::placeholder {
  color: var(--color-stone);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-charcoal);
  border: none;
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
  outline: none;
}

.chat-send-btn:hover {
  background: var(--color-primary-dark);
  transform: scale(1.05);
}

.chat-send-btn:active {
  transform: scale(0.92);
}

/* Direct user ask: dim Send while there's nothing to send (no text typed,
   no attachment staged) — see updateSendButtonState() in chat-widget.js. */
.chat-send-btn:disabled,
.chat-send-btn:disabled:hover {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  background: var(--color-charcoal);
}

/* Connecting state */
.chat-connecting {
  padding: var(--space-1) var(--space-3);
  background-color: var(--bg-section-alt);
  border-top: 1px solid var(--border-light);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  color: var(--color-brown-light);
  text-align: center;
  display: none;
}

.chat-connecting.visible {
  display: block;
}

/* ------------------------------------------------------------
   2b. SHARED CHAT BUBBLE SYSTEM (chat-common.js) — customer widget
   side. The admin single room page (chat.ejs) has its own copy of
   these same class names in chat.css, styled with the --adm-* token
   set instead — the two pages never load together, so there's no
   collision, just two skins for one shared JS component.
   ------------------------------------------------------------ */
.chat-msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.chat-msg-wrap--mine   { align-self: flex-end;   align-items: flex-end; }
.chat-msg-wrap--theirs { align-self: flex-start; align-items: flex-start; }

.chat-msg-bubble {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  word-break: break-word;
  cursor: pointer;
}

.chat-msg-wrap--mine .chat-msg-bubble {
  background: var(--color-charcoal);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-msg-wrap--theirs .chat-msg-bubble {
  background-color: var(--bg-section-alt);
  color: var(--color-charcoal);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: var(--radius-sm);
}

/* Automated chat: small label distinguishing a bot bubble from a real
   admin's, on top of the one-time divider disclaimer. */
.chat-msg-wrap--bot .chat-msg-bubble::before {
  content: "Mira Home Chat Bot";
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-primary-dark);
  margin-bottom: 2px;
}

.chat-msg-text { white-space: pre-wrap; }

.chat-msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 0 var(--space-1);
}

.chat-msg-time {
  font-family: var(--font-body);
  font-size: 0.6rem;
  color: var(--color-brown-light);
}

.chat-msg-check { font-size: 0.7rem; color: var(--color-brown-light); line-height: 1; }
.chat-msg-check--seen { color: var(--color-primary-dark); }

/* Date/time dividers (Telegram-style, direct user ask) */
.chat-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--space-2) 0;
}
.chat-divider span {
  font-family: var(--font-body);
  font-size: 0.65rem;
  color: var(--color-brown-light);
  background-color: var(--bg-section-alt);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
}

/* "N new messages" — inserted above the first reply from support that this
   customer hasn't seen (see ChatCommon.markUnseenFrom in chat-common.js),
   which the widget also scrolls to when opened. The unseen bubbles glow
   briefly and then settle; the divider stays for the rest of the page view. */
.chat-unseen-divider {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0;
  color: var(--color-danger);
}
.chat-unseen-divider::before,
.chat-unseen-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: currentColor;
  opacity: 0.35;
}
.chat-unseen-divider span {
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  background-color: rgba(201, 90, 90, 0.10);
  white-space: nowrap;
}
@keyframes chat-unseen-glow {
  0%, 60% { box-shadow: 0 0 0 3px rgba(240, 196, 25, 0.75); }
  100%    { box-shadow: 0 0 0 3px rgba(240, 196, 25, 0); }
}
.chat-msg-wrap--unseen .chat-msg-bubble {
  animation: chat-unseen-glow 5s ease-out forwards;
}

/* Rate-limit / spam-guard notice */
.chat-rate-limit-notice {
  padding: var(--space-1) var(--space-3);
  background-color: rgba(201, 90, 90, 0.10);
  color: var(--color-danger);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  text-align: center;
}

/* Load-older affordance */
.chat-load-older {
  display: block;
  width: 100%;
  padding: var(--space-1);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-light);
  color: var(--color-primary-dark);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.chat-load-older:hover { background-color: var(--bg-section-alt); }

/* FIX (bug report: "X button stuck in admin side" — the actual cause:
   these two elements set their own `display`, which OVERRIDES the
   browser's default `[hidden] { display: none }` rule since an author
   class selector beats that UA attribute selector. Toggling the
   `hidden` attribute in JS therefore never actually hid them — this
   forces `display: none` back whenever `hidden` is present, same as the
   artifact convention `[hidden]{display:none!important}`. */
.chat-load-older[hidden],
.chat-staged-attachment[hidden] {
  display: none !important;
}

/* Attachments */
.chat-att-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-md);
  display: block;
  margin-top: var(--space-1);
  cursor: pointer;
}

/* Full-size image lightbox — direct user ask: sent images should
   "appear bigger with dark background like as if it is on top". Shared
   by chat-widget.js and chat-admin.js (see chat-common.js). */
.chat-image-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background-color: rgba(20, 16, 10, 0.85);
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}
.chat-image-lightbox.open { display: flex; }
.chat-image-lightbox-img {
  max-width: min(90vw, 900px);
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.chat-image-lightbox-close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background-color: rgba(255, 255, 255, 0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}
.chat-image-lightbox-close:hover { background-color: rgba(255, 255, 255, 0.3); }
.chat-att-card {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
  padding: var(--space-2);
  background-color: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  text-decoration: none;
  max-width: 220px;
}
.chat-msg-wrap--mine .chat-att-card { background-color: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.2); }
.chat-att-card-img { width: 40px; height: 40px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }
.chat-att-card-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chat-att-card-body strong { font-size: var(--fs-xs); color: inherit; }
.chat-att-card-sub { font-size: 0.65rem; color: inherit; opacity: 0.75; }

/* Automated chat: a plain clickable link a bot reply points somewhere with
   (e.g. /refund-policy, /shop) — no thumbnail, unlike .chat-att-card. */
.chat-att-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-1);
  padding: 4px var(--space-2);
  border-radius: var(--radius-full);
  background-color: var(--color-primary-dark);
  color: #fff;
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-decoration: none;
}
.chat-msg-wrap--mine .chat-att-link { background-color: #fff; color: var(--color-charcoal); }

/* A voucher Staff sent in the chat (2026-11-04): amount band, name, terms, the code with a Copy button, one link. Built by
   ChatCommon.buildVoucherCard (public/js/chat-common.js). */
.chat-att-voucher {
  width: 100%; max-width: 240px; margin-top: var(--space-1);
  border: 1px dashed var(--color-primary-dark); border-radius: var(--radius-md);
  background-color: var(--color-primary-xlight); color: var(--color-charcoal);
  overflow: hidden; text-align: left;
}
.chat-att-voucher-off {
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-primary-dark); color: #fff;
  font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; line-height: 1.15;
  overflow-wrap: anywhere;
}
.chat-att-voucher-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--space-2) var(--space-3); }
.chat-att-voucher-name { font-size: var(--fs-xs); font-weight: 600; overflow-wrap: anywhere; }
.chat-att-voucher-terms { font-size: 0.7rem; opacity: 0.8; overflow-wrap: anywhere; }
.chat-att-voucher-tag {
  align-self: flex-start; margin-top: 2px; padding: 1px var(--space-2);
  font-size: 0.65rem; font-weight: 600; color: var(--color-primary-dark);
  background-color: #fff; border-radius: var(--radius-full);
}
.chat-att-voucher-code-row { display: flex; align-items: center; gap: var(--space-2); min-width: 0; margin-top: var(--space-1); }
.chat-att-voucher-code {
  flex: 1 1 auto; min-width: 0; padding: var(--space-1) var(--space-2);
  font-family: ui-monospace, 'JetBrains Mono', monospace; font-size: var(--fs-xs); letter-spacing: 0.06em; color: var(--color-charcoal);
  background-color: #fff; border: 1px solid var(--color-stone); border-radius: var(--radius-sm); overflow-wrap: anywhere;
}
.chat-att-voucher-copy {
  flex-shrink: 0; min-width: 44px; min-height: 44px; padding: 0 var(--space-3);
  font-family: var(--font-body); font-size: var(--fs-xs); font-weight: 600; color: var(--color-charcoal);
  background-color: #fff; border: 1px solid var(--color-primary-dark); border-radius: var(--radius-md); cursor: pointer;
}
.chat-att-voucher-copy:hover { background-color: var(--color-primary-light); }
.chat-att-voucher-cta {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs); font-weight: 600; color: var(--color-primary-dark); text-decoration: none;
  border-top: 1px dashed var(--color-primary-dark);
}
.chat-att-voucher-cta:hover { background-color: var(--color-primary-light); color: var(--color-charcoal); }

/* Attach button + honeypot */
.chat-attach-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--color-brown-light);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.chat-attach-btn:hover { background-color: var(--bg-section-alt); color: var(--color-charcoal); }

.chat-hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Staged attachment — direct user ask: "just put them in the input
   field and do not send them yet, put X button too" */
.chat-staged-attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border-light);
  background-color: var(--bg-section-alt);
}
.chat-staged-attachment-preview { display: flex; align-items: center; min-width: 0; }
.chat-staged-attachment-thumb {
  max-height: 56px;
  max-width: 90px;
  border-radius: var(--radius-md);
  display: block;
  cursor: pointer;
}
.chat-staged-attachment-card {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--color-charcoal);
  min-width: 0;
}
.chat-staged-attachment-card span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-staged-attachment-remove {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background-color: #fff;
  color: var(--color-brown-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.75rem;
  transition: all 0.2s ease;
}
.chat-staged-attachment-remove:hover { background-color: var(--color-danger); color: #fff; }

/* Attach picker */
.chat-picker {
  border-top: 1px solid var(--border-light);
  background-color: #fff;
  padding: var(--space-2) var(--space-3);
}
.chat-picker-tabs { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.chat-picker-close {
  margin-left: auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-brown-light);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.7rem;
  flex-shrink: 0;
}
.chat-picker-close:hover { background-color: var(--bg-section-alt); color: var(--color-charcoal); }
.chat-picker-tab {
  background: none; border: none;
  padding: 2px var(--space-2);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  color: var(--color-brown-light);
  border-radius: var(--radius-full);
  cursor: pointer;
}
.chat-picker-tab.active { background-color: var(--color-charcoal); color: #fff; }

/* Image picker — direct user ask: "improve choose file ui... show what
   is the image size limit" */
.chat-image-pick-buttons {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.chat-image-pick-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background-color: var(--color-charcoal);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background 0.2s ease;
}
.chat-image-pick-btn:hover { background-color: var(--color-primary-dark); }
.chat-image-pick-info { margin-top: var(--space-2); }
.chat-image-pick-filename {
  display: block;
  font-size: var(--fs-xs);
  color: var(--color-charcoal);
  font-weight: var(--fw-medium);
  word-break: break-all;
}
.chat-image-pick-hint {
  margin: 2px 0 0;
  font-size: 0.65rem;
  color: var(--color-brown-light);
}
.chat-image-pick-hint.chat-image-pick-error { color: var(--color-danger); font-weight: var(--fw-medium); }
.chat-image-pick-preview {
  display: block;
  max-width: 100px;
  max-height: 100px;
  border-radius: var(--radius-md);
  margin-top: var(--space-2);
  border: 1px solid var(--border-light);
}
.chat-picker-search {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-1);
}
.chat-picker-results { max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-picker-empty-note {
  margin: var(--space-2) 0;
  font-size: var(--fs-xs);
  color: var(--color-brown-light);
  text-align: center;
}
.chat-picker-result {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1);
  border: none; background: none;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-xs);
}
.chat-picker-result:hover { background-color: var(--bg-section-alt); }
.chat-picker-result img { width: 28px; height: 28px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }


/* ------------------------------------------------------------
   3. ADMIN CHAT ROOMS PAGE
   ------------------------------------------------------------ */

/* Page-level stat row */
.chat-stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.chat-stat-card {
  background-color: var(--adm-card-bg);
  border: 1px solid var(--adm-card-border);
  border-radius: var(--adm-card-radius);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.chat-stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-stat-icon--active   { background-color: rgba(107, 143, 94, 0.10); color: var(--adm-status-delivered); }
.chat-stat-icon--waiting  { background-color: rgba(201, 147, 90, 0.10); color: var(--adm-status-pending);   }
.chat-stat-icon--resolved { background-color: rgba(200, 168, 130, 0.10); color: var(--adm-nav-active-color); }

.chat-stat-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-stat-num {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: var(--fw-semibold);
  color: var(--adm-nav-text);
  line-height: 1;
}

.chat-stat-label {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  color: var(--adm-nav-text-muted);
  font-weight: var(--fw-medium);
}

/* Rooms table card */
.chat-rooms-card {
  background-color: var(--adm-card-bg);
  border: 1px solid var(--adm-card-border);
  border-radius: var(--adm-card-radius);
  overflow: hidden;
}

.chat-rooms-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--adm-card-border);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.chat-rooms-card-title {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--adm-nav-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--adm-status-delivered);
  display: inline-block;
  flex-shrink: 0;
}

/* Table */
/* FIX (mobile): unlike every other admin table, this one wasn't wrapped
   in a scrollable container — since .chat-rooms-card clips overflow
   (overflow:hidden), any column whose padding+content couldn't actually
   fit inside its fixed percentage width on a narrow phone (Room is only
   13% wide but carries 2rem+1.5rem of edge padding) had nowhere to go
   but get silently cut off, with no way to scroll to see it. */
.chat-rooms-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-rooms-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  /* FIX (bug report: column spacing kept fighting itself under plain
     auto layout — a fixed % of the table per column, always summing to
     100%, is the only way to get a stable, predictable distribution
     regardless of content length or container width. */
  table-layout: fixed;
}

@media (max-width: 767.98px) {
  .chat-rooms-table { min-width: 480px; }
}

.chat-rooms-table thead tr {
  background-color: var(--adm-table-head-bg);
  border-bottom: 1px solid var(--adm-table-border);
}

.chat-rooms-table thead th {
  padding: var(--space-2) var(--space-6);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--adm-nav-text-muted);
  text-align: left;
  white-space: nowrap;
}

/* FIX (bug reports: column spacing needed several passes — "too much
   space between customer/session and started at", then "too close to
   each other... message is over", then "more space between the three...
   and more space on left of action", then "use the percentage to apply
   more spacing" between Room and Customer/Session, then again for the
   table's own outer edges — "more space on left side of room and right
   side of action since they seem more on edge") — table-layout: fixed
   above means these percentages are the FINAL word on each column's
   width, not just a hint an auto layout can override. Room and Action
   both got extra width AND matching edge padding (padding-left on Room,
   padding-right on Action) so the table's first/last content doesn't
   sit flush against its outer boundary; Message keeps whatever's left.
   Rebalanced when the "Last Replied By" column (4th) was added — direct
   user ask: show which admin last replied, not just "Started At":
   100 - 11 - 23 - 14 - 16 - 14 = 22%. */
.chat-rooms-table thead th:nth-child(1) { width: 11%; padding-left: var(--space-8); }
.chat-rooms-table thead th:nth-child(2) { width: 23%; }
.chat-rooms-table thead th:nth-child(3) { width: 14%; }
.chat-rooms-table thead th:nth-child(4) { width: 16%; }
.chat-rooms-table thead th:nth-child(6) { width: 14%; padding-left: var(--space-3); padding-right: var(--space-8); }

.chat-rooms-table tbody tr {
  border-bottom: 1px solid var(--adm-table-border);
  transition: background-color 0.15s ease;
}

.chat-rooms-table tbody tr:last-child {
  border-bottom: none;
}

.chat-rooms-table tbody tr:hover {
  background-color: var(--adm-table-row-hover);
}

.chat-rooms-table td {
  padding: var(--space-3) var(--space-6);
  color: var(--adm-nav-text);
  vertical-align: middle;
}

/* Extra breathing room at the table's own outer edges — direct user
   ask: "more space on left side of room and right side of action since
   they seem more on edge". Action's LEFT padding is deliberately small
   (not matched to its right) — direct user ask: "reduce more space
   between message and action" — the gap between two adjacent columns
   is the sum of the left cell's right-padding and the right cell's
   left-padding, so Message's own right-padding is trimmed to match. */
.chat-rooms-table td:nth-child(1) {
  padding-left: var(--space-8);
}
.chat-rooms-table td:nth-child(5) {
  padding-right: var(--space-3);
}
.chat-rooms-table td:nth-child(6) {
  padding-left: var(--space-3);
  padding-right: var(--space-8);
}

/* Room ID cell */
.chat-room-id {
  font-weight: var(--fw-semibold);
  color: var(--adm-nav-active-color);
}

/* Customer cell */
.chat-room-customer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.chat-room-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--bg-section-alt);
  border: 1px solid var(--adm-card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--adm-nav-text-muted);
  flex-shrink: 0;
}

.chat-room-customer-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-room-customer-name,
.chat-room-customer-type {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-customer-name {
  font-weight: var(--fw-semibold);
  color: var(--adm-nav-text);
  font-size: var(--fs-sm);
}

.chat-room-customer-type {
  font-size: var(--fs-xs);
  color: var(--adm-nav-text-muted);
}

/* Status badge */
.chat-status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}

.chat-status-badge--active {
  background-color: rgba(107, 143, 94, 0.10);
  color: var(--adm-status-delivered);
}

.chat-status-badge--waiting {
  background-color: rgba(201, 147, 90, 0.10);
  color: var(--adm-status-pending);
}

.chat-status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: currentColor;
  flex-shrink: 0;
}

/* Direct user ask: "a different color for chats that are not seened
   yet" — a soft highlight on the whole row, plus a numeric badge next
   to the room id (replaces the old, broken admin_joined-based styling). */
/* FIX (bug report: "properly highlight as yellow rooms that are not
   seen yet") — the previous tan tint at 6% opacity was too subtle to
   register as a highlight at all; this is a real, clearly-visible
   yellow (matching the warm "unread/attention" color used for alerts
   elsewhere), plus a left accent bar so it reads at a glance even in
   peripheral vision while scanning the list. */
.chat-rooms-table tbody tr.chat-room-unread {
  background-color: #fff6d8;
  box-shadow: inset 3px 0 0 #f0c419;
}
.chat-rooms-table tbody tr.chat-room-unread:hover {
  background-color: #ffedb0;
}
.chat-room-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: var(--space-1);
  background-color: var(--color-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* Message preview column — direct user ask: put a preview between
   Started At and Action, with the unread badge moved here. */
.chat-room-preview-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.chat-room-preview-text {
  color: var(--adm-nav-text-muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-rooms-table tbody tr.chat-room-unread .chat-room-preview-text {
  color: var(--adm-nav-text);
  font-weight: var(--fw-medium);
}

/* Guest vs registered — direct user ask: "different color too for
   guests and registered users" (admin room list, at a glance). */
.chat-room-customer-type--guest { color: var(--adm-status-pending); }

/* Presence dot on the room-list avatar */
.chat-room-avatar { position: relative; }
.chat-room-presence-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 14px; height: 14px;
  border-radius: 50%;
  background-color: #6fcf97;
  border: 2.5px solid var(--adm-card-bg, #fff);
}

/* Profile pictures (2026-10-24): the customer's picture fills the room circle. main.css gives .has-avatar-img overflow:hidden, which would
   clip the presence dot that sits on the circle's edge, so here the circle stays visible (the picture rounds itself with border-radius:
   inherit) and the person icon is hidden. */
.chat-room-avatar.has-avatar-img { overflow: visible; }
.chat-room-avatar.has-avatar-img > i { display: none; }

/* Real presence text ("Active now" / "Last seen 5m ago"). */
.chat-room-presence-text {
  font-size: 0.65rem;
  color: var(--adm-nav-text-muted);
}
.chat-room-presence-text.is-online {
  color: var(--adm-status-delivered);
  font-weight: var(--fw-semibold);
}

/* Search/filter bar */
.chat-rooms-filters {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 220px;
}
.chat-room-search-input {
  flex: 1;
  max-width: 220px;
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  border: 1px solid var(--adm-card-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
}
.chat-room-unread-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--adm-nav-text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.adm-page-header-actions a.btn-adm-secondary.active {
  background-color: var(--color-charcoal);
  color: #fff;
  border-color: var(--color-charcoal);
}

/* Time cell */
.chat-room-time {
  font-size: var(--fs-xs);
  color: var(--adm-nav-text-muted);
}

/* Last Replied By cell — name over time, same muted time style as
   Started At. */
.chat-room-handler {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.chat-room-handler-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--adm-nav-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-room-handler-none {
  font-size: var(--fs-xs);
  font-style: italic;
  color: var(--adm-nav-text-muted);
}

/* Join button */
.btn-join-chat {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background-color: var(--adm-nav-active-color);
  border: 1px solid var(--adm-nav-active-color);
  border-radius: var(--radius-md);
  color: #fff;
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s ease;
  cursor: pointer;
  height: 32px;
}

.btn-join-chat:hover {
  background-color: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  color: #fff;
}

/* Empty state */
.chat-rooms-empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.chat-rooms-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-xl);
  background-color: rgba(200, 168, 130, 0.08);
  border: 1px solid var(--adm-card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--adm-nav-text-muted);
}

.chat-rooms-empty-title {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--adm-nav-text);
  margin: 0;
}

.chat-rooms-empty-desc {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--adm-nav-text-muted);
  margin: 0;
}


/* ------------------------------------------------------------
   4. RESPONSIVE
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
  .customer-chat-widget {
    width: calc(100vw - 32px);
    right: 16px;
    bottom: 16px;
    max-height: 460px;
  }

  /* FIX (mobile): .chat-box's min-height:200px floor plus the header +
     a fully-open attach picker (tabs + search + up to 180px of results)
     + the message form could together exceed the widget's 460px cap —
     since the widget clips overflow instead of scrolling as a whole,
     the message input/send button could end up clipped off-screen while
     the picker was open. Shrinking the messages floor while the picker
     is visible reclaims that room (chat-box keeps its own internal
     scroll, so older messages are still reachable). */
  .customer-chat-widget:has(#chatPicker:not([hidden])) .chat-box {
    min-height: 80px;
  }

  /* FIX (bug report: the floating Chat pill overlapping order/profile
     action buttons — "View Order", "Save Changes", etc. — on phones):
     those buttons routinely span the full card width on mobile (a
     304px-wide button measured on a 375px viewport), so shrinking the
     pill's padding/font-size alone still left an ~80px-wide pill
     covering a real chunk of them. Collapsing to an icon-only circle
     (see the span/i rules below) cuts that footprint to 48px, matching
     the common mobile pattern for chat FABs. */
  .chat-open-btn {
    right: 16px;
    bottom: 16px;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    gap: 0;
  }

  .chat-open-btn span:not(.chat-unread-dot) {
    display: none;
  }

  .chat-open-btn i {
    font-size: 1.2rem;
  }

  .chat-stat-row {
    grid-template-columns: 1fr;
  }

  /* Started At and Last Replied By both drop on phones — the message
     preview's "<name>: " prefix still says which admin replied last. */
  .chat-rooms-table thead th:nth-child(3),
  .chat-rooms-table tbody td:nth-child(3),
  .chat-rooms-table thead th:nth-child(4),
  .chat-rooms-table tbody td:nth-child(4) {
    display: none;
  }

  .chat-rooms-table td,
  .chat-rooms-table th {
    padding: var(--space-2) var(--space-3);
    font-size: var(--fs-xs);
  }

  /* FIX (direct user ask: "look at that color in action column which got
     cut off and the join chat maxed out to the right side") — with
     table-layout:fixed, Action's desktop width:14% (of the table's
     min-width:480px, ~67px) stayed in force here even after hiding
     Started At freed up its 17% — nowhere near enough room for the
     "Join Chat" pill (icon + text), which then visually overflowed past
     its own cell/the table's right edge instead of fitting inside it.
     Redistributing the freed-up percentage into a wider, fixed-px Action
     column (sized to the pill's own mobile footprint) fixes the overflow
     directly; Room/Customer keep most of the remaining space so names
     still have room to read. */
  .chat-rooms-table thead th:nth-child(1) { width: 16%; }
  .chat-rooms-table thead th:nth-child(2) { width: 38%; }
  .chat-rooms-table thead th:nth-child(6) { width: 104px; }

  /* These nth-child rules (desktop "breathing room at the table's own
     outer edges" fix, above) have higher specificity than the shorthand
     reset just above and would otherwise keep their full 2rem/1.5rem
     edge padding here too — on a 13%-wide Room column that leaves almost
     no room for its own "#1234" content. */
  .chat-rooms-table td:nth-child(1),
  .chat-rooms-table th:nth-child(1) {
    padding-left: var(--space-3);
  }
  .chat-rooms-table td:nth-child(6),
  .chat-rooms-table th:nth-child(6) {
    padding-left: var(--space-2);
    /* FIX (direct user ask: "add padding to the right of join chat as it
       really touches the wall of the table") — space-3 (12px) read as
       flush against the table/viewport edge; more breathing room here. */
    padding-right: var(--space-5);
  }

  .btn-join-chat {
    font-size: 0.7rem;
    padding: var(--space-1) var(--space-2);
    height: 28px;
  }
}

/* ── Chat button visibility ── */
/* FIX (bug: the 767.98px media query above shrinks this button and
   repositions it to right:16px/bottom:16px on mobile, but this ID rule
   used to also force right/bottom to 24px !important — same specificity
   tier (id + !important beats class + !important) always won regardless
   of source order, so the mobile reposition was dead code and the button
   sat 8px further into the corner than intended on every phone. Only
   position/z-index actually need forcing here (this rule exists to
   guarantee the button stays visible/on-top); right/bottom are left to
   whichever breakpoint's rule applies. */
#chat-open-btn.chat-open-btn {
  position: fixed !important;
  z-index: 9999 !important;
}

/* FIX (direct user ask: the chat bubble must not be clickable while a Buy
   Now/Add to Cart (or any other) modal is open, but it must stay visible
   instead of disappearing) — chat-widget.js toggles this class instead of
   display:none now. Dropping z-index below Bootstrap's modal backdrop
   (1050 by default) lets the SAME semi-transparent backdrop that dims the
   rest of the page dim this button too, instead of hiding it outright;
   pointer-events:none is belt-and-suspenders in case a page ever puts the
   button somewhere the backdrop doesn't cover. Needs the id+2-class
   selector below to out-specificity the !important rule right above.
   Not `display:none` — that's the exact bug being fixed here. */
#chat-open-btn.chat-open-btn.chat-open-btn-suppressed {
  z-index: 1 !important;
  pointer-events: none;
}

/* ── Ensure chat button text is white ── */
#chat-open-btn.chat-open-btn i,
#chat-open-btn.chat-open-btn span:not(.chat-unread-dot) {
  color: #fff !important;
}