:root {
  --bg: #ededed;
  --panel: #f7f7f7;
  --line: #e2e2e2;
  --green: #07c160;
  --green-dark: #06ad56;
  --text: #191919;
  --muted: #9a9a9a;
  --white: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ------------------------------------------------------------ login ---- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f5f5f5 0%, #e6ebe8 100%);
}

.login-card {
  width: min(380px, 100%);
  background: var(--white);
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .08);
  display: flex;
  flex-direction: column;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--green);
  color: #fff;
  font-size: 26px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-card label { font-size: 12px; color: var(--muted); margin: 0 0 6px; }

.login-card input,
.modal-card input,
.add-friend input,
.send-bar input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
  background: #fafafa;
}

.login-card input:focus,
.modal-card input:focus,
.add-friend input:focus,
.send-bar input:focus { border-color: var(--green); background: #fff; }

.login-card input { margin-bottom: 16px; }

.login-card button[type="submit"],
.add-friend button,
.send-bar button,
.modal-actions button[type="submit"] {
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.login-card button[type="submit"] { margin-top: 8px; }
.login-card button:hover,
.add-friend button:hover,
.send-bar button:hover { background: var(--green-dark); }
button:disabled { opacity: .55; cursor: default; }

.login-error { min-height: 18px; margin: 10px 0 0; color: #e64340; font-size: 12px; }

/* ------------------------------------------------------------ layout --- */
.layout {
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 300px 1fr;
  background: #fff;
  box-shadow: 0 0 30px rgba(0, 0, 0, .06);
}

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

.sidebar-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 14px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
}

.friend-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 6px;
  background: #b9c4bd;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
}

.sidebar-me { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar-me strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-me span { font-size: 11px; color: var(--muted); }

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 20px;
  color: #666;
  padding: 2px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: #e6e6e6; }

.menu {
  position: absolute;
  right: 12px;
  top: 58px;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  overflow: hidden;
  min-width: 130px;
}
.menu button {
  display: block;
  width: 100%;
  border: 0;
  background: #fff;
  padding: 11px 16px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
}
.menu button:hover { background: #f2f2f2; }

.add-friend { display: flex; gap: 8px; padding: 12px 14px 0; }
.add-friend input { flex: 1; min-width: 0; height: 36px; font-size: 13px; }
.add-friend button { height: 36px; padding: 0 14px; font-size: 13px; }
.hint { font-size: 11px; color: var(--muted); margin: 6px 14px 4px; min-height: 14px; }
.hint.error { color: #e64340; }

.friend-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 0; }
.friend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  border: 0;
  width: 100%;
  background: transparent;
  text-align: left;
}
.friend-item:hover { background: #eaeaea; }
.friend-item.active { background: #dedede; }
.friend-info { flex: 1; min-width: 0; }
.friend-row { display: flex; justify-content: space-between; gap: 8px; }
.friend-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-time { font-size: 10px; color: var(--muted); flex: 0 0 auto; }
.friend-preview { font-size: 12px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 14px; }
.sidebar-foot { padding: 12px 14px; font-size: 11px; color: #b0b0b0; border-top: 1px solid var(--line); }

/* -------------------------------------------------------------- chat --- */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-head {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chat-head strong { font-size: 15px; }
.chat-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.back-btn { display: none; border: 0; background: transparent; font-size: 26px; line-height: 1; padding: 0 6px 0 0; color: #555; }

.empty-chat { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #b5b5b5; }
.empty-icon { font-size: 42px; opacity: .45; margin-bottom: 10px; }
.empty-chat p { font-size: 13px; margin: 0; }

.message-list { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; }
.msg-row { display: flex; margin-bottom: 16px; align-items: flex-start; gap: 8px; }
.msg-row.mine { flex-direction: row-reverse; }
.msg-bubble {
  max-width: min(68%, 520px);
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
}
.msg-row.mine .msg-bubble { background: #95ec69; }
.msg-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  background: #b9c4bd;
}
.msg-row.mine .msg-avatar { background: var(--green); }
.msg-time { font-size: 10px; color: #aaa; margin: 4px 2px 0; }

.send-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.send-bar input { flex: 1; min-width: 0; background: #fff; }
.send-bar button { padding: 0 22px; }

/* ------------------------------------------------------------- modal --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
}
.modal-card h2 { font-size: 17px; margin: 0 0 18px; }
.modal-card label { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.modal-card input { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-actions button { padding: 0 20px; }
.ghost-btn { background: #f0f0f0 !important; color: #444 !important; }

/* ---------------------------------------------------------- responsive - */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; box-shadow: none; }
  .layout.show-chat #sidebar { display: none; }
  .layout:not(.show-chat) #chat { display: none; }
  .back-btn { display: block; }
  .chat-head { padding-left: 10px; }
}
