:root {
  color-scheme: dark;
  --bg: #0f1115;
  --rail: #14181d;
  --panel: #191d23;
  --panel-soft: #20262d;
  --panel-strong: #272f38;
  --line: #303842;
  --line-strong: #48525f;
  --text: #eef2f6;
  --muted: #9da7b2;
  --accent: #23b38f;
  --accent-dark: #15906f;
  --accent-soft: #173b34;
  --warn: #ff6b5f;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

input,
textarea {
  color: var(--text);
}

.shell {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.rail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--rail);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand.compact {
  margin-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #07110e;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.05rem;
  line-height: 1.2;
}

h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.brand p,
.status-notice,
.person-email,
.message-email,
.message-time,
.room-sub {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.rooms-panel,
.people-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.people-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2,
.people-panel h2 {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.icon-button,
.formatbar button,
.message-delete {
  display: grid;
  place-items: center;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

.icon-button:hover,
.formatbar button:hover,
.message-delete:hover,
.ghost-button:hover {
  border-color: var(--accent);
}

.mini-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 10px;
}

.mini-form.inline {
  margin-bottom: 0;
}

.mini-form input,
.profile-form input,
.composer textarea {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #111419;
  outline: none;
}

.mini-form input {
  min-height: 38px;
  padding: 0 10px;
}

.mini-form button {
  min-height: 38px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 800;
}

.room-list,
.people-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.room-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.room {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.room.active {
  background: var(--panel-soft);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.room-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.room.private .room-dot {
  background: #f2c94c;
}

.room-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.people-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.person {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #73e7c7;
  font-size: 0.86rem;
  font-weight: 900;
}

.person-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--panel);
}

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

.chat-title {
  min-width: 0;
}

.status-notice {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 18px;
}

.status-spinner {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.status-progress-text {
  color: var(--muted);
}

.status-progress {
  width: min(220px, 100%);
  height: 4px;
  margin-top: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #0f1216;
}

.status-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 120ms ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ghost-button {
  min-width: 84px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 800;
}

.owner-tools {
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #15191f;
}

.owner-tools[hidden] {
  display: none;
}

.danger-button {
  align-self: center;
  min-height: 38px;
  height: 38px;
  border: 1px solid rgba(255, 107, 95, 0.5);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 107, 95, 0.12);
  color: var(--warn);
  font-weight: 900;
}

.messages-frame {
  grid-row: 3;
  min-height: 0;
  overflow: hidden;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  overflow-y: auto;
  padding: 22px min(4vw, 34px);
}

.empty-state {
  margin: auto;
  color: var(--muted);
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  max-width: 900px;
}

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

.message-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 9px;
  margin-bottom: 4px;
}

.message-name {
  font-weight: 900;
}

.message-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.46;
}

.message-text code {
  border-radius: 6px;
  padding: 1px 5px;
  background: #101318;
  color: #f2c94c;
}

.message-actions {
  margin-left: auto;
}

.message-delete {
  min-width: 58px;
  min-height: 28px;
  color: var(--warn);
  font-size: 0.78rem;
}

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

.attachment-link,
.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
}

.attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  color: var(--muted);
  font-size: 0.78rem;
}

.attachment-preview {
  max-width: min(680px, 100%);
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101318;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 6px 8px 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #15191f;
}

.preview-label {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-toggle {
  min-width: 54px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.preview-body {
  max-height: 420px;
  overflow: auto;
}

.preview-body.loading,
.preview-hidden {
  padding: 12px;
  color: var(--muted);
}

.attachment-preview img,
.attachment-preview video {
  display: block;
  max-width: 100%;
  max-height: 420px;
}

.attachment-preview audio {
  display: block;
  width: min(480px, 100%);
  margin: 10px;
}

.attachment-preview iframe {
  display: block;
  width: min(680px, 100%);
  height: 420px;
  border: 0;
}

.attachment-preview pre {
  max-width: 100%;
  margin: 0;
  padding: 12px;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  grid-row: 4;
  display: grid;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--line);
  background: #15191f;
  align-content: start;
}

.formatbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.attachment-pill button {
  min-width: 22px;
  min-height: 22px;
  border-radius: 6px;
  background: transparent;
  color: var(--warn);
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  max-height: 150px;
  resize: none;
  padding: 12px 13px;
  align-self: end;
}

.composer textarea:focus,
.profile-form input:focus,
.mini-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 179, 143, 0.18);
}

.composer-row > button,
.profile-form button {
  min-width: 92px;
  min-height: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #06100d;
  font-weight: 900;
  align-self: end;
}

.composer-row > button:hover,
.profile-form button:hover {
  background: #38d8ae;
}

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 17, 21, 0.88);
  backdrop-filter: blur(8px);
}

.gate[hidden] {
  display: none;
}

.profile-form {
  display: grid;
  gap: 14px;
  width: min(100%, 390px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.profile-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.profile-form input {
  min-height: 44px;
  padding: 0 12px;
}

.form-error {
  min-height: 19px;
  color: var(--warn);
  font-size: 0.88rem;
}

@media (max-width: 800px) {
  body {
    overflow: hidden;
  }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 34dvh minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
  }

  .rail {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: auto;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    grid-column: 1 / -1;
  }

  .chat-panel {
    height: auto;
    min-height: 0;
  }

  .owner-tools {
    grid-template-columns: 1fr;
  }

  .message {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

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

  .composer-row > button {
    width: 100%;
  }

  .composer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
