/* ========================================================
   TCTarget AI Chatbot Widget Styles
   Ultra-modern Glassmorphism & High-tech Aesthetic
   ======================================================== */

:root {
  --tc-primary: #2563eb;
  --tc-primary-hover: #1d4ed8;
  --tc-accent: #06b6d4;
  --tc-bg-dark: #0f172a;
  --tc-bg-card: #1e293b;
  --tc-text-main: #f8fafc;
  --tc-text-muted: #94a3b8;
  --tc-border: rgba(255, 255, 255, 0.1);
  --tc-user-bubble: #2563eb;
  --tc-bot-bubble: #1e293b;
  --tc-admin-bubble: #059669;
  --tc-radius-lg: 20px;
  --tc-radius-md: 12px;
  --tc-radius-sm: 8px;
  --tc-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5), 0 0 25px rgba(37, 99, 235, 0.2);
}

/* Floating Launcher Button */
#tc-chatbot-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4), 0 0 20px rgba(6, 182, 212, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99999;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

#tc-chatbot-launcher:hover {
  transform: scale(1.08) translateY(-3px);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.5), 0 0 30px rgba(6, 182, 212, 0.4);
}

#tc-chatbot-launcher svg {
  width: 30px;
  height: 30px;
  fill: #ffffff;
  transition: transform 0.3s ease;
}

#tc-chatbot-launcher.active svg {
  transform: rotate(90deg);
}

/* Notification Badge */
.tc-badge-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background-color: #10b981;
  border-radius: 50%;
  border: 2px solid #0f172a;
  animation: tc-pulse 2s infinite;
}

@keyframes tc-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Centered Modal Backdrop for PC Browser */
#tc-chatbot-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(11, 15, 25, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 99997;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
#tc-chatbot-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* Chat Widget Container - Default PC Centered Large Layout */
#tc-chatbot-window {
  position: fixed;
  top: 50%;
  left: 50%;
  bottom: auto;
  right: auto;
  width: 860px;
  max-width: calc(100vw - 50px);
  height: 720px;
  max-height: calc(100vh - 80px);
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--tc-radius-lg);
  box-shadow: 0 25px 60px -10px rgba(0, 0, 0, 0.8), 0 0 35px rgba(37, 99, 235, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99998;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -46%) scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

#tc-chatbot-window.open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

/* Responsive Mobile Layout (iOS Safari & Chrome Compatibility) */
@media (max-width: 768px) {
  #tc-chatbot-backdrop {
    display: none;
  }

  /* Prevent background page scroll on mobile while chat is open */
  body.tc-chatbot-open {
    overflow: hidden !important;
    touch-action: none !important;
  }

  #tc-chatbot-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    /* Uses exact JS-measured viewport height (--tc-real-vh) to perfectly clear iOS Chrome bottom bar */
    height: var(--tc-real-vh, 100%) !important;
    max-height: var(--tc-real-vh, 100%) !important;
    border-radius: 0 !important;
    border: none !important;
    transform: translateY(100%) !important;
    z-index: 100000 !important;
    box-shadow: none !important;
    touch-action: auto !important;
  }

  #tc-chatbot-window.open {
    transform: translateY(0) !important;
  }

  /* Hide floating launcher when chat window is open on mobile */
  #tc-chatbot-launcher.active,
  body.tc-chatbot-open #tc-chatbot-launcher {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: scale(0.5) !important;
  }

  #tc-chatbot-launcher {
    bottom: 20px !important;
    right: 20px !important;
    width: 56px !important;
    height: 56px !important;
  }

  .tc-chat-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px 16px !important;
    flex-shrink: 0 !important;
  }

  /* Footer: ensure input sits clearly above iOS Chrome toolbar and Home indicator */
  .tc-chat-footer {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 12px)) 14px !important;
    background: rgba(15, 23, 42, 0.98) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
    flex-shrink: 0 !important;
    z-index: 10 !important;
  }

  /* Prevent iOS Safari/Chrome from auto-zooming input field */
  .tc-chat-input {
    font-size: 16px !important;
    padding: 10px 12px !important;
  }

  .tc-quick-replies {
    padding: 6px 14px 8px 14px !important;
    flex-shrink: 0 !important;
  }
}

