/* TMC AI Chat Widget Styles v2.0
   Scoped with .tmc-chat- prefix to avoid Webflow conflicts.
   Brand: navy #2A2D49, gold #E3AF5B, white #fff */

/* ─── Chat Button (Pill) ─── */
.tmc-chat-btn {
  position: fixed !important;
  bottom: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  height: 52px;
  border-radius: 26px;
  background: #2A2D49;
  border: 2px solid #E3AF5B;
  color: #fff;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 0 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  transition: all 0.3s ease;
  font-family: 'Lato', -apple-system, BlinkMacSystemFont, sans-serif;
  /* iOS sticky fix */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.tmc-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0,0,0,0.3);
  background: #1f2138;
}
.tmc-chat-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tmc-chat-btn-icon svg {
  width: 24px;
  height: 24px;
  fill: #E3AF5B;
  transition: transform 0.3s ease;
}
.tmc-chat-btn-label {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.tmc-chat-btn.tmc-chat-open {
  border-radius: 50%;
  width: 52px;
  padding: 0;
  justify-content: center;
}
.tmc-chat-btn.tmc-chat-open .tmc-chat-btn-label {
  display: none;
}
.tmc-chat-btn.tmc-chat-open .tmc-chat-btn-icon svg {
  transform: rotate(0deg);
}

/* ─── Chat Panel ─── */
.tmc-chat-panel {
  position: fixed;
  bottom: 84px;
  left: 20px;
  width: 400px;
  height: 560px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  z-index: 10000;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Lato', -apple-system, BlinkMacSystemFont, sans-serif;
  animation: tmc-chat-slide-up 0.3s ease-out;
}
.tmc-chat-panel.tmc-chat-visible {
  display: flex;
}
@keyframes tmc-chat-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Header ─── */
.tmc-chat-header {
  background: #2A2D49;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.tmc-chat-header-left {
  flex: 1;
  min-width: 0;
}
.tmc-chat-header-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.tmc-chat-header-sub {
  font-size: 12px;
  color: #E3AF5B;
  margin-top: 2px;
}
.tmc-chat-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tmc-chat-new,
.tmc-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  opacity: 0.7;
  transition: opacity 0.2s;
  font-size: 18px;
  line-height: 1;
  border-radius: 4px;
}
.tmc-chat-new:hover,
.tmc-chat-close:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

