:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #687a75;
  --line: #dce5e1;
  --panel: #f4f7f5;
  --brand: #0b806b;
  --bubble-me: #d9fdd3;
  --bubble-them: #ffffff;
  --wash: #efe9dd;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: #d6d9d1;
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 390px) 1fr;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

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

.topbar,
.conversation-header {
  min-height: 64px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar span,
.conversation-header span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 9px 12px;
  font-weight: 600;
  cursor: pointer;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
  background: #fff;
}

input:focus {
  border-color: var(--brand);
}

.searchbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.chat-list {
  overflow: auto;
}

.chat {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f0;
  cursor: pointer;
}

.chat:hover,
.chat.active {
  background: #edf5f2;
}

.chat strong,
.chat p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0;
}

.chat p,
.chat time {
  color: var(--muted);
  font-size: 13px;
}

.conversation {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--wash);
}

.conversation-header input {
  max-width: 360px;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 22px clamp(14px, 4vw, 72px);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.messages.empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.message {
  max-width: min(680px, 78%);
  padding: 7px 9px 5px;
  border-radius: 8px;
  background: var(--bubble-them);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.07);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.message.me {
  align-self: flex-end;
  background: var(--bubble-me);
}

.message .sender {
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 3px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.message time {
  display: block;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.media-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--brand);
  font-weight: 600;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(520px, calc(100vw - 28px));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(20, 30, 28, 0.45);
}

.dialog-body {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.dialog-body h2,
.dialog-body p {
  margin: 0;
}

.dialog-body label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-body label input {
  color: var(--ink);
}

.check {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.check input {
  width: auto;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.actions button:first-child {
  background: #e8eeeb;
  color: var(--ink);
}

.setup-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  background: rgba(24, 34, 31, 0.42);
}

.setup-panel.open {
  display: block;
}

.setup-shell {
  height: min(92vh, 860px);
  width: min(1120px, calc(100vw - 28px));
  margin: 4vh auto;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

.setup-head {
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setup-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.setup-grid {
  overflow: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.setup-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.setup-card.wide {
  grid-column: 1 / -1;
}

.setup-card h2,
.setup-card p {
  margin: 0;
}

.setup-card h2 {
  font-size: 18px;
}

.setup-card p,
.hint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.setup-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.setup-card code {
  background: #edf3f0;
  padding: 1px 4px;
  border-radius: 4px;
}

.upload-box {
  border: 1px dashed #9fb3ad;
  border-radius: 8px;
  min-height: 74px;
  place-items: center;
  color: var(--brand);
  cursor: pointer;
}

.upload-box input {
  max-width: 260px;
}

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

.status-line span {
  background: #edf5f2;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.logs {
  height: 280px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: #111816;
  color: #d8f5e8;
  border-radius: 6px;
  font: 12px/1.45 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

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

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

  .sidebar:has(.chat.active) {
    display: none;
  }

  .conversation-header input {
    max-width: 48vw;
  }

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