/* ==========================================================================
   TTPixel AI Live Chat Widget — Premium UI v2.0
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ttpixel-primary: #6366f1;
  --ttpixel-secondary: #4f46e5;
  --ttpixel-accent: #818cf8;
  --ttpixel-bg: #0a0f1e;
  --ttpixel-surface: #111827;
  --ttpixel-card-bg: #1a2235;
  --ttpixel-border: rgba(255, 255, 255, 0.08);
  --ttpixel-text-main: #f1f5f9;
  --ttpixel-text-muted: #64748b;
  --ttpixel-text-soft: #94a3b8;
  --ttpixel-user-msg-bg: linear-gradient(135deg, #6366f1, #4f46e5);
  --ttpixel-bot-msg-bg: #1e2d45;
  --ttpixel-shadow-lg: 0 32px 64px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(99, 102, 241, 0.15);
  --ttpixel-radius: 20px;
  --ttpixel-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ttpixel-green: #10b981;
}

/* ---- Container ---- */
#ttpixel-chat-container {
  position: fixed;
  bottom: 28px;
  z-index: 999999;
  font-family: var(--ttpixel-font);
  font-size: 14px;
  line-height: 1.6;
  box-sizing: border-box;
}

#ttpixel-chat-container * {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

#ttpixel-chat-container.ttpixel-pos-right { right: 28px; }
#ttpixel-chat-container.ttpixel-pos-left  { left: 28px; }

/* ---- Floating Toggle Button ---- */
#ttpixel-chat-toggle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ttpixel-primary), var(--ttpixel-secondary));
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5), 0 0 0 0 rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  outline: none;
  animation: ttpixel-ring-pulse 3s infinite;
}

@keyframes ttpixel-ring-pulse {
  0%   { box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5), 0 0 0 0 rgba(99, 102, 241, 0.4); }
  70%  { box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5), 0 0 0 14px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5), 0 0 0 0 rgba(99, 102, 241, 0); }
}

#ttpixel-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 36px rgba(99, 102, 241, 0.65);
  animation: none;
}

#ttpixel-chat-toggle:active { transform: scale(0.93); }

/* Unread Badge */
.ttpixel-toggle-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0a0f1e;
  animation: ttpixel-badge-pulse 1.8s infinite ease-in-out;
}

@keyframes ttpixel-badge-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}

.ttpixel-icon-open, .ttpixel-icon-close {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#ttpixel-chat-toggle .ttpixel-icon-close { display: none; }
#ttpixel-chat-toggle.active .ttpixel-icon-open  { display: none; }
#ttpixel-chat-toggle.active .ttpixel-icon-close { display: flex; }

/* ---- Chat Window ---- */
#ttpixel-chat-window {
  width: 390px;
  height: 600px;
  max-height: calc(100vh - 110px);
  background: var(--ttpixel-bg);
  color: var(--ttpixel-text-main);
  border-radius: var(--ttpixel-radius);
  box-shadow: var(--ttpixel-shadow-lg);
  border: 1px solid rgba(99, 102, 241, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: 80px;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s;
  transform-origin: bottom right;
}

#ttpixel-chat-container.ttpixel-pos-left #ttpixel-chat-window {
  left: 0;
  transform-origin: bottom left;
}
#ttpixel-chat-container.ttpixel-pos-right #ttpixel-chat-window {
  right: 0;
}

#ttpixel-chat-window.ttpixel-chat-hidden {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.88) translateY(24px);
  pointer-events: none;
}

/* ---- Header ---- */
.ttpixel-chat-header {
  padding: 18px 20px;
  background: linear-gradient(135deg, var(--ttpixel-primary) 0%, var(--ttpixel-secondary) 60%, #3730a3 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.ttpixel-chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
  pointer-events: none;
}

.ttpixel-header-info {
  display: flex;
  align-items: center;
  gap: 13px;
  position: relative;
  z-index: 1;
}

.ttpixel-avatar-wrapper { position: relative; }

.ttpixel-avatar-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.ttpixel-avatar-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ttpixel-online-indicator {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: var(--ttpixel-green);
  border: 2.5px solid var(--ttpixel-primary);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
  animation: ttpixel-online-glow 2.5s infinite;
}

@keyframes ttpixel-online-glow {
  0%, 100% { box-shadow: 0 0 4px rgba(16,185,129,0.5); }
  50%       { box-shadow: 0 0 10px rgba(16,185,129,0.9); }
}

.ttpixel-header-text h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.ttpixel-header-text p {
  margin: 3px 0 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 400;
}

.ttpixel-header-actions {
  display: flex;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.ttpixel-header-actions button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.15s ease;
  backdrop-filter: blur(6px);
}

.ttpixel-header-actions button:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.08);
}

