:root {
  color-scheme: dark;
  --bg: #171717;
  --sidebar: #111111;
  --surface: #252525;
  --border: #333333;
  --text: #f2f2f2;
  --muted: #999999;
  --accent: #d97757;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
}

.brand {
  font-size: 19px;
  font-weight: 650;
  padding: 8px 10px 26px;
}

#new-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 11px;
  padding: 13px;
  text-align: left;
}

#new-chat:hover,
.chat-item:hover {
  background: #303030;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 20px;
}

.chat-item {
  padding: 12px;
  border-radius: 9px;
  cursor: pointer;
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item.active {
  background: var(--surface);
  color: white;
}

.sidebar-footer {
  color: var(--muted);
  font-size: 12px;
  padding: 14px 10px 0;
  border-top: 1px solid var(--border);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 65px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

#chat-title {
  font-weight: 600;
}

.status {
  font-size: 13px;
  color: var(--muted);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 30px 24px;
}

.welcome {
  text-align: center;
  margin: 15vh auto 0;
}

.welcome h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 10px;
}

.welcome p {
  color: var(--muted);
}

.message {
  max-width: 800px;
  margin: 0 auto 24px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 18px;
  width: fit-content;
  max-width: min(80%, 650px);
  margin-right: max(0px, calc((100% - 800px) / 2));
}

.message.assistant {
  padding: 8px 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: calc(100% - 48px);
  max-width: 850px;
  margin: 0 auto 24px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
}

#message-input {
  flex: 1;
  min-width: 0;
  max-height: 180px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 10px;
  line-height: 1.5;
}

#send-button {
  border: none;
  background: var(--accent);
  color: white;
  padding: 11px 17px;
  border-radius: 11px;
  font-weight: 600;
}

#send-button:hover {
  background: #c66547;
}

#send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .sidebar {
    width: 200px;
    padding: 14px 8px;
  }

  .brand {
    font-size: 15px;
  }

  .topbar {
    padding: 0 15px;
  }

  .messages {
    padding: 20px 15px;
  }

  .composer {
    width: calc(100% - 24px);
    margin-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .welcome h1 {
    font-size: 25px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 150px;
  }

  .brand {
    font-size: 13px;
  }

  #new-chat {
    font-size: 12px;
    padding: 10px 7px;
  }

  .sidebar-footer {
    font-size: 10px;
  }

  .status {
    display: none;
  }

  #send-button {
    padding: 10px;
    font-size: 12px;
  }
}
