/**
 * 10 Creative Solutions - Floating Chat Widget Styles
 * Namespaced under #tcs-chat-widget to avoid WordPress theme conflicts
 */

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

/* CSS Variables & Base Styles */
#tcs-chat-widget {
  /* Color Tokens */
  --w-bg: #F6F8FB;
  --w-surface: #FFFFFF;
  --w-surface-2: #F2F5F9;
  --w-text: #0F172A;
  --w-muted: #5B677A;
  --w-border: #E6EAF0;
  --w-ring: #1D9BF0;
  --w-primary: #1E6BFF;
  --w-primary-2: #1557D6;
  --w-primary-contrast: #FFFFFF;
  --w-success: #137A5B;
  --w-warning: #B45309;
  --w-danger: #C2413A;
  --w-danger-bg: #FEF2F2;
  --w-shadow: 0 14px 40px rgba(15, 23, 42, 0.14);
  --w-shadow-soft: 0 8px 18px rgba(15, 23, 42, 0.12);
  --w-radius: 16px;
  --w-radius-sm: 12px;
  --w-radius-xs: 10px;
  
  /* Typography */
  font-family: 'Figtree', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--w-text);
  
  /* Position */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483000;
}

/* Safe area for mobile devices */
@supports (padding: max(0px)) {
  #tcs-chat-widget {
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
  }
}

/* Box sizing reset */
#tcs-chat-widget *,
#tcs-chat-widget *::before,
#tcs-chat-widget *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#tcs-chat-widget button {
  font: inherit;
  border: none;
  cursor: pointer;
  background: none;
}

/* Focus styles */
#tcs-chat-widget :focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(29, 155, 240, 0.35), 0 0 0 5px rgba(29, 155, 240, 0.18);
  border-radius: var(--w-radius-xs);
}

/* ===== LAUNCHER BUTTON ===== */
#tcs-chat-widget .tcs-launcher {
  width: 56px;
  height: 56px;
  background: var(--w-primary);
  color: var(--w-primary-contrast);
  border-radius: 18px;
  box-shadow: var(--w-shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 120ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

#tcs-chat-widget .tcs-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(30, 107, 255, 0.3);
}

#tcs-chat-widget .tcs-launcher:active {
  transform: scale(0.98);
}

@media (max-width: 640px) {
  #tcs-chat-widget .tcs-launcher {
    width: 52px;
    height: 52px;
  }
}

/* ===== CHAT PANEL ===== */
#tcs-chat-widget .tcs-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 96px));
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
  box-shadow: var(--w-shadow);
  display: flex;
  flex-direction: column;
  animation: panelOpen 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

@media (max-width: 640px) {
  #tcs-chat-widget .tcs-panel {
    right: 12px;
    left: 12px;
    width: calc(100vw - 24px);
    bottom: 76px;
  }
}

/* ===== HEADER ===== */
#tcs-chat-widget .tcs-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--w-border);
  background: var(--w-surface);
  border-radius: var(--w-radius) var(--w-radius) 0 0;
}

#tcs-chat-widget .tcs-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

#tcs-chat-widget .tcs-header-text {
  flex: 1;
}

#tcs-chat-widget .tcs-title {
  font-family: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--w-text);
  line-height: 1.25;
}

#tcs-chat-widget .tcs-subtitle {
  font-size: 12px;
  color: var(--w-muted);
  line-height: 1.25;
}

#tcs-chat-widget .tcs-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--w-muted);
  border-radius: 8px;
  transition: background 120ms ease, color 120ms ease;
}

#tcs-chat-widget .tcs-close-btn:hover {
  background: var(--w-surface-2);
  color: var(--w-text);
}

/* ===== MESSAGES AREA ===== */
#tcs-chat-widget .tcs-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--w-bg);
}

/* Custom scrollbar */
#tcs-chat-widget .tcs-messages::-webkit-scrollbar {
  width: 6px;
}

#tcs-chat-widget .tcs-messages::-webkit-scrollbar-track {
  background: transparent;
}

