/**
 * Agent Chat Modal Styles
 *
 * @license MIT
 * @copyright (c) 2025 Universal AI Cloud Development Team
 * @version 1.0.2
 *
 * Version History:
 * - 1.0.0 (2025-10-22): Initial implementation
 * - 1.0.1 (2025-11-23): UI Refinements
 *   - Updated banner styling for better visibility
 * - 1.0.2 (2025-11-26): Minor cleanup
 *   - Removed unused CSS rules
 */

/* Overlay */
.agent-chat-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}

/* Modal */
.agent-chat-modal {
  position: relative;
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 600px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.agent-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  background: #2c3e50;
  color: #ecf0f1;
  border-bottom: 1px solid #34495e;
}

.agent-chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 600;
}

.agent-chat-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #95a5a6;
  transition: background 0.3s;
}

.agent-chat-status-connecting {
  background: #f39c12;
  animation: pulse 1.5s ease-in-out infinite;
}

.agent-chat-status-connected {
  background: #27ae60;
}

.agent-chat-status-disconnected {
  background: #e74c3c;
}

.agent-chat-status-error {
  background: #c0392b;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.agent-chat-close {
  background: transparent;
  border: none;
  color: #ecf0f1;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

@media (hover: hover) {
  .agent-chat-close:hover {
    background-color: #34495e;
  }
}

/* Messages Wrapper (frame for banner positioning) */
.agent-chat-messages-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Messages Container */
.agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

.agent-chat-messages::-webkit-scrollbar {
  width: 8px;
}

.agent-chat-messages::-webkit-scrollbar-track {
  background: #ddd;
}

.agent-chat-messages::-webkit-scrollbar-thumb {
  background: #95a5a6;
  border-radius: 4px;
}

@media (hover: hover) {
  .agent-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #7f8c8d;
  }
}

/* Message Bubbles */
.agent-chat-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: slideInDown 0.3s ease-out;
  margin-top: 4px;
  margin-bottom: 4px;
}

.agent-chat-message.no-animate {
  animation: none;
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.agent-chat-message-user {
  align-self: flex-end;
}

.agent-chat-message-agent {
  align-self: flex-start;
}

.agent-chat-message-error {
  align-self: flex-start;
}

.agent-chat-message-content {
  padding: 12px 16px;
  border-radius: 6px;
  word-wrap: break-word;
  line-height: 1.6;
  overflow-x: auto;
}

.agent-chat-message-user .agent-chat-message-content {
  background: #3498db;
  color: white;
  border-bottom-right-radius: 2px;
  margin-bottom: 4px;
}

.agent-chat-message-agent .agent-chat-message-content {
  background: white;
  color: #333;
  border: 1px solid #ddd;
  border-bottom-left-radius: 2px;
}

.agent-chat-message-metrics {
  font-size: 9px;
  line-height: 1;
  color: #CCCCCC;
  text-align: right;
  margin: 2px 4px 0 0;
  padding: 0;
}

.agent-chat-message-error .agent-chat-message-content {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-bottom-left-radius: 2px;
}

/* Typing Indicator */
.agent-chat-typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.agent-chat-typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #95a5a6;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.agent-chat-typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.agent-chat-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.agent-chat-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }

  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Markdown Styles */
.agent-chat-message-content h1,
.agent-chat-message-content h2,
.agent-chat-message-content h3 {
  margin: 8px 0;
  font-weight: 600;
}

.agent-chat-message-content h1 {
  font-size: 1.5em;
}

.agent-chat-message-content h2 {
  font-size: 1.3em;
}

.agent-chat-message-content h3 {
  font-size: 1.1em;
}

.agent-chat-message-content p {
  margin: 8px 0;
}

.agent-chat-message-content code {
  background: #f5f5f5;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', 'Courier', monospace;
  font-size: 0.85rem;
  border: 1px solid #e0e0e0;
}

.agent-chat-message-agent .agent-chat-message-content code {
  background: #f8f8f8;
}

.agent-chat-message-content pre {
  background: #f8f8f8;
  color: #333;
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 6px 0;
  border: 1px solid #e0e0e0;
  line-height: 1.4;
}

.agent-chat-message-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  border: none;
  font-size: 0.8rem;
}

.agent-chat-message-content strong {
  font-weight: 600;
}

.agent-chat-message-content em {
  font-style: italic;
}

.agent-chat-message-content a {
  color: #3498db;
  text-decoration: underline;
}

/* KaTeX LaTeX rendering */
.agent-chat-message-content .katex {
  font-size: 0.95em;
}

.agent-chat-message-content .katex-display {
  text-align: left;
  margin: 0.5em 0;
}

.agent-chat-message-content .katex-display > .katex {
  display: inline-block;
  text-align: left;
}

.agent-chat-message-content .katex-html {
  text-align: left;
}

.agent-chat-message-user .agent-chat-message-content a {
  color: #ecf0f1;
}

