:root {
  --bg: #101319;
  --panel: #171c25;
  --panel2: #1f2632;
  --text: #e8edf5;
  --muted: #95a1b2;
  --line: #2a3443;
  --accent: #76a9ff;
  --good: #7ddc9b;
  --warn: #ffd37a;
  --danger: #ff7f88;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; }
button { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select { width: 100%; background: #0c0f14; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
textarea { resize: vertical; }
.composer textarea {
  min-height: 86px;
  max-height: 140px;
  resize: vertical;
}
.app {
  display: grid;
  grid-template-columns: 300px minmax(360px, 1fr) 240px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.sidebar, .rightbar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  min-height: 0;
  padding: 14px;
}
.rightbar { border-right: 0; border-left: 1px solid var(--line); }
.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.brand h1 { margin: 0; font-size: 22px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel { border: 1px solid var(--line); background: rgba(255,255,255,.025); border-radius: 14px; padding: 12px; margin: 12px 0; }
.panel h2 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.row { display: flex; gap: 8px; }
.row button { white-space: nowrap; }
.wide { width: 100%; margin-top: 8px; }
.room-list { display: flex; flex-direction: column; gap: 6px; }
.room-btn { display: flex; justify-content: space-between; align-items: center; text-align: left; width: 100%; }
.room-btn.active { border-color: var(--accent); background: rgba(118,169,255,.14); }
.badge { min-width: 22px; padding: 2px 7px; border-radius: 999px; background: var(--accent); color: #06101f; font-size: 12px; text-align: center; }
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 14px 18px; }
.chat-heading { min-width: 0; flex: 1; }
.chat-header h2 { margin: 0; }
.chat-header p { margin: 4px 0 0; color: var(--muted); }
.status { color: var(--good); font-size: 12px; }
.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.message { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 10px; max-width: 900px; width: min(900px, 100%); }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); font-weight: 700; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.name { font-weight: 700; }
.time { color: var(--muted); font-size: 12px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.mention { color: var(--warn); font-weight: 700; }
.link-card, .media-card { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: #0c0f14; }
.link-card a { color: var(--accent); word-break: break-all; }
.media-card img, .media-card video { max-width: 100%; border-radius: 10px; display: block; }
.composer { border-top: 1px solid var(--line); padding: 14px 18px; background: rgba(0,0,0,.14); }
.composer-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.composer-actions > div:first-child { flex: 1; }
.mention-preview { color: var(--warn); min-height: 18px; font-size: 12px; }
.ui-status { min-height: 18px; color: var(--muted); font-size: 12px; }
.ui-status.ok { color: var(--good); }
.ui-status.warn { color: var(--warn); }
.ui-status.error { color: var(--danger); }
.member-list { display: flex; flex-direction: column; gap: 8px; }
.member { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dm-requests { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.dm-card { border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: #0c0f14; font-size: 13px; }
.dm-actions { display: flex; gap: 6px; margin-top: 8px; }
.small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.mobile-menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  font-size: 22px;
}
.drawer-overlay {
  display: none;
}

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

  .app {
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .mobile-menu-btn {
    display: grid;
    place-items: center;
  }

  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, .48);
    backdrop-filter: blur(2px);
  }

  .drawer-overlay[hidden] {
    display: none;
  }

  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 360px);
    max-width: 360px;
    border-right: 1px solid var(--line);
    border-left: 0;
    padding: 14px;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .18s ease;
    box-shadow: 18px 0 40px rgba(0,0,0,.38);
  }

  .app.drawer-open .sidebar {
    transform: translateX(0);
  }

  .rightbar {
    display: none;
  }

  .main {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border: 0;
  }

  .chat-header {
    padding: 10px 12px;
    gap: 10px;
  }

  .chat-header h2 {
    font-size: 22px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-header p {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status {
    display: none;
  }

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

  .message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    max-width: none;
  }

  .avatar {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .bubble {
    padding: 9px 10px;
    border-radius: 13px;
  }

  .meta {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  .time {
    font-size: 11px;
  }

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

  .composer textarea {
    min-height: 62px;
    max-height: 108px;
  }

  .composer-actions {
    align-items: flex-end;
  }

  .composer-actions button {
    min-width: 64px;
    height: 46px;
  }

  .panel {
    margin: 10px 0;
  }
}

.auth-panel input { margin-top: 7px; }
.auth-block h3 { margin: 0 0 6px; font-size: 13px; color: var(--text); }
.border-top { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.login-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #0c0f14; }
.logged-in-name { margin-top: 4px; font-weight: 700; }
.danger-btn { border-color: rgba(255,127,136,.5); color: var(--danger); }
.empty-state { margin: auto; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; padding: 18px; }
code { background: #0c0f14; border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; color: var(--warn); }
