:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --line: #d9dee7;
  --brand: #0f766e;
  --brand-strong: #0b5d57;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  padding: 9px 13px;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

button.secondary {
  background: #e7eaef;
  color: var(--text);
}

button.secondary:hover {
  background: #d9dee7;
}

button.success {
  background: var(--ok);
  color: #fff;
}

button.success:hover {
  background: #08705f;
}

button.danger-button {
  background: var(--danger);
  color: #fff;
}

button.danger-button:hover {
  background: #912018;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  background: #101828;
  color: #fff;
  padding: 22px 18px;
}

.brand {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.sub {
  color: #bac4d2;
  font-size: 13px;
  line-height: 1.5;
}

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

.nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #e5e7eb;
  border: 1px solid transparent;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
}

.main {
  padding: 22px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar,
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.panel {
  padding: 18px;
}

.panel h2,
.panel h3 {
  margin: 0 0 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.inline-form:has(select) {
  grid-template-columns: minmax(0, 1fr) 88px auto;
}

.inline-form button,
.inline-form select,
.inline-form input {
  min-height: 38px;
}

.member-admin {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
}

.member-selects {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
}

.member-field {
  min-width: 0;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.member-field-wide {
  grid-column: 1 / -1;
}

.member-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.member-selects select,
.member-actions button {
  min-height: 40px;
  min-width: 0;
}

.member-selects select {
  width: 100%;
  color: var(--text);
}

.member-actions button {
  width: 100%;
  font-weight: 700;
  padding-inline: 8px;
  white-space: nowrap;
}

.member-current {
  display: grid;
  gap: 6px;
  padding-top: 2px;
}

.member-current-title {
  color: var(--muted);
  font-size: 12px;
}

.member-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 82px;
  overflow: auto;
}

.member-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  max-width: 100%;
  min-height: 0;
  cursor: pointer;
}

.member-chip em {
  color: var(--muted);
  font-style: normal;
}

.member-chip strong {
  color: var(--brand-strong);
  font-size: 11px;
  margin-left: 2px;
}

.member-chip.owner {
  background: #f5fbfa;
  border-color: #b9d8d1;
}

.member-chip:hover,
.member-chip.active {
  border-color: var(--brand);
  background: #edf7f5;
}

.member-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.card {
  padding: 13px;
  box-shadow: none;
}

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

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: #edf7f5;
  color: var(--brand-strong);
  font-size: 12px;
}

.danger {
  color: var(--danger);
}

.ok {
  color: var(--ok);
}

.hidden {
  display: none !important;
}

.log {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  background: #0f172a;
  color: #d1e7dd;
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.mobile-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.mobile-header {
  background: #101828;
  color: #fff;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
}

.mobile-main {
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 0;
  overflow: auto;
}

.mobile-tabs {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.mobile-tabs button {
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  padding: 12px 6px;
}

.mobile-tabs button.active {
  color: var(--brand);
  font-weight: 700;
}

.chat {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding: 4px;
}

.bubble {
  padding: 10px 12px;
  border-radius: 8px;
  background: #edf2f7;
  max-width: 78%;
  justify-self: start;
  cursor: pointer;
}

.bubble.self {
  background: #dff4ef;
  justify-self: end;
}

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

.quote {
  border-left: 3px solid var(--brand);
  background: rgba(15, 118, 110, 0.08);
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 7px;
  font-size: 12px;
}

.replybar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  background: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--muted);
}

.replybar.active {
  display: flex;
}

.replybar button {
  padding: 4px 8px;
}

.composer {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar,
  .grid,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 14px;
  }
}

.im-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 64px minmax(236px, 292px) minmax(0, 1fr) minmax(220px, 260px);
  background: #eef1f5;
  overflow: hidden;
}

.rail {
  background: #1f2933;
  color: #fff;
  display: grid;
  grid-auto-rows: min-content;
  gap: 14px;
  justify-items: center;
  padding: 16px 10px;
}

.rail-logo,
.rail-btn,
.avatar {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
}

.rail-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--brand);
  font-weight: 700;
}

.rail-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: transparent;
  color: #d0d5dd;
  padding: 0;
}