/* Header */
.tc-chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.95) 100%);
  border-bottom: 1px solid var(--tc-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tc-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tc-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.tc-header-avatar svg {
  width: 24px;
  height: 24px;
  fill: #ffffff;
}

.tc-header-title {
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
}

.tc-header-subtitle {
  font-size: 12px;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.tc-status-dot {
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  display: inline-block;
}

.tc-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tc-header-actions button {
  background: transparent;
  border: none;
  color: var(--tc-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.tc-header-actions button:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

/* Multi-language Selector */
.tc-lang-dropdown {
  position: relative;
}

.tc-lang-btn {
  display: flex !important;
  align-items: center !important;
  gap: 4px !important;
  background: rgba(255, 255, 255, 0.08) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  color: #e2e8f0 !important;
  font-size: 11.5px !important;
  font-weight: 600 !important;
  padding: 5px 8px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
}

.tc-lang-btn:hover {
  background: rgba(255, 255, 255, 0.15) !important;
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
}

.tc-lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 175px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6);
  padding: 5px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 100005;
  backdrop-filter: blur(12px);
}

.tc-lang-menu.open {
  display: flex;
}

.tc-lang-item {
  padding: 8px 12px;
  font-size: 12px;
  color: #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.tc-lang-item:hover {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.tc-lang-item.active {
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
}

/* Handoff Banner */
.tc-handoff-banner {
  background: linear-gradient(90deg, #065f46, #047857);
  color: #ecfdf5;
  padding: 8px 16px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(16, 185, 129, 0.3);
}

.tc-handoff-banner.hidden {
  display: none;
}

/* Messages Area */
.tc-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.tc-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.tc-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

/* Message Item */
.tc-msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.tc-msg-wrapper.user {
  align-self: flex-end;
  align-items: flex-end;
}

.tc-msg-wrapper.model, .tc-msg-wrapper.admin {
  align-self: flex-start;
  align-items: flex-start;
}

.tc-msg-sender {
  font-size: 11px;
  color: var(--tc-text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.tc-msg-bubble {
  padding: 12px 16px;
  border-radius: var(--tc-radius-md);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--tc-text-main);
  word-break: break-word;
  position: relative;
}

.tc-msg-wrapper.user .tc-msg-bubble {
  background: var(--tc-user-bubble);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.tc-msg-wrapper.model .tc-msg-bubble {
  background: var(--tc-bot-bubble);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--tc-border);
}

.tc-msg-wrapper.admin .tc-msg-bubble {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.tc-msg-time {
  font-size: 10px;
  color: var(--tc-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Markdown formatting inside bubbles */
.tc-msg-bubble p {
  margin: 0 0 8px 0;
}
.tc-msg-bubble p:last-child {
  margin-bottom: 0;
}

/* Headings */
.tc-msg-bubble h3 {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  margin: 14px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  letter-spacing: 0.2px;
}
.tc-msg-bubble h3:first-child {
  margin-top: 0;
}

.tc-msg-bubble h4 {
  font-size: 14px;
  font-weight: 700;
  color: #38bdf8;
  margin: 12px 0 6px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tc-msg-bubble h4:first-child {
  margin-top: 0;
}

.tc-msg-bubble h5, .tc-msg-bubble h6 {
  font-size: 13.5px;
  font-weight: 600;
  color: #93c5fd;
  margin: 10px 0 4px 0;
}

/* Horizontal Dividers */
.tc-msg-bubble hr.tc-divider {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0.05) 100%);
  margin: 12px 0;
}

/* Lists */
.tc-msg-bubble ul, .tc-msg-bubble ol {
  margin: 6px 0 10px 20px;
  padding: 0;
}
.tc-msg-bubble li {
  margin-bottom: 5px;
  line-height: 1.55;
  color: #e2e8f0;
}
.tc-msg-bubble li:last-child {
  margin-bottom: 0;
}

/* Links & Inline Code */
.tc-msg-bubble a {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
  transition: color 0.15s ease;
}
.tc-msg-bubble a:hover {
  color: #7dd3fc;
}

.tc-msg-bubble code {
  background: rgba(15, 23, 42, 0.7);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: #38bdf8;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tc-msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}
.tc-msg-bubble th, .tc-msg-bubble td {
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 10px;
  text-align: left;
}
.tc-msg-bubble th {
  background: rgba(255, 255, 255, 0.08);
  color: #38bdf8;
  font-weight: 600;
}
.tc-msg-bubble img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 10px;
  margin-bottom: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.tc-msg-bubble img:hover {
  transform: scale(1.015);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* Quick Replies Chips */
.tc-quick-replies {
  flex-shrink: 0;
  padding: 8px 16px 12px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
}
.tc-quick-replies::-webkit-scrollbar {
  height: 0px;
}
.tc-chip-btn {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #38bdf8;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tc-chip-btn:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* Typing Indicator */
.tc-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--tc-bot-bubble);
  border-radius: var(--tc-radius-md);
  width: fit-content;
  border: 1px solid var(--tc-border);
}
.tc-typing-dot {
  width: 6px;
  height: 6px;
  background: #38bdf8;
  border-radius: 50%;
  animation: tc-typing 1.4s infinite ease-in-out both;
}
.tc-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.tc-typing-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* Footer Input Area */
.tc-chat-footer {
  flex-shrink: 0;
  padding: 14px 16px;
  background: rgba(30, 41, 59, 0.95);
  border-top: 1px solid var(--tc-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.tc-chat-input {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--tc-border);
  border-radius: var(--tc-radius-md);
  padding: 10px 14px;
  color: #ffffff;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.2s ease;
}

.tc-chat-input:focus {
  border-color: var(--tc-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.tc-chat-input::placeholder {
  color: var(--tc-text-muted);
}

.tc-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--tc-radius-md);
  background: var(--tc-primary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tc-send-btn:hover {
  background: var(--tc-primary-hover);
  transform: scale(1.05);
}

.tc-send-btn svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
}

.tc-handoff-action-btn {
  background: transparent;
  border: none;
  color: #38bdf8;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.tc-handoff-action-btn:hover {
  background: rgba(56, 189, 248, 0.15);
}
