/* ===== Overall Layout ===== */
body {
  background: #343541;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

#chat-container {
  width: 900px;
  height: 95vh;
  background: #343541;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 30px rgba(0,0,0,0.3);
}

/* ===== Header ===== */
#header {
  background: #202123;
  color: white;
  text-align: center;
  padding: 16px;
  font-size: 1.2rem;
  font-weight: 600;
  border-bottom: 1px solid #444654;
}

/* ===== Chat Box ===== */
#chat-box {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ===== Message Styles ===== */
.message {
  padding: 28px 24px;
  border-bottom: 1px solid #444654;
  line-height: 1.75;
  font-size: 16px;
}

.user-message {
  background: #343541;
  color: #ececf1;
}

.ai-message {
  background: #444654;
  color: #ececf1;
}

/* ===== First element margin fix ===== */
.ai-message > *:first-child {
  margin-top: 0 !important;
}

.ai-message > *:last-child {
  margin-bottom: 0 !important;
}

/* ===== Typography in AI Messages ===== */
.ai-message h1,
.ai-message h2,
.ai-message h3,
.ai-message h4,
.ai-message h5,
.ai-message h6 {
  color: #ececf1;
  margin-top: 28px;
  margin-bottom: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.ai-message h1 { 
  font-size: 2em;
  border-bottom: 2px solid #555;
  padding-bottom: 8px;
}

.ai-message h2 { 
  font-size: 1.6em;
  border-bottom: 1px solid #555;
  padding-bottom: 6px;
}

.ai-message h3 { font-size: 1.3em; }
.ai-message h4 { font-size: 1.1em; }
.ai-message h5 { font-size: 1em; font-weight: 600; }
.ai-message h6 { font-size: 0.95em; font-weight: 600; }

.ai-message p {
  margin: 16px 0;
  color: #ececf1;
  line-height: 1.75;
}

/* ===== Lists ===== */
.ai-message ul,
.ai-message ol {
  margin: 16px 0;
  padding-left: 28px;
  color: #ececf1;
  line-height: 1.75;
}

.ai-message li {
  margin: 10px 0;
  padding-left: 8px;
}

.ai-message ul {
  list-style-type: disc;
}

.ai-message ol {
  list-style-type: decimal;
}

.ai-message ul ul,
.ai-message ol ol,
.ai-message ul ol,
.ai-message ol ul {
  margin: 8px 0;
}

/* ===== Code Blocks ===== */
.ai-message pre {
  background: #000000;
  color: #d4d4d4;
  padding: 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid #333;
  position: relative;
  line-height: 1.6;
}

.ai-message pre code {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: #d4d4d4;
  display: block;
}

/* Inline code */
.ai-message code {
  background: #2d2d2d;
  color: #eb5757;
  padding: 3px 6px;
  border-radius: 4px;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 0.9em;
}

.ai-message p code,
.ai-message li code {
  background: #2d2d2d;
  color: #eb5757;
}

/* ===== Tables ===== */
.ai-message table {
  border-collapse: collapse;
  width: 100%;
  margin: 20px 0;
  background: #2d2d2d;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #444;
}

.ai-message table thead {
  background: #1a1a1a;
}

.ai-message table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: #ececf1;
  border-bottom: 2px solid #444654;
}

.ai-message table td {
  padding: 12px 16px;
  border-bottom: 1px solid #444654;
  color: #d1d5db;
  line-height: 1.6;
}

.ai-message table tr:last-child td {
  border-bottom: none;
}

.ai-message table tr:hover {
  background: #3a3a3a;
}

/* ===== Blockquotes ===== */
.ai-message blockquote {
  border-left: 4px solid #10a37f;
  padding: 12px 0 12px 20px;
  margin: 20px 0;
  color: #b4b4b4;
  font-style: italic;
  background: #3a3a3a;
  border-radius: 0 4px 4px 0;
}

.ai-message blockquote p {
  margin: 8px 0;
}

/* ===== Links ===== */
.ai-message a {
  color: #10a37f;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.ai-message a:hover {
  border-bottom-color: #10a37f;
}

/* ===== Strong and Emphasis ===== */
.ai-message strong {
  font-weight: 700;
  color: #fff;
}

.ai-message em {
  font-style: italic;
  color: #d4d4d4;
}

/* ===== Horizontal Rules ===== */
.ai-message hr {
  border: none;
  border-top: 1px solid #444654;
  margin: 28px 0;
}

/* ===== Input Area ===== */
#chat-form {
  display: flex;
  padding: 16px;
  background: #343541;
  border-top: 1px solid #444654;
  gap: 12px;
}

#user-input {
  flex: 1;
  resize: none;
  height: 50px;
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #40414f;
  color: #ececf1;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
}

#user-input::placeholder {
  color: #8e8ea0;
}

#user-input:focus {
  outline: none;
  border-color: #10a37f;
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

button {
  background: #10a37f;
  color: white;
  border: none;
  padding: 0 24px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

button:hover {
  background: #0e8b6a;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Scrollbar ===== */
#chat-box::-webkit-scrollbar {
  width: 8px;
}

#chat-box::-webkit-scrollbar-track {
  background: #2d2d2d;
}

#chat-box::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}

#chat-box::-webkit-scrollbar-thumb:hover {
  background: #666;
}

/* ===== Thinking Animation ===== */
#thinking-message {
  opacity: 0.7;
}

@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

#thinking-message {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ===== Image Support ===== */
.ai-message img {
  max-width: 100%;
  border-radius: 8px;
  margin: 16px 0;
  display: block;
}

/* ===== Nested Lists Fix ===== */
.ai-message li > ul,
.ai-message li > ol {
  margin-top: 8px;
  margin-bottom: 4px;
}