/**
 * Crownservice Hera Comm — Native Chat Widget Styles
 * Integrated UIkit 3 & YOOtheme Pro Design System
 * Palette: Primary Blue Hera (#0055a5) & Solar Amber (#f59e0b)
 */

:root {
  --cw-chat-primary: #0055a5;
  --cw-chat-primary-hover: #004485;
  --cw-chat-secondary: #0ea5e9;
  --cw-chat-secondary-hover: #0284c7;
  --cw-chat-secondary-light: #f0f9ff;
  --cw-chat-accent: #f59e0b;
  --cw-chat-dark: #0f172a;
  --cw-chat-dark-rgb: 15, 23, 42;
  --cw-chat-bg: #f8fafc;
  --cw-chat-card-bg: #ffffff;
  --cw-chat-border: #e2e8f0;
  --cw-chat-text: #1e293b;
  --cw-chat-text-muted: #64748b;
  --cw-chat-radius: 16px;
  --cw-chat-shadow: 0 12px 36px -6px rgba(15, 23, 42, 0.18), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
}

/* ==========================================================================
   Widget Container & Base
   ========================================================================== */
.cw-chat-widget-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--cw-chat-text);
  box-sizing: border-box;
}

.cw-chat-widget-container *,
.cw-chat-widget-container *::before,
.cw-chat-widget-container *::after {
  box-sizing: border-box;
}

/* ==========================================================================
   Floating Toggle Button
   ========================================================================== */
.cw-chat-toggle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cw-chat-primary) 0%, var(--cw-chat-secondary) 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 85, 165, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
  position: relative;
}

.cw-chat-toggle-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 85, 165, 0.55);
}

.cw-chat-toggle-btn:active {
  transform: scale(0.96);
}

.cw-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--cw-chat-accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
}

/* ==========================================================================
   Proactive Teaser Balloon
   ========================================================================== */
.cw-chat-teaser {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 280px;
  background: #ffffff;
  border-radius: 14px;
  padding: 14px 36px 14px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--cw-chat-border);
  cursor: pointer;
  animation: cwTeaserSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10;
}

.cw-chat-teaser::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 24px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-right: 1px solid var(--cw-chat-border);
  border-bottom: 1px solid var(--cw-chat-border);
  transform: rotate(45deg);
}

.cw-chat-teaser-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.cw-chat-teaser-icon {
  font-size: 20px;
  line-height: 1;
}

.cw-chat-teaser-text {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--cw-chat-dark);
}

.cw-chat-teaser-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--cw-chat-text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.cw-chat-teaser-close:hover {
  color: var(--cw-chat-dark);
}

@keyframes cwTeaserSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================================
   Chat Window / Drawer
   ========================================================================== */
.cw-chat-window {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 380px;
  height: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 100px);
  background: var(--cw-chat-card-bg);
  border-radius: var(--cw-chat-radius);
  box-shadow: var(--cw-chat-shadow);
  border: 1px solid var(--cw-chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cwChatWindowPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cwChatWindowPop {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.cw-chat-header {
  background: linear-gradient(135deg, var(--cw-chat-primary) 0%, #003e7a 100%);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.cw-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cw-chat-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cw-chat-avatar-icon {
  font-size: 20px;
}

.cw-chat-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid var(--cw-chat-primary);
}

.cw-chat-title-wrap {
  display: flex;
  flex-direction: column;
}

.cw-chat-header-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.cw-chat-header-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 3px;
}

.cw-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cw-chat-action-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  outline: none;
}

.cw-chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Messages Area */
.cw-chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--cw-chat-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.cw-msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: cwMsgFadeIn 0.2s ease-out;
}

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

.cw-msg-wrap-ai {
  align-self: flex-start;
}

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

.cw-msg-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.cw-msg-wrap-ai .cw-msg-bubble {
  background: #ffffff;
  color: var(--cw-chat-text);
  border: 1px solid var(--cw-chat-border);
  border-top-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.cw-msg-wrap-ai .cw-msg-bubble a {
  color: var(--cw-chat-primary);
  text-decoration: underline;
  font-weight: 600;
}

.cw-msg-wrap-user .cw-msg-bubble {
  background: var(--cw-chat-primary);
  color: #ffffff;
  border-top-right-radius: 4px;
}

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

.cw-msg-wrap-user .cw-msg-time {
  text-align: right;
}

/* Quick Chips Container */
.cw-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 0;
}

.cw-chip-btn {
  background: #ffffff;
  border: 1.5px solid var(--cw-chat-primary);
  color: var(--cw-chat-primary);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.cw-chip-btn:hover {
  background: var(--cw-chat-primary);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 85, 165, 0.25);
}

.cw-chips-disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* Typing Indicator */
.cw-chat-typing {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cw-chat-bg);
  border-top: 1px solid rgba(226, 232, 240, 0.6);
  flex-shrink: 0;
}

.cw-typing-bubble {
  background: #e2e8f0;
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  gap: 4px;
}

.cw-typing-bubble span {
  width: 6px;
  height: 6px;
  background: #64748b;
  border-radius: 50%;
  animation: cwBounce 1.4s infinite ease-in-out both;
}

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

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

.cw-typing-text {
  font-size: 11px;
  color: var(--cw-chat-text-muted);
  font-style: italic;
}

/* Footer & Input */
.cw-chat-footer {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid var(--cw-chat-border);
  flex-shrink: 0;
}

.cw-chat-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.cw-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cw-chat-bg);
  border: 1px solid var(--cw-chat-border);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cw-chat-input-row:focus-within {
  border-color: var(--cw-chat-primary);
  box-shadow: 0 0 0 3px rgba(0, 85, 165, 0.12);
  background: #ffffff;
}

.cw-chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  color: var(--cw-chat-text);
  resize: none;
  padding: 6px 0;
  max-height: 80px;
  font-family: inherit;
  line-height: 1.4;
}

.cw-chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cw-chat-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  outline: none;
  flex-shrink: 0;
}

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

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

.cw-chat-gdpr-notice {
  font-size: 10px;
  color: var(--cw-chat-text-muted);
  text-align: center;
  line-height: 1.2;
}

.cw-chat-gdpr-notice a {
  color: var(--cw-chat-text-muted);
  text-decoration: underline;
}

/* Responsive Mobile Rules */
@media (max-width: 480px) {
  .cw-chat-widget-container {
    bottom: 16px;
    right: 16px;
  }
  .cw-chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .cw-chat-toggle-btn {
    width: 54px;
    height: 54px;
  }
}
