:root {
  --bg: #0b1220;
  --bg-soft: #111c30;
  --panel: #16233a;
  --panel-2: #1c2b45;
  --line: #24344f;
  --text: #e8eefc;
  --muted: #93a4c4;
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --mine: #1d4ed8;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px rgba(3, 8, 20, 0.45);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #eef2fa;
    --line: #d9e0ee;
    --text: #16233a;
    --muted: #64748b;
    --accent: #0284c7;
    --accent-2: #4f46e5;
    --mine: #2563eb;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  background: radial-gradient(1100px 700px at 12% -10%, rgba(56, 189, 248, 0.14), transparent 60%),
              radial-gradient(900px 600px at 100% 0%, rgba(99, 102, 241, 0.16), transparent 55%),
              var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; }

code {
  background: rgba(148, 163, 184, 0.18);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 600;
  padding: 10px 16px;
  transition: transform 0.14s ease, filter 0.14s ease;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  padding: 6px 10px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

.icon-btn {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  display: inline-flex;
  height: 38px;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  width: 38px;
}
.icon-btn:hover { background: rgba(148, 163, 184, 0.16); color: var(--text); }
.icon-btn.small { height: 26px; width: 26px; }

/* ---------- 登录 ---------- */
.login-view {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 440px;
  padding: 30px;
  width: 100%;
}

.brand { align-items: center; display: flex; gap: 14px; margin-bottom: 6px; }
.brand svg { color: var(--accent); flex: none; }
.brand h1 { font-size: 22px; margin: 0; }
.brand p { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.login-card label { color: var(--muted); font-size: 13px; }
.login-card input {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.login-card input:focus { border-color: var(--accent); outline: none; }
.hint { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }
.api-line { color: var(--muted); font-size: 12px; margin: 8px 0 0; text-align: center; }
.error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

/* ---------- 主布局 ---------- */
.app {
  display: grid;
  grid-template-columns: 288px 1fr;
  height: 100%;
}

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

.sidebar-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 14px 14px 8px;
}
.logo {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 9px;
}

.room-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px; }

.room-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  display: grid;
  gap: 2px 8px;
  grid-template-columns: 1fr auto;
  margin-bottom: 2px;
  padding: 9px 11px;
  text-align: left;
  width: 100%;
}
.room-item:hover { background: var(--panel-2); }
.room-item.active { background: var(--panel-2); border-color: var(--accent); }
.room-item .rname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item .rprev {
  color: var(--muted);
  font-size: 12.5px;
  grid-column: 1 / -1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  background: var(--accent);
  border-radius: 999px;
  color: #04212f;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
}
.me { align-items: center; display: flex; gap: 9px; font-weight: 600; }
.foot-actions { display: flex; gap: 6px; }
.foot-actions .ghost-btn { flex: 1; font-size: 12.5px; }

.avatar {
  align-items: center;
  border-radius: 50%;
  color: #06121f;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  height: 26px;
  justify-content: center;
  width: 26px;
}

