:root {
  color-scheme: light;
  --bg: #eef2ef;
  --panel: #fbfcfb;
  --panel-soft: #f4f7f5;
  --text: #1d2421;
  --muted: #66736e;
  --line: #d9e1dc;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #d9f3ee;
  --gold: #b7791f;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(30, 45, 38, 0.14);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(183, 121, 31, 0.08)),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-view {
  display: grid;
  grid-template-columns: minmax(280px, 430px) minmax(320px, 420px);
  align-items: center;
  justify-content: center;
  gap: 56px;
  min-height: 100vh;
  padding: 32px;
  overflow: auto;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.brand-block h1 {
  margin: 0 0 8px;
  font-size: 42px;
  line-height: 1.08;
}

.brand-block p {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.auth-panel {
  background: rgba(251, 252, 251, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
  padding: 4px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.tab {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 5px 18px rgba(20, 34, 29, 0.08);
}

.auth-form {
  display: grid;
  gap: 15px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 16px;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  resize: none;
  min-height: 44px;
  max-height: 130px;
  padding: 12px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.primary-btn,
.send-btn,
.small-btn {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary-btn {
  min-height: 44px;
  margin-top: 4px;
}

.primary-btn:hover,
.send-btn:hover,
.small-btn:hover {
  background: var(--accent-dark);
}

.error-text {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.chat-view {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 280px;
  height: 100vh;
  height: 100dvh;
  min-height: 620px;
  overflow: hidden;
  background: var(--panel);
}

.sidebar,
.members-panel {
  min-width: 0;
  background: var(--panel-soft);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
}

.members-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.profile-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 11px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #183a37;
  color: #fff;
  font-weight: 900;
}

.profile-copy {
  min-width: 0;
}

.profile-copy strong,
.profile-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy span {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
}

.nav-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
}

.nav-item.active {
  border-color: rgba(15, 118, 110, 0.22);
  background: var(--accent-soft);
}

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

.members-dot {
  background: #b7791f;
}

.admin-dot {
  background: var(--danger);
}

.mobile-menu-btn,
.mobile-sheet-head,
.mobile-close-btn,
.sheet-backdrop {
  display: none;
}

.private-nav-section {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sidebar-section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.private-room-list {
  display: grid;
  gap: 7px;
}

.private-room-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 4px;
}

.private-room-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  text-align: left;
}

.private-room-item:hover,
.private-room-item.active {
  border-color: rgba(15, 118, 110, 0.22);
  background: #fff;
}

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

.private-room-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.private-room-copy strong,
.private-room-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.private-room-copy small {
  color: var(--muted);
  font-size: 12px;
}

.admin-panel {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.small-btn {
  min-height: 32px;
  padding: 0 12px;
}

.danger-head {
  margin-bottom: 16px;
}

.danger-btn {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: var(--danger);
  color: #fff;
  padding: 0 12px;
  font-weight: 900;
}

.danger-btn:hover {
  background: #8f1d14;
}

.clear-private-btn {
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

.new-invite {
  margin-bottom: 10px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  color: var(--accent-dark);
  font-weight: 900;
  word-break: break-all;
}

.invite-list {
  display: grid;
  gap: 8px;
}

.invite-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
}

.invite-code {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  word-break: break-all;
}

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

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.78)),
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.13), transparent 28%),
    radial-gradient(circle at bottom right, rgba(183, 121, 31, 0.12), transparent 24%),
    #fff;
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
}

.conversation-head > div:first-child {
  min-width: 0;
}

.conversation-head h2 {
  margin: 0 0 4px;
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.connection-state {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fff7ed;
  color: var(--gold);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
}

.connection-state.connected {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-width: 100%;
  padding: 22px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

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

.message-row {
  display: grid;
  grid-template-columns: 36px minmax(0, min(620px, calc(100% - 46px)));
  gap: 10px;
  align-items: end;
  max-width: 100%;
}

.message-row.mine {
  grid-template-columns: minmax(0, min(620px, calc(100% - 46px))) 36px;
  justify-content: end;
}

.message-row.mine .message-avatar {
  order: 2;
}

.message-row.mine .message-bubble {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.message-row.mine .message-meta {
  color: rgba(255, 255, 255, 0.72);
}

.message-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #28433f;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.message-bubble {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(27, 39, 35, 0.08);
}

.message-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.message-attachment + .message-content {
  margin-top: 8px;
}

.message-attachment {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 8px;
  text-decoration: none;
}

.message-row.mine .message-attachment {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.image-attachment {
  display: grid;
  gap: 6px;
  align-items: start;
  max-width: 310px;
  text-align: left;
  cursor: zoom-in;
}

.image-attachment img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.08);
}

.image-attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(8, 13, 12, 0.9);
  color: #fff;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.image-viewer.hidden {
  display: none;
}