/* ---- Messages Body ---- */
.ttpixel-chat-body {
  flex: 1;
  padding: 20px 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--ttpixel-bg);
  scroll-behavior: smooth;
}

.ttpixel-chat-body::-webkit-scrollbar { width: 4px; }
.ttpixel-chat-body::-webkit-scrollbar-track { background: transparent; }
.ttpixel-chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
.ttpixel-chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---- Message Rows ---- */
.ttpixel-message-row {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: ttpixel-msg-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes ttpixel-msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.ttpixel-message-row.ttpixel-user-row {
  align-self: flex-end;
  align-items: flex-end;
}

.ttpixel-message-row.ttpixel-bot-row {
  align-self: flex-start;
  align-items: flex-start;
}

/* ---- Message Bubbles ---- */
.ttpixel-message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  word-break: break-word;
  font-size: 13.5px;
  line-height: 1.65;
  position: relative;
}

.ttpixel-user-row .ttpixel-message-bubble {
  background: linear-gradient(135deg, var(--ttpixel-primary), var(--ttpixel-secondary));
  color: #ffffff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.ttpixel-bot-row .ttpixel-message-bubble {
  background: var(--ttpixel-bot-msg-bg);
  color: #e2e8f0;
  border-bottom-left-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.ttpixel-message-time {
  font-size: 10px;
  color: var(--ttpixel-text-muted);
  margin-top: 5px;
  padding: 0 6px;
  font-weight: 400;
}

/* ---- Markdown Formatting inside Bot Bubble ---- */
.ttpixel-bot-row .ttpixel-message-bubble h1,
.ttpixel-bot-row .ttpixel-message-bubble h2,
.ttpixel-bot-row .ttpixel-message-bubble h3 {
  margin: 10px 0 6px;
  color: #f1f5f9;
  font-weight: 700;
  line-height: 1.3;
}

.ttpixel-bot-row .ttpixel-message-bubble h1 { font-size: 16px; }
.ttpixel-bot-row .ttpixel-message-bubble h2 { font-size: 14.5px; }
.ttpixel-bot-row .ttpixel-message-bubble h3 { font-size: 13.5px; }

.ttpixel-bot-row .ttpixel-message-bubble p {
  margin: 0 0 8px;
  color: #cbd5e1;
}
.ttpixel-bot-row .ttpixel-message-bubble p:last-child { margin-bottom: 0; }

.ttpixel-bot-row .ttpixel-message-bubble ul,
.ttpixel-bot-row .ttpixel-message-bubble ol {
  margin: 8px 0;
  padding-left: 22px;
}

.ttpixel-bot-row .ttpixel-message-bubble li {
  margin: 4px 0;
  color: #cbd5e1;
  line-height: 1.6;
}

.ttpixel-bot-row .ttpixel-message-bubble li::marker { color: var(--ttpixel-accent); }

.ttpixel-bot-row .ttpixel-message-bubble strong {
  color: #f1f5f9;
  font-weight: 600;
}

.ttpixel-bot-row .ttpixel-message-bubble em { color: #a5b4fc; }

.ttpixel-bot-row .ttpixel-message-bubble code {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  padding: 2px 7px;
  border-radius: 5px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.ttpixel-bot-row .ttpixel-message-bubble pre {
  background: #060b16;
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
}

.ttpixel-bot-row .ttpixel-message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: #a5f3fc;
  font-size: 12.5px;
}

.ttpixel-bot-row .ttpixel-message-bubble a {
  color: #818cf8;
  text-decoration: none;
  border-bottom: 1px solid rgba(129, 140, 248, 0.4);
  transition: color 0.2s, border-color 0.2s;
}

.ttpixel-bot-row .ttpixel-message-bubble a:hover {
  color: #a5b4fc;
  border-color: rgba(165, 180, 252, 0.7);
}

.ttpixel-bot-row .ttpixel-message-bubble blockquote {
  border-left: 3px solid var(--ttpixel-accent);
  margin: 8px 0;
  padding: 6px 12px;
  background: rgba(99, 102, 241, 0.08);
  border-radius: 0 6px 6px 0;
  color: #94a3b8;
  font-style: italic;
}

.ttpixel-bot-row .ttpixel-message-bubble hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 10px 0;
}

/* ---- Typing Indicator ---- */
.ttpixel-typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: var(--ttpixel-bot-msg-bg);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  border: 1px solid rgba(255,255,255,0.07);
  width: fit-content;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.ttpixel-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--ttpixel-accent);
  border-radius: 50%;
  opacity: 0.6;
  animation: ttpixel-bounce 1.4s infinite ease-in-out both;
}

