:root {
  --bg: #0d1017;
  --bg-soft: #141924;
  --panel: #171d2b;
  --panel-2: #1e2536;
  --line: #26304a;
  --text: #e7ecf6;
  --muted: #8b97ad;
  --accent: #4f8cff;
  --accent-soft: #22355c;
  --danger: #ff5d6c;
  --ok: #35d08a;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2540 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: #26314a; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06101f; font-weight: 600; }
button.primary:hover { background: #6ba0ff; }
button.danger { background: transparent; border-color: #5a2a33; color: var(--danger); }
button.danger:hover { background: #2a161b; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea, select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

.hidden { display: none !important; }

.shell {
  max-width: 760px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; white-space: pre-wrap; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tabs button { flex: 1; }
.tabs button.active { background: var(--accent-soft); border-color: var(--accent); }

.emoji-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-picker button { padding: 6px 0; font-size: 18px; background: var(--bg-soft); }
.emoji-picker button.selected { border-color: var(--accent); background: var(--accent-soft); }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 25, 36, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .title { flex: 1; min-width: 0; }
.topbar h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  border-radius: 12px;
  flex: none;
}

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 8px; }
.list .row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.list .row:hover { background: var(--panel); }
.list .row.active { background: var(--accent-soft); }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: var(--panel-2);
  flex: none;
  position: relative;
}
.avatar .dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg);
}
.row .body { flex: 1; min-width: 0; }
.row .name { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.row .name .time { color: var(--muted); font-size: 11px; font-weight: 400; flex: none; }
.row .preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #06101f;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.8; }

.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.day { align-self: center; font-size: 11px; color: var(--muted); padding: 4px 10px; background: var(--panel); border-radius: 999px; }
.msg { display: flex; max-width: 86%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-main { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .msg-main { align-items: flex-end; }
.msg-row { display: flex; align-items: flex-start; gap: 8px; }
.msg.mine .msg-row { flex-direction: row-reverse; }
.msg-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  font-size: 16px;
}
.msg-avatar.spacer { background: transparent; }
.msg-body { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .msg-body { align-items: flex-end; }
.who {
  font-size: 11px;
  color: var(--muted);
  padding-left: 38px;
  margin-bottom: 4px;
  line-height: 16px;
}
.msg .bubble {
  padding: 9px 13px;
  border-radius: 16px;
  background: var(--panel-2);
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg .meta { font-size: 10px; color: var(--muted); margin-top: 4px; }
.msg.mine { align-self: flex-end; }
.msg.mine .bubble { background: linear-gradient(135deg, #3c6fd8, #4f8cff); color: #06101f; border-bottom-right-radius: 6px; }
.msg.theirs .bubble { border-bottom-left-radius: 6px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}
.composer textarea {
  resize: none;
  height: 44px;
  max-height: 130px;
  line-height: 1.4;
  padding: 12px;
}
.composer button { flex: none; padding: 0 18px; }

.banner {
  margin: 8px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #2a1d22;
  border: 1px solid #5a2a33;
  color: #ffb3bb;
  font-size: 13px;
}

/* 管理后台 */
.admin-shell { max-width: 1100px; margin: 0 auto; padding: 20px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-head h1 { font-size: 18px; margin: 0; }
.admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.admin-tabs button.active { background: var(--accent-soft); border-color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 24px; font-weight: 700; margin-top: 6px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.actions { white-space: nowrap; }
td.actions button { padding: 5px 10px; font-size: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.pill.ok { background: #10331f; color: var(--ok); }
.pill.bad { background: #33161a; color: var(--danger); }
.pill.dim { background: var(--panel-2); color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.scroll-x { overflow-x: auto; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #232c40;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 600px) {
  .shell { box-shadow: none; }
  .admin-shell { padding: 12px; }
  .toolbar input, .toolbar select { min-width: 120px; flex: 1; }
}
