/* Chat container */
.chat-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 45%;
  max-width: 550px;
  min-width: 320px;
  min-height: 300px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(180%);
  border-radius: 16px;
  padding: 0;
  color: var(--text-main);
  z-index: 9999;
  resize: both;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  cursor: default;
  touch-action: none;
  display: flex;
  flex-direction: column;
}

.chat-container:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-container.dragging {
  user-select: none;
  cursor: grabbing;
}

.chat-container::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-top-color: transparent;
  border-left-color: transparent;
  background: radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.35) 0, rgba(255, 255, 255, 0) 60%);
  opacity: 0.7;
  pointer-events: none;
}

.chat-container:hover::after {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: transparent;
  border-left-color: transparent;
}

.chat-container.offline-mode {
  box-shadow: 0 0 20px rgba(255, 105, 180, 0.5);
  border-color: rgba(255, 105, 180, 0.4);
  animation: pulse-glow 3s infinite ease-in-out;
  transition: box-shadow 0.5s ease-in-out, border-color 0.5s ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 15px rgba(255, 105, 180, 0.4); border-color: rgba(255, 105, 180, 0.3); }
  50% { box-shadow: 0 0 30px rgba(255, 105, 180, 0.7); border-color: rgba(255, 105, 180, 0.6); }
}

#chat-status-indicator {
  font-size: 10px;
  margin-left: 8px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 255, 0, 0.2);
  color: #00ff00;
  display: none;
}

.offline-mode #chat-status-indicator {
  display: inline-block;
  background: rgba(255, 105, 180, 0.2);
  color: #ff69b4;
}

/* Chat header */
.chat-header {
  height: 40px;
  background: rgba(255, 255, 255, 0.03);
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  user-select: none;
}

.chat-header:active {
  cursor: grabbing;
}

.chat-header span:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 4px;
}

#chatTitle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 2px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.go-online-btn {
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.05);
  color: #ff69b4;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.go-online-btn:hover {
  background: rgba(255,255,255,0.15);
}

.offline-mode .go-online-btn {
  display: inline-flex;
}

.chat-sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  margin-right: 6px;
}

.chat-sidebar-toggle:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-main);
}

.new-chat-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  margin-left: auto;
}

.new-chat-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #ff69b4;
}

.regenerate-title-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.regenerate-title-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #ff69b4;
}

/* Chat content */
.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
}

.chat-history {
  overflow-y: auto;
  margin-bottom: 10px;
  padding: 10px;
  flex: 1;
  min-height: 100px;
}

/* Messages */
.message {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 85%;
  animation: message-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  line-height: 1.5;
  font-size: 14px;
}

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

.message-actions {
  position: absolute;
  bottom: -15px;
  right: 4px;
  display: none;
  gap: 4px;
  background: rgba(30, 30, 30, 0.8);
  padding: 4px;
  border-radius: 6px;
  z-index: 10;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

.message-action-btn {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.message-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.message-action-btn.delete-msg:hover {
  background: rgba(255, 68, 68, 0.6);
}

.message-action-btn.tts-play:hover {
  background: rgba(0, 123, 255, 0.6);
}

.user-message .message-actions {
  right: 4px;
}

.user-message {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(168, 85, 247, 0.4));
  align-self: flex-end;
  border-bottom-right-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}

.model-message {
  background: rgba(255, 255, 255, 0.08);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
}

.message-original-text {
  font-weight: normal;
}

.sentence-chunk {
  transition: background-color 0.3s ease, color 0.3s ease;
  padding: 0 2px;
  border-radius: 2px;
}

.sentence-highlight {
  background-color: rgba(255, 255, 0, 0.2);
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.retry-tts-btn {
  background: rgba(255, 165, 0, 0.3);
  border: 1px solid rgba(255, 165, 0, 0.5);
  color: #ffcc00;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
  width: fit-content;
}

.retry-tts-btn:hover {
  background: rgba(255, 165, 0, 0.5);
}

.message-transliteration-text {
  font-style: italic;
  font-size: 0.9em;
  color: #ccc;
  margin-top: 3px;
}

.message-translation-text {
  font-size: 0.9em;
  color: #b0e0e6;
  margin-top: 3px;
  padding-left: 10px;
  border-left: 2px solid #b0e0e6;
}

/* Streaming message styles */
.streaming-message {
  opacity: 0.9;
}

.streaming-message .message-original-text {
  font-style: italic;
}

.streaming-message .message-actions button {
  cursor: default;
}

/* Cursor animation for streaming text */
.streaming-text::after {
  content: '▋';
  animation: blink 1s infinite;
  color: #888;
}

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

.summary-cutoff-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 25px 0;
  position: relative;
  opacity: 0.7;
  pointer-events: none;
  user-select: none;
}

.summary-cutoff-marker::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  z-index: 1;
}

