/* KAI House Chat Widget - Modern Style */
:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --me: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bot: #ffffff;
  --text: #374151;
  --muted: #6b7280;
  --accent: #10b981;
  --kai-primary: #667eea;
  --kai-secondary: #764ba2;
  --modern-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --border: #e5e7eb;
  --shadow: rgba(0, 0, 0, 0.1);
}

/* Chat Toggle Button */
.chat-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--me);
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--shadow);
  z-index: 10000;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px var(--shadow);
}

.chat-toggle:active {
  transform: scale(0.95);
}

/* Chat Widget Container */
.chat-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 560px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 32px var(--shadow);
  border: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-wrap.hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 50px;
  background: var(--modern-bg);
  color: white;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
}

.chat-title {
  color: white;
  font: 700 16px/1.2 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
}

.chat-subtitle {
  color: rgba(255,255,255,0.9);
  font: 13px/1.2 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
}

.chat-badge {
  font: 11px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: white;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 4px 8px;
  border-radius: 12px;
  flex-shrink: 0;
  font-weight: 500;
  margin-left: auto;
}

.chat-badge.offline {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.2);
  border-color: rgba(255, 107, 107, 0.3);
}

/* Chat Close Button */
.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  transform: scale(1.05);
}

.chat-close-btn:active {
  transform: scale(0.95);
}

/* Chat Body */
.chat-body {
  flex: 1;
  overflow: auto;
  padding: 20px;
  scroll-behavior: smooth;
  background: var(--bg);
}

.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* Chat Messages */
.chat-msg {
  max-width: 80%;
  padding: 10px 20px;
  border-radius: 20px;
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 8px 0;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 2px 8px var(--shadow);
}

.chat-msg.me {
  margin-left: auto;
  background: var(--me);
  color: white;
  border-bottom-right-radius: 8px;
}

.chat-msg.bot {
  margin-right: auto;
  background: var(--bot);
  border-bottom-left-radius: 8px;
}

.chat-time {
  display: block;
  font: 11px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--muted);
  margin-top: 4px;
  opacity: 0.7;
}

/* Typing Indicator */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .6;
  animation: blink 1.2s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }

/* User typing indicator */
.chat-msg.me .chat-typing span {
  background: rgba(255, 255, 255, 0.8);
}

@keyframes blink {
  0%, 80%, 100% { opacity: .2; }
  40% { opacity: 1; }
}

/* Chat Input */
.chat-input {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-input textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  height: 40px;
  padding: 12px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
  font-size: 14px;
  /* Remove scrollbar and controls */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-input textarea::-webkit-scrollbar {
  display: none;
}

.chat-input textarea::-webkit-outer-spin-button,
.chat-input textarea::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.chat-input textarea::-webkit-resizer {
  display: none;
}

.chat-input textarea::-webkit-input-placeholder {
  color: var(--muted);
}

.chat-input textarea::-moz-placeholder {
  color: var(--muted);
  opacity: 1;
}

.chat-input textarea:-ms-input-placeholder {
  color: var(--muted);
}

.chat-input textarea:focus {
  border-color: var(--kai-primary);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.chat-input button {
  height: 40px;
  padding: 0 20px;
  border-radius: 20px;
  border: none;
  background: var(--me);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px var(--shadow);
}

.chat-input button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow);
}

.chat-input button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 4px var(--shadow);
}

/* Message Animation */
.chat-msg.new {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Design */
@media (max-width: 420px) {
  .chat-wrap {
    right: 12px;
    left: 12px;
    bottom: 12px;
    height: 70vh;
    width: auto;
  }

  .chat-toggle {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 768px) {
  .chat-wrap {
    width: calc(100vw - 24px);
    max-width: none;
  }
}

/* Print styles */
@media print {
  .chat-toggle,
  .chat-wrap {
    display: none !important;
  }
}
