:root {
  --page: #eef2f1;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --line: #d8e0e3;
  --line-strong: #adc0c8;
  --ink: #14212a;
  --muted: #5f7079;
  --accent: #128268;
  --accent-strong: #0b6a55;
  --accent-soft: #dff3ee;
  --blue: #266aa6;
  --blue-soft: #e0efff;
  --mine: #dbeeff;
  --theirs: #ffffff;
  --danger: #b33b4a;
  --danger-soft: #fde8eb;
  --shadow: 0 20px 50px rgba(29, 43, 49, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #e8eeee 0%, var(--page) 48%, #f7f9f9 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1120px, 100%);
  height: 100%;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.top-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  min-height: 50px;
  padding: 8px 20px;
}

.brand-block {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 10px;
}

.brand {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 760;
  line-height: 1.1;
}

.room-id {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-details {
  display: grid;
  gap: 10px;
  padding: 0 20px 14px;
}

.topbar.is-collapsed .top-details {
  display: none;
}

.topbar-toggle {
  min-width: 64px;
  min-height: 34px;
}

.top-actions {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.composer textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfdfd;
  outline: none;
}

.field input {
  height: 38px;
  padding: 0 10px;
}

.field input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 650;
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  background: var(--accent);
  color: #ffffff;
}

.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary,
.icon-button {
  background: #edf3f4;
  border-color: var(--line);
  color: var(--ink);
}

.secondary:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  background: #e2eaed;
}

.danger {
  background: var(--danger-soft);
  border-color: #f2bdc5;
  color: var(--danger);
}

.danger:hover:not(:disabled) {
  background: #f9d7dd;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

#connectionText {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.retention {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.status-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
}

.dot.connected {
  background: var(--accent);
}

.chat-panel {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.78)),
    repeating-linear-gradient(135deg, #edf3f2 0, #edf3f2 1px, transparent 1px, transparent 22px);
}

.messages {
  height: 100%;
  overflow-y: auto;
  padding: 22px 20px;
}

.message-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  width: min(74%, 680px);
  margin-bottom: 16px;
}

.message-row.mine {
  grid-template-columns: minmax(0, 1fr) 34px;
  margin-left: auto;
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #e6eef0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.mine .avatar {
  grid-column: 2;
  background: var(--blue-soft);
  color: var(--blue);
}

.message-stack {
  min-width: 0;
}

.mine .message-stack {
  grid-column: 1;
  grid-row: 1;
  text-align: right;
}

.sender {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--theirs);
  box-shadow: 0 8px 22px rgba(42, 57, 64, 0.08);
  text-align: left;
  word-break: break-word;
}

.mine .bubble {
  background: var(--mine);
  border-color: #bfd8f5;
}

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

.bubble img {
  display: block;
  width: min(420px, 100%);
  max-height: 440px;
  border-radius: 7px;
  object-fit: contain;
  background: #eef2f4;
}

.bubble img + p {
  margin-top: 8px;
}

.quoted-reply {
  display: block;
  max-width: 100%;
  margin-bottom: 8px;
  border-left: 3px solid var(--accent);
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(18, 130, 104, 0.08);
  color: var(--muted);
  font-size: 12px;
}

.quoted-reply strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
}

.quoted-reply span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.message-action {
  border: 0;
  border-radius: 7px;
  padding: 4px 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.reply-button {
  margin-top: 2px;
  opacity: 0;
}

.message-row:hover .reply-button,
.message-row:focus-within .reply-button {
  opacity: 1;
}

.mine .reply-button {
  justify-self: end;
}

.message-action:hover {
  background: var(--accent-soft);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.empty-state[hidden] {
  display: none;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.composer textarea {
  min-height: 42px;
  max-height: 150px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.35;
}

.reply-preview {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-soft);
}

.reply-preview[hidden] {
  display: none;
}

.reply-label {
  margin-right: 6px;
  color: var(--muted);
  font-size: 12px;
}

.reply-preview strong {
  font-size: 13px;
}

.reply-preview p {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    box-shadow: none;
  }

  .top-summary {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    min-height: 46px;
    padding: 7px 14px;
  }

  .brand-block {
    gap: 8px;
  }

  .brand {
    font-size: 18px;
  }

  .room-id {
    font-size: 12px;
  }

  .topbar-toggle {
    min-width: 56px;
    padding: 0 10px;
  }

  .top-details {
    padding: 0 14px 10px;
  }

  .top-actions {
    grid-template-columns: 1fr auto;
  }

  .field-url {
    grid-column: 1 / -1;
  }

  .status-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .retention {
    text-align: left;
  }

  .messages {
    padding: 16px 14px;
  }

  .message-row {
    width: 92%;
  }

  .reply-button {
    opacity: 1;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 12px 14px 14px;
  }

  .composer .primary {
    grid-column: 1 / -1;
  }
}