/* New Conversation Link Container */
.agent-chat-new-conversation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 20px;
  background: #f5f5f5;
  font-size: 0.75rem;
  user-select: none;
}

/* Individual link styles */
.agent-chat-reload-link,
.agent-chat-start-new-link {
  color: #d0d0d0;
  cursor: pointer;
  transition: color 0.2s ease;
  white-space: nowrap;
}

@media (hover: hover) {
  .agent-chat-reload-link:hover,
  .agent-chat-start-new-link:hover {
    color: #3498db;
  }
}

.agent-chat-separator {
  color: #d0d0d0;
}

/* Banner / Info Message Area (overlay) */
.agent-chat-banner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  text-align: left;
  color: #333;
  font-size: 14px;
  line-height: 1.5;
  background: white;
  border-top: none;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out, padding 0.3s ease-out;
}

.agent-chat-banner.visible {
  padding: 8px 16px;
  border-top: 1px solid #ddd;
  max-height: 40px;
  opacity: 1;
}

/* Override common spinner for banner context - use display instead of visibility */
.agent-chat-banner .spinner {
  width: 16px;
  height: 16px;
  display: none;
  opacity: 1;
  visibility: visible;
}

.agent-chat-banner .spinner.visible {
  display: block;
}

.agent-chat-indicator {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: none;
}

.agent-chat-indicator.visible {
  display: block;
}

.agent-chat-indicator.disconnected {
  background: #e74c3c;
}

.agent-chat-indicator.connected {
  background: none;
  width: auto;
  height: auto;
}

.agent-chat-indicator.info {
  background: #3498db;
}

.agent-chat-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-height: 21px; /* 1 line */
  overflow: hidden;
}

.agent-chat-banner-line {
  flex-shrink: 0;
}

/* Markdown styling for banner */
.agent-chat-banner-line p {
  margin: 0;
  display: inline;
}

.agent-chat-banner-line a {
  color: #3498db;
}

.agent-chat-cursor {
  display: inline;
  font-weight: normal;
  animation: cursor-blink 0.5s step-end infinite;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Input Container */
.agent-chat-input-container {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  padding: 20px;
  background: white;
  border-top: 1px solid #ddd;
  flex-wrap: nowrap;
}

.agent-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  width: auto !important;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  resize: none;
  overflow-y: auto;
  min-height: 48px;
  max-height: 120px;
  line-height: 1.5;
}

.agent-chat-input:focus {
  border-color: #3498db;
}

.agent-chat-send {
  flex: 0 0 auto;
  width: auto !important;
  padding: 10px 20px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
  white-space: nowrap;
}

@media (hover: hover) {
  .agent-chat-send:hover:not(:disabled) {
    background: #2980b9;
  }
}

.agent-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Responsive */
@media (max-width: 640px) {
  .agent-chat-modal {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-width: 100%;
    border-radius: 0;
  }

  .agent-chat-message {
    max-width: 90%;
  }
}

/* Embedded Mode Styles */
.agent-chat-embedded {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: white;
}

/* Embedded mode takes full height of container */
.agent-chat-embedded .agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

/* Input container for embedded mode */
.agent-chat-embedded .agent-chat-input-container {
  display: flex;
  flex-direction: row;
  gap: 10px;
  padding: 15px;
  background: white;
  border-top: 1px solid #ddd;
}

/* Mobile-specific adjustments for embedded mode */
@media (max-width: 640px) {
  .agent-chat-embedded .agent-chat-input-container {
    flex-direction: row;
  }
}

/* Draft Styles */
.agent-chat-message-draft {
  padding: 12px 16px;
  border-radius: 6px;
  word-wrap: break-word;
  line-height: 1.6;
  background: #fff9e6;
  color: #333;
  border: 1px solid #f0e6cc;
  border-bottom-left-radius: 2px;
  margin-bottom: 12px;
}

.agent-chat-message-draft p {
  margin: 4px 0;
}

.agent-chat-draft-approve {
  margin-top: 10px;
  padding: 6px 14px;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

@media (hover: hover) {
  .agent-chat-draft-approve:hover:not(:disabled) {
    background: #218838;
  }
}

.agent-chat-draft-approve:disabled {
  background: #6c757d;
  cursor: not-allowed;
}

/* Generated Image Styles */
.agent-chat-generated-image-container {
  position: relative;
  display: inline-block;
  margin-bottom: 12px;
}
.agent-chat-generated-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}
.agent-chat-image-download {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 14px;
}

/* System message style */
.agent-chat-message-system {
  align-self: center;
  max-width: 90%;
}

.agent-chat-message-system .agent-chat-message-content {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
}

/* Draft text body style */
.draft-text {
    border: 1px solid #999;
    background: white;
    font-family: monospace;
    font-size: 9pt;
    padding: 12px;
    margin-top: 8px;
    word-wrap: break-word;
    overflow-x: auto;
    color: black;
}
