/* ============================================
   H&I ROOFING CHATBOT - Custom Styles
   ============================================ */

:root {
  --chat-primary: #3b709f;
  --chat-primary-dark: #2a5478;
  --chat-primary-light: #5a93b8;
  --chat-secondary: #4d8ab5;
  --chat-bg: #ffffff;
  --chat-surface: #f0f4f8;
  --chat-surface-dark: #e2e8f0;
  --chat-text: #1a202c;
  --chat-text-light: #64748b;
  --chat-text-muted: #94a3b8;
  --chat-success: #22c55e;
  --chat-danger: #ef4444;
  --chat-shadow: 0 20px 60px rgba(59, 112, 159, 0.25);
  --chat-shadow-sm: 0 4px 20px rgba(59, 112, 159, 0.15);
  --chat-radius: 20px;
  --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   FLOATING TAB BUTTON (Right Side)
   ============================================ */

.hi-chat-trigger {
  position: fixed;
  right: 0;
  bottom: 28%;
  z-index: 9997;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 130px;
  padding: 12px 8px;
  border: none;
  border-radius: 16px 0 0 16px;
  background: linear-gradient(180deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow: -4px 4px 20px rgba(42, 84, 120, 0.35);
  transition: var(--chat-transition);
  overflow: hidden;
}

.hi-chat-trigger::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 100%);
  border-radius: inherit;
  pointer-events: none;
}

.hi-chat-trigger:hover {
  right: 0;
  width: 58px;
  box-shadow: -6px 6px 30px rgba(42, 84, 120, 0.45);
}

.hi-chat-trigger.active {
  background: linear-gradient(180deg, var(--chat-primary-dark) 0%, #1e3a5f 100%);
  height: 52px;
  width: 52px;
  border-radius: 14px 0 0 14px;
  bottom: calc(28% + 39px);
}

.hi-chat-trigger-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: var(--chat-transition);
}

.hi-chat-trigger-icon svg {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
  transition: transform 0.3s ease;
}

.hi-chat-trigger:hover .hi-chat-trigger-icon svg {
  transform: scale(1.1);
}

.hi-chat-trigger-text {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  opacity: 0.9;
  transition: var(--chat-transition);
}

.hi-chat-trigger.active .hi-chat-trigger-text {
  display: none;
}

.hi-chat-trigger-close {
  display: none;
}

.hi-chat-trigger.active .hi-chat-trigger-icon {
  display: none;
}

.hi-chat-trigger.active .hi-chat-trigger-close {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hi-chat-trigger-close svg {
  width: 22px;
  height: 22px;
  transition: transform 0.3s ease;
}

.hi-chat-trigger.active:hover .hi-chat-trigger-close svg {
  transform: rotate(90deg);
}

/* Pulse Animation */
.hi-chat-trigger::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 20px 0 0 20px;
  border: 2px solid var(--chat-primary-light);
  opacity: 0;
  animation: chatTriggerPulse 3s ease-in-out infinite;
}

.hi-chat-trigger.active::after {
  display: none;
}

@keyframes chatTriggerPulse {
  0%, 100% { opacity: 0; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.03); }
}

/* Notification Badge */
.hi-chat-badge {
  position: absolute;
  top: 6px;
  left: 4px;
  width: 18px;
  height: 18px;
  background: var(--chat-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
  animation: badgeBounce 0.5s ease;
}

.hi-chat-badge.show {
  display: flex;
}

@keyframes badgeBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ============================================
   CHAT CONTAINER
   ============================================ */

.hi-chat-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 520px;
  z-index: 9997;
  border-radius: var(--chat-radius);
  background: var(--chat-bg);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateX(30px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.hi-chat-container.open {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: all;
}

/* ============================================
   HEADER
   ============================================ */

.hi-chat-header {
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.hi-chat-header::before {
  content: '';
  position: absolute;
  top: -20px;
  right: -20px;
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
  pointer-events: none;
}

.hi-chat-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
}

.hi-chat-header-avatar svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.hi-chat-header-info {
  flex: 1;
}

.hi-chat-header-name {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.hi-chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

.hi-chat-header-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.hi-chat-header-status-text {
  color: rgba(255,255,255,0.75);
  font-size: 12px;
}

.hi-chat-header-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--chat-transition);
  flex-shrink: 0;
}

.hi-chat-header-close:hover {
  background: rgba(255,255,255,0.25);
}

.hi-chat-header-close svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   MESSAGES AREA
   ============================================ */

.hi-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.hi-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.hi-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.hi-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-surface-dark);
  border-radius: 2px;
}

