/* ============================================
   Tellme Admin Panel — Chat Drawer Styles
   ============================================ */

/* --- Chat Drawer --- */

.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  z-index: 500;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.chat-drawer.open {
  transform: translateX(0);
}

.chat-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 499;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.chat-drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* --- Drawer Header --- */

.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-drawer-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.chat-drawer-close {
  background: none;
  border: none;
  color: var(--text-primary);
  opacity: 0.5;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.chat-drawer-close:hover {
  opacity: 1;
}

/* --- Tab Bar --- */

.chat-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  scrollbar-width: none;
}

.chat-tabs::-webkit-scrollbar {
  display: none;
}

.chat-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  opacity: 0.5;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  font-family: var(--font-family);
}

.chat-tab:hover {
  opacity: 0.8;
}

.chat-tab.active {
  opacity: 1;
  border-bottom-color: var(--highlight);
  color: var(--highlight);
}

.chat-tab .tab-badge {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  background: var(--highlight);
  border-radius: 8px;
  font-size: 10px;
  color: #fff;
  text-align: center;
  line-height: 16px;
  margin-left: 6px;
  padding: 0 4px;
}

/* --- Message List --- */

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

.chat-messages:empty::after {
  content: 'No messages yet';
  text-align: center;
  opacity: 0.3;
  margin-top: 40px;
  font-size: 13px;
}

/* --- Messages --- */

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msg-in 0.2s ease;
}

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

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

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--bg-accent);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-sidebar);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 11px;
  opacity: 0.4;
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-meta {
  text-align: right;
}

/* --- Message Actions --- */

.message-actions {
  display: none;
  position: absolute;
  top: -8px;
  right: 4px;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.message:hover .message-actions {
  display: flex;
}

.message-action-btn {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--text-primary);
  opacity: 0.5;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-action-btn:hover {
  opacity: 1;
  background: var(--bg-hover);
}

.message-action-btn.danger:hover {
  color: var(--color-danger);
}

/* --- Tool Use Blocks --- */

.tool-block {
  margin: 8px 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.tool-block-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-primary);
  cursor: pointer;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--color-info);
  user-select: none;
}

.tool-block-header::before {
  content: '\25B6';
  font-size: 8px;
  transition: transform 0.2s;
}

.tool-block.expanded .tool-block-header::before {
  transform: rotate(90deg);
}

.tool-block-body {
  display: none;
  padding: 10px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text-primary);
  opacity: 0.8;
}

.tool-block.expanded .tool-block-body {
  display: block;
}

/* --- Streaming Indicator --- */

.streaming-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12px;
  opacity: 0.5;
}

.streaming-dot {
  width: 6px;
  height: 6px;
  background: var(--highlight);
  border-radius: 50%;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* --- Markdown Rendering --- */

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}

.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 14px; }
.message-bubble h4 { font-size: 13px; }

.message-bubble p {
  margin: 4px 0;
}

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

.message-bubble li {
  margin: 2px 0;
}

.message-bubble blockquote {
  border-left: 3px solid var(--highlight);
  margin: 8px 0;
  padding: 4px 12px;
  opacity: 0.8;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 4px 4px 0;
}

.message-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-bubble pre {
  margin: 8px 0;
  border-radius: 6px;
  overflow-x: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
}

.message-bubble pre code {
  display: block;
  padding: 12px;
  background: none;
  line-height: 1.5;
  tab-size: 2;
}

.message-bubble strong {
  font-weight: 600;
  color: #fff;
}

.message-bubble em {
  font-style: italic;
  opacity: 0.9;
}

.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 12px 0;
}

.message-bubble a {
  color: var(--highlight);
  text-decoration: underline;
}

/* --- Code Copy Button --- */

.code-block-wrap {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-accent);
  border: none;
  color: var(--text-primary);
  opacity: 0;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: opacity var(--transition);
}

.code-block-wrap:hover .code-copy-btn {
  opacity: 0.7;
}

.code-copy-btn:hover {
  opacity: 1 !important;
}

/* --- File Attachment Preview --- */

.file-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin: 6px 0;
  font-size: 12px;
}

.file-attachment-icon {
  font-size: 20px;
  opacity: 0.6;
}

.file-attachment-info {
  flex: 1;
  min-width: 0;
}

.file-attachment-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-attachment-size {
  font-size: 11px;
  opacity: 0.4;
}

.file-attachment-remove {
  background: none;
  border: none;
  color: var(--text-primary);
  opacity: 0.4;
  cursor: pointer;
  font-size: 14px;
}

.file-attachment-remove:hover {
  opacity: 1;
  color: var(--color-danger);
}

/* --- Input Area --- */

.chat-input-area {
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  flex-shrink: 0;
}

.chat-input-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-family);
  line-height: 1.5;
  resize: none;
  min-height: 40px;
  max-height: 150px;
  outline: none;
  transition: border-color var(--transition);
}

.chat-textarea:focus {
  border-color: var(--highlight);
}

.chat-textarea::placeholder {
  color: var(--text-primary);
  opacity: 0.3;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--highlight);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: #d63851;
}

.chat-send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.chat-attach-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--text-primary);
  opacity: 0.4;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}

.chat-attach-btn:hover {
  opacity: 0.8;
  background: var(--bg-hover);
}

/* --- Responsive --- */

@media (max-width: 480px) {
  .chat-drawer {
    width: 100vw;
  }
}

@media (max-width: 768px) {
  .chat-drawer {
    width: min(420px, 100vw);
  }
}
