:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --line: #2a3542;
  --text: #e7eef6;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --mhd: #e8a838;
  --bubble-in: #243041;
  --bubble-out: #1e3a2f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.gate {
  max-width: 360px;
  margin: 12vh auto;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 0.75rem;
}

.gate h1 {
  margin: 0;
  font-size: 1.4rem;
}

.gate input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

.gate button,
.ghost {
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.ghost {
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
}

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

.error {
  color: #f07178;
  margin: 0;
  font-size: 0.9rem;
}

.app {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  height: 100%;
}

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

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.conv-list {
  overflow: auto;
  flex: 1;
}

.conv {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  width: 100%;
  background: transparent;
  color: inherit;
  border-left: none;
  border-right: none;
  border-top: none;
}

.conv:hover,
.conv.active {
  background: #222c38;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #2c3a4a;
}

.avatar.placeholder {
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.conv-top {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

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

.tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mhd) 25%, transparent);
  color: var(--mhd);
  flex-shrink: 0;
}

.preview {
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread {
  margin-left: auto;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  display: grid;
  place-items: center;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.thread-head {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.thread {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bubble {
  max-width: min(520px, 92%);
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: var(--bubble-in);
  align-self: flex-start;
}

.bubble.out {
  background: var(--bubble-out);
  align-self: flex-end;
}

.bubble img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

.bubble .cap {
  margin-top: 0.4rem;
  font-size: 0.9rem;
}

.bubble .time {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 40vh 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
