* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body {
  background: #343541;
  color: #ececf1;
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.app-container {
  display: flex;
  width: 100%;
}
.sidebar {
  width: 260px;
  background: #202123;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #4d4d4f;
}
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #4d4d4f;
}
.sidebar-header h1 {
  font-size: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.new-chat-btn {
  width: 100%;
  padding: 10px;
  background: #5436da;
  border: none;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}
.new-chat-btn:hover {
  background: #4a2fc1;
}
.user-info {
  padding: 12px 16px;
  border-bottom: 1px solid #4d4d4f;
}
.user-guest,
.user-loggedin {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.user-guest i,
.user-loggedin i {
  font-size: 14px;
  color: #9ca3af;
}
.login-link {
  margin-left: auto;
  color: #5436da;
  text-decoration: none;
  font-size: 13px;
}
.login-link:hover {
  text-decoration: underline;
}
.logout-btn {
  margin-left: auto;
  background: none;
  border: 1px solid #4d4d4f;
  color: #9ca3af;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.logout-btn:hover {
  background: #343541;
}
.chat-history {
  flex: 1;
  overflow-y: auto;
}
.history-header {
  padding: 12px 16px;
  border-bottom: 1px solid #4d4d4f;
}
.history-header h3 {
  font-size: 13px;
  color: #9ca3af;
  display: flex;
  align-items: center;
  gap: 6px;
}
.history-list {
  padding: 8px;
}
.history-item {
  padding: 10px;
  margin: 4px 0;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d1d5db;
  background: transparent;
  font-size: 13px;
}
.history-item:hover {
  background: #343541;
}
.history-item.active {
  background: #343541;
  border-left: 2px solid #5436da;
}
.history-item i {
  font-size: 12px;
  color: #9ca3af;
}
.history-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-date {
  font-size: 11px;
  color: #9ca3af;
}
.chat-header {
  padding: 16px;
  text-align: center;
  border-bottom: 1px solid #4d4d4f;
}
.chat-header h2 {
  font-size: 24px;
  margin-bottom: 4px;
  background: linear-gradient(90deg, #5436da, #10a37f);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.chat-header p {
  color: #9ca3af;
  font-size: 13px;
}
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.message {
  display: flex;
  gap: 16px;
  max-width: 800px;
  position: relative;
}
.user-message {
  margin-left: auto;
  flex-direction: row-reverse;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.user-message .avatar {
  background: #5436da;
}
.ai-message .avatar {
  background: #10a37f;
}
.content {
  flex: 1;
  position: relative;
}
.user-message .content p {
  background: #5436da;
  color: white;
  padding: 12px 16px;
  border-radius: 12px 12px 0 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}
.ai-message .content {
  background: #444654;
  padding: 16px;
  border-radius: 0 12px 12px 12px;
}
.ai-message .content p {
  margin: 0;
  line-height: 1.5;
  font-size: 14px;
}

/* Markdown Content - FIXED SPACING */
.markdown-content {
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 14px;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  margin: 1em 0 0.5em;
  font-weight: 600;
  color: #ffffff;
}

.markdown-content h1 {
  font-size: 1.3em;
  padding-bottom: 0.2em;
  margin-top: 0;
}

.markdown-content h2 {
  font-size: 1.2em;
}

.markdown-content h3 {
  font-size: 1.1em;
}

.markdown-content p {
  margin: 0.75em 0;
}

.markdown-content ul,
.markdown-content ol {
  margin: 0.75em 0;
  padding-left: 1.5em;
}

.markdown-content li {
  margin: 0.3em 0;
}

.markdown-content li > p {
  margin: 0;
}

.markdown-content blockquote {
  border-left: 2px solid #5436da;
  margin: 1em 0;
  padding-left: 1em;
  color: #9ca3af;
  font-style: italic;
}

.markdown-content pre {
  margin: 1em 0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: #2d2d2d;
}

/* CODE BLOCK WITH INLINE COPY BUTTON */
.code-block-wrapper {
  position: relative;
  margin: 1em 0;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 12px;
  border-radius: 6px;
  background: #2d2d2d;
  overflow-x: auto;
}

.code-block-wrapper code {
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 13px;
  line-height: 1.4;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(84, 54, 218, 0.9);
  border: none;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  z-index: 10;
}

.code-block-wrapper:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: #5436da;
}

.code-copy-btn.success {
  background: #10a37f;
}

.code-language {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  color: #9ca3af;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.markdown-content code:not(pre code) {
  background: #2d2d2d;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 13px;
  color: #f8f8f2;
}

.markdown-content table {
  border-collapse: collapse;
  margin: 1em 0;
  width: 100%;
  font-size: 13px;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid #4d4d4f;
  padding: 8px 12px;
  text-align: left;
}

.markdown-content th {
  background: #2d2d2d;
  font-weight: 600;
}

.markdown-content tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.05);
}

.markdown-content hr {
  border: none;
  border-top: 1px solid #4d4d4f;
  margin: 1.5em 0;
}

/* Message Actions */
.message-actions {
  position: absolute;
  top: -28px;
  right: 0;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  background: #202123;
  border-radius: 4px;
  padding: 3px;
  border: 1px solid #4d4d4f;
}

.message:hover .message-actions {
  opacity: 1;
}

.action-btn {
  background: #444654;
  border: 1px solid #565869;
  color: #9ca3af;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.2s;
}

.action-btn:hover {
  background: #5436da;
  color: white;
}

.copy-btn:hover {
  background: #10a37f;
}
.edit-btn:hover {
  background: #f59e0b;
}
.run-btn:hover {
  background: #3b82f6;
}
.regenerate-btn:hover {
  background: #8b5cf6;
}
.tts-btn:hover {
  background: #ef4444;
}
.share-btn:hover {
  background: #06b6d4;
}

/* Input Area */
.input-area {
  padding: 16px;
  border-top: 1px solid #4d4d4f;
  background: #343541;
}
.input-wrapper {
  position: relative;
  display: flex;
  background: #40414f;
  border-radius: 8px;
  border: 1px solid #565869;
}
textarea#userInput {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: white;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.5;
}
#sendButton {
  background: #5436da;
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 6px;
  transition: background 0.2s;
}
#sendButton:hover {
  background: #4a2fc1;
}
#sendButton:disabled {
  background: #666;
  cursor: not-allowed;
}
.input-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11px;
  color: #9ca3af;
}
.disclaimer,
.model-info {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Connection Status */
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-bottom: 8px;
  background: rgba(16, 163, 127, 0.1);
  border: 1px solid rgba(16, 163, 127, 0.3);
}

.connection-status.offline {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10a37f;
}

.status-dot.offline {
  background: #ef4444;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: #10a37f;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s;
  z-index: 1000;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Typing cursor */
.typing-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: #10a37f;
  margin-left: 2px;
  animation: blink 1s infinite;
  vertical-align: middle;
}

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

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: left 0.3s;
  }
  .sidebar.active {
    left: 0;
  }
  .chat-header {
    padding: 12px;
  }
  .chat-header h2 {
    font-size: 20px;
  }
  .message {
    max-width: 100%;
    gap: 12px;
  }
  .avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
}
