:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f6f4;
  color: #1f2528;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

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

button {
  border: 1px solid #1f2528;
  background: #1f2528;
  color: white;
  min-height: 42px;
  padding: 0 14px;
}

button.secondary,
#cancelNewThread,
#refresh {
  background: white;
  color: #1f2528;
}

button:disabled {
  opacity: 0.55;
}

.shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 16px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

p {
  margin: 4px 0 0;
  color: #5e686d;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.setup,
.newThread {
  background: white;
  border: 1px solid #d8d8d2;
  padding: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #4a5357;
  font-size: 13px;
  margin-bottom: 12px;
}

.fieldHint {
  margin: 0;
  overflow: hidden;
  color: #79848a;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8cbc6;
  background: white;
  color: #1f2528;
  border-radius: 0;
  padding: 10px;
}

textarea {
  min-height: 48px;
  max-height: 180px;
  resize: vertical;
}

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 86px);
}

.threads,
.chat {
  min-width: 0;
  background: white;
  border: 1px solid #d8d8d2;
}

.threads {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 100px);
}

.threadActions {
  padding: 12px;
  border-bottom: 1px solid #e4e4df;
}

.threadActions button {
  width: 100%;
}

.threadList {
  overflow: auto;
}

.thread {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #ecece8;
  background: white;
  color: #1f2528;
  min-height: 56px;
  padding: 10px 12px;
}

.thread.active {
  background: #e9f2ee;
}

.thread strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

.thread span {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #667176;
  font-size: 12px;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 100px);
}

.newThread {
  border-width: 0 0 1px;
}

.formActions {
  display: flex;
  gap: 10px;
}

.messages {
  overflow: auto;
  padding: 14px;
}

.empty {
  color: #667176;
  padding: 30px 0;
  text-align: center;
}

.message {
  max-width: 860px;
  margin: 0 0 14px;
  padding: 11px 12px;
  border: 1px solid #e0e0da;
  background: #fafaf8;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.message.user {
  margin-left: auto;
  background: #eaf0f7;
  border-color: #d6e2ef;
}

.message.assistant {
  margin-right: auto;
}

.message.system {
  max-width: none;
  background: #fff8e5;
  border-color: #eadfbf;
  color: #675b36;
  font-size: 13px;
}

.role {
  display: block;
  margin-bottom: 5px;
  color: #667176;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

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

.imageGrid:first-child {
  margin-top: 0;
}

.chatImage {
  display: block;
  width: auto;
  max-width: min(100%, 360px);
  max-height: 420px;
  border: 1px solid #d8d8d2;
  background: #f1f1ed;
  object-fit: contain;
}

.messageMarkdown {
  display: grid;
  gap: 8px;
}

.messageMarkdown > * {
  margin: 0;
}

.messageMarkdown h2,
.messageMarkdown h3,
.messageMarkdown h4,
.messageMarkdown h5,
.messageMarkdown h6 {
  color: #1f2528;
  font-size: 15px;
  line-height: 1.3;
}

.messageMarkdown p,
.messageMarkdown li {
  white-space: pre-wrap;
}

.messageMarkdown ul,
.messageMarkdown ol {
  display: grid;
  gap: 4px;
  padding-left: 22px;
}

.messageMarkdown blockquote {
  border-left: 3px solid #c8cbc6;
  color: #4a5357;
  padding-left: 10px;
}

.messageMarkdown pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid #d8d8d2;
  background: #f1f1ed;
  padding: 10px;
  white-space: pre;
}

.messageMarkdown code {
  border: 1px solid #d8d8d2;
  background: #f1f1ed;
  padding: 1px 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.93em;
}

.messageMarkdown pre code {
  display: block;
  border: 0;
  padding: 0;
}

.messageMarkdown a {
  color: #245c8f;
  text-decoration: underline;
}

.messageMarkdown hr {
  width: 100%;
  border: 0;
  border-top: 1px solid #d8d8d2;
}

.markdownImage {
  display: block;
  max-width: min(100%, 360px);
  max-height: 420px;
  border: 1px solid #d8d8d2;
  background: #f1f1ed;
  object-fit: contain;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #e4e4df;
}

.composerBody {
  display: grid;
  gap: 8px;
}

.composerActions {
  display: flex;
  gap: 8px;
  align-items: end;
}

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

.attachment {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: min(100%, 360px);
  border: 1px solid #deded8;
  background: #fafaf8;
  padding: 6px;
}

.attachment img {
  width: 44px;
  height: 44px;
  background: #f1f1ed;
  object-fit: cover;
}

.attachment span {
  overflow: hidden;
  color: #4a5357;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment button {
  min-height: 32px;
  padding: 0 9px;
  border-color: #c8cbc6;
  background: white;
  color: #1f2528;
  font-size: 12px;
}

@media (max-width: 760px) {
  .shell {
    padding: 10px;
  }

  .app {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 76px);
  }

  .threads {
    max-height: 210px;
  }

  .chat {
    min-height: calc(100vh - 300px);
  }

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

  .composerActions {
    align-items: stretch;
  }

  .composerActions button {
    flex: 1;
  }

  .formActions {
    flex-direction: column;
  }
}
