/**
 * ==========================================================================
 * CRAFTEGON CORPORATE SERVICES (CCS) - MINIMALIST AI COMPLIANCE ASSISTANT
 * Modern, Minimalist, High-Elegance Fintech Aesthetic (Mint & Deep Teal)
 * Inspired by Linear, Stripe & Apple Design Principles
 * ==========================================================================
 */

/* --- 1. FLOATING LAUNCHER TRIGGER --- */
body.mobile-nav-open #craftegon-chat-trigger,
body.mobile-nav-open #craftegon-chat-badge,
body.mobile-nav-open #craftegon-chat-window {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.8) !important;
  visibility: hidden !important;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease !important;
}

#craftegon-chat-trigger {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-green-primary, #247A62) 0%, var(--navy-800, #193B46) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 24px rgba(25, 59, 70, 0.22), 0 2px 6px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 140;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
  outline: none;
}

#craftegon-chat-trigger:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 30px rgba(25, 59, 70, 0.3), 0 4px 12px rgba(36, 122, 98, 0.2);
}

#craftegon-chat-trigger .chat-pulse {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(36, 122, 98, 0.5);
  animation: triggerGlow 2.5s infinite ease-out;
  pointer-events: none;
}

@keyframes triggerGlow {
  0% { box-shadow: 0 0 0 0 rgba(36, 122, 98, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(36, 122, 98, 0); }
  100% { box-shadow: 0 0 0 0 rgba(36, 122, 98, 0); }
}

#craftegon-chat-trigger .trigger-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #FFFFFF;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}

#craftegon-chat-trigger .close-icon {
  display: none;
  width: 20px;
  height: 20px;
  stroke: #FFFFFF;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#craftegon-chat-trigger.active {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.6) !important;
  visibility: hidden !important;
}

