/* ============================================================
   TypeChat AI - Frontend Chat Widget
   ============================================================ */

:root {
  --tc-primary:   #2271b1;
  --tc-text:      #ffffff;
  --tc-bg:        #ffffff;
  --tc-border:    #e5e7eb;
  --tc-bot-bg:    #f3f4f6;
  --tc-user-bg:   var(--tc-primary);
  --tc-user-text: #ffffff;
  --tc-radius:    16px;
  --tc-shadow:    0 8px 40px rgba(0,0,0,.18);
  --tc-z:         99999;
}

/* ── Container ── */
.typechat-widget {
  position: fixed;
  bottom: 24px;
  z-index: var(--tc-z);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
.typechat-right { right: 24px; }
.typechat-left  { left: 24px; }

/* ── Toggle Button ── */
.typechat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tc-primary);
  color: var(--tc-text);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform .2s, box-shadow .2s;
}
.typechat-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,.3); }
.typechat-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  width: 20px; height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ── Chat Window ── */
.typechat-window {
  position: absolute;
  bottom: 68px;
  width: 370px;
  max-height: 580px;
  background: var(--tc-bg);
  border-radius: var(--tc-radius);
  box-shadow: var(--tc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--tc-border);
  animation: tcSlideUp .2s ease;
}
.typechat-right .typechat-window { right: 0; }
.typechat-left  .typechat-window { left: 0; }

@keyframes tcSlideUp {
  from { opacity:0; transform: translateY(10px); }
  to   { opacity:1; transform: translateY(0); }
}

/* ── Header ── */
.typechat-header {
  background: var(--tc-primary);
  color: var(--tc-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.typechat-header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
  overflow: hidden;
}
.typechat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.typechat-header-title { font-weight: 700; font-size: 15px; }
.typechat-header-subtitle { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; }
.typechat-status-dot {
  width: 8px; height: 8px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
}
.typechat-minimize {
  margin-left: auto;
  background: none; border: none;
  color: var(--tc-text); font-size: 18px;
  cursor: pointer; opacity: .8; line-height: 1;
  flex-shrink: 0;
}
.typechat-minimize:hover { opacity: 1; }

/* ── Messages ── */
.typechat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.typechat-messages::-webkit-scrollbar { width: 4px; }
.typechat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* ── Message Bubbles ── */
.typechat-msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.typechat-msg.bot  { align-self: flex-start; }
.typechat-msg.user { align-self: flex-end;   }

.typechat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.typechat-msg.bot  .typechat-bubble { background: var(--tc-bot-bg); color: #1f2937; border-bottom-left-radius: 4px; }
.typechat-msg.user .typechat-bubble { background: var(--tc-user-bg); color: var(--tc-user-text); border-bottom-right-radius: 4px; }

.typechat-time { font-size: 11px; color: #9ca3af; }
.typechat-msg.user .typechat-time { text-align: right; }

/* ── Typing Indicator ── */
.typechat-typing .typechat-bubble {
  padding: 12px 16px;
  display: flex; gap: 4px; align-items: center;
}
.typechat-dot {
  width: 7px; height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: tcDot 1.2s infinite;
}
.typechat-dot:nth-child(2) { animation-delay: .2s; }
.typechat-dot:nth-child(3) { animation-delay: .4s; }
@keyframes tcDot { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }

/* ── Product Cards ── */
.typechat-products {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: thin;
}
.typechat-product-card {
  min-width: 130px;
  max-width: 140px;
  border: 1px solid var(--tc-border);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
  transition: box-shadow .15s;
}
.typechat-product-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.typechat-product-card img {
  width: 100%; height: 90px;
  object-fit: cover;
  background: #f9fafb;
}
.typechat-product-card-no-image {
  width: 100%; height: 90px;
  background: #f3f4f6;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
}
.typechat-product-info { padding: 8px 8px 10px; }
.typechat-product-name { font-size: 12px; font-weight: 600; line-height: 1.3; margin-bottom: 4px; color: #111827; }
.typechat-product-price { font-size: 12px; color: var(--tc-primary); font-weight: 700; }
.typechat-product-price del { color: #9ca3af; font-weight: 400; }
.typechat-product-stock { font-size: 11px; margin-top: 3px; }
.typechat-product-stock.in-stock  { color: #16a34a; }
.typechat-product-stock.out-stock { color: #dc2626; }

/* ── Sources ── */
.typechat-sources {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}
.typechat-sources a {
  color: var(--tc-primary);
  text-decoration: none;
  display: inline-block;
  margin-right: 6px;
}
.typechat-sources a:hover { text-decoration: underline; }

/* ── Quick Replies ── */
.typechat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 4px;
}
.typechat-qr-btn {
  background: none;
  border: 1px solid var(--tc-primary);
  color: var(--tc-primary);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.typechat-qr-btn:hover { background: var(--tc-primary); color: #fff; }

/* ── Input Area ── */
.typechat-input-area {
  border-top: 1px solid var(--tc-border);
  flex-shrink: 0;
  background: #fff;
}
.typechat-input-row {
  display: flex;
  align-items: flex-end;
  padding: 10px 12px 6px;
  gap: 8px;
}
#typechat-input {
  flex: 1;
  border: 1px solid var(--tc-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  transition: border-color .15s;
}
#typechat-input:focus { border-color: var(--tc-primary); }
#typechat-send {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--tc-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#typechat-send:hover { filter: brightness(1.1); transform: scale(1.05); }
#typechat-send:disabled { background: #9ca3af; cursor: not-allowed; transform: none; }

/* ── Footer Bar ── */
.typechat-footer-bar {
  display: flex;
  align-items: center;
  padding: 4px 12px 10px;
  gap: 8px;
}
.typechat-footer-btn {
  background: none;
  border: none;
  color: #6b7280;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
  transition: background .15s;
}
.typechat-footer-btn:hover { background: #f3f4f6; color: #374151; }
.typechat-powered {
  margin-left: auto;
  font-size: 11px;
  color: #d1d5db;
}

/* ── Order / Handoff Forms ── */
.typechat-order-form,
.typechat-handoff-form {
  border-top: 1px solid var(--tc-border);
  padding: 14px;
  background: #fafafa;
  flex-shrink: 0;
  font-size: 13px;
}
.typechat-order-form p,
.typechat-handoff-form p { margin: 0 0 8px; }
.typechat-order-form input,
.typechat-handoff-form input,
.typechat-handoff-form textarea {
  width: 100%;
  border: 1px solid var(--tc-border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  margin-bottom: 6px;
  box-sizing: border-box;
  font-family: inherit;
}
.typechat-order-form input:focus,
.typechat-handoff-form input:focus,
.typechat-handoff-form textarea:focus {
  outline: none;
  border-color: var(--tc-primary);
}
.typechat-order-form button,
.typechat-handoff-form button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.typechat-order-form button:first-of-type,
.typechat-handoff-form button:first-of-type {
  background: var(--tc-primary);
  color: #fff;
  margin-right: 8px;
}
.typechat-cancel {
  background: none !important;
  color: #6b7280 !important;
  border: 1px solid var(--tc-border) !important;
}

/* ── Error / Success States ── */
.typechat-error .typechat-bubble { background: #fef2f2; color: #dc2626; }
.typechat-success-msg { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ── Mobile ── */
@media (max-width: 480px) {
  .typechat-widget.typechat-right { right: 12px; }
  .typechat-widget.typechat-left  { left: 12px; }
  .typechat-window {
    width: calc(100vw - 24px);
    bottom: 70px;
  }
}
