/*
    TAT AI Assistant - Premium Chatbot Experience
*/

:root {
  --tat-ai-primary: #c9b18c;
  --tat-ai-primary-dark: #a1886d;
  --tat-ai-text: #1a1a1a;
  --tat-ai-text-light: #8e8e8e;
  --tat-ai-bg: #f8f8f8;
  --tat-ai-surface: #ffffff;
  --tat-ai-border: rgba(201, 177, 140, 0.2);
  --tat-ai-shadow: rgba(26, 26, 26, 0.15);
  --tat-ai-success: #10b981;
  --tat-ai-radius: 24px;
  --tat-ai-radius-sm: 16px;
}

/* Touch and Accessibility Optimizations */
.tat-ai-assistant-wrapper * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.tat-ai-text-input {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

.tat-ai-message-bubble {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

/* iOS Specific Optimizations */
@supports (-webkit-appearance: none) {
  .tat-ai-chat-window {
    -webkit-backdrop-filter: blur(20px);
  }

  .tat-ai-messages-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  .tat-ai-text-input {
    -webkit-appearance: none;
    -webkit-border-radius: 0;
    border-radius: var(--tat-ai-radius-sm);
  }

  .tat-ai-launch-btn,
  .tat-ai-send-btn,
  .tat-ai-close-btn {
    -webkit-appearance: none;
    -webkit-border-radius: 0;
  }
}

/* High DPI / Retina Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .tat-ai-launch-btn {
    box-shadow: 0 8px 32px var(--tat-ai-shadow), 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .tat-ai-chat-window {
    box-shadow: 0 20px 60px rgba(54, 36, 25, 0.25),
      0 4px 16px rgba(0, 0, 0, 0.1);
  }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
  .tat-ai-pulse-ring {
    animation: none;
  }

  .tat-ai-typing-dot {
    animation: none;
  }

  .tat-ai-status::before {
    animation: none;
  }

  .tat-ai-message-bubble {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .tat-ai-chat-window {
    transition: opacity 0.2s ease;
  }

  .tat-ai-launch-btn:hover {
    transform: none;
  }

  .tat-ai-send-btn:hover {
    transform: none;
  }
}

/* Main Wrapper */
.tat-ai-assistant-wrapper {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  z-index: 2000 !important;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Mobile Safety Override */
@media (max-width: 768px) {
  .tat-ai-chat-window {
    position: fixed !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
  }

  .tat-ai-window-hidden {
    transform: translateX(-50%) translateY(20px) scale(0.95) !important;
  }

  .tat-ai-window-visible {
    transform: translateX(-50%) translateY(0) scale(1) !important;
  }
}

@media (max-width: 768px) {
  .tat-ai-assistant-wrapper {
    bottom: 16px !important;
    right: 16px !important;
  }
}

/* Launch Button */
.tat-ai-launch-btn {
  position: relative;
  width: 64px;
  height: 64px;
  background: linear-gradient(
    135deg,
    var(--tat-ai-primary),
    var(--tat-ai-primary-dark)
  );
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px var(--tat-ai-shadow);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.tat-ai-launch-btn:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 16px 48px var(--tat-ai-shadow);
}

.tat-ai-launch-btn:active {
  transform: translateY(-2px) scale(1.02);
}

.tat-ai-launch-btn:focus {
  outline: none;
  box-shadow: 0 8px 32px var(--tat-ai-shadow),
    0 0 0 3px rgba(200, 162, 200, 0.4);
}

@media (hover: hover) {
  .tat-ai-launch-btn:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 16px 48px var(--tat-ai-shadow);
  }
}

@media (hover: none) {
  .tat-ai-launch-btn:hover {
    transform: none;
    box-shadow: 0 8px 32px var(--tat-ai-shadow);
  }

  .tat-ai-launch-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
}

.tat-ai-btn-content {
  position: relative;
  z-index: 2;
}

.tat-ai-chat-icon {
  width: 28px;
  height: 28px;
  color: white;
  stroke-width: 2.5;
}

.tat-ai-pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border: 2px solid var(--tat-ai-primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: tat-ai-pulse 2s infinite;
  opacity: 0.6;
}

@keyframes tat-ai-pulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.3);
    opacity: 0.3;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.6);
    opacity: 0;
  }
}

/* Chat Window */
.tat-ai-chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 400px;
  height: 600px;
  max-height: 85vh;
  background: var(--tat-ai-surface);
  border-radius: var(--tat-ai-radius);
  box-shadow: 0 20px 60px rgba(54, 36, 25, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(20px);
  border: 1px solid var(--tat-ai-border);
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.tat-ai-window-hidden {
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
}

.tat-ai-window-visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Window Header */
.tat-ai-window-header {
  background: linear-gradient(
    135deg,
    var(--tat-ai-primary),
    var(--tat-ai-primary-dark)
  );
  color: white;
  padding: 0;
  position: relative;
  overflow: hidden;
}

.tat-ai-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  position: relative;
  z-index: 2;
}

