/* ═══════════════════════════════════════════════════════════════
   Asset Foundry — Custom Chat Widget
   ═══════════════════════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --af-chat-dark:    #1D1D1F;
  --af-chat-dark-2:  #2d2d2f;
  --af-chat-green:   #059669;
  --af-chat-green-2: #34d399;
  --af-chat-light:   #F5F5F7;
  --af-chat-border:  rgba(0,0,0,0.06);
  --af-chat-radius:  20px;
  --af-chat-w:       380px;
  --af-chat-w-reg:   700px;
  --af-chat-h:       580px;
  --af-chat-sidebar: 220px;
  --af-chat-z:       9998;
}

/* ── Float button ── */
#af-chat-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--af-chat-dark);
  box-shadow: 0 8px 28px rgba(0,0,0,0.30);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--af-chat-z);
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#af-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 36px rgba(0,0,0,0.35);
}
#af-chat-btn svg { display: block; }

/* ── Chat window (shared) ── */
#af-chat-window {
  position: fixed;
  bottom: 88px;
  right: 20px;
  width: var(--af-chat-w);
  height: var(--af-chat-h);
  border-radius: var(--af-chat-radius);
  background: #fff;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18);
  border: 1px solid var(--af-chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--af-chat-z);
  transform-origin: bottom right;
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
#af-chat-window.af-hidden {
  opacity: 0;
  transform: scale(0.88) translateY(16px);
  pointer-events: none;
}
#af-chat-window.af-chat--registered {
  width: var(--af-chat-w-reg);
}

/* ── Header ── */
.af-chat-header {
  background: var(--af-chat-dark);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.af-chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--af-chat-dark-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.af-chat-header-info { flex: 1; min-width: 0; }
.af-chat-header-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  color: #f3f4f6;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.af-chat-header-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.af-chat-header-sub span { color: var(--af-chat-green-2); font-weight: 600; }
.af-chat-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  transition: color 0.15s;
  flex-shrink: 0;
}
.af-chat-close:hover { color: rgba(255,255,255,0.9); }

/* ── Body layout (visitor = single col, registered = split) ── */
.af-chat-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar (registered only) ── */
.af-chat-sidebar {
  width: var(--af-chat-sidebar);
  flex-shrink: 0;
  background: var(--af-chat-light);
  border-right: 1px solid var(--af-chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.af-new-chat-btn {
  margin: 12px 12px 8px;
  padding: 10px 14px;
  background: var(--af-chat-dark);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.af-new-chat-btn:hover { opacity: 0.85; }
.af-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}
.af-conv-item {
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 3px;
}
.af-conv-item:hover { background: rgba(0,0,0,0.05); }
.af-conv-item.af-active { background: rgba(0,0,0,0.09); }
.af-conv-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 5px;
  display: inline-block;
  margin-bottom: 4px;
}
.af-conv-badge.personal { background: #ede9fe; color: #7c3aed; }
.af-conv-badge.catalogo { background: #d1fae5; color: #065f46; }
.af-conv-title {
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  color: var(--af-chat-dark);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.af-conv-date {
  font-size: 10.5px;
  color: #aaa;
  margin-top: 3px;
}
.af-conv-delete {
  float: right;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.af-conv-item:hover .af-conv-delete { opacity: 1; }
.af-conv-delete:hover { color: #ef4444; }
.af-sidebar-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: #bbb;
  line-height: 1.5;
  text-align: center;
}

/* ── Main chat area ── */
.af-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.af-chat-conv-title {
  padding: 12px 16px 8px;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--af-chat-dark);
  border-bottom: 1px solid var(--af-chat-border);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Messages ── */
.af-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--af-chat-light);
}
.af-messages::-webkit-scrollbar { width: 4px; }
.af-messages::-webkit-scrollbar-track { background: transparent; }
.af-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 4px; }

.af-msg {
  display: flex;
  max-width: 82%;
}
.af-msg.af-msg--user { align-self: flex-end; }
.af-msg.af-msg--bot  { align-self: flex-start; }
.af-msg-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
}
.af-msg--bot .af-msg-bubble {
  background: #fff;
  color: var(--af-chat-dark);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.af-msg--user .af-msg-bubble {
  background: var(--af-chat-dark);
  color: #fff;
  border-bottom-right-radius: 4px;
}
/* Markdown in bubbles */
.af-msg-bubble strong { font-weight: 700; }
.af-msg-bubble em { font-style: italic; }
.af-msg-bubble hr {
  border: none;
  border-top: 1px solid rgba(0,0,0,0.12);
  margin: 8px 0;
}
.af-msg-bubble a {
  color: var(--af-chat-green);
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
}
.af-msg--user .af-msg-bubble a { color: var(--af-chat-green-2); }
.af-msg-bubble h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  margin: 6px 0 4px;
}

/* Typing indicator */
.af-typing { display: flex; align-items: center; gap: 4px; padding: 12px 14px; }
.af-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #aaa;
  animation: af-bounce 1.2s infinite ease-in-out;
}
.af-typing span:nth-child(2) { animation-delay: 0.2s; }
.af-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes af-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ── Input area ── */
.af-chat-input {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--af-chat-border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.af-chat-textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  overflow-y: auto;
  background: var(--af-chat-light);
  color: var(--af-chat-dark);
  transition: border-color 0.15s;
}
.af-chat-textarea:focus { border-color: var(--af-chat-dark); }
.af-chat-textarea::placeholder { color: #aaa; }
.af-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--af-chat-dark);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.af-chat-send:hover { opacity: 0.8; }
.af-chat-send:disabled { opacity: 0.35; cursor: default; }
.af-chat-send svg { display: block; }

/* ── Empty state (no conversations) ── */
.af-chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #aaa;
}
.af-chat-empty-state p { font-size: 13px; line-height: 1.5; margin-top: 8px; }

/* ── Book cards ── */
.af-book-card {
  display: flex;
  gap: 12px;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.07);
  border-radius: 14px;
  padding: 12px;
  margin: 8px 0 4px;
  max-width: 320px;
  align-self: flex-start;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: box-shadow 0.15s;
}
.af-book-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.10); }
.af-book-card-cover {
  width: 64px;
  height: 88px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f0f0f2;
  cursor: pointer;
}
.af-book-card-cover img {
  width: 100%; height: 100%; object-fit: cover;
}
.af-book-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.af-book-card-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--af-chat-dark);
  line-height: 1.3;
  cursor: pointer;
}
.af-book-card-title:hover { color: var(--af-chat-green); }
.af-book-card-synopsis {
  font-size: 11.5px;
  color: #777;
  line-height: 1.45;
  cursor: pointer;
}
.af-book-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
}
.af-book-card-original {
  font-size: 11px;
  color: #bbb;
  text-decoration: line-through;
}
.af-book-card-buy {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--af-chat-dark);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: 'Inter', sans-serif;
}
.af-book-card-buy:hover { opacity: 0.8; }

/* ── Mobile ── */
@media (max-width: 640px) {
  #af-chat-window {
    right: 0; bottom: 0;
    width: 100vw !important;
    height: 92vh;
    border-radius: var(--af-chat-radius) var(--af-chat-radius) 0 0;
  }
  #af-chat-btn { bottom: 16px; right: 16px; }
  .af-chat-sidebar { width: 180px; }
  .af-conv-title { font-size: 12px; }
}
@media (max-width: 480px) {
  .af-chat-sidebar { display: none; }
  .af-chat-sidebar.af-sidebar--open { display: flex; position: absolute; top: 0; left: 0; height: 100%; z-index: 10; width: 240px; box-shadow: 4px 0 16px rgba(0,0,0,0.1); }
}
