:root {
  --bg-dark: #343541;
  --bg-light: #f7f7f8;
  --text-dark: #ececf1;
  --text-light: #343541;
  --user-color: #444654;
  --bot-color: #444654;
  --error-color: #d93025;
  --border-dark: #40414f;
  --border-light: #c3c3c8;
  --header-dark: #202123;
  --header-light: #fff;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: var(--bg-dark);
  color: var(--text-dark);
  transition: background 0.3s, color 0.3s;
}

body.light {
  background-color: var(--bg-light);
  color: var(--text-light);
}

html.light body {
  background-color: var(--bg-light);
  color: var(--text-light);
}
html.light #inputContainer { background: var(--bg-light); }
html.light #chatHeader, html.light header#chatHeader {
  background: #f5f5f5;
  color: #0b93f6;
  border-bottom: 1px solid #e0e0e0;
}
html.light #userInput { background: #e0e0e0; color: var(--text-light); }

#chatContainer {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  position: relative;
}

#modelContainer {
  padding:10px; border-top:1px solid #444; background:#202124;
}
#modelSelect {
  min-width: 120px;
  max-width: 180px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #303134;
  color: #e8eaed;
  font-size: 15px;
  margin-right: 8px;
  flex-shrink: 0;
}

body.light #modelSelect {
  background: #f7f7f8;
  color: #17191c;
  border: 1px solid #c3c3c8;
}

#scrollBtn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 70px;
  background: var(--user-color);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  display: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  z-index: 10;
}

.message {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: 12px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-size: 16px;
}
.message b {
  font-weight: bold;
  color: inherit;
}
.user {
  align-self: flex-end;
  background: var(--user-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bot {
  align-self: flex-start;
  background: var(--bot-color);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
}
.user, .bot {
  border: 1px solid #fff; /* Default: white for dark mode */
}
body.light .user, body.light .bot {
  border: 1px solid #c3c3c8; /* Grey for light mode */
}
body.light .bot {
  background: #ececf1;
  color: var(--text-light);
}
.error {
  background: var(--error-color);
  color: #fff;
}

.message ul, .message ol {
  margin: 8px 0 8px 24px;
  padding: 0;
}
.message li {
  margin-bottom: 4px;
}
.message code {
  background: hsl(219, 8%, 43%);
  color: #f7f7f8;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.97em;
}
body.light .message code {
  background: #f7f7f8;
  color: #080909;
  border: 1px solid #e0e0e0;
}
.message i {
  font-style: italic;
}
.message h1, .message h2, .message h3 {
  margin: 8px 0 4px 0;
  font-weight: bold;
}
.message h1 { font-size: 1.3em; }
.message h2 { font-size: 1.15em; }
.message h3 { font-size: 1.05em; }

pre {
  background: #111112;           /* Dark background for dark mode */
  color: #f7f7f8;                /* Light text for dark mode */
  padding: 12px;
  border-radius: 10px;
  overflow: auto;
  font-size: 15px;
  margin: 0 0 6px 0;
  position: relative;
  max-height: 400px;
  border: 1px solid #343541;     /* Subtle border for dark mode */
}
body.light pre {
  background: #e8e8ea;           /* Light grey background for light mode */
  color: #0f0f0f;                /* Dark text for light mode */
  border: 1px solid #959393;     /* Light border for light mode */
}
pre code {
  display: block;
  white-space: pre;
  margin: 0;
  background: none !important;   /* Remove Prism background */
  color: inherit !important;     /* Inherit color from pre */
  padding: 0;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--user-color);
  border: none;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  opacity: 1;
  transition: opacity 0.2s;
}
pre:hover .copy-btn { opacity: 1; }

#inputContainer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--border-dark);
  background: var(--header-dark);
  flex-wrap: wrap; /* allow wrapping on small screens */
}
body.light #inputContainer {
  background: var(--header-light);
  border-top: 1px solid var(--border-light);
}

#userInput {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border-dark);
  background: #40414f;
  color: var(--text-dark);
  font-size: 16px;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.5;
  overflow-y: auto;
  box-sizing: border-box;
  transition: background 0.3s, color 0.3s;
}
body.light #userInput {
  background: #fff;
  color: var(--text-light);
  border: 1px solid var(--border-light);
}

#sendBtn {
  margin-left: 10px;
  padding: 10px 20px;
  border-radius: 20px;
  border: none;
  background: var(--user-color);
  color: #fff;
  font-weight: bold;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}
#sendBtn:hover {
  background: #6e7170;
}

#themeToggle {
  margin-left: 8px;
  padding: 6px 10px;
  border-radius: 20px;
  border: none;
  background: #565869;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
}

.typing {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 2px;
  background: #ececf1;
  border-radius: 50%;
  animation: blink 1s infinite;
}
.typing:nth-child(2) { animation-delay: 0.2s; }
.typing:nth-child(3) { animation-delay: 0.4s; }
body.light .typing {
  background: #343541; /* dark gray for visibility on light background */
}
@keyframes blink { 0%,80%,100%{opacity:0;} 40%{opacity:1;} }

#chatHeader, header#chatHeader {
  background: var(--header-dark);
  color: var(--user-color);
  font-size: 1.4rem;
  font-weight: 700;
  padding: 18px 0 10px 28px;
  border-bottom: 1px solid var(--border-dark);
  margin-bottom: 0;
  text-align: left;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  letter-spacing: 0.5px;
}
body.light #chatHeader, body.light header#chatHeader {
  background: var(--header-light);
  color: var(--user-color);
  border-bottom: 1px solid var(--border-light);
}
body.dark #chatHeader, body.dark header#chatHeader {
  background: #202124;
  color: #eaedef;
  border-bottom: 1px solid #444;
}

.spinner {
  border: 2px solid #fff;
  border-top: 2px solid #fefbfb;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: inline-block;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  100% { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  #inputContainer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }
  #modelSelect {
    width: 100%;
    max-width: none;
    margin-right: 0;
    margin-bottom: 6px;
  }
  #userInput {
    min-height: 38px;
    font-size: 15px;
  }
  #sendBtn, #themeToggle {
    width: 100%;
    margin-left: 0;
    margin-top: 6px;
  }
}