/* ---------- 聊天区 ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.chat-head {
  align-items: center;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  padding: 12px 16px;
}
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-head h2 { font-size: 17px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic { color: var(--muted); font-size: 12.5px; margin: 1px 0 0; }
.typing-hint { color: var(--accent); font-size: 12.5px; margin: 1px 0 0; min-height: 0; }

.online { display: flex; gap: 4px; }
.online .avatar { border: 2px solid var(--panel); margin-left: -8px; }
.online .avatar:first-child { margin-left: 0; }
.bell[data-mode="auto"] { color: var(--muted); }
.bell[data-mode="all"] { color: var(--accent); }
.bell[data-mode="all"]::after { content: ""; position: absolute; }
.bell[data-mode="off"] { color: var(--muted); opacity: 0.45; }

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  scroll-behavior: smooth;
}
.messages.plain { scroll-behavior: auto; }

.day-sep {
  align-self: center;
  background: var(--panel-2);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 12px;
}

.msg { display: flex; gap: 9px; max-width: 100%; }
.msg.mine { flex-direction: row-reverse; }
.msg.system { align-self: center; color: var(--muted); font-size: 12.5px; }
.msg .body { display: flex; flex-direction: column; gap: 3px; max-width: min(680px, 78%); }
.msg.mine .body { align-items: flex-end; }

.msg .meta { color: var(--muted); display: flex; font-size: 12px; gap: 7px; }
.msg .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top-left-radius: 5px;
  overflow-wrap: anywhere;
  padding: 9px 13px;
  white-space: pre-wrap;
}
.msg.mine .bubble {
  background: linear-gradient(135deg, var(--accent-2), var(--mine));
  border-color: transparent;
  border-top-left-radius: var(--radius);
  border-top-right-radius: 5px;
  color: #fff;
}
.msg.mine .bubble a { color: #dbeafe; }
.bubble pre {
  background: rgba(2, 6, 23, 0.55);
  border-radius: 9px;
  margin: 6px 0 2px;
  overflow-x: auto;
  padding: 10px;
  white-space: pre;
}
.bubble a { color: var(--accent); }

.atts { display: flex; flex-direction: column; gap: 6px; }
.att-img { border-radius: 12px; display: block; max-height: 320px; max-width: min(420px, 70vw); }

.audio-att {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: flex;
  gap: 10px;
  padding: 7px 14px 7px 8px;
}
.audio-att button {
  background: var(--accent);
  border: 0;
  border-radius: 50%;
  color: #04212f;
  height: 30px;
  width: 30px;
}
.wave { display: flex; gap: 2px; height: 20px; align-items: center; }
.wave i { background: var(--muted); border-radius: 2px; display: block; width: 3px; }
.audio-att.playing .wave i { background: var(--accent); }
.audio-att .duration { color: var(--muted); font-size: 12px; }

.file-att {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  display: flex;
  gap: 9px;
  padding: 9px 12px;
  text-decoration: none;
}
.file-att span { color: var(--muted); font-size: 12px; }
.att-icon { color: var(--accent); flex: none; }
.chip .att-icon { color: var(--muted); }

.msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s ease; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 11.5px;
  padding: 2px 7px;
}

.reply-quote {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 3px;
  max-width: 100%;
  overflow: hidden;
  padding-left: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jump-latest {
  align-self: center;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  color: #04212f;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: -46px;
  padding: 7px 15px;
  position: relative;
  z-index: 3;
}

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 14px;
}
.composer-row { align-items: flex-end; display: flex; gap: 6px; }
.composer textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 180px;
  min-height: 42px;
  padding: 11px 13px;
  resize: none;
  width: 100%;
}
.composer textarea:focus { border-color: var(--accent); outline: none; }
.send { height: 42px; padding: 0 14px; }

.pending { display: flex; flex-wrap: wrap; gap: 7px; }
.pending:empty { display: none; }
.chip {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: flex;
  font-size: 12.5px;
  gap: 7px;
  padding: 4px 10px;
}
.chip img { border-radius: 5px; height: 22px; object-fit: cover; width: 22px; }
.chip button { background: none; border: 0; color: var(--danger); }
.chip.uploading { opacity: 0.6; }

.reply-bar {
  align-items: center;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  display: flex;
  font-size: 12.5px;
  gap: 8px;
  justify-content: space-between;
  padding: 5px 9px;
}

.record-status { align-items: center; color: var(--danger); display: flex; font-size: 13px; gap: 8px; }
.rec-dot { background: var(--danger); border-radius: 50%; height: 9px; width: 9px; animation: blink 1s infinite; }
.rec-hint { color: var(--muted); }
@keyframes blink { 50% { opacity: 0.25; } }

.record-btn-active { background: rgba(248, 113, 113, 0.2) !important; color: var(--danger) !important; }

/* ---------- 弹层 ---------- */
.modal-backdrop {
  align-items: center;
  backdrop-filter: blur(3px);
  background: rgba(3, 8, 20, 0.62);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: 88vh;
  max-width: 520px;
  padding: 22px;
  width: 100%;
}
.modal.wide { max-width: 760px; }
.modal h3 { margin: 0; }
.modal label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.modal input, .modal textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.modal textarea {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  min-height: 300px;
  resize: vertical;
  white-space: pre;
}
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.error-bar {
  align-items: center;
  background: rgba(248, 113, 113, 0.16);
  border: 1px solid var(--danger);
  border-radius: 10px;
  bottom: 18px;
  color: var(--text);
  display: flex;
  gap: 10px;
  left: 50%;
  max-width: min(680px, 92vw);
  padding: 10px 12px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 60;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  bottom: 24px;
  box-shadow: var(--shadow);
  left: 50%;
  padding: 9px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 70;
}

.only-mobile { display: none; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    bottom: 0;
    left: 0;
    position: fixed;
    top: 0;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    width: 82vw;
    z-index: 40;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .only-mobile { display: inline-flex; }
  .msg .body { max-width: 86%; }
  .messages { padding: 14px 12px 6px; }
}
