/* Chat Layout */
.chat-layout {
  display: flex;
  height: calc(100vh - var(--nav-height));
}

.chat-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-list { flex: 1; overflow-y: auto; }

.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.agent-item:hover { background: var(--bg-tertiary); }
.agent-item.active {
  background: var(--bg-tertiary);
  border-left-color: var(--accent);
}

.agent-item .icon { font-size: 24px; }

.agent-item .info { flex: 1; }
.agent-item .name { font-weight: 600; font-size: 14px; }
.agent-item .desc { font-size: 12px; color: var(--text-secondary); }
.agent-item .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
}

/* Chat Main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.msg {
  max-width: 80%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.agent {
  align-self: flex-start;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg .msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.msg.agent .msg-text p { margin: 4px 0; }
.msg.agent .msg-text pre { background: rgba(0,0,0,0.2); padding: 8px; border-radius: 6px; overflow-x: auto; margin: 4px 0; }
.msg.agent .msg-text code { font-size: 13px; }
.msg.agent .msg-text ul, .msg.agent .msg-text ol { padding-left: 18px; margin: 4px 0; }
.msg.agent .msg-text a { color: var(--accent); }

.chat-input-area {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  align-items: flex-end;
}

.chat-input-container {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.chat-input-container:focus-within { border-color: var(--accent); }

.chat-toolbar {
  display: flex;
  gap: 2px;
  padding: 6px 10px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  align-items: center;
  flex-wrap: wrap;
}
.toolbar-btn {
  background: none;
  border: none;
  color: var(--text-secondary, rgba(255,255,255,0.5));
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1;
  transition: all 0.15s;
  user-select: none;
}
.toolbar-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.toolbar-btn:active { background: rgba(255,255,255,0.12); }
.toolbar-divider { width: 1px; height: 16px; background: rgba(255,255,255,0.1); margin: 0 4px; }

.chat-attachments {
  display: flex;
  gap: 8px;
  padding: 0;
  flex-wrap: wrap;
  max-height: 0;
  overflow: hidden;
  transition: all 0.2s;
}
.chat-attachments:not(:empty) {
  padding: 8px 12px;
  max-height: 200px;
  overflow-y: auto;
}
.attachment-preview {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.attachment-preview img {
  max-height: 48px;
  max-width: 80px;
  border-radius: 4px;
  object-fit: cover;
}
.attachment-remove {
  cursor: pointer;
  color: #ff4757;
  font-size: 14px;
  margin-left: 4px;
  opacity: 0.7;
}
.attachment-remove:hover { opacity: 1; }

#chat-input {
  width: 100%;
  background: transparent;
  border: none;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 20px;
  max-height: 200px;
  line-height: 1.5;
  box-sizing: border-box;
}

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); transform: scale(1.05); }
.btn-send:active { transform: scale(0.95); }

/* Emoji picker */
.chat-input-area { position: relative; }
.emoji-picker {
  display: none;
  position: absolute;
  bottom: 100%;
  right: 50px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  max-height: 320px;
  width: 320px;
  overflow-y: auto;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  z-index: 100;
}
.emoji-search-input {
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}
.emoji-search-input:focus { border-color: var(--accent); }
.emoji-cat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 8px 0 4px;
  padding: 0 2px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-item {
  cursor: pointer;
  font-size: 20px;
  padding: 4px;
  border-radius: 4px;
  text-align: center;
  transition: background 0.1s;
}
.emoji-item:hover { background: rgba(255,255,255,0.1); }
.emoji-no-results { grid-column: 1/-1; text-align: center; color: var(--text-secondary); font-size: 13px; padding: 12px; }

/* Toolbar overflow menu */
.toolbar-overflow-wrap { position: relative; }
.toolbar-overflow {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--bg-secondary, #1a1a2e);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
  z-index: 90;
  min-width: 140px;
}
.toolbar-overflow.open { display: flex; flex-direction: column; }
.toolbar-overflow .toolbar-btn {
  text-align: left;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
  border-radius: 6px;
}
.toolbar-overflow .toolbar-btn:hover { background: rgba(255,255,255,0.08); }

/* @mention / slash autocomplete */
.chat-autocomplete {
  display: none;
  max-height: 200px;
  overflow-y: auto;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.chat-autocomplete.open { display: block; }
.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 13px;
}
.autocomplete-item:hover, .autocomplete-item.active {
  background: rgba(255,255,255,0.06);
}
.autocomplete-icon { font-size: 18px; }
.autocomplete-name { font-weight: 600; color: var(--text-primary); }
.autocomplete-desc { color: var(--text-secondary, rgba(255,255,255,0.5)); font-size: 12px; }
.autocomplete-hint {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-secondary, rgba(255,255,255,0.3));
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

/* Message actions */
.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.msg-actions {
  display: none;
  gap: 2px;
}
.msg:hover .msg-actions { display: flex; }
.msg-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.5;
  transition: all 0.15s;
}
.msg-action-btn:hover { opacity: 1; background: rgba(255,255,255,0.08); }
.msg-reaction {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  margin-left: 8px;
}
.msg-reaction:hover { background: rgba(255,255,255,0.12); }

/* Typing indicator */
.typing-indicator .typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 8px 16px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary, rgba(255,255,255,0.4));
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Voice recording state */
.toolbar-btn.recording {
  color: #ff4757;
  animation: voicePulse 1s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Drag & drop overlay */
.chat-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  z-index: 50;
  pointer-events: none;
}

@media (max-width: 768px) {
  .chat-layout { flex-direction: column; }
  .chat-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    max-height: none;
    overflow: visible;
  }
  .sidebar-header { display: none; }
  .agent-list {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0;
    -webkit-overflow-scrolling: touch;
  }
  .agent-item {
    flex-direction: column;
    padding: 10px 14px;
    min-width: 80px;
    text-align: center;
    border-left: none;
    border-bottom: 3px solid transparent;
    gap: 4px;
  }
  .agent-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
    background: var(--bg-tertiary);
  }
  .agent-item .icon { font-size: 28px; }
  .agent-item .info { flex: none; }
  .agent-item .name { font-size: 12px; }
  .agent-item .desc { display: none; }
  .agent-item .dot { width: 6px; height: 6px; position: absolute; top: 6px; right: 6px; }
  .chat-messages { padding: 12px; }
  .msg { max-width: 85%; }
  .chat-input-area { padding: 8px 12px; }
}
