* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #0f0f0f;
  color: #e5e5e5;
  height: 100vh;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.app-shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid #2b2b2b;
  background-color: #111;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-header {
  height: 61px;
  padding: 14px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #2b2b2b;
  flex-shrink: 0;
}

select.model {
  font: inherit;
  color: inherit;
  background: #1a1a1a;
  border: 1px solid #2b2b2b;
  border-radius: 6px;
  padding: 4px 8px;
  max-width: min(420px, 55vw);
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: #d5d5d5;
}

.conversation-list {
  padding: 8px;
  overflow-y: auto;
}

.conversation-list,
.chat-container,
.table-scroll,
.message.assistant .message-content pre {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.conversation-list::-webkit-scrollbar,
.chat-container::-webkit-scrollbar,
.table-scroll::-webkit-scrollbar,
.message.assistant .message-content pre::-webkit-scrollbar {
  display: none;
}

.conversation-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ccc;
  cursor: pointer;
  text-align: left;
}

.conversation-item:hover {
  background: #1d1d1d;
}

.conversation-item.active {
  background: #242424;
  color: #fff;
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.conversation-delete {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #888;
  cursor: pointer;
  flex-shrink: 0;
}

.conversation-delete:hover {
  background: #333;
  color: #eee;
}

.container {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0 18px;
  min-width: 0;
  justify-self: center;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  gap: 12px;
}

.header-stats {
  font-size: 13px;
  color: #888;
  background: #1a1a1a;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #333;
  line-height: 1.4;
  min-width: 0;
  max-width: 56%;
}

.header-stats #tokenStats {
  font-family: monospace;
  overflow-wrap: anywhere;
}

.header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.model {
  font-size: 13px;
  color: #888;
  font-weight: 400;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user .message-content {
  background-color: #2a2a2a;
  border-bottom-right-radius: 4px;
}

.message.queued-message .message-content {
  border: 1px dashed #555;
  color: #cfcfcf;
  opacity: 0.82;
}

.message.assistant .message-content {
  background-color: transparent;
  border-radius: 0;
  max-width: 100%;
  width: 100%;
  padding: 4px 0 14px;
  white-space: normal;
}

.message.assistant .message-content > :first-child {
  margin-top: 0;
}

.message.assistant .message-content > :last-child {
  margin-bottom: 0;
}

.message.assistant .message-content p {
  margin: 0 0 12px;
}

.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
  margin: 16px 0 8px;
  line-height: 1.25;
  font-weight: 650;
}

.message.assistant .message-content h1 {
  font-size: 20px;
}

.message.assistant .message-content h2 {
  font-size: 17px;
}

.message.assistant .message-content h3 {
  font-size: 15px;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
  margin: 8px 0 12px;
  padding-left: 24px;
}

.message.assistant .message-content li {
  margin: 4px 0;
}

.message.assistant .message-content blockquote {
  margin: 10px 0 12px;
  padding-left: 12px;
  border-left: 3px solid #4b5563;
  color: #cfcfcf;
}

.message.assistant .message-content a {
  color: #8ab4ff;
  text-decoration: none;
}

.message.assistant .message-content a:hover {
  text-decoration: underline;
}

.message.assistant .message-content code {
  font-family: Consolas, 'SFMono-Regular', Menlo, monospace;
  font-size: 0.92em;
  background: #151515;
  border: 1px solid #333;
  border-radius: 5px;
  padding: 1px 4px;
}

.message.assistant .message-content pre {
  margin: 10px 0 12px;
  max-width: 100%;
  overflow: visible;
  padding: 12px;
  background: #121212;
  border: 1px solid #333;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.assistant .message-content pre code {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.table-scroll {
  max-width: 100%;
  margin: 10px 0 12px;
  overflow: visible;
  border: 1px solid #333;
  border-radius: 8px;
}

.message.assistant .message-content table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
  white-space: normal;
}

.message.assistant .message-content th,
.message.assistant .message-content td {
  padding: 8px 10px;
  border-bottom: 1px solid #303030;
  border-right: 1px solid #303030;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: normal;
}

.message.assistant .message-content th:last-child,
.message.assistant .message-content td:last-child {
  border-right: 0;
}

.message.assistant .message-content tbody tr:last-child td {
  border-bottom: 0;
}

.message.assistant .message-content th {
  background: #181818;
  color: #f0f0f0;
  font-weight: 600;
}

.message.assistant .message-content td {
  color: #dedede;
}

.input-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  margin: 12px 0 22px;
  padding: 10px;
  border: 1px solid #333;
  border-radius: 18px;
  background: #181818;
  flex-shrink: 0;
  align-items: end;
}

textarea {
  grid-column: 1;
  background-color: transparent;
  border: 0;
  color: #eee;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 15px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  min-height: 42px;
}

.attachment-preview,
.attach-status {
  grid-column: 1 / -1;
}

.attachment-preview {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
}

.attachment-preview.has-items {
  display: flex;
}

.attachment-item {
  width: 92px;
  height: 74px;
  position: relative;
  border: 1px solid #333;
  border-radius: 8px;
  overflow: hidden;
  background: #181818;
  flex: 0 0 auto;
}

.attachment-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.attachment-file {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: end;
  padding: 8px;
  color: #ddd;
  font-size: 11px;
  line-height: 1.25;
  word-break: break-word;
  background: #202020;
}

.attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.74);
  color: #fff;
  cursor: pointer;
  line-height: 1;
}

.attach-status {
  min-height: 0;
  color: #aaa;
  font-size: 12px;
}

.attach-status.error {
  color: #ff8b8b;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

#attachBtn {
  grid-column: 2;
}

#sendBtn {
  grid-column: 3;
}

textarea:focus {
  box-shadow: none;
}

.btn {
  background-color: #2a2a2a;
  color: #ddd;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.compact {
  padding: 7px 10px;
  font-size: 13px;
}

.btn:hover {
  background-color: #3a3a3a;
}

.btn.primary {
  background-color: #2563eb;
  color: white;
}

.btn.primary:hover {
  background-color: #1d4ed8;
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #888;
  font-style: italic;
}

.error {
  color: #ff6b6b;
  background-color: #2a1f1f;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}

.message-meta {
  font-size: 12px;
  color: #aaa;
  margin-top: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  line-height: 1.4;
}

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

.message-images img {
  width: 120px;
  height: 92px;
  object-fit: cover;
  border: 1px solid #333;
  border-radius: 8px;
  background: #111;
}

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

  .sidebar {
    height: 132px;
    border-right: 0;
    border-bottom: 1px solid #2b2b2b;
  }

  .conversation-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .conversation-item {
    width: 190px;
    flex: 0 0 190px;
  }

  .container {
    height: calc(100vh - 132px);
  }

  .message-content {
    max-width: 88%;
  }

  .message.assistant .message-content {
    max-width: 100%;
  }

  .message.assistant .message-content table {
    min-width: 0;
  }

  .input-area {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #sendBtn {
    grid-column: 2;
  }

  #attachBtn {
    grid-column: 1;
    justify-self: end;
  }
}