.tat-ai-brand-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tat-ai-avatar-circle {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.tat-ai-avatar-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.tat-ai-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tat-ai-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.tat-ai-status {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tat-ai-status::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--tat-ai-success);
  border-radius: 50%;
  animation: tat-ai-status-pulse 2s infinite;
}

@keyframes tat-ai-status-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.tat-ai-close-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.tat-ai-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

.tat-ai-close-btn:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

@media (hover: none) {
  .tat-ai-close-btn:hover {
    transform: none;
  }

  .tat-ai-close-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
  }
}

.tat-ai-close-icon {
  width: 18px;
  height: 18px;
  color: white;
}

/* Messages Container */
.tat-ai-messages-container {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(
    180deg,
    var(--tat-ai-bg) 0%,
    var(--tat-ai-surface) 100%
  );
}

.tat-ai-messages-container::-webkit-scrollbar {
  width: 6px;
}

.tat-ai-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.tat-ai-messages-container::-webkit-scrollbar-thumb {
  background: var(--tat-ai-border);
  border-radius: 3px;
}

/* Message Bubbles */
.tat-ai-message-bubble {
  max-width: 85%;
  padding: 16px 20px;
  border-radius: 20px;
  line-height: 1.6;
  font-size: 14px;
  opacity: 0;
  transform: translateY(12px);
  animation: tat-ai-message-appear 0.5s ease forwards;
}

@keyframes tat-ai-message-appear {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tat-ai-bot-message {
  background: var(--tat-ai-surface);
  color: var(--tat-ai-text);
  align-self: flex-start;
  border-bottom-left-radius: 8px;
  box-shadow: 0 2px 12px rgba(200, 162, 200, 0.15);
  border: 1px solid var(--tat-ai-border);
}

.tat-ai-user-message {
  background: linear-gradient(
    135deg,
    var(--tat-ai-primary),
    var(--tat-ai-primary-dark)
  );
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 8px;
  box-shadow: 0 2px 12px rgba(200, 162, 200, 0.3);
}

/* Typing Animation */
.tat-ai-typing-animation {
  align-self: flex-start;
  margin-bottom: 8px;
}

.tat-ai-typing-bubble {
  background: var(--tat-ai-surface);
  border: 1px solid var(--tat-ai-border);
  padding: 16px 20px;
  border-radius: 20px;
  border-bottom-left-radius: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 12px rgba(200, 162, 200, 0.15);
}

.tat-ai-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--tat-ai-primary);
  border-radius: 50%;
  animation: tat-ai-typing-bounce 1.4s infinite both;
}

.tat-ai-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.tat-ai-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes tat-ai-typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-12px);
  }
}

.tat-ai-hidden {
  display: none !important;
}

/* Screen Reader Only Content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Input Section */
.tat-ai-input-section {
  padding: 20px 24px;
  background: var(--tat-ai-surface);
  border-top: 1px solid var(--tat-ai-border);
}

.tat-ai-message-form {
  width: 100%;
}

.tat-ai-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tat-ai-bg);
  border-radius: var(--tat-ai-radius-sm);
  padding: 4px 4px 4px 20px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.tat-ai-input-wrapper:focus-within {
  border-color: var(--tat-ai-primary);
  background: var(--tat-ai-surface);
  box-shadow: 0 0 0 4px rgba(200, 162, 200, 0.1);
}

.tat-ai-text-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 0;
  font-size: 14px;
  color: var(--tat-ai-text);
  outline: none;
  font-family: inherit;
}

.tat-ai-text-input::placeholder {
  color: var(--tat-ai-text-light);
}

.tat-ai-send-btn {
  width: 40px;
  height: 40px;
  background: linear-gradient(
    135deg,
    var(--tat-ai-primary),
    var(--tat-ai-primary-dark)
  );
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.tat-ai-send-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(200, 162, 200, 0.4);
}

.tat-ai-send-btn:active {
  transform: translateY(0) scale(1);
}

.tat-ai-send-btn:focus {
  outline: none;
  box-shadow: 0 6px 20px rgba(200, 162, 200, 0.4),
    0 0 0 3px rgba(200, 162, 200, 0.3);
}

@media (hover: hover) {
  .tat-ai-send-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(200, 162, 200, 0.4);
  }
}

@media (hover: none) {
  .tat-ai-send-btn:hover {
    transform: none;
  }

  .tat-ai-send-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
}

.tat-ai-send-icon {
  width: 18px;
  height: 18px;
  color: white;
  stroke-width: 2.5;
}

