:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #d9dde5;
  --text: #1f2328;
  --muted: #687385;
  --blue: #2878ff;
  --green: #2da44e;
  --danger: #d1242f;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:disabled,
textarea:disabled,
input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  min-height: 620px;
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

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

.filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.community-picker {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

#communityState {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.filter {
  padding: 0 8px;
}

.filter.active {
  border-color: var(--blue);
  color: var(--blue);
}

.conversation-list {
  overflow: auto;
}

.conversation {
  width: 100%;
  min-height: 76px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 12px 14px;
}

.conversation.active {
  background: #eef4ff;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e6e9ef;
  display: grid;
  place-items: center;
  color: var(--muted);
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conversation-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

.badge {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  display: grid;
  place-items: center;
  font-size: 12px;
  padding: 0 6px;
}

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

.chat-header {
  min-height: 72px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 0 10px;
}

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

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.message {
  max-width: min(680px, 82%);
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message.outbound {
  margin-left: auto;
  border-color: #b8d3ff;
  background: #eef6ff;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-time {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

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

.attachment {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 13px;
  background: white;
}

.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

#sendButton {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  min-width: 96px;
}

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

.pending-attachment {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  background: #f8fafc;
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
    min-height: 100vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-header {
    padding: 12px;
  }

  .messages {
    padding: 12px;
  }

  .message {
    max-width: 94%;
  }
}
