/* sample-im styles. One stylesheet serves both pages: shared element styles
   below, the login card scoped under body.login, the room layout under
   body.chat. Light palette first, dark-mode overrides at the end. */

:root { color-scheme: light dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f4f5f7;
  color: #1d1d1f;
}

input,
textarea {
  display: block;
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid #c6c9cf;
  border-radius: 6px;
}

button {
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: #ffffff;
  background: #2f6fed;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: #265fd0; }

/* ---- login page ---- */

body.login {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.login main {
  width: 20rem;
  padding: 1.75rem;
  background: #ffffff;
  border: 1px solid #e2e4e8;
  border-radius: 10px;
}
body.login h1 { margin: 0 0 1.25rem; font-size: 1.4rem; }
body.login h2 { margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; }
body.login label { display: block; margin-bottom: 0.75rem; font-size: 0.85rem; }
body.login input { width: 100%; margin-top: 0.25rem; }
body.login button { width: 100%; }
body.login #error {
  margin-bottom: 1rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  color: #a4161a;
  background: #fbeaea;
  border: 1px solid #efc7c7;
  border-radius: 6px;
}
body.login .switch { margin: 1rem 0 0; font-size: 0.85rem; text-align: center; }
body.login form:not(.active) { display: none; }

/* ---- chat page ---- */

body.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#conn-banner {
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  text-align: center;
  color: #7a5300;
  background: #ffe9b3;
  border-bottom: 1px solid #e8cf8e;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #ffffff;
  border-bottom: 1px solid #e2e4e8;
}
.chat-header h1 { margin: 0; font-size: 1.1rem; }
.room-name { font-weight: 400; color: #5b6068; }
.user-box { display: flex; align-items: center; gap: 0.75rem; }
#me { font-weight: 600; }

/* Tab bar: the 聊天室/私聊 switcher between the header and the views. The
   active tab gets the accent color plus an inset underline that meets the
   bar's bottom border. */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem;
  background: #ffffff;
  border-bottom: 1px solid #e2e4e8;
}
.tabs .tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  background: none;
  border-radius: 6px 6px 0 0;
  color: #5b6068;
  font-weight: 600;
}
.tabs .tab:hover { background: #eef1f6; color: #1d1d1f; }
.tabs .tab.active {
  color: #2f6fed;
  box-shadow: inset 0 -2px 0 #2f6fed;
}
.tab-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: #d23f31;
}
.tabs [hidden] { display: none; }

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* The room and DM panes are exclusive views behind the tab bar: exactly one
   carries .active. .view:not(.active) outspecifies both per-view display
   rules, so the toggle always wins. */
.view { flex: 1; min-width: 0; }
.view:not(.active) { display: none; }
.view-dm { display: flex; }

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.messages {
  flex: 1;
  margin: 0;
  padding: 1rem;
  overflow-y: auto;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.msg {
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  max-width: min(72%, 34rem);
}
.msg .meta {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.15rem;
  font-size: 0.78rem;
  color: #5b6068;
}
.msg .author { font-weight: 600; }
.msg .body {
  display: block;
  padding: 0.45rem 0.75rem;
  background: #ffffff;
  border: 1px solid #e2e4e8;
  border-radius: 14px 14px 14px 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.empty { color: #5b6068; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid #e2e4e8;
  background: #ffffff;
}
.composer textarea { flex: 1; resize: vertical; }
.composer-error {
  padding: 0 0.75rem 0.5rem;
  font-size: 0.85rem;
  color: #a4161a;
}

.online {
  width: 15rem;
  padding: 1rem;
  background: #ffffff;
  border-left: 1px solid #e2e4e8;
  overflow-y: auto;
}
.online h2,
.dm-list-pane h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #5b6068;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.online ul,
.dm-list-pane ul { margin: 0 0 1.25rem; padding: 0; list-style: none; }

/* ---- direct messages ---- */

/* The 私聊 view's left region: the conversation list, relocated from the old
   sidebar. The .dm pane's border-left separates it from this list. */
.dm-list-pane {
  width: 13rem;
  flex: none;
  padding: 1rem;
  background: #ffffff;
  overflow-y: auto;
}

.dm {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: #ffffff;
  border-left: 1px solid #e2e4e8;
}
.dm-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #e2e4e8;
}
.dm-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #5b6068;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg.own { align-self: flex-end; align-items: flex-end; }
.msg.own .body {
  background: #2f6fed;
  border-color: #2f6fed;
  color: #ffffff;
  border-radius: 14px 14px 4px 14px;
}

.composer textarea:disabled,
.composer button:disabled { opacity: 0.55; cursor: not-allowed; }

.online .online-row {
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
}
.online .online-row:hover { background: #eef1f6; }
.online .self { padding: 0.25rem 0.4rem; color: #5b6068; }

.conv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
}
.conv-row:hover { background: #eef1f6; }
.conv-row.active { background: #e4ecfd; }
.conv-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  flex: none;
  min-width: 1.3rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: #d23f31;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}

/* ---- dark mode ---- */

@media (prefers-color-scheme: dark) {
  body { background: #16181d; color: #e8eaed; }

  body.login main { background: #1f2229; border-color: #33363e; }
  input, textarea { background: #16181d; color: #e8eaed; border-color: #3f434c; }
  body.login #error { background: #3a2020; border-color: #5c2b2b; }

  #conn-banner { color: #ffd98a; background: #3a2f14; border-color: #5c4a1c; }
  .chat-header, .tabs, .composer, .online, .dm, .dm-list-pane {
    background: #1f2229;
    border-color: #33363e;
  }
  .dm-header { border-color: #33363e; }
  .room-name, .msg .meta, .empty { color: #9aa1ab; }
  .msg .body { background: #262a32; border-color: #33363e; }
  .msg.own .body { background: #2f6fed; border-color: #2f6fed; }
  .composer-error { color: #ff8f94; }
  .online .online-row:hover, .conv-row:hover { background: #2a2e37; }
  .conv-row.active { background: #2c3a5e; }
  .online .self { color: #9aa1ab; }

  .tabs .tab { color: #9aa1ab; }
  .tabs .tab:hover { background: #2a2e37; color: #e8eaed; }
  .tabs .tab.active { color: #8ab4f8; box-shadow: inset 0 -2px 0 #8ab4f8; }
}