/* Device Optimizations */

/* Large Desktop (1440px+) */
@media (min-width: 1440px) {
  .tat-ai-chat-window {
    width: 420px;
    height: 650px;
  }

  .tat-ai-launch-btn {
    width: 68px;
    height: 68px;
  }

  .tat-ai-chat-icon {
    width: 30px;
    height: 30px;
  }
}

/* Desktop (1024px - 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
  .tat-ai-chat-window {
    width: 400px;
    height: 600px;
  }
}

/* Tablet Landscape (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .tat-ai-assistant-wrapper {
    bottom: 20px !important;
    right: 20px !important;
  }

  .tat-ai-chat-window {
    width: 380px;
    height: 70vh;
    max-height: 550px;
    bottom: 75px;
  }

  .tat-ai-launch-btn {
    width: 60px;
    height: 60px;
  }

  .tat-ai-messages-container {
    padding: 20px;
  }

  .tat-ai-input-section {
    padding: 16px 20px;
  }
}

/* Tablet Portrait & Large Mobile (481px - 767px) */
@media (min-width: 481px) and (max-width: 767px) {
  .tat-ai-assistant-wrapper {
    bottom: 16px !important;
    right: 16px !important;
    left: 16px !important;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .tat-ai-chat-window {
    width: calc(100vw - 32px);
    height: 80vh;
    max-height: 600px;
    bottom: 75px;
    right: 0;
    left: 0;
    margin: 0 auto;
    transform: none;
    border-radius: 20px;
    position: fixed;
  }

  .tat-ai-window-hidden {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
  }

  .tat-ai-window-visible {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
  }

  .tat-ai-launch-btn {
    width: 58px;
    height: 58px;
  }

  .tat-ai-chat-icon {
    width: 26px;
    height: 26px;
  }

  .tat-ai-header-content {
    padding: 18px 20px;
  }

  .tat-ai-messages-container {
    padding: 20px 16px;
  }

  .tat-ai-input-section {
    padding: 16px;
  }

  .tat-ai-text-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 16px 0;
  }
}

/* Mobile (320px - 480px) */
@media (max-width: 480px) {
  .tat-ai-assistant-wrapper {
    bottom: 12px !important;
    right: 12px !important;
    left: 12px !important;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .tat-ai-chat-window {
    width: calc(100vw - 24px);
    height: 85vh;
    max-height: none;
    bottom: 70px;
    right: 0;
    left: 0;
    margin: 0 auto;
    transform: none;
    border-radius: 16px;
    position: fixed;
  }

  .tat-ai-window-hidden {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
  }

  .tat-ai-window-visible {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
  }

  .tat-ai-launch-btn {
    width: 54px;
    height: 54px;
    box-shadow: 0 6px 24px var(--tat-ai-shadow);
  }

  .tat-ai-chat-icon {
    width: 22px;
    height: 22px;
  }

  .tat-ai-header-content {
    padding: 16px 18px;
  }

  .tat-ai-title {
    font-size: 16px;
  }

  .tat-ai-avatar-circle {
    width: 40px;
    height: 40px;
  }

  .tat-ai-avatar-icon {
    width: 18px;
    height: 18px;
  }

  .tat-ai-close-btn {
    width: 32px;
    height: 32px;
  }

  .tat-ai-close-icon {
    width: 16px;
    height: 16px;
  }

  .tat-ai-messages-container {
    padding: 16px 12px;
    gap: 12px;
  }

  .tat-ai-message-bubble {
    padding: 14px 16px;
    font-size: 14px;
    max-width: 90%;
  }

  .tat-ai-typing-bubble {
    padding: 14px 16px;
  }

  .tat-ai-input-section {
    padding: 14px 12px;
  }

  .tat-ai-input-wrapper {
    padding: 3px 3px 3px 16px;
    border-radius: 14px;
  }

  .tat-ai-text-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px 0;
  }

  .tat-ai-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .tat-ai-send-icon {
    width: 16px;
    height: 16px;
  }
}

/* Extra Small Mobile (max 320px) */
@media (max-width: 320px) {
  .tat-ai-assistant-wrapper {
    left: 8px !important;
    right: 8px !important;
  }

  .tat-ai-chat-window {
    width: calc(100vw - 16px);
    height: 90vh;
    bottom: 65px;
    left: 0;
    right: 0;
    margin: 0 auto;
  }

  .tat-ai-launch-btn {
    width: 50px;
    height: 50px;
  }

  .tat-ai-chat-icon {
    width: 20px;
    height: 20px;
  }

  .tat-ai-messages-container {
    padding: 12px 8px;
  }

  .tat-ai-input-section {
    padding: 12px 8px;
  }
}