.ttpixel-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ttpixel-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.ttpixel-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes ttpixel-bounce {
  0%, 80%, 100% { transform: scale(0.4); opacity: 0.3; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ---- Quick Questions ---- */
.ttpixel-quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 14px;
  background: var(--ttpixel-bg);
  border-top: 1px solid var(--ttpixel-border);
  flex-shrink: 0;
}

.ttpixel-quick-btn {
  background: rgba(99, 102, 241, 0.1);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.28);
  padding: 6px 13px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.22s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--ttpixel-font);
}

.ttpixel-quick-btn:hover {
  background: var(--ttpixel-primary);
  color: #ffffff;
  border-color: var(--ttpixel-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}

.ttpixel-quick-btn:active { transform: translateY(0); }

/* ---- Footer / Input Area ---- */
.ttpixel-chat-footer {
  padding: 12px 14px 14px;
  background: var(--ttpixel-surface);
  border-top: 1px solid var(--ttpixel-border);
  flex-shrink: 0;
}

#ttpixel-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ttpixel-card-bg);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 26px;
  padding: 6px 8px 6px 16px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

#ttpixel-chat-form:focus-within {
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

#ttpixel-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f1f5f9;
  font-size: 13.5px;
  font-family: var(--ttpixel-font);
  resize: none;
  min-height: 24px;
  height: 24px;
  max-height: 90px;
  padding: 3px 0 0 0;
  line-height: 1.4;
  box-sizing: border-box;
  overflow-y: auto;
  display: block;
}

#ttpixel-chat-input::placeholder { color: #475569; }

#ttpixel-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ttpixel-primary), var(--ttpixel-secondary));
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,0.4);
}

#ttpixel-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(99,102,241,0.55);
}

#ttpixel-send-btn:active { transform: scale(0.94); }

#ttpixel-send-btn:disabled {
  background: #2d3748;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.55;
}

/* ---- Footer Branding ---- */
.ttpixel-footer-branding {
  text-align: center;
  font-size: 10px;
  color: #334155;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

.ttpixel-footer-branding strong {
  color: #475569;
  font-weight: 600;
}

/* ---- Date Divider ---- */
.ttpixel-date-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}

.ttpixel-date-divider span {
  font-size: 10px;
  color: var(--ttpixel-text-muted);
  background: var(--ttpixel-card-bg);
  padding: 2px 10px;
  border-radius: 10px;
  white-space: nowrap;
  border: 1px solid var(--ttpixel-border);
}

.ttpixel-date-divider::before,
.ttpixel-date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--ttpixel-border);
}

/* ---- Mobile Responsiveness ---- */
@media (max-width: 480px) {
  #ttpixel-chat-container { bottom: 14px; }
  #ttpixel-chat-container.ttpixel-pos-right { right: 14px; }
  #ttpixel-chat-container.ttpixel-pos-left  { left: 14px; }

  #ttpixel-chat-window {
    width: calc(100vw - 28px);
    height: calc(100svh - 100px);
    bottom: 76px;
    border-radius: 16px;
  }
}
