:root {
  --bg: #111315;
  --panel: #181b1f;
  --panel-2: #1f2328;
  --line: #2b3138;
  --text: #e6e9ed;
  --muted: #98a2ad;
  --accent: #4f8cff;
  --accent-2: #356fe0;
  --outgoing: #242a31;
}

* {
  box-sizing: border-box;
}

[x-cloak] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
input,
textarea {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: #050607;
  overflow: hidden;
}

.loading-screen__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
}

.loading-screen__video {
  display: block;
  width: min(480px, 100vw);
  max-width: 100vw;
  max-height: 100vh;
  margin: auto;
  object-fit: contain;
  background: #050607;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card p {
  color: var(--muted);
}

.legal-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.legal-note a,
.sidebar-footer a {
  color: var(--accent);
}

.login-card label {
  display: grid;
  gap: 8px;
}

.login-card input,
.composer textarea {
  width: 100%;
  padding: 12px;
}

.login-card button,
.composer button {
  padding: 12px;
}

.error {
  color: #ff8d8d;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

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

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

.small-text {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.secondary {
  padding: 8px 10px;
}

.filters {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.filters button {
  padding: 8px 10px;
}

.filters button.active,
.toggle.on {
  border-color: var(--accent);
  background: var(--accent-2);
  color: #ffffff;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
}

.sidebar-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
}

.group-dropdown {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.group-builder {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.group-builder input {
  width: 100%;
  padding: 10px;
}

.group-builder-actions {
  display: flex;
  gap: 8px;
}

.chat-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
}

.chat-item.active {
  border-color: var(--line);
  background: var(--panel-2);
}

.chat-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-name {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
}

.chat-preview,
.chat-status,
.chat-subtitle,
.meta {
  color: var(--muted);
}

.chat-preview,
.chat-status {
  font-size: 13px;
}

.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #5d6875;
  box-shadow: 0 0 0 1px #0d0f11;
}

.presence-dot.online {
  background: #40d06d;
}

.small-badge {
  padding: 2px 6px;
  font-size: 11px;
  border: 1px solid var(--line);
  color: var(--accent);
}

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

.chat-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

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

.chat-header-main {
  min-width: 0;
}

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

.chat-title {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.chat-subtitle {
  margin-top: 4px;
  font-size: 13px;
  text-transform: lowercase;
}

.toggle {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  white-space: nowrap;
}

.compact {
  padding: 8px 10px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
  background: #13161a;
}

.message {
  display: flex;
}

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

.bubble {
  max-width: 680px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.bubble.deleted {
  opacity: 0.75;
}

.message.outbound .bubble {
  background: var(--outgoing);
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12px;
}

.message-author {
  font-weight: 700;
  color: var(--text);
}

.message-author.group-author {
  font-size: 14px;
  color: #ffffff;
}

.reply-block {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
  font-size: 12px;
  color: var(--muted);
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.markdown-body {
  white-space: normal;
  word-break: break-word;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote,
.markdown-body table,
.markdown-body hr,
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 0 0 12px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  line-height: 1.2;
  color: #ffffff;
}

.markdown-body h1 {
  font-size: 1.3rem;
}

.markdown-body h2 {
  font-size: 1.18rem;
}

.markdown-body h3 {
  font-size: 1.05rem;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 20px;
}

.markdown-body li + li {
  margin-top: 4px;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(79, 140, 255, 0.08);
  color: var(--text);
}

.markdown-body a,
.link-preview {
  color: var(--accent);
}

.markdown-body pre {
  overflow-x: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101317;
}

.markdown-body pre code {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.92em;
  line-height: 1.5;
}

.markdown-body code {
  padding: 1px 5px;
  border: 1px solid var(--line);
  background: #101317;
  font-family: Consolas, Monaco, monospace;
  font-size: 0.95em;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.03);
}

.markdown-body img {
  display: block;
  max-width: 100%;
  margin-top: 10px;
  border-radius: 12px;
}

.link-preview {
  display: grid;
  gap: 4px;
  max-width: 520px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: #151a20;
  text-decoration: none;
}

.link-preview-host {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.link-preview-url {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent);
  text-decoration: none;
}

.image-attachment {
  display: block;
  margin-top: 10px;
}

.image-attachment img {
  display: block;
  max-width: min(420px, 100%);
  max-height: 360px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #0f1114;
}

.media-attachment {
  display: grid;
  gap: 10px;
  max-width: min(420px, 100%);
  margin-top: 10px;
}

.audio-attachment,
.video-attachment {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  background: #0f1114;
}

.video-attachment {
  max-height: 360px;
}

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

.read-receipt {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent);
  text-align: right;
}

.message-actions.inline {
  margin-top: 0;
}

.linkish {
  padding: 4px 8px;
  font-size: 12px;
}

.danger {
  color: #ff8d8d;
}

.edit-box {
  display: grid;
  gap: 10px;
}

.edit-box input {
  width: 100%;
  padding: 10px;
}

.composer-tools {
  display: grid;
  gap: 10px;
  padding: 12px 20px 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.emoji-picker-wrap,
.file-row,
.reply-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.emoji-picker-wrap {
  position: relative;
}

.emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(8, 36px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.emoji-picker button {
  padding: 6px 10px;
}

.reply-banner {
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: #15181c;
  color: var(--muted);
}

.file-button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.compact-tool {
  min-height: 38px;
  padding: 8px 10px;
  white-space: nowrap;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.composer {
  padding: 12px 20px 18px;
  background: var(--panel);
}

.composer-surface {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 96px;
  gap: 10px;
  align-items: stretch;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.composer-left-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border-right: 0;
}

.composer-surface:focus-within {
  box-shadow: none;
}

.composer-input {
  display: block;
  min-height: 52px;
  max-height: 160px;
  overflow-y: auto;
  resize: none;
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #13161a;
  color: var(--text);
  box-shadow: none;
}

.composer-surface button {
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--accent-2);
  border-radius: 0;
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: #ffffff;
  font-weight: 700;
}

.composer-left-tools button,
.composer-left-tools .file-button {
  min-height: 38px;
  padding: 8px 10px;
  border-color: var(--line);
  border-radius: 0;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 400;
}

.composer-left-tools button:hover,
.composer-left-tools .file-button:hover {
  background: #242930;
}

.composer-surface button:disabled {
  border-color: var(--line);
  background: #2b3440;
  color: var(--muted);
}

.composer-input:focus {
  outline: none;
  box-shadow: none;
}

.composer-input::placeholder {
  color: #8b98a7;
}

.composer-tools-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.pending-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-name {
  max-width: 160px;
  margin-top: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-word;
  color: var(--muted);
}

.pending-file-remove {
  min-height: 32px;
  padding: 6px 10px;
}

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

@media (max-width: 800px) {
  .app {
    display: block;
    height: 100dvh;
  }

  .sidebar {
    height: 100dvh;
    max-height: none;
    border-right: 0;
    border-bottom: 0;
  }

  .chat {
    height: 100dvh;
  }

  .chat-shell,
  .empty-state {
    height: 100dvh;
    min-height: 100dvh;
  }

  .sidebar-header,
  .chat-header {
    padding: 12px 14px;
  }

  .filters {
    padding: 10px 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .filters button {
    flex: 0 0 auto;
  }

  .group-dropdown {
    padding: 10px 12px;
  }

  .sidebar-footer {
    padding: 10px 12px;
  }

  .chat-list {
    padding: 6px;
  }

  .chat-item {
    padding: 10px;
  }

  .chat-topline {
    align-items: flex-start;
  }

  .chat-header {
    align-items: flex-start;
  }

  .chat-header-main {
    display: grid;
    gap: 8px;
  }

  .mobile-back {
    justify-self: start;
  }

  .messages {
    gap: 10px;
    padding: 12px;
  }

  .message,
  .bubble {
    max-width: 100%;
  }

  .meta {
    flex-wrap: wrap;
    gap: 6px 10px;
  }

  .image-attachment img,
  .media-attachment,
  .link-preview {
    max-width: 100%;
  }

  .composer-tools {
    padding: 10px 12px 0;
  }

  .reply-banner {
    align-items: flex-start;
    flex-direction: column;
    padding: 10px;
  }

  .composer {
    padding: 10px 12px 12px;
  }

  .composer-surface {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "tools tools"
      "input submit";
    gap: 8px;
  }

  .composer-left-tools {
    grid-area: tools;
    flex-wrap: wrap;
  }

  .composer-input {
    grid-area: input;
    min-height: 48px;
  }

  .composer-submit {
    grid-area: submit;
    min-height: 48px;
  }

  .emoji-picker {
    grid-template-columns: repeat(6, 36px);
    max-width: calc(100vw - 24px);
  }

  .file-name {
    width: 100%;
    max-width: none;
  }
}
