/* ============================ 基础 ============================ */
:root {
  --bg: #0a0e13;
  --bg-2: #0d131a;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.075);
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: #e8eef6;
  --muted: #8a98a9;
  --accent: #22d3ee;
  --accent-2: #34d399;
  --bubble-me: linear-gradient(135deg, #0f7f8c, #123f4a);
  --bubble-other: rgba(255, 255, 255, 0.065);
  --radius: 14px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", -apple-system,
    BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1100px 640px at 12% -8%, rgba(34, 211, 238, 0.11), transparent 62%),
    radial-gradient(900px 520px at 92% 108%, rgba(52, 211, 153, 0.09), transparent 60%),
    var(--bg);
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* ============================ 品牌 ============================ */
.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 13px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: 24px;
  color: #04121a;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 26px rgba(34, 211, 238, 0.28);
}
.brand-mark.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 16px; box-shadow: none; }

.brand-text { display: flex; flex-direction: column; }
.brand-name {
  font-size: 22px; font-weight: 700; letter-spacing: 0.4px;
  background: linear-gradient(100deg, #ffffff, #a9f3ff 55%, #7df0c4);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-name.sm { font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============================ 登录页 ============================ */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  width: min(400px, 100%);
  padding: 26px 22px 20px;
  border-radius: 20px;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.022));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  animation: rise 0.45s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 22px 0 18px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-soft);
}
.seg-btn {
  padding: 9px 0;
  border-radius: 9px;
  font-size: 14px;
  color: var(--muted);
  transition: 0.18s ease;
}
.seg-btn.is-on {
  color: #051318;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(34, 211, 238, 0.22);
}

.field { margin-bottom: 14px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.field input::placeholder { color: #5d6b7c; }
.field input:focus {
  border-color: rgba(34, 211, 238, 0.6);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.auth-error {
  margin: -2px 0 12px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  color: #ffb4b4;
  background: rgba(255, 92, 92, 0.12);
  border: 1px solid rgba(255, 92, 92, 0.28);
}

.btn-primary {
  width: 100%;
  padding: 13px 0;
  border-radius: 12px;
  font-weight: 650;
  font-size: 15px;
  color: #04141a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px rgba(34, 211, 238, 0.22);
  transition: transform 0.14s, filter 0.18s;
}
.btn-primary:active { transform: scale(0.976); }
.btn-primary:disabled { filter: grayscale(0.4) brightness(0.85); cursor: not-allowed; }

.auth-foot {
  margin: 14px 2px 0;
  font-size: 11.5px;
  color: #6b7a8b;
  text-align: center;
}

/* ============================ 主界面骨架 ============================ */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

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

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.012));
  backdrop-filter: blur(10px);
  min-height: 0;
}
.side-brand { display: flex; align-items: center; gap: 9px; padding: 0 4px 18px; }
.side-label {
  padding: 0 6px 8px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #5f6f81;
}

.room-list { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; min-height: 0; }

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 11px;
  text-align: left;
  color: var(--muted);
  border: 1px solid transparent;
  transition: 0.16s ease;
}
.room-item:hover { background: rgba(255, 255, 255, 0.045); color: var(--text); }
.room-item .r-emoji { font-size: 15px; width: 20px; text-align: center; }
.room-item .r-name { font-size: 14px; flex: 1; }
.room-item .r-count {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  color: #7ef0c9;
  background: rgba(52, 211, 153, 0.12);
}
.room-item.is-on {
  color: #ffffff;
  background: linear-gradient(100deg, rgba(34, 211, 238, 0.16), rgba(52, 211, 153, 0.08));
  border-color: rgba(34, 211, 238, 0.28);
}
.room-item.is-on .r-name { font-weight: 600; }