.viewer-open {
  overflow: hidden;
}

.image-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.image-viewer-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.image-viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.viewer-download,
.viewer-close {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  font-weight: 900;
}

.viewer-download {
  padding: 0 14px;
}

.viewer-close {
  font-size: 26px;
  line-height: 1;
}

.image-viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
}

.image-viewer-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  -webkit-touch-callout: default;
  user-select: auto;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: #173f3b;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.file-info {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.file-info strong,
.file-info small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info small {
  color: var(--muted);
}

.message-row.mine .file-info small {
  color: rgba(255, 255, 255, 0.72);
}

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

.composer-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.composer-actions {
  position: relative;
  display: grid;
  grid-template-columns: 44px 44px 88px;
  gap: 8px;
  align-items: end;
}

.tool-btn,
.clear-attachment {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
}

.tool-btn {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.tool-btn:hover,
.clear-attachment:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.emoji-panel {
  position: absolute;
  right: 96px;
  bottom: 52px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 36px);
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 8px;
}

.emoji-panel button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: var(--panel-soft);
  font-size: 20px;
}

.emoji-panel button:hover {
  background: var(--accent-soft);
}

.attachment-preview {
  display: grid;
  gap: 8px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
}

.attachment-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.attachment-preview-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview-image {
  display: block;
  width: min(260px, 100%);
  max-height: 180px;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(15, 118, 110, 0.08);
}

.clear-attachment {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.send-btn {
  min-height: 44px;
}

.send-btn:disabled,
.tool-btn:disabled {
  cursor: wait;
  opacity: 0.62;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-item {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 10px auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  text-align: left;
}

.user-item:hover,
.user-item.active {
  border-color: var(--line);
  background: #fff;
}

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

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

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a6b2ad;
}

.status-dot.online {
  background: #10b981;
}

.unread-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  padding: 0 6px;
  font-size: 12px;
  line-height: 1;
  font-weight: 900;
}

.nav-item .unread-badge {
  margin-left: auto;
}

.mobile-menu-btn .unread-badge {
  position: absolute;
  top: -6px;
  right: -5px;
  margin-left: 0;
}

