/* =============================================================
   PipaOS Chat Widget — CSS
   Dark theme, orange accent, Inter font
   ============================================================= */

/* --- FAB (Floating Action Button) --- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #f97316;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  box-shadow: 0 4px 14px rgba(249,115,22,.45);
  z-index: 9999;
  transition: transform .2s ease, box-shadow .2s ease;
}
.chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(249,115,22,.6);
}
.chat-fab:active { transform: scale(.95); }

/* Notification badge */
.chat-fab .chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #0f172a;
  display: none;
}
.chat-fab .chat-badge.show { display: block; }

/* --- Chat Panel --- */
.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 400px;
  height: 520px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 9999;
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* animation */
  opacity: 0;
  transform: translateY(20px) scale(.96);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Header --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}
.chat-header-title {
  font-weight: 700;
  font-size: .95rem;
  color: #f8fafc;
  white-space: nowrap;
}
.chat-agent-select {
  margin-left: auto;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: .8rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
.chat-agent-select:focus { border-color: #f97316; }
.chat-close-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color .15s;
}
.chat-close-btn:hover { color: #f8fafc; }

/* --- Messages Area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: #475569; }

/* --- Message bubbles --- */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; align-items: flex-start; }
.chat-msg.system { align-self: center; align-items: center; max-width: 90%; }

.chat-msg-name {
  font-size: .7rem;
  font-weight: 600;
  margin-bottom: 2px;
  padding: 0 4px;
}
.chat-msg.user .chat-msg-name { color: #fb923c; }
.chat-msg.assistant .chat-msg-name { color: #38bdf8; }

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.chat-msg.user .chat-msg-bubble {
  background: #f97316;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-msg-bubble {
  background: #1e293b;
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}
.chat-msg.system .chat-msg-bubble {
  background: #7f1d1d;
  color: #fca5a5;
  font-size: .8rem;
  border-radius: 8px;
}

.chat-msg-time {
  font-size: .65rem;
  color: #64748b;
  margin-top: 2px;
  padding: 0 4px;
}

/* Markdown inside bubbles */
.chat-msg-bubble code {
  background: rgba(0,0,0,.25);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .82em;
}
.chat-msg-bubble pre {
  background: rgba(0,0,0,.3);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: .82em;
}
.chat-msg-bubble pre code {
  background: none;
  padding: 0;
}
.chat-msg-bubble strong { font-weight: 700; }
.chat-msg-bubble em { font-style: italic; }
.chat-msg-bubble ul, .chat-msg-bubble ol {
  margin: 4px 0;
  padding-left: 18px;
}
.chat-msg-bubble li { margin-bottom: 2px; }

/* --- Typing indicator --- */
.chat-typing {
  display: none;
  align-self: flex-start;
  padding: 0 16px 8px;
}
.chat-typing.show { display: flex; }
.chat-typing-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e293b;
  padding: 10px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat-typing-name {
  font-size: .7rem;
  font-weight: 600;
  color: #38bdf8;
  margin-right: 4px;
}
.chat-typing-dots {
  display: flex;
  gap: 4px;
}
.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #64748b;
  animation: chatTypingBounce 1.4s infinite ease-in-out both;
}
.chat-typing-dot:nth-child(1) { animation-delay: -.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -.16s; }
@keyframes chatTypingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Footer / Input --- */
.chat-footer {
  padding: 12px 16px;
  border-top: 1px solid #1e293b;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #0f172a;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  color: #e2e8f0;
  font-family: inherit;
  font-size: .875rem;
  padding: 10px 14px;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: calc(1.4em * 4 + 20px); /* ~4 lines */
  overflow-y: auto;
  transition: border-color .15s;
}
.chat-input::placeholder { color: #64748b; }
.chat-input:focus { border-color: #f97316; }
.chat-input:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #f97316;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.chat-send-btn:hover { background: #ea580c; }
.chat-send-btn:active { transform: scale(.92); }
.chat-send-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* --- Welcome state --- */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #64748b;
  text-align: center;
  padding: 32px;
  gap: 8px;
}
.chat-welcome-icon { font-size: 2.5rem; }
.chat-welcome-title {
  font-size: 1rem;
  font-weight: 600;
  color: #94a3b8;
}
.chat-welcome-sub {
  font-size: .8rem;
  line-height: 1.5;
}

/* --- Mobile responsive --- */
@media (max-width: 480px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
  .chat-fab {
    bottom: 16px;
    right: 16px;
  }
}