#tcs-chat-widget .tcs-messages::-webkit-scrollbar-thumb {
  background: var(--w-border);
  border-radius: 3px;
}

#tcs-chat-widget .tcs-messages::-webkit-scrollbar-thumb:hover {
  background: var(--w-muted);
}

/* ===== EMPTY STATE ===== */
#tcs-chat-widget .tcs-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--w-muted);
}

#tcs-chat-widget .tcs-empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--w-text);
  margin-bottom: 8px;
}

#tcs-chat-widget .tcs-empty-state p {
  font-size: 14px;
  line-height: 1.5;
}

/* ===== MESSAGE BUBBLES ===== */
#tcs-chat-widget .tcs-message {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

#tcs-chat-widget .tcs-message-user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

#tcs-chat-widget .tcs-message-assistant {
  align-self: flex-start;
}

#tcs-chat-widget .tcs-message-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

#tcs-chat-widget .tcs-message-content {
  padding: 10px 12px;
  border-radius: var(--w-radius-sm);
  max-width: 80%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#tcs-chat-widget .tcs-message-user .tcs-message-content {
  background: var(--w-primary);
  color: var(--w-primary-contrast);
  border: none;
}

#tcs-chat-widget .tcs-message-assistant .tcs-message-content {
  background: var(--w-surface-2);
  color: var(--w-text);
  border: 1px solid var(--w-border);
}

/* ===== TYPING INDICATOR ===== */
#tcs-chat-widget .tcs-typing {
  display: flex;
  gap: 8px;
  align-items: center;
  align-self: flex-start;
}

#tcs-chat-widget .tcs-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--w-surface-2);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius-sm);
}

#tcs-chat-widget .tcs-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--w-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

#tcs-chat-widget .tcs-typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

#tcs-chat-widget .tcs-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

#tcs-chat-widget .tcs-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-3px);
  }
}

/* ===== ERROR BANNER ===== */
#tcs-chat-widget .tcs-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--w-danger-bg);
  border-top: 1px solid var(--w-border);
}

#tcs-chat-widget .tcs-error-text {
  flex: 1;
  font-size: 13px;
  color: var(--w-danger);
}

#tcs-chat-widget .tcs-error-retry {
  padding: 6px 12px;
  background: var(--w-danger);
  color: white;
  border-radius: var(--w-radius-xs);
  font-size: 13px;
  font-weight: 600;
  transition: background 120ms ease;
}

#tcs-chat-widget .tcs-error-retry:hover {
  background: #A73530;
}

/* ===== INPUT COMPOSER ===== */
#tcs-chat-widget .tcs-composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--w-border);
  background: var(--w-surface);
  align-items: flex-end;
}

#tcs-chat-widget .tcs-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius-xs);
  font-family: inherit;
  font-size: 14px;
  color: var(--w-text);
  background: var(--w-surface);
  resize: none;
  max-height: 120px;
  transition: border-color 120ms ease;
}

#tcs-chat-widget .tcs-input:focus {
  border-color: var(--w-ring);
  outline: none;
}

#tcs-chat-widget .tcs-input::placeholder {
  color: var(--w-muted);
}

#tcs-chat-widget .tcs-send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--w-primary);
  color: var(--w-primary-contrast);
  border-radius: var(--w-radius-xs);
  transition: background 120ms ease, transform 120ms ease;
  flex-shrink: 0;
}

#tcs-chat-widget .tcs-send-btn:hover:not(:disabled) {
  background: var(--w-primary-2);
}

#tcs-chat-widget .tcs-send-btn:active:not(:disabled) {
  transform: scale(0.98);
}

#tcs-chat-widget .tcs-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== WATERMARK ===== */
#tcs-chat-widget .tcs-watermark {
  padding: 10px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--w-muted);
  background: var(--w-surface);
  border-top: 1px solid var(--w-border);
  border-radius: 0 0 var(--w-radius) var(--w-radius);
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  #tcs-chat-widget * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