.side-foot {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}
.me { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.me-info { display: flex; flex-direction: column; min-width: 0; }
.me-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-tip { font-size: 11px; color: #6b7a8b; }

.btn-ghost {
  padding: 7px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--muted);
  border: 1px solid var(--line);
  transition: 0.16s;
}
.btn-ghost:hover { color: #ff9c9c; border-color: rgba(255, 92, 92, 0.4); }

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 14, 19, 0.65);
  backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.topbar-title h1 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: 0.2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-desc { font-size: 11.5px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 12px;
  color: #a9f0dc;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.2);
}
.pill .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
}
.pill-warn {
  color: #ffd48a;
  background: rgba(255, 190, 92, 0.12);
  border-color: rgba(255, 190, 92, 0.26);
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 16px;
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ---------- 房间 tab（移动端） ---------- */
.room-tabs {
  display: flex;
  gap: 6px;
  padding: 9px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 14, 19, 0.5);
}
.room-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 7px 13px;
  border-radius: 99px;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  display: inline-flex; align-items: center; gap: 5px;
}
.tab.is-on {
  color: #051318;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

/* ============================ 消息区 ============================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
  min-height: 0;
}

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #5f6f81;
  font-size: 13.5px;
}
.empty-icon { font-size: 34px; opacity: 0.7; }

.day {
  margin: 18px 0 12px;
  text-align: center;
  font-size: 11.5px;
  color: #5f6f81;
  position: relative;
}
.day span {
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.045);
}

.msg { display: flex; gap: 9px; margin-bottom: 12px; align-items: flex-start; animation: pop 0.22s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.mine { flex-direction: row-reverse; }

.avatar {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 650;
  color: #04121a;
}
.sm-avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 13px; }

.bubble-wrap { max-width: min(76%, 560px); display: flex; flex-direction: column; }
.msg.mine .bubble-wrap { align-items: flex-end; }

.meta {
  font-size: 11px;
  color: #6b7a8b;
  margin: 0 2px 4px;
  display: flex; gap: 6px; align-items: center;
}
.meta .who { color: #9fb0c2; font-weight: 600; }

.bubble {
  padding: 9px 13px;
  border-radius: 13px;
  font-size: 14.2px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bubble-other);
  border: 1px solid var(--line-soft);
  border-top-left-radius: 5px;
}
.msg.mine .bubble {
  background: var(--bubble-me);
  border-color: rgba(34, 211, 238, 0.3);
  border-top-left-radius: 13px;
  border-top-right-radius: 5px;
}

/* ============================ 输入区 ============================ */
.composer {
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: rgba(10, 14, 19, 0.72);
  backdrop-filter: blur(12px);
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 7px 7px 13px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.34);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.composer-inner:focus-within {
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

#input {
  flex: 1;
  min-height: 34px;
  max-height: 132px;
  padding: 7px 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  line-height: 1.45;
  font-size: 14.5px;
}
#input::placeholder { color: #5d6b7c; }

.send-btn {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 11px;
  display: grid; place-items: center;
  color: #04141a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(34, 211, 238, 0.2);
  transition: transform 0.14s;
}
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { filter: grayscale(0.5) brightness(0.7); cursor: not-allowed; }

.composer-hint {
  margin-top: 5px;
  padding-right: 2px;
  text-align: right;
  font-size: 10.5px;
  color: #55636f;
}

/* ============================ 其它 ============================ */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: grid; }
  .sidebar { display: none; }
  .room-tabs { display: flex; }
  .topbar { padding: 10px 12px; }
  .messages { padding: 14px 12px 8px; }
}
@media (min-width: 861px) {
  .room-tabs { display: none; }

  /* 宽屏时把消息和输入框收拢成居中的一列，不要贴着屏幕边缘 */
  .messages,
  .composer {
    padding-left: max(24px, calc((100% - 900px) / 2));
    padding-right: max(24px, calc((100% - 900px) / 2));
  }
  .composer { padding-bottom: 18px; }
  .topbar { padding-left: max(24px, calc((100% - 900px) / 2)); padding-right: max(24px, calc((100% - 900px) / 2)); }
}

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13.5px;
  background: var(--bg);
  z-index: 5;
}

/* 移动端抽屉（点 ☰ 时弹出房间列表） */
@media (max-width: 860px) {
  .sidebar.is-drawer {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    z-index: 20;
    background: #0c1219;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.7);
    animation: slidein 0.2s ease both;
  }
  @keyframes slidein { from { transform: translateX(-16px); opacity: 0; } to { transform: none; opacity: 1; } }
  .drawer-mask {
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
  }
}

/* 滚动条 */
.messages::-webkit-scrollbar, .room-list::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb, .room-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}