@media (max-width: 980px) {
  .chat-view {
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
  }

  .members-panel {
    grid-column: 1 / -1;
    display: block;
    max-height: 210px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .user-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .message-row,
  .message-row.mine {
    grid-template-columns: 34px minmax(0, min(620px, calc(100% - 44px)));
  }

  .message-row.mine {
    grid-template-columns: minmax(0, min(620px, calc(100% - 44px))) 34px;
  }
}

@media (max-width: 720px) {
  body {
    min-height: 100dvh;
    overflow: hidden;
  }

  .auth-view {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 28px;
    min-height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .auth-panel {
    width: 100%;
    padding: 18px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 14px;
    font-size: 28px;
  }

  .brand-block h1 {
    font-size: 31px;
  }

  .brand-block p {
    font-size: 15px;
  }

  .chat-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    display: grid;
    gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px
      max(12px, env(safe-area-inset-left));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .profile-row {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 10px;
    padding-bottom: 10px;
  }

  .avatar {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }

  .nav-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 0;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav-item {
    justify-content: center;
    min-height: 42px;
    padding: 0 8px;
    white-space: nowrap;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .private-nav-section {
    display: none;
  }

  .admin-panel {
    display: none;
    margin-top: 0;
    padding-top: 0;
  }

  .invite-list {
    max-height: min(42vh, 320px);
    overflow: auto;
  }

  .panel-head {
    margin-bottom: 8px;
  }

  .conversation {
    min-height: 0;
  }

  .conversation-head,
  .composer,
  .messages {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .conversation-head {
    min-height: 58px;
    padding-top: 10px;
    padding-bottom: 10px;
    gap: 10px;
  }

  .conversation-head h2 {
    font-size: 18px;
  }

  .conversation-head p {
    font-size: 12px;
  }

  .connection-state {
    padding: 5px 8px;
    font-size: 11px;
  }

  .clear-private-btn {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .messages {
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .message-row {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 8px;
  }

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

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .message-bubble {
    max-width: calc(100vw - 72px);
    padding: 9px 10px;
  }

  .image-attachment {
    max-width: min(300px, 70vw);
  }

  .image-viewer {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .image-viewer-head {
    min-height: 46px;
  }

  .viewer-download,
  .viewer-close {
    height: 42px;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .composer-actions {
    grid-template-columns: 46px 46px minmax(0, 1fr);
  }

  .attachment-preview {
    padding: 8px;
  }

  .attachment-preview-image {
    width: 100%;
    max-height: 150px;
  }

  .tool-btn {
    width: 46px;
    height: 46px;
  }

  .send-btn {
    width: 100%;
    min-height: 46px;
  }

  .emoji-panel {
    right: auto;
    left: 0;
    bottom: 54px;
  }

  .mobile-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  .mobile-sheet-head h2 {
    margin: 0;
    font-size: 18px;
  }

  .mobile-close-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    font-weight: 700;
  }

  .sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    border: 0;
    background: rgba(20, 30, 26, 0.32);
    padding: 0;
  }

  .sheet-backdrop.hidden {
    display: none;
  }

  .sheet-open {
    overflow: hidden;
  }

  .admin-panel.mobile-sheet-open,
  .members-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    display: block;
    max-height: 76vh;
    max-height: 76dvh;
    border-top: 1px solid var(--line);
    border-right: 0;
    border-left: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -18px 46px rgba(25, 39, 34, 0.18);
    padding: 14px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    overflow: auto;
  }

  .admin-panel:not(.mobile-sheet-open),
  .members-panel:not(.mobile-sheet-open) {
    display: none;
  }

  .members-panel .panel-head {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel-soft);
    padding-bottom: 6px;
  }

  .members-panel .panel-head h2 {
    font-size: 18px;
  }

  .user-list {
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  }

  .user-item {
    min-height: 44px;
    grid-template-columns: 34px minmax(0, 1fr) 10px auto;
  }
}

@media (max-width: 480px) {
  .auth-view {
    align-content: start;
    gap: 18px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .brand-block {
    display: grid;
    gap: 12px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    font-size: 25px;
  }

  .brand-block h1 {
    font-size: 28px;
  }

  .tabs {
    margin-bottom: 16px;
  }

  .tab,
  .primary-btn {
    min-height: 46px;
  }

  .sidebar {
    max-height: none;
  }

  .panel-head {
    align-items: flex-start;
  }

  .danger-btn,
  .small-btn {
    min-height: 34px;
    padding: 0 10px;
  }

  .conversation-head {
    align-items: flex-start;
    gap: 8px;
  }

  .conversation-actions {
    display: grid;
    justify-items: end;
    gap: 6px;
  }

  .connection-state {
    margin-top: 1px;
  }

  .message-row,
  .message-row.mine {
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
  }

  .message-avatar {
    display: none;
  }

  .message-row.mine .message-bubble {
    justify-self: end;
  }

  .message-bubble {
    max-width: min(88vw, 360px);
  }

  .image-attachment {
    max-width: min(82vw, 320px);
  }

  .image-viewer {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .image-viewer-head {
    align-items: flex-start;
  }

  .image-viewer-head span {
    padding-top: 10px;
  }

  .composer-actions {
    grid-template-columns: 44px 44px minmax(84px, 1fr);
    gap: 7px;
  }

  .attachment-preview-image {
    max-height: 136px;
  }

  .tool-btn {
    width: 44px;
    height: 44px;
  }

  .emoji-panel {
    grid-template-columns: repeat(4, 40px);
    gap: 7px;
    max-width: calc(100vw - 24px);
  }

  .emoji-panel button {
    width: 40px;
    height: 40px;
  }

  .members-panel {
    max-height: 78vh;
    max-height: 78dvh;
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .auth-view {
    align-content: start;
    grid-template-columns: minmax(240px, 0.85fr) minmax(300px, 1fr);
    gap: 24px;
    padding: 14px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    font-size: 24px;
  }

  .brand-block h1 {
    font-size: 28px;
  }

  .chat-view {
    grid-template-columns: 210px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .sidebar {
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    overflow: auto;
  }

  .conversation-head {
    min-height: 52px;
  }

  .members-panel {
    display: none;
  }

  .admin-panel.mobile-sheet-open,
  .members-panel.mobile-sheet-open {
    display: block;
    max-height: 86vh;
    max-height: 86dvh;
  }

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

  .composer-actions {
    grid-template-columns: 44px 44px 82px;
  }
}

@media (max-width: 360px) {
  .brand-block h1 {
    font-size: 25px;
  }

  .conversation-head p {
    display: none;
  }

  .composer-actions {
    grid-template-columns: 42px 42px minmax(76px, 1fr);
  }

  .tool-btn {
    width: 42px;
  }
}
