/* ============================================
   Mixfree Chat Widget Styles
   ============================================ */

.mfx-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.mfx-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: mfxMsgIn 0.35s ease-out;
}
@keyframes mfxMsgIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.mfx-chat-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.mfx-chat-msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.mfx-chat-bubble {
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}
.mfx-chat-msg.user .mfx-chat-bubble {
  background: var(--primary-color, #4B4B4E);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.mfx-chat-msg.assistant .mfx-chat-bubble {
  background: #F7F6F7;
  color: #2B2B2E;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0,0,0,0.06);
}
.mfx-chat-msg.assistant .mfx-chat-bubble p { margin: 0 0 8px; }
.mfx-chat-msg.assistant .mfx-chat-bubble p:last-child { margin-bottom: 0; }
.mfx-chat-msg.assistant .mfx-chat-bubble strong { color: #111; }
.mfx-chat-msg.assistant .mfx-chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.85rem;
}
.mfx-chat-msg.assistant .mfx-chat-bubble th,
.mfx-chat-msg.assistant .mfx-chat-bubble td {
  border: 1px solid #ddd;
  padding: 6px 10px;
  text-align: left;
}
.mfx-chat-msg.assistant .mfx-chat-bubble th {
  background: #eee;
  font-weight: 600;
}

/* Think block */
.mfx-chat-think {
  margin-bottom: 6px;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  font-size: 0.82rem;
}
.mfx-chat-think-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 14px;
  background: #fafafa;
  border: none;
  cursor: pointer;
  color: #888;
  font-size: 0.82rem;
  text-align: left;
  transition: background 0.2s;
}
.mfx-chat-think-toggle:hover { background: #f0f0f0; }
.mfx-chat-think-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.25s;
  flex-shrink: 0;
}
.mfx-chat-think.open .mfx-chat-think-toggle svg {
  transform: rotate(90deg);
}
.mfx-chat-think-body {
  display: none;
  padding: 10px 14px;
  color: #999;
  line-height: 1.6;
  border-top: 1px solid #e8e8e8;
  white-space: pre-wrap;
  font-style: italic;
  max-height: calc(1.6em * 3 + 20px);
  overflow-y: auto;
  word-break: break-all;
}
.mfx-chat-think.open .mfx-chat-think-body { display: block; }

/* Loading dots inside assistant bubble */
.mfx-chat-loading {
  display: flex;
  gap: 5px;
  padding: 6px 0;
  align-items: center;
}
.mfx-chat-loading span {
  width: 8px; height: 8px;
  background: #aaa;
  border-radius: 50%;
  animation: mfxDot 1.2s infinite ease-in-out both;
}
.mfx-chat-loading span:nth-child(1) { animation-delay: -0.24s; }
.mfx-chat-loading span:nth-child(2) { animation-delay: -0.12s; }
.mfx-chat-loading span:nth-child(3) { animation-delay: 0s; }
@keyframes mfxDot {
  0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.mfx-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid #f0f0f0;
  background: #fff;
  flex-shrink: 0;
}
.mfx-chat-input {
  flex: 1;
  border: 1px solid #e8e8e8;
  border-radius: 16px;
  padding: 12px 18px;
  font-size: 0.95rem;
  outline: none;
  resize: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  max-height: 80px;
  background: #fafafa;
}
.mfx-chat-input:focus {
  border-color: var(--primary-color, #4B4B4E);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
  background: #fff;
}
.mfx-chat-send {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--primary-color, #1a1a1a);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s, background 0.2s;
}
.mfx-chat-send:hover { background: #333; transform: scale(1.04); }
.mfx-chat-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.mfx-chat-send svg { width: 18px; height: 18px; }

/* Product shelf */
.mfx-chat-products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 10px;
  width: 100%;
}
.mfx-chat-product-card {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.25s, transform 0.25s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.mfx-chat-product-card:hover {
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}
.mfx-chat-product-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #f5f5f5;
}
.mfx-chat-product-info {
  padding: 10px 12px;
}
.mfx-chat-product-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #222;
  margin-bottom: 4px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.mfx-chat-product-summary {
  font-size: 0.78rem;
  color: #888;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Empty state */
.mfx-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.mfx-chat-empty svg { width: 48px; height: 48px; opacity: 0.4; }
.mfx-chat-empty-title { font-size: 1.1rem; font-weight: 500; color: #888; }
.mfx-chat-empty-hint { font-size: 0.85rem; color: #bbb; }

/* Floating button */
.side-widget-btn {
  position: fixed; right: 40px; bottom: 40px; width: 65px; height: 65px;
  background: var(--primary-color, #000); color: var(--white, #fff); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3); cursor: pointer; z-index: 1500;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.side-widget-btn:hover { transform: scale(1.1) translateY(-4px); }
.side-widget-btn svg { width: 28px; height: 28px; }

/* No backdrop needed — panel is anchored to button */

/* Popup — anchored to bottom-right, expands from button */
.side-widget-panel {
  position: fixed; bottom: 120px; right: 40px;
  width: 440px; max-width: 92vw; height: 78vh; max-height: 720px;
  background: var(--white, #fff);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.22), 0 0 0 1px rgba(0,0,0,0.06);
  z-index: 2000;
  transform: scale(0); transform-origin: bottom right;
  opacity: 0; pointer-events: none;
  transition: opacity 0.30s ease, transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex; flex-direction: column; overflow: hidden;
}
@media (max-width: 768px) {
  .side-widget-panel { width: calc(100% - 24px); max-width: none; right: 12px; bottom: 110px; height: 70vh; max-height: none; border-radius: 16px; }
}
.side-widget-panel.open { opacity: 1; pointer-events: auto; transform: scale(1); }
.side-widget-close {
  position: absolute; top: 14px; right: 14px; width: 36px; height: 36px;
  background: transparent; border: none; border-radius: 50%;
  font-size: 28px; font-weight: 300; cursor: pointer; color: #888;
  display: flex; align-items: center; justify-content: center;
  z-index: 10; transition: all 0.2s;
}
.side-widget-close:hover { background: #f0f0f0; color: #333; }
.side-widget-panel iframe { width: 100%; height: 100%; border: none; flex-grow: 1; }

/* Desktop panel header */
.mfx-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 50px 18px 24px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  background: #fafafa;
}
.mfx-chat-header-title { font-size: 1.05rem; font-weight: 600; color: #1a1a1a; display: flex; align-items: center; gap: 8px; }
.mfx-chat-header-title span { font-weight: 500; font-size: 0.78rem; color: #666; background: #f0f0f0; padding: 3px 12px; border-radius: 12px; letter-spacing: 0.02em; }
.mfx-chat-header-clear {
  background: none; border: none; color: #999; font-size: 0.82rem; cursor: pointer; padding: 6px 10px;
  border-radius: 6px; transition: all 0.2s;
}
.mfx-chat-header-clear:hover { color: #333; background: #f0f0f0; }

/* Mobile */
@media (max-width: 768px) {
  .mfx-chat-header {
    padding-right: 52px;
  }
  .mfx-chat-messages {
    padding: 12px 16px;
    gap: 12px;
  }
  .mfx-chat-input-area {
    padding: 10px 16px;
    gap: 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .mfx-chat-input {
    font-size: 16px;
    padding: 10px 16px;
  }
  .mfx-chat-products {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }
  .mfx-chat-bubble {
    padding: 10px 14px;
    font-size: 0.9rem;
  }
  .mfx-chat-msg {
    max-width: 92%;
  }
}
