/* ================================================================
   Carmela Live Chat Widget
   ================================================================ */

:root {
  --chat-color:       #2c6fad;
  --chat-color-dark:  #1e4f7e;
  --chat-color-light: #e8f1fa;
  --chat-radius:      12px;
  --chat-shadow:      0 8px 32px rgba(0,0,0,.18);
  --chat-z:           9000;
}

/* ---- FAB button ---- */
.chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--chat-color);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(44,111,173,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--chat-z);
  transition: transform .2s, background .2s;
}
.chat-fab:hover   { background: var(--chat-color-dark); transform: scale(1.08); }
.chat-fab svg     { width: 28px; height: 28px; fill: #fff; }
.chat-fab.chat-fab--offline { background: #757575; box-shadow: 0 4px 20px rgba(0,0,0,.2); }

/* Unread badge on FAB */
.chat-fab-badge {
  position: absolute;
  top: 0; right: 0;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  border: 2px solid #fff;
}

/* Online indicator dot */
.chat-fab-dot {
  position: absolute;
  bottom: 3px; right: 3px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #43a047;
  border: 2px solid #fff;
}

/* ---- Chat window ---- */
.chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 370px;
  max-height: 580px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  z-index: calc(var(--chat-z) + 1);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chatWindowOpen .22s ease;
}
.chat-window.chat-window--hidden {
  display: none;
}

@keyframes chatWindowOpen {
  from { opacity: 0; transform: scale(.92) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---- Header ---- */
.chat-header {
  background: var(--chat-color);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-header-avatar svg { width: 22px; height: 22px; fill: #fff; }
.chat-header-info       { flex: 1; min-width: 0; }
.chat-header-title      { font-size: 15px; font-weight: 600; line-height: 1.2; }
.chat-header-sub        { font-size: 12px; opacity: .85; margin-top: 1px; }
.chat-header-close      { background: none; border: none; color: #fff; cursor: pointer; padding: 4px; border-radius: 4px; opacity: .8; }
.chat-header-close:hover { opacity: 1; background: rgba(255,255,255,.15); }
.chat-header-close svg  { width: 18px; height: 18px; fill: #fff; display: block; }

/* ---- Offline inquiry confirmation ---- */
.chat-offline-done {
  text-align: center;
  padding: 28px 12px 12px;
  color: #333;
}
.chat-offline-done svg {
  width: 48px; height: 48px;
  color: #43a047;
  margin-bottom: 14px;
}
.chat-offline-done h3 { margin: 0 0 8px; font-size: 16px; }
.chat-offline-done p  { margin: 0; font-size: 13px; color: #666; line-height: 1.5; }

/* ---- Pre-chat form ---- */
.chat-prechat {
  padding: 20px 18px;
  flex: 1;
  overflow-y: auto;
}
.chat-prechat h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: #1a1a1a;
}
.chat-prechat p {
  margin: 0 0 18px;
  font-size: 13px;
  color: #555;
  line-height: 1.5;
}
.chat-field {
  margin-bottom: 12px;
}
.chat-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #444;
  margin-bottom: 4px;
}
.chat-field input {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.chat-field input:focus { border-color: var(--chat-color); }
.chat-field .chat-field-hint { font-size: 11px; color: #888; margin-top: 2px; }
.chat-prechat-error {
  color: #c62828;
  font-size: 13px;
  margin: 0 0 10px;
  display: none;
}
.chat-btn-start {
  width: 100%;
  padding: 11px;
  background: var(--chat-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  margin-top: 4px;
}
.chat-btn-start:hover    { background: var(--chat-color-dark); }
.chat-btn-start:disabled { background: #bbb; cursor: default; }

/* ---- Messages area ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.chat-msg--visitor { align-self: flex-end; align-items: flex-end; }
.chat-msg--agent   { align-self: flex-start; align-items: flex-start; }

.chat-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg--visitor .chat-msg-bubble {
  background: var(--chat-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--agent .chat-msg-bubble {
  background: #f1f3f4;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.chat-msg-meta {
  font-size: 10px;
  color: #999;
  margin-top: 3px;
  padding: 0 4px;
}

/* System / status messages */
.chat-msg--system {
  align-self: center;
  max-width: 100%;
}
.chat-msg--system .chat-msg-bubble {
  background: #fef9e7;
  color: #795548;
  font-size: 12px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid #f9e4b7;
}

/* Typing indicator */
.chat-typing-indicator {
  align-self: flex-start;
  display: none;
  padding: 8px 12px;
  background: #f1f3f4;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat-typing-indicator span {
  display: inline-block;
  width: 7px; height: 7px;
  background: #999;
  border-radius: 50%;
  animation: chatTyping 1.2s infinite;
  margin: 0 2px;
}
.chat-typing-indicator span:nth-child(2) { animation-delay: .2s; }
.chat-typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes chatTyping {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40%            { transform: scale(1);  opacity: 1; }
}

/* Waiting for agent notice */
.chat-waiting-notice {
  text-align: center;
  padding: 16px;
  color: #666;
  font-size: 13px;
  font-style: italic;
}

/* ---- Input area ---- */
.chat-input-area {
  border-top: 1px solid #eee;
  padding: 8px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-input-actions {
  display: flex;
  justify-content: flex-end;
}
.chat-end-btn {
  background: none;
  border: none;
  color: #bbb;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 0 4px;
  transition: color .15s;
}
.chat-end-btn:hover { color: #e53935; }
.chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color .15s;
  line-height: 1.4;
}
.chat-input:focus { border-color: var(--chat-color); }
.chat-send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--chat-color);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.chat-send-btn:hover   { background: var(--chat-color-dark); }
.chat-send-btn:active  { transform: scale(.93); }
.chat-send-btn svg     { width: 18px; height: 18px; fill: #fff; }
.chat-send-btn:disabled { background: #ccc; cursor: default; }

/* Canned responses dropdown */
.chat-canned-list {
  position: absolute;
  bottom: 72px;
  right: 12px;
  left: 12px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1;
  display: none;
}
.chat-window { position: fixed; } /* ensure relative ancestor for canned list */
.chat-canned-list.active { display: block; }
.chat-canned-item {
  padding: 9px 13px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f5f5f5;
}
.chat-canned-item:last-child { border-bottom: none; }
.chat-canned-item:hover { background: var(--chat-color-light); }
.chat-canned-shortcut { font-weight: 600; color: var(--chat-color); margin-right: 6px; }

/* ---- Rating screen ---- */
.chat-rating {
  padding: 22px 18px;
  text-align: center;
}
.chat-rating h3  { margin: 0 0 8px; font-size: 16px; }
.chat-rating p   { margin: 0 0 16px; font-size: 13px; color: #555; }
.chat-stars      { display: flex; justify-content: center; gap: 6px; margin-bottom: 14px; }
.chat-star {
  font-size: 30px;
  cursor: pointer;
  color: #ccc;
  transition: color .1s, transform .1s;
  line-height: 1;
}
.chat-star:hover,
.chat-star.active { color: #ffc107; }
.chat-star:hover  { transform: scale(1.15); }
.chat-rating-comment {
  text-align: left;
  margin-top: 6px;
}
.chat-rating-comment textarea {
  width: 100%;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  min-height: 68px;
  box-sizing: border-box;
  margin-bottom: 8px;
  line-height: 1.4;
  display: block;
}
.chat-rating-comment textarea:focus { outline: none; border-color: var(--chat-color); }
.chat-rating-submit {
  display: block;
  width: 100%;
  padding: 9px;
  background: var(--chat-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 6px;
  transition: background .15s;
}
.chat-rating-submit:hover { background: var(--chat-color-dark); }
.chat-rating-skip {
  background: none;
  border: none;
  color: #999;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 8px;
}
.chat-rating-skip:hover { color: #555; }
.chat-rating-done       { font-size: 14px; color: #555; padding: 8px 0; }

/* ---- Message delivery ticks ---- */
.chat-tick {
  width: 14px;
  height: 10px;
  display: inline-block;
  vertical-align: middle;
  margin-left: 3px;
  flex-shrink: 0;
  overflow: visible;
}
.chat-tick--sent      { color: #9aa8b4; }
.chat-tick--delivered { color: #9aa8b4; }
.chat-tick--read      { color: #4FC3F7; }

/* ---- Mobile ---- */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0; right: 0; left: 0;
    width: 100%;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
    max-height: 90vh;
  }
  .chat-fab {
    bottom: 18px;
    right: 18px;
  }
}

/* ---- Rich message cards ---- */
.chat-rich-card {
  border-radius: 14px;
  overflow: hidden;
  max-width: 252px;
}
.chat-product-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.09);
  box-shadow: 0 3px 12px rgba(0,0,0,0.09);
  border-radius: 14px;
}
.chat-product-img-wrap { display: block; line-height: 0; }
.chat-product-img { width: 100%; height: 165px; object-fit: cover; display: block; }
.chat-product-body { padding: 11px 13px 13px; display: flex; flex-direction: column; gap: 5px; }
.chat-product-name {
  font-size: 13px; font-weight: 600; color: #1a1a1a; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-product-price { font-size: 22px; font-weight: 800; color: #111; line-height: 1.1; letter-spacing: -.3px; }
.chat-product-link { font-size: 11.5px; color: #2563eb; text-decoration: none; font-weight: 500; opacity: .85; }
.chat-product-link:hover { opacity: 1; text-decoration: underline; }
.chat-product-cart-btn {
  background: #2563eb; color: #fff; border: none; border-radius: 9px;
  padding: 10px 10px; font-size: 13px; font-weight: 700; cursor: pointer;
  text-align: center; margin-top: 4px; width: 100%; letter-spacing: .01em;
  transition: background .15s;
}
.chat-product-cart-btn:hover:not(:disabled) { background: #1d4ed8; }
.chat-product-cart-btn:disabled { opacity: .6; cursor: default; }

.chat-coupon-card {
  background: #fffbe6;
  border: 1.5px dashed #f0be57;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #4f3d12;
}
.chat-coupon-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }
.chat-coupon-code { font-size: 20px; font-weight: 900; letter-spacing: .12em; color: #b8760a; }
.chat-coupon-desc { font-size: 12px; }
.chat-coupon-copy {
  background: #f1a90a; color: #fff; border: none;
  border-radius: 6px; padding: 5px 12px;
  font-size: 12px; font-weight: 700; cursor: pointer; margin-top: 2px;
}

.chat-payment-card {
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg--visitor .chat-payment-card { background: rgba(0,0,0,0.04); }
.chat-payment-label { font-size: 13px; }
.chat-payment-btn {
  display: inline-block;
  background: #009ee3;
  color: #fff;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
}
.chat-order-ref { font-style: italic; }