/* Message Bubbles */
.hi-chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  animation: messageIn 0.3s ease-out;
  word-wrap: break-word;
}

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

.hi-chat-msg.bot {
  align-self: flex-start;
  background: var(--chat-surface);
  color: var(--chat-text);
  border-radius: 4px 16px 16px 16px;
}

.hi-chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
  color: #ffffff;
  border-radius: 16px 4px 16px 16px;
}

.hi-chat-msg a {
  color: var(--chat-secondary);
  text-decoration: underline;
}

.hi-chat-msg.user a {
  color: #bde0fe;
}

.hi-chat-msg strong {
  font-weight: 600;
}

.hi-chat-msg ul,
.hi-chat-msg ol {
  margin: 6px 0;
  padding-left: 18px;
}

.hi-chat-msg li {
  margin-bottom: 3px;
}

/* Typing Indicator */
.hi-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--chat-surface);
  border-radius: 4px 16px 16px 16px;
  align-self: flex-start;
  animation: messageIn 0.3s ease-out;
}

.hi-chat-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--chat-text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.hi-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.hi-chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

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

/* ============================================
   QUICK BUTTONS
   ============================================ */

.hi-chat-quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
  flex-shrink: 0;
}

.hi-chat-quick-btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--chat-primary);
  background: transparent;
  border: 1.5px solid var(--chat-primary);
  border-radius: 20px;
  cursor: pointer;
  transition: var(--chat-transition);
  white-space: nowrap;
}

.hi-chat-quick-btn:hover {
  background: var(--chat-primary);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--chat-shadow-sm);
}

/* ============================================
   INPUT AREA
   ============================================ */

.hi-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--chat-surface);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--chat-bg);
}

.hi-chat-textarea {
  flex: 1;
  border: 1.5px solid var(--chat-surface-dark);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  max-height: 80px;
  min-height: 40px;
  outline: none;
  transition: border-color 0.2s ease;
  color: var(--chat-text);
  background: var(--chat-bg);
}

.hi-chat-textarea::placeholder {
  color: var(--chat-text-muted);
}

.hi-chat-textarea:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(59, 112, 159, 0.12);
}

.hi-chat-send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--chat-transition);
}

.hi-chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--chat-shadow-sm);
}

.hi-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.hi-chat-send-btn svg {
  width: 18px;
  height: 18px;
}

/* ============================================
   POWERED BY
   ============================================ */

.hi-chat-powered {
  text-align: center;
  padding: 6px;
  font-size: 10px;
  color: var(--chat-text-muted);
  background: var(--chat-surface);
  flex-shrink: 0;
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */

@media (max-width: 480px) {
  .hi-chat-container {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-width: none;
    max-height: none;
  }

  .hi-chat-trigger {
    bottom: 16px;
    height: 110px;
    width: 46px;
  }

  .hi-chat-trigger.active {
    height: 46px;
    width: 46px;
    bottom: 16px;
  }

  .hi-chat-quick-buttons {
    padding: 0 12px 8px;
  }

  .hi-chat-messages {
    padding: 12px;
  }
}

@media (min-width: 481px) and (max-width: 640px) {
  .hi-chat-container {
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
    height: calc(100vh - 80px);
  }
}