.summary-cutoff-marker span {
  background: #2d2d2d;
  padding: 4px 12px;
  font-size: 10px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Chat input */
.chat-input {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-shrink: 0;
}

.chat-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  color: white;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input input:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.chat-input button {
  padding: 0 20px;
  border: none;
  border-radius: 12px;
  background: var(--primary-accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.1s, filter 0.2s;
}

.chat-input button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.chat-input button:active {
  transform: translateY(0);
}

#resetChatBtn {
  background-color: #dc3545;
}

#resetChatBtn:hover {
  background-color: #c82333;
}

.chat-input button:hover {
  background: #0056b3;
}

/* Queue status bar */
.chat-input-status-bar {
  display: none;
  background: rgba(99, 102, 241, 0.15);
  padding: 8px 12px;
  border-radius: 12px 12px 0 0;
  font-size: 0.8em;
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.chat-input-status-bar.visible {
  display: flex;
}

.chat-input-status-bar .queue-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-input-status-bar #queueLengthText {
  font-weight: bold;
  color: var(--primary-accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.queued-messages-list {
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.85em;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.queue-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.clear-queue-chat-btn {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.2);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75em;
  cursor: pointer;
  width: fit-content;
  align-self: flex-end;
  transition: all 0.2s;
}

.clear-queue-chat-btn:hover {
  background: rgba(244, 63, 94, 0.3);
  transform: translateY(-1px);
}

.typing-indicator {
  font-style: italic;
  color: #aaa;
  margin-top: 5px;
  display: none;
}

/* Mic button */
.mic-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: none;
  border-radius: 5px;
  background: #333;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  z-index: 1;
}

.mic-button:hover { background: #444; }
.mic-button.active { background: #c62828; }
.mic-button svg { pointer-events: none; }

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 320px;
  max-width: calc(100vw - 48px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(180%);
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-110%);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

.chat-sidebar.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-sidebar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.chat-sidebar-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-main);
}

.chat-sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-sidebar-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.chat-sidebar-action-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #ff69b4;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.chat-list-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 20px 10px;
  opacity: 0.6;
}

.chat-list-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  margin-bottom: 4px;
  transition: background 0.15s ease;
  overflow: hidden;
}

.chat-list-item:hover {
  background: rgba(255,255,255,0.06);
}

.chat-list-item.active {
  background: rgba(255, 105, 180, 0.12);
  border: 1px solid rgba(255, 105, 180, 0.2);
}

.chat-list-item-content {
  flex: 1;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 0;
}

.chat-list-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.chat-list-item-meta {
  display: flex;
  gap: 8px;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
}

.chat-list-item-preview {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.chat-list-item-actions {
  display: flex;
  gap: 2px;
  padding-right: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.chat-list-item:hover .chat-list-item-actions {
  opacity: 1;
}

.chat-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}

.chat-action-btn:hover {
  background: rgba(255,255,255,0.1);
}

.chat-action-delete:hover {
  color: #ff4444;
}