.rail-btn.active,
.rail-btn:hover {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

.session-pane {
  border-right: 1px solid var(--line);
  background: #f8fafc;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-width: 0;
}

.session-head {
  padding: 14px 14px 8px;
}

.searchbox {
  padding: 0 12px 10px;
}

.searchbox input {
  background: #eef2f6;
  border-color: transparent;
}

.session-list {
  overflow: auto;
  padding: 4px 8px 12px;
}

.session-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  text-align: left;
  padding: 10px 8px;
  border-radius: 8px;
}

.session-item.active,
.session-item:hover {
  background: #e6ebf1;
}

.session-item span:last-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.session-item strong,
.session-item em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item em {
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
  flex: none;
}

.avatar.large {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  font-size: 28px;
  margin: 0 auto;
}

.workbench {
  min-width: 0;
  display: grid;
  background: #fff;
  overflow: hidden;
}

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

.chat-head {
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.chat-head h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

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

.message-list {
  overflow: auto;
  padding: 20px 22px;
  background: #f5f7fa;
}

.message-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 14px;
  align-items: start;
}

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

.message-row.self .avatar {
  grid-column: 2;
}

.message-row.self .message-bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  background: #dff4ef;
}

.message-bubble {
  max-width: min(680px, 78%);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  line-height: 1.55;
}

.message-bubble:hover {
  border-color: #b7c0cc;
}

.im-composer {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  position: relative;
}

.im-composer textarea {
  min-height: 48px;
  max-height: 112px;
  border: 0;
  background: #f8fafc;
  resize: vertical;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
  width: max-content;
}

.composer-actions button {
  min-width: 58px;
  white-space: nowrap;
}

.mention-panel {
  position: absolute;
  left: 12px;
  right: 86px;
  bottom: calc(100% - 4px);
  max-height: 240px;
  overflow: auto;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.mention-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 8px;
  border-radius: 7px;
}

.mention-item:hover {
  background: #eef2f6;
}

.mention-item .avatar {
  width: 30px;
  height: 30px;
  border-radius: 7px;
}

.mention-type {
  color: var(--muted);
  font-size: 12px;
}

.profile-pane {
  border-left: 1px solid var(--line);
  background: #f8fafc;
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.profile-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.profile-card h3 {
  margin: 12px 0 4px;
}

.cap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.contact-grid {
  padding: 18px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-content: start;
}

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

.moments-compose {
  margin: 18px 18px 0;
  box-shadow: none;
}

.moments-compose textarea {
  min-height: 72px;
}

.moment-list {
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.moment-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
}

.moment-card p {
  margin: 8px 0;
  line-height: 1.6;
}

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

.comment-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 10px;
}

.compact-label {
  display: grid;
  gap: 6px;
  padding: 6px 12px 10px;
  color: var(--muted);
  font-size: 12px;
}

.compact-label select,
.mobile-user-select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.mobile-user-select {
  max-width: 78px;
  min-height: 30px;
  font-size: 12px;
}

.mobile-session-list {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
}

.mobile-room {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 10px;
  height: calc(100vh - 126px);
  min-height: 0;
  position: relative;
}

.mobile-message-list {
  height: auto;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 1000px) {
  .im-shell {
    grid-template-columns: 56px minmax(210px, 32vw) minmax(0, 1fr);
  }

  .profile-pane {
    display: none;
  }
}

@media (min-width: 1001px) and (max-width: 1280px) {
  .im-shell {
    grid-template-columns: 64px minmax(240px, 292px) minmax(0, 1fr);
  }

  .profile-pane {
    display: none;
  }
}

@media (max-width: 760px) {
  .im-shell {
    grid-template-columns: 52px minmax(180px, 36vw) minmax(0, 1fr);
  }

  .chat-head {
    min-height: 54px;
    padding: 8px 10px;
  }

  .chat-head h2 {
    font-size: 15px;
  }

  .message-list {
    padding: 14px 12px;
  }

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

  .member-selects,
  .member-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .composer-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .mention-panel {
    right: 12px;
    bottom: 96px;
  }
}
