/* --- Reset and Basic Setup --- */
:root {
  --sidebar-bg: #202123;
  --main-bg: #343541;
  --user-bubble-bg: #444654;
  --ai-bubble-bg: #444654;
  --input-bg: #40414f;
  --text-color: #ececf1;
  --subtle-text-color: #8e8ea0;
  --border-color: rgba(255, 255, 255, 0.1);
  --button-hover-bg: #2a2b32;
  --code-bg: #1e1e1e;
  --user-bubble: #10a37f;
  --ai-bubble: rgba(68, 70, 84, 1);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  background-color: var(--main-bg);
  color: var(--text-color);
  overflow: hidden;
}

/* --- Main App Layout --- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* --- Sidebar --- */
.sidebar {
  background-color: var(--sidebar-bg);
  width: 260px;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color);
}

.sidebar-header {
  padding: 0.5rem 0.5rem 0.75rem;
}

.new-chat-button {
  width: 100%;
  padding: 0.75rem;
  border-radius: 0.375rem;
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.new-chat-button:hover {
  background-color: var(--button-hover-bg);
}

.chat-history-nav {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0.5rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin-top: 0.5rem;
}

.history-label {
    font-size: 0.75rem;
    color: var(--subtle-text-color);
    padding: 0.5rem 0.75rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.history-item {
  display: block;
  padding: 0.75rem;
  border-radius: 0.375rem;
  text-decoration: none;
  color: var(--text-color);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.2s;
}

.history-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 1rem 0.75rem;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.user-profile:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  background-color: #7b1fa2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.875rem;
}

/* --- Main Chat Area --- */
.main-chat-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--main-bg);
  overflow: hidden;
  position: relative;
}

#chat-view {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem 0 2rem;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
#chat-view::-webkit-scrollbar { width: 8px; }
#chat-view::-webkit-scrollbar-track { background: transparent; }
#chat-view::-webkit-scrollbar-thumb { background-color: #555; border-radius: 4px; }
#chat-view::-webkit-scrollbar-thumb:hover { background-color: #777; }

#chat-history {
    display: flex;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 0 1rem;
}

/* --- Welcome Screen --- */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

#welcome-screen h2 {
    margin-top: 1.5rem;
    font-weight: 500;
    font-size: 1.5rem;
}

#welcome-screen.hidden {
  display: none;
}

.logo-container {
    width: 60px;
    height: 60px;
    background-color: #10a37f;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
}

/* --- Chat Messages --- */
.message {
  padding: 1.5rem 0;
  display: flex;
  gap: 1.5rem;
  width: 100%;
}

.message:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 2px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: bold;
  margin-top: 0.25rem;
}

.avatar.user {
  background-color: var(--user-bubble);
}
.avatar.ai {
  background-color: #5436da;
}

.message-content {
  flex-grow: 1;
  padding-top: 0.125rem;
}

.message-text {
  line-height: 1.75;
  font-size: 1rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-text p {
  margin-bottom: 1rem;
}

.message-text p:last-child {
  margin-bottom: 0;
}

/* --- Code Blocks --- */
.code-block-wrapper {
  background-color: var(--code-bg);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: rgba(0, 0, 0, 0.2);
  color: var(--subtle-text-color);
  font-size: 0.8rem;
}

.language-name {
    text-transform: lowercase;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.75rem;
}

.copy-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: var(--subtle-text-color);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
  font-family: var(--font-family);
  font-size: 0.75rem;
}

.copy-button:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-color);
}

.copy-button:disabled {
  cursor: default;
  color: var(--text-color);
}

.copy-button svg {
  width: 14px;
  height: 14px;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
}

.code-block-wrapper code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  font-size: 0.9rem;
  white-space: pre;
  color: #f0f0f0;
  line-height: 1.5;
}

/* --- Loading Indicator --- */
.loading-indicator {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0;
}

.loading-indicator span {
  width: 10px;
  height: 10px;
  background-color: var(--text-color);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-indicator span:nth-child(1) { animation-delay: -0.32s; }
.loading-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.5); }
  40% { transform: scale(1); }
}

/* --- Input Area --- */
footer {
  padding: 1.5rem 1rem;
  width: 100%;
  background: linear-gradient(180deg, rgba(52, 53, 65, 0), var(--main-bg) 58.85%);
  position: relative;
}

.input-container {
    max-width: 768px;
    margin: 0 auto;
    position: relative;
}

#chat-form {
  display: flex;
  align-items: flex-end;
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  transition: border-color 0.2s;
}

#chat-form:focus-within {
  border-color: rgba(255, 255, 255, 0.3);
}

#chat-input {
  flex-grow: 1;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-size: 1rem;
  line-height: 1.5;
  padding: 0.25rem 0;
  outline: none;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-family);
}

#chat-input::-webkit-scrollbar { width: 8px; }
#chat-input::-webkit-scrollbar-track { background: transparent; }
#chat-input::-webkit-scrollbar-thumb { background-color: #555; border-radius: 4px; }

#chat-form button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 0.375rem;
  background-color: var(--user-bubble);
  color: white;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

#chat-form button:not(:disabled):hover {
  background-color: #0d8e6d;
}

#chat-form button:disabled {
  background-color: var(--subtle-text-color);
  cursor: not-allowed;
  opacity: 0.5;
}

.footer-note {
    text-align: center;
    font-size: 0.75rem;
    color: var(--subtle-text-color);
    margin-top: 1rem;
    padding: 0 1rem;
}

/* --- Responsive adjustments --- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
  }
  
  .sidebar.active {
    transform: translateX(260px);
  }
  
  .message {
    padding: 1.25rem 0;
    gap: 1rem;
  }
  
  .avatar {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
  }
}

@media (max-width: 600px) {
  #welcome-screen h2 {
    font-size: 1.25rem;
  }
  
  .message-text {
    font-size: 0.9375rem;
  }
  
  footer {
    padding: 1rem;
  }
  
  #chat-form {
    padding: 0.75rem;
  }
  
  .footer-note {
    font-size: 0.6875rem;
  }
}