/* Tooltip Badge */
#craftegon-chat-badge {
  position: fixed;
  bottom: 28px;
  right: 88px;
  background: #FFFFFF;
  border: 1px solid var(--border-color, #DCE8E5);
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  color: var(--navy-900, #10262E);
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(16, 38, 46, 0.08);
  pointer-events: none;
  z-index: 139;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#craftegon-chat-badge .badge-dot {
  width: 7px;
  height: 7px;
  background: var(--success, #059669);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(5, 150, 105, 0.6);
}

/* --- 2. CHAT WINDOW CONTAINER --- */
#craftegon-chat-window {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 384px;
  height: 580px;
  max-height: calc(100vh - 110px);
  background: #FFFFFF;
  border: 1px solid rgba(220, 232, 229, 0.95);
  border-radius: 20px;
  box-shadow: 0 20px 48px -10px rgba(16, 38, 46, 0.18), 0 4px 16px rgba(16, 38, 46, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(0.98);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

#craftegon-chat-window.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* --- 3. ELEGANT MINIMALIST HEADER --- */
.cchat-header {
  padding: 0.85rem 1.15rem;
  background: #FFFFFF;
  border-bottom: 1px solid #EDF3F1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 0.5rem;
}

.cchat-brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.cchat-avatar-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  min-width: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1px solid rgba(220, 232, 229, 0.9);
  box-shadow: 0 2px 6px rgba(16, 38, 46, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.cchat-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: contain;
  padding: 2px;
  display: block;
}

.cchat-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  background: var(--success, #059669);
  border: 2px solid #FFFFFF;
  border-radius: 50%;
  z-index: 2;
}

.cchat-status-dot.ai-active {
  background: #10B981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.35);
  animation: aiPulse 2s infinite ease-in-out;
}

@keyframes aiPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

.cchat-brand-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.cchat-brand-info h4 {
  margin: 0;
  font-family: var(--font-heading, 'Manrope', sans-serif);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--navy-900, #10262E);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cchat-brand-info span {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary, #52717A);
  display: block;
  margin-top: 0.12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cchat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* User Mode Toggle: Smart AI vs Statutory Guide */
.cchat-mode-toggle {
  display: inline-flex;
  align-items: center;
  background: #F1F5F4;
  padding: 2px;
  border-radius: 20px;
  border: 1px solid #DCE8E5;
  flex-shrink: 0;
}

.cchat-mode-btn {
  background: transparent;
  border: none;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary, #52717A);
  padding: 3px 8px;
  border-radius: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  line-height: 1.2;
}

.cchat-mode-btn.active {
  background: #FFFFFF;
  color: var(--navy-900, #10262E);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(16, 38, 46, 0.12);
}

.cchat-mode-btn.active.ai-btn {
  color: var(--accent-green-primary, #247A62);
}

.cchat-btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary, #52717A);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  outline: none;
  padding: 0;
  flex-shrink: 0;
  position: relative;
}

.cchat-btn-icon::after {
  content: '';
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: -8px;
  right: -8px;
}

.cchat-btn-icon:hover {
  background: var(--surface-mint-white, #F4FAF7);
  color: var(--accent-green-primary, #247A62);
}

/* --- 4. MESSAGES STREAM --- */
.cchat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
  scroll-padding-top: 1rem;
  background: #FFFFFF;
}

.cchat-body::-webkit-scrollbar {
  width: 4px;
}

.cchat-body::-webkit-scrollbar-thumb {
  background: #DCE8E5;
  border-radius: 4px;
}

/* Bubbles */
.cchat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: cchatSlideIn 0.2s ease-out;
}

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

.cchat-msg.bot {
  align-self: flex-start;
}

.cchat-msg.user {
  align-self: flex-end;
}

.cchat-bubble {
  padding: 0.8rem 1rem;
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
}

.cchat-msg.bot .cchat-bubble {
  background: var(--surface-mint-white, #F4FAF7);
  border: 1px solid #E2EDE9;
  color: var(--navy-800, #193B46);
  border-radius: 16px 16px 16px 4px;
}

.cchat-msg.user .cchat-bubble {
  background: linear-gradient(135deg, var(--navy-800, #193B46) 0%, var(--accent-green-primary, #247A62) 100%);
  color: #FFFFFF;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 2px 8px rgba(25, 59, 70, 0.12);
}

.cchat-bubble strong {
  color: var(--navy-900, #10262E);
  font-weight: 700;
}

.cchat-msg.user .cchat-bubble strong {
  color: #FFFFFF;
}

.cchat-bubble ul {
  margin: 0.4rem 0;
  padding-left: 1.2rem;
}

.cchat-bubble li {
  margin-bottom: 0.25rem;
  line-height: 1.45;
}

.cchat-bubble code {
  font-family: var(--font-mono, monospace);
  font-size: 0.82em;
  background: rgba(36, 122, 98, 0.08);
  color: var(--accent-green-primary, #247A62);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.cchat-timestamp {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-light, #708A93);
  margin-top: 0.25rem;
}

.cchat-msg.bot .cchat-timestamp { align-self: flex-start; margin-left: 2px; }
.cchat-msg.user .cchat-timestamp { align-self: flex-end; margin-right: 2px; }

/* Action Links / Buttons */
.cchat-actions-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(220, 232, 229, 0.8);
}

.cchat-action-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #FFFFFF;
  border: 1px solid #DCE8E5;
  color: var(--navy-800, #193B46);
  padding: 0.48rem 0.8rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.15s ease;
}

.cchat-action-btn:hover {
  background: #F0F8F5;
  border-color: var(--accent-green-primary, #247A62);
  color: var(--accent-green-primary, #247A62);
  transform: translateY(-1px);
}

.cchat-action-btn span:last-child {
  color: var(--accent-green-primary, #247A62);
  font-size: 0.9rem;
}

.cchat-sources {
  display: grid;
  gap: 0.2rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(220, 232, 229, 0.8);
  font-size: 0.72rem;
}

.cchat-sources strong {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #52717A);
}

.cchat-sources a {
  color: var(--accent-green-primary, #247A62);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Typing Indicator */
.cchat-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface-mint-white, #F4FAF7);
  border: 1px solid #E2EDE9;
  border-radius: 14px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary, #52717A);
  align-self: flex-start;
}

.cchat-typing-dots {
  display: flex;
  gap: 3px;
}

.cchat-typing-dots span {
  width: 4px;
  height: 4px;
  background: var(--accent-green-primary, #247A62);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.cchat-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.cchat-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* --- 5. SUGGESTION PILLS --- */
.cchat-pills-bar {
  padding: 0.5rem 0.85rem;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  background: #FFFFFF;
  border-top: 1px solid #EDF3F1;
  white-space: nowrap;
  scrollbar-width: none;
  flex-shrink: 0;
}

.cchat-pills-bar::-webkit-scrollbar {
  display: none;
}

.cchat-pill {
  background: #FFFFFF;
  border: 1px solid #DCE8E5;
  color: var(--navy-800, #193B46);
  padding: 0.32rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  outline: none;
}

.cchat-pill:hover {
  background: #E8F6F0;
  border-color: var(--accent-mint-vibrant, #75CDA9);
  color: var(--navy-900, #10262E);
}

/* --- 6. MINIMALIST INPUT & FOOTER --- */
.cchat-footer {
  padding: 0.75rem 1rem 0.85rem;
  background: #FFFFFF;
  border-top: 1px solid #EDF3F1;
  flex-shrink: 0;
}

.cchat-input-row {
  display: flex;
  align-items: center;
  background: #F6FAF8;
  border: 1.5px solid #DCE8E5;
  border-radius: 12px;
  padding: 0.25rem 0.35rem 0.25rem 0.85rem;
  transition: all 0.15s ease;
}

.cchat-input-row:focus-within {
  background: #FFFFFF;
  border-color: var(--accent-green-primary, #247A62);
  box-shadow: 0 0 0 3px rgba(36, 122, 98, 0.12);
}

.cchat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: 0.85rem;
  color: var(--navy-900, #10262E);
}

.cchat-input::placeholder {
  color: var(--text-secondary, #52717A);
  font-size: 0.82rem;
}

.cchat-send-btn {
  width: 36px;
  height: 36px;
  background: var(--accent-green-primary, #247A62);
  border: none;
  border-radius: 8px;
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
  position: relative;
}

.cchat-send-btn::after {
  content: '';
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: -4px;
  right: -4px;
}

.cchat-send-btn:hover {
  background: var(--navy-800, #193B46);
  transform: scale(1.04);
}

.cchat-disclaimer {
  font-size: 0.68rem;
  color: var(--text-light, #708A93);
  text-align: center;
  margin-top: 0.45rem;
  line-height: 1.45;
}

.cchat-disclaimer a,
.cchat-disclaimer-btn {
  color: var(--accent-green-primary, #247A62);
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  display: inline;
  font-weight: 600;
}

.cchat-disclaimer a:hover,
.cchat-disclaimer-btn:hover {
  color: var(--navy-900, #10262E);
}

/* --- 7. SETTINGS MODAL --- */
.cchat-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(16, 38, 46, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.cchat-modal-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color, #DCE8E5);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  animation: modalFadeIn 0.2s ease-out;
}

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

.cchat-modal-header {
  padding: 1rem 1.25rem;
  background: var(--surface-mint-white, #F4FAF7);
  border-bottom: 1px solid var(--border-color, #DCE8E5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cchat-modal-header h5 {
  margin: 0;
  font-family: var(--font-heading, 'Manrope', sans-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--navy-900, #10262E);
}

.cchat-modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-secondary, #52717A);
  cursor: pointer;
}

.cchat-modal-body {
  padding: 1.25rem;
}

.cchat-modal-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  font-family: var(--font-mono, monospace);
  border: 1.5px solid var(--border-color, #DCE8E5);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--navy-900, #10262E);
  outline: none;
  box-sizing: border-box;
}

.cchat-modal-input:focus {
  border-color: var(--accent-green-primary, #247A62);
  box-shadow: 0 0 0 3px rgba(36, 122, 98, 0.15);
}

/* Mobile Responsiveness */
@media (max-width: 767.98px) {
  #craftegon-chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85vh;
    height: 85dvh;
    max-height: 85dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    z-index: 950 !important; /* Elevated safely above sticky mobile dock (z-index: 850) */
  }
  .cchat-input {
    font-size: 16px !important; /* Prevents iOS Safari auto-zoom */
  }
  #craftegon-chat-trigger {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
    right: calc(16px + env(safe-area-inset-right, 0px)) !important;
    width: 48px;
    height: 48px;
    z-index: 860 !important;
  }
  #craftegon-chat-badge {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    right: 74px !important;
    z-index: 859 !important;
  }
}

@media (max-width: 480px) {
  #craftegon-chat-badge {
    display: none;
  }
}

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