/* ─── Messages Area ─── */
.tmc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.tmc-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.tmc-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}
.tmc-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* ─── Message Bubbles ─── */
.tmc-chat-msg {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.tmc-chat-msg p {
  margin: 0 0 8px 0;
}
.tmc-chat-msg p:last-child {
  margin-bottom: 0;
}
.tmc-chat-msg-user {
  align-self: flex-end;
  background: #2A2D49;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.tmc-chat-msg-bot {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
}
.tmc-chat-msg-bot strong {
  font-weight: 700;
  color: #2A2D49;
}

/* Message entrance animation */
.tmc-chat-msg-enter {
  animation: tmc-chat-msg-fade 0.25s ease-out;
}
@keyframes tmc-chat-msg-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Page Recommendation Cards ─── */
.tmc-chat-pages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  animation: tmc-chat-msg-fade 0.3s ease-out;
}
.tmc-chat-page-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  text-decoration: none;
  color: #1a1a2e;
  transition: all 0.2s ease;
  font-size: 14px;
}
.tmc-chat-page-card:hover {
  border-color: #E3AF5B;
  background: #fffbf0;
  transform: translateX(3px);
  box-shadow: 0 2px 8px rgba(227, 175, 91, 0.15);
}
.tmc-chat-page-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 22px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0 6px;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}
.tmc-chat-page-badge[data-type="community"] { background: #dbeafe; color: #1e40af; }
.tmc-chat-page-badge[data-type="article"]   { background: #fef3c7; color: #92400e; }
.tmc-chat-page-badge[data-type="area"]      { background: #d1fae5; color: #065f46; }
.tmc-chat-page-badge[data-type="builder"]   { background: #ede9fe; color: #5b21b6; }
.tmc-chat-page-badge[data-type="team"]      { background: #fce7f3; color: #9d174d; }
.tmc-chat-page-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.tmc-chat-page-arrow {
  color: #9ca3af;
  font-size: 18px;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.tmc-chat-page-card:hover .tmc-chat-page-arrow {
  transform: translateX(2px);
  color: #E3AF5B;
}

/* ─── Quick-Start CTA Buttons ─── */
.tmc-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}
.tmc-chat-quick-btn {
  background: #fff;
  border: 1.5px solid #2A2D49;
  color: #2A2D49;
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.tmc-chat-quick-btn:hover {
  background: #2A2D49;
  color: #E3AF5B;
  border-color: #2A2D49;
  transform: translateY(-1px);
}

/* ─── Typing Indicator ─── */
.tmc-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: #f3f4f6;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: tmc-chat-msg-fade 0.2s ease-out;
}
.tmc-chat-typing span {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: tmc-chat-bounce 1.4s ease-in-out infinite;
}
.tmc-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.tmc-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tmc-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-7px); }
}

/* ─── CTA Footer ─── */
.tmc-chat-cta {
  padding: 8px 16px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
  border-top: 1px solid #f3f4f6;
  flex-shrink: 0;
  background: #fafafa;
}
.tmc-chat-cta-phone {
  color: #2A2D49;
  font-weight: 700;
  text-decoration: none;
}
.tmc-chat-cta-phone:hover {
  color: #E3AF5B;
}

/* ─── Input Area ─── */
.tmc-chat-input-area {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
  gap: 8px;
}
.tmc-chat-input-wrap {
  flex: 1;
  position: relative;
}
.tmc-chat-input {
  width: 100%;
  border: 1.5px solid #d1d5db;
  border-radius: 22px;
  padding: 10px 18px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafafa;
  box-sizing: border-box;
}
.tmc-chat-input:focus {
  border-color: #E3AF5B;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(227, 175, 91, 0.15);
}
.tmc-chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.tmc-chat-input::placeholder {
  color: #9ca3af;
  font-size: 14px;
}

/* Character counter */
.tmc-chat-char-count {
  position: absolute;
  right: 14px;
  bottom: -16px;
  font-size: 10px;
  color: #9ca3af;
  pointer-events: none;
}
.tmc-chat-char-count.tmc-chat-char-warn {
  color: #f59e0b;
}
.tmc-chat-char-count.tmc-chat-char-max {
  color: #ef4444;
  font-weight: 600;
}

/* Send button */
.tmc-chat-send {
  background: #2A2D49;
  border: none;
  color: #E3AF5B;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  flex-shrink: 0;
}
.tmc-chat-send:hover:not(:disabled) {
  background: #1a1c33;
  transform: scale(1.05);
}
.tmc-chat-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.tmc-chat-send svg {
  width: 17px;
  height: 17px;
  fill: #E3AF5B;
}

/* ─── Welcome Message ─── */
.tmc-chat-welcome {
  text-align: center;
  padding: 24px 16px 16px;
  color: #4b5563;
  font-size: 15px;
  line-height: 1.6;
}
.tmc-chat-welcome strong {
  color: #2A2D49;
  display: block;
  font-size: 18px;
  margin-bottom: 6px;
}
.tmc-chat-welcome p {
  margin: 0 0 4px;
}

/* ─── Toast Notification ─── */
.tmc-chat-toast {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #2A2D49;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 10001;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  white-space: nowrap;
  animation: tmc-chat-msg-fade 0.2s ease-out;
  transition: opacity 0.3s;
}
.tmc-chat-toast-hide {
  opacity: 0;
}

/* ─── Contact Form CTA Card ─── */
.tmc-contact-card {
  background: linear-gradient(135deg, #fefce8 0%, #fff7ed 100%);
  border: 1.5px solid #E3AF5B;
  border-radius: 14px;
  padding: 18px 16px;
  margin-top: 4px;
  animation: tmc-chat-msg-fade 0.3s ease-out;
}
.tmc-contact-header {
  text-align: center;
  margin-bottom: 14px;
}
.tmc-contact-header strong {
  font-size: 16px;
  color: #2A2D49;
  display: block;
  margin-bottom: 4px;
}
.tmc-contact-header p {
  font-size: 13px;
  color: #6b7280;
  margin: 0;
}
.tmc-contact-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tmc-contact-input,
.tmc-contact-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  color: #1a1a2e;
}
.tmc-contact-input:focus,
.tmc-contact-textarea:focus {
  border-color: #E3AF5B;
  box-shadow: 0 0 0 3px rgba(227, 175, 91, 0.15);
}
.tmc-contact-input::placeholder,
.tmc-contact-textarea::placeholder {
  color: #9ca3af;
  font-size: 14px;
}
.tmc-contact-input:disabled,
.tmc-contact-textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.tmc-contact-textarea {
  resize: none;
  min-height: 50px;
}
.tmc-contact-submit {
  background: #2A2D49;
  color: #E3AF5B;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  letter-spacing: 0.3px;
}
.tmc-contact-submit:hover:not(:disabled) {
  background: #1a1c33;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(42, 45, 73, 0.3);
}
.tmc-contact-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Contact form success state */
.tmc-contact-success {
  text-align: center;
  padding: 12px 16px;
  font-size: 15px;
  color: #065f46;
  font-weight: 600;
  line-height: 1.5;
}
.tmc-contact-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: #d1fae5;
  color: #065f46;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: middle;
}

/* ─── Language Toggle — iOS sticky fix ─── */
/* Override Webflow's lang-toggle to ensure sticky on mobile */
.lang-toggle {
  position: fixed !important;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  bottom: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

/* ─── Mobile Responsive ─── */
@media (max-width: 480px) {
  /* Chat panel — 1/3 screen height, anchored to bottom-left */
  .tmc-chat-panel {
    position: fixed !important;
    bottom: 70px !important;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 33vh !important;
    max-height: 33vh !important;
    border-radius: 16px 16px 0 0 !important;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  /* Hide welcome message on mobile to save space in compact panel */
  .tmc-chat-panel .tmc-chat-welcome {
    font-size: 13px;
    padding: 8px 10px 6px;
  }
  .tmc-chat-panel .tmc-chat-welcome h3 {
    font-size: 15px;
    margin-bottom: 4px;
  }
  .tmc-chat-panel .tmc-chat-welcome p {
    font-size: 12px;
    line-height: 1.3;
    margin-bottom: 6px;
  }
  /* Compact header on mobile */
  .tmc-chat-header {
    padding: 8px 12px !important;
    min-height: auto !important;
  }
  .tmc-chat-header-title {
    font-size: 14px !important;
  }
  .tmc-chat-header-sub {
    font-size: 11px !important;
  }
  /* Compact CTA bar */
  .tmc-chat-cta {
    padding: 4px 10px !important;
    font-size: 12px !important;
  }
  /* Compact input area */
  .tmc-chat-input-area {
    padding: 6px 8px !important;
  }
  /* Sticky chat button — bulletproof for iOS */
  .tmc-chat-btn {
    position: fixed !important;
    bottom: 16px !important;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    height: 46px;
    padding: 0 14px 0 10px;
    z-index: 99998 !important;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  .tmc-chat-btn-icon svg {
    width: 20px;
    height: 20px;
  }
  .tmc-chat-btn-label {
    font-size: 13px;
  }
  .tmc-chat-msg {
    font-size: 14px;
    max-width: 92%;
    padding: 8px 12px;
  }
  .tmc-chat-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
  .tmc-chat-quick-btn {
    font-size: 12px;
    padding: 5px 12px;
  }
  /* Contact form mobile — prevent iOS zoom on focus */
  .tmc-contact-input,
  .tmc-contact-textarea {
    font-size: 16px;
  }
  /* Sticky language toggle — bulletproof for iOS */
  .lang-toggle {
    position: fixed !important;
    bottom: 16px !important;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    right: 12px !important;
    z-index: 99999 !important;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}

/* Tablet tweaks */
@media (min-width: 481px) and (max-width: 768px) {
  .tmc-chat-panel {
    width: 360px;
    height: 500px;
  }
}

/* ─── iOS-specific fixes ─── */
@supports (-webkit-touch-callout: none) {
  /* iOS only — force GPU compositing for fixed elements */
  .tmc-chat-btn,
  .tmc-chat-panel,
  .lang-toggle {
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
  }
}
