:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e4e7ec;
  --text: #171a1f;
  --muted: #6b7280;
  --soft: #eef2f6;
  --accent: #18b566;
  --accent-strong: #0f9f58;
  --accent-soft: #dcf8e9;
  --blue: #3b82f6;
  --red: #ef4444;
  --shadow: 0 18px 50px rgba(20, 31, 49, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(24, 181, 102, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(59, 130, 246, 0.1), transparent 30%),
    var(--bg);
  color: var(--text);
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(24, 181, 102, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(59, 130, 246, 0.14), transparent 34%),
    var(--bg);
}

.gate.hidden {
  display: none;
}

.gate-box {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.gate-box h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.gate-box input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: 0;
}

.gate-box input:focus {
  border-color: #91d8b5;
  box-shadow: 0 0 0 3px rgba(24, 181, 102, 0.14);
}

.gate-box button {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.gate-box p {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

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

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  width: min(1180px, calc(100vw - 32px));
  height: min(820px, calc(100vh - 32px));
  margin: 16px auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(228, 231, 236, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  background: #fbfcfd;
  border-right: 1px solid var(--line);
}

.side-head,
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  padding: 16px 18px;
}

.side-head {
  justify-content: space-between;
}

.status {
  flex: 0 0 auto;
  min-width: 64px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.status.online {
  background: var(--accent-soft);
  color: #087341;
}

.status.offline {
  background: #fee2e2;
  color: #b91c1c;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.15;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: #323943;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.icon-btn:hover {
  background: var(--soft);
  border-color: #d4dae2;
}

.icon-btn:active {
  transform: translateY(1px);
}

.profile-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  margin: 0 18px 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.profile-box label {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.profile-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.profile-box input {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  outline: 0;
}

.profile-box input:focus {
  border-color: #91d8b5;
  box-shadow: 0 0 0 3px rgba(24, 181, 102, 0.14);
}

.profile-box button {
  align-self: end;
  min-width: 58px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #26313f;
  color: #fff;
  font-weight: 820;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 18px 14px;
  padding: 0 12px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 18px 14px;
}

.tab {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.tab.active {
  border-color: #cbeedc;
  background: var(--accent-soft);
  color: #087341;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 14px;
}

.conversation {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  color: inherit;
}

.conversation .avatar::after {
  background: #94a3b8;
}

.conversation:hover {
  background: #f0f3f6;
}

.conversation.active {
  background: #e9f8f0;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, #24b47e, #2f80ed);
  color: #fff;
  font-size: 18px;
  font-weight: 850;
}

.avatar.large {
  width: 50px;
  height: 50px;
  font-size: 19px;
}

.avatar.direct {
  background: linear-gradient(135deg, #18b566, #3b82f6);
}

.avatar.group {
  background: linear-gradient(135deg, #f97316, #e11d48);
}

.avatar::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #22c55e;
}

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

.conv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.conv-name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  color: var(--muted);
  font-size: 12px;
}

.conv-preview {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  align-self: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
}

.chat-panel {
  display: grid;
  min-width: 0;
  grid-template-rows: auto 1fr auto;
  background: #f4f6f8;
}

.chat-head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
}

.back-btn {
  display: none;
}

.chat-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  margin-right: auto;
}

.chat-title-wrap h2 {
  overflow: hidden;
  max-width: 48vw;
  font-size: 18px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title-wrap p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

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

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 22px min(4vw, 46px);
}

.day-divider {
  margin: 8px 0 18px;
  color: #8a94a3;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.message-row {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  align-items: flex-end;
}

.message-row.me {
  justify-content: flex-end;
}

.bubble {
  max-width: min(560px, 72%);
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: #1f2937;
  line-height: 1.55;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 14px rgba(31, 41, 55, 0.05);
}

.message-row.me .bubble {
  background: var(--accent-soft);
  border-color: #bdeccd;
}

.sender {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.message-image {
  display: block;
  max-width: min(320px, 100%);
  max-height: 320px;
  border-radius: 8px;
  object-fit: cover;
}

.time {
  margin-top: 4px;
  color: #95a0ad;
  font-size: 11px;
  text-align: right;
}

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

.empty-state.small {
  align-content: start;
  height: auto;
  padding: 22px 10px;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: #303742;
  font-size: 18px;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.file-input {
  display: none;
}

textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: 132px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: 0;
  color: var(--text);
  background: #fbfcfd;
  line-height: 1.5;
}

textarea:focus,
.dialog-box input:focus,
.dialog-box select:focus {
  border-color: #91d8b5;
  box-shadow: 0 0 0 3px rgba(24, 181, 102, 0.14);
}

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.send-btn:hover {
  background: var(--accent-strong);
}

.send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.new-chat {
  width: min(420px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.new-chat::backdrop {
  background: rgba(17, 24, 39, 0.42);
}

.dialog-box {
  padding: 18px;
}

.dialog-box header,
.dialog-box menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.dialog-box h3 {
  font-size: 18px;
}

.dialog-box label {
  display: grid;
  gap: 7px;
  margin-top: 16px;
  color: #3f4652;
  font-size: 14px;
  font-weight: 760;
}

.dialog-box input,
.dialog-box select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  outline: 0;
  background: #fbfcfd;
  color: var(--text);
}

.dialog-box menu {
  justify-content: flex-end;
  margin-top: 20px;
}

.dialog-box menu button {
  min-width: 76px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #2b313a;
  font-weight: 780;
}

.dialog-box menu .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

@media (max-width: 760px) {
  body {
    background: var(--panel);
  }

  .shell {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    grid-template-columns: 1fr;
  }

  .sidebar,
  .chat-panel {
    grid-row: 1;
    grid-column: 1;
    transition: transform 180ms ease;
  }

  .chat-panel {
    transform: translateX(100%);
  }

  .shell.chat-open .sidebar {
    transform: translateX(-28%);
  }

  .shell.chat-open .chat-panel {
    transform: translateX(0);
  }

  .back-btn {
    display: inline-grid;
  }

  .side-head,
  .chat-head {
    min-height: 68px;
    padding: 12px 14px;
  }

  .chat-actions .icon-btn:first-child {
    display: none;
  }

  .chat-title-wrap h2 {
    max-width: 48vw;
    font-size: 16px;
  }

  .messages {
    padding: 16px 12px;
  }

  .bubble {
    max-width: 78%;
  }

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

  .send-btn {
    min-width: 48px;
    width: 48px;
  }

  .send-btn span {
    display: none;
  }
}
