:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #176b87;
  --accent-dark: #0f5065;
  --user: #176b87;
  --assistant: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  background: #101828;
  color: #ffffff;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #3ba6b9;
  font-weight: 700;
}

.brand h1,
.chat-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand p,
.chat-header p {
  margin: 4px 0 0;
  color: #98a2b3;
  font-size: 13px;
}

.new-chat,
.debug-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

.link-button {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.new-chat {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.chat-search {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  min-height: 38px;
  padding: 0 12px;
}

.chat-search::placeholder {
  color: #98a2b3;
}

.chat-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.chat-tabs button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: transparent;
  color: #d0d5dd;
  min-height: 34px;
  cursor: pointer;
}

.chat-tabs button.active {
  background: #ffffff;
  color: #101828;
}

.history-group {
  min-height: 0;
  flex: 1;
}

.history-group h2 {
  margin: 0 0 8px;
  color: #98a2b3;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.conversation-list {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  max-height: calc(100vh - 250px);
}

.conversation-item {
  position: relative;
  display: grid;
  gap: 3px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffffff;
  padding: 10px 32px 10px 10px;
  text-align: left;
  cursor: pointer;
}

.conversation-item:hover,
.conversation-item.selected {
  background: rgba(255, 255, 255, 0.1);
}

.conversation-title,
.conversation-preview {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title {
  font-size: 14px;
  font-weight: 700;
}

.conversation-preview {
  color: #98a2b3;
  font-size: 12px;
}

.conversation-menu {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.empty-state {
  color: #98a2b3;
  font-size: 13px;
  padding: 8px 2px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  color: #d0d5dd;
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #12b76a;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.menu-button {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  min-width: 38px;
  height: 38px;
  cursor: pointer;
}

.messages {
  overflow-y: auto;
  padding: 28px 24px;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 820px);
  gap: 12px;
  margin: 0 auto 18px;
  max-width: 920px;
}

.message.user {
  grid-template-columns: minmax(0, 820px) 36px;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
  background: #0f5065;
}

.message.user .bubble {
  grid-column: 1;
  justify-self: end;
  background: var(--user);
  color: #ffffff;
}

.message.failed .bubble {
  border-color: #fecdca;
  background: #fff5f5;
  color: #912018;
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #344054;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--assistant);
  padding: 14px 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.suggestions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

.debug {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.sources {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

.source blockquote {
  margin: 6px 0 0;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  color: #344054;
}

.message-tools {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.message-tools button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  min-height: 30px;
  padding: 0 10px;
  cursor: pointer;
}

.feedback-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.feedback-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.feedback-form input,
.feedback-form select,
.feedback-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  min-height: 36px;
  padding: 8px 10px;
  color: var(--text);
}

.feedback-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

.feedback-actions button[type="submit"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.feedback-status {
  color: var(--accent-dark);
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 20px;
}

textarea {
  width: 100%;
  max-height: 160px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 13px 14px;
  color: var(--text);
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
}

#sendButton,
.composer button[type="submit"] {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-size: 22px;
}

#sendButton:disabled,
.composer button[type="submit"]:disabled {
  background: #98a2b3;
  cursor: wait;
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    display: flex;
    width: min(84vw, 320px);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: 16px 0 40px rgba(16, 24, 40, 0.22);
  }

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

  .menu-button {
    display: grid;
    place-items: center;
  }

  .chat-header {
    padding: 14px 16px;
  }

  .messages {
    padding: 18px 12px;
  }

  .message,
  .message.user {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .message.user .avatar {
    grid-column: 1;
  }

  .message.user .bubble {
    grid-column: 2;
    justify-self: stretch;
  }

  .feedback-grid {
    grid-template-columns: 1fr;
  }
}
