html,
body {
  margin: 0;
  padding: 0;
  height: 100dvh;
}

body {
  display: flex;
  font-family: "Roboto", sans-serif;
  background: #121212;
  color: #e0e0e0;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Sidebar */
#sidebar {
  z-index: 1000;
  background: #1e1e1e;
  border-right: 1px solid #333;
  overflow-y: auto;
  padding: 10px;
  box-sizing: border-box;
  min-width: 150px;
  max-width: 300px;
  transition: transform 0.3s;
}

/* Sidebar toggle */
#sidebarToggle {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top, 10px) + 5px);
  left: 10px;
  z-index: 1003;
  background: #007bff;
  border: none;
  color: white;
  padding: 6px;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}

/* New chat form */
#newChatForm {
  margin-top: 5px;
}

#newChatForm input,
#newChatForm button {
  background: #2c2c2c;
  border: 1px solid #333;
  color: #e0e0e0;
  box-sizing: border-box;
  height: 2rem;
  padding: 0.25rem;
  font-size: 1rem;
}

#newChatForm button {
  width: 2rem;
}

/* Chat list items */
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0;
  padding: 4px 8px;
  border-radius: 4px;
}

.chat-item a {
  flex: 1;
  color: #cfcfcf;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.delete {
  background: none;
  border: none;
  color: #ff5555;
  font-size: 1rem;
  margin-left: 8px;
  cursor: pointer;
}

/* Main content */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #181818;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header controls */
#controls {
  position: sticky;
  top: 0;
  z-index: 1002;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #333;
  background: #181818;
}

#chatTitle {
  font-size: 1.2rem;
}

#closeChatBtn {
  background: #333;
  border: 1px solid #444;
  color: #e0e0e0;
  padding: 6px 12px;
  cursor: pointer;
}

/* Chat window */
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px;
}

.message {
  position: relative;
  max-width: 80%;
  padding: 8px;
  padding-right: 60px;
  margin: 6px 0;
  line-height: 18pt;
}

.message.system {
  align-self: center;
  color: #cb8080;
  max-width: 100%;
  border-bottom: solid 1px #666;
}

.message.user {
  align-self: flex-end;
  color: #ffcc80;
  border: 2px solid #555;
  border-radius: 6px;
  background: #1e1e1e;
  /* white-space: pre; */
}

.message.assistant {
  align-self: flex-start;
}

.message.error {
  align-self: center;
  text-align: center;
  color: #ff5555;
  border-color: #ff4444;
  background: #330000;
}

/* Edit button */
.edit-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: inherit;
  border: none;
  color: #ccc;
  padding: 2px 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Input bar */
#inputBar {
  display: flex;
  border-top: 1px solid #333;
  background: #1e1e1e;
  position: sticky;
  bottom: env(safe-area-inset-bottom);
  z-index: 10;
  padding-bottom: 3px;
}

#inputBar textarea {
  flex: 1;
  padding: 10px;
  resize: none;
  background: #2c2c2c;
  border: none;
  color: #e0e0e0;
  z-index: 10;
}

#inputBar button {
  padding: 10px;
  background: #2c2c2c;
  border: 1px solid #333;
  color: #e0e0e0;
  cursor: pointer;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  #controls #chatTitle {
    margin-left: 2.5rem;
  }

  body {
    flex-direction: column;
  }

  #sidebarToggle {
    display: block;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    padding-top: 3rem;
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  #chat {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  #inputBar {
    position: fixed;
    bottom: env(safe-area-inset-bottom);
    left: 0;
    right: 0;
  }
}

/* Markdown formatting */
.message.markdown p {
  margin: 0 0 1em;
}

.message.markdown pre {
  background: #2c2c2c;
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.modal-backdrop {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: #1e1e1e;
  padding: 20px;
  border-radius: 6px;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 10001;
  min-width: 320px;
  color: #e0e0e0;
}

.modal-content h2 {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.vector-item {
  margin-bottom: 0.5rem;
}

.files-form {
  display: flex;
  flex-direction: column;
}
.files-form >* {
  margin: 0.5rem 0;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
}

.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 0.2em solid rgba(0,0,0,0.1);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}