/* Floating Chat Widget CSS */

:root {
  --chat-bg: rgba(255, 255, 255, 0.85);
  --chat-border: rgba(220, 224, 230, 0.5);
  --chat-primary-gradient: linear-gradient(135deg, #005a8b, #004165);
  --chat-user-bubble: linear-gradient(135deg, #e8f4fd, #dbeeff);
  --chat-assistant-bubble: #f1f3f5;
  --chat-assistant-color: #212529;
  --chat-card-bg: rgba(248, 249, 250, 0.9);
  --chat-shadow: 0 12px 28px rgba(0, 0, 0, 0.12), 0 8px 10px rgba(0, 0, 0, 0.08);
}

/* Fix icon colors to inherit container colors and prevent global overrides */
.chat-panel-header .fa,
.chat-header-btn .fa,
.chat-widget-toggle .fa,
.chat-send-btn .fa {
  color: inherit;
}

/* Toggle Button */
.chat-widget-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  max-width: 56px;
  max-height: 56px;
  border-radius: 50%;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  background: #ffffff;
  color: #004165;
  border: 1px solid rgba(0, 65, 101, 0.15);
  box-shadow: 0 4px 16px rgba(0, 65, 101, 0.15);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-widget-toggle:hover {
  transform: scale(1.08);
  background: #f8fafc;
  border-color: rgba(0, 65, 101, 0.25);
  box-shadow: 0 6px 20px rgba(0, 65, 101, 0.25);
}

.chat-widget-toggle:active {
  transform: scale(0.95);
}

.chat-widget-toggle i {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

.chat-widget-toggle .chat-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0);
}

.chat-widget-toggle.active .chat-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0);
}

.chat-widget-toggle.active .chat-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.chat-widget-toggle .badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background-color: #ff4757;
  border: 2px solid white;
  border-radius: 50%;
  animation: pulse-dot 1.5s infinite;
}

/* Floating Chat Panel */
.chat-widget-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 520px;
  border-radius: 16px;
  background: var(--chat-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(40px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.chat-widget-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.chat-panel-header {
  padding: 16px;
  background: var(--chat-primary-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.chat-header-title {
  font-weight: 600;
  font-size: 16px;
  margin: 0;
}

.chat-header-mode-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.25);
  font-weight: bold;
}

.chat-header-actions {
  display: flex;
  gap: 12px;
}

.chat-header-btn {
  background: none;
  border: none;
  color: white;
  opacity: 0.8;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  transition: opacity 0.2s;
}

.chat-header-btn:hover {
  opacity: 1;
}

/* Messages Area */
.chat-panel-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(248, 249, 250, 0.4);
}

/* Scrollbar styles */
.chat-panel-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-panel-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-panel-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

/* Bubble Styling */
.chat-msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: slide-in 0.25s ease-out;
}

.chat-msg-bubble p {
  margin: 0 0 8px 0;
}
.chat-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chat-msg-bubble.user {
  align-self: flex-end;
  background: var(--chat-user-bubble);
  color: #004165;
  border-bottom-right-radius: 2px;
  box-shadow: 0 2px 6px rgba(0, 65, 101, 0.08);
}

.chat-msg-bubble.assistant {
  align-self: flex-start;
  background: var(--chat-assistant-bubble);
  color: var(--chat-assistant-color);
  border-bottom-left-radius: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.chat-msg-bubble.system {
  align-self: center;
  background: rgba(255, 171, 0, 0.15);
  color: #b7791f;
  font-size: 12px;
  text-align: center;
  border-radius: 16px;
  max-width: 90%;
  padding: 6px 12px;
}

/* Tool execution summaries cards */
.chat-tool-card {
  align-self: flex-start;
  width: 90%;
  background: var(--chat-card-bg);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  animation: slide-in 0.25s ease-out;
}

.chat-tool-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #495057;
  margin-bottom: 6px;
}

.chat-tool-card-header i {
  color: #28a745;
}

.chat-tool-card-body {
  color: #6c757d;
  font-size: 12px;
}

/* Input Area */
.chat-panel-input-container {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input-textarea {
  flex: 1;
  border: 1px solid #ced4da;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  outline: none;
  resize: none;
  height: 36px;
  max-height: 80px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color 0.2s;
}

.chat-input-textarea:focus {
  border-color: #004165;
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-primary-gradient);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}

.chat-send-btn:hover {
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  background: #ced4da;
  cursor: not-allowed;
  transform: none;
}

/* Typing indicator */
.chat-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 6px 12px;
  align-items: center;
  justify-content: center;
  width: fit-content;
  align-self: flex-start;
  background: var(--chat-assistant-bubble);
  border-radius: 12px;
  border-bottom-left-radius: 2px;
  margin-left: 2px;
  height: 32px;
}

.chat-typing-indicator span {
  width: 6px;
  height: 6px;
  background: #868e96;
  border-radius: 50%;
  animation: bounce-dot 1.4s infinite ease-in-out both;
}

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

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

/* Markdown styling inside messages */
.chat-msg-bubble strong {
  font-weight: 600;
}

.chat-msg-bubble ul, .chat-msg-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chat-msg-bubble li {
  margin: 3px 0;
}

.chat-msg-bubble a {
  color: #004165;
  text-decoration: underline;
}
.chat-msg-bubble.user a {
  color: #004165;
  text-decoration: underline;
}

.chat-msg-bubble code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
}
.chat-msg-bubble.user code {
  background: rgba(0, 65, 101, 0.08);
}

/* Animations */
@keyframes pulse-dot {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(255, 71, 87, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(255, 71, 87, 0);
  }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce-dot {
  0%, 80%, 100% { 
    transform: scale(0);
  } 40% { 
    transform: scale(1.0);
  }
}

.chat-widget-panel.maximized {
  bottom: 5vh !important;
  right: 24px !important;
  width: max(40vw, 380px);
  height: max(90vh, 520px);
  max-width: max(40vw, 380px) !important;
  max-height: max(90vh, 520px) !important;
  border-radius: 16px !important;
  transform: none !important;
  top: auto !important;
  left: auto !important;
}

.chat-widget-panel.maximized + .chat-widget-toggle {
  display: none !important;
}

/* Responsive */
@media (max-width: 576px) {
  .chat-widget-panel {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    z-index: 10000;
  }
  .chat-widget-toggle {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    max-width: 56px;
    max-height: 56px;
    padding: 0;
  }
  .chat-widget-panel.open {
    transform: translateY(0) scale(1);
  }
  .chat-widget-panel.maximized {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    border-radius: 0 !important;
  }
}

/* Tables inside chat bubbles */
.chat-table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
  background: white;
  font-family: inherit;
}

.chat-table th {
  background: #f8f9fa;
  color: #495057;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid #e9ecef;
  white-space: nowrap;
}

.chat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f3f5;
  color: #333333;
}

.chat-table tr:last-child td {
  border-bottom: none;
}

.chat-table tr:nth-child(even) {
  background: #fafbfc;
}

/* Scrollbar styling for table wrapper */
.chat-table-wrapper::-webkit-scrollbar {
  height: 6px;
}
.chat-table-wrapper::-webkit-scrollbar-track {
  background: #f1f3f5;
  border-radius: 4px;
}
.chat-table-wrapper::-webkit-scrollbar-thumb {
  background: #ced4da;
  border-radius: 4px;
}
.chat-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Resize Handles */
.chat-resize-handle {
  position: absolute;
  background: transparent;
  z-index: 10005;
}

.chat-resize-n {
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
}

.chat-resize-w {
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  cursor: ew-resize;
}

.chat-resize-nw {
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  z-index: 10006;
}



/* Resizing Helper Class for Body selection lock */
body.chat-resizing {
  user-select: none !important;
  -webkit-user-select: none !important;
}

