:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e2e5ec;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --warn: #d97706;
  --shadow-lg: 0 24px 60px rgba(23, 27, 45, 0.16);
  --shadow-md: 0 10px 30px rgba(23, 27, 45, 0.1);
  --shadow-sm: 0 2px 8px rgba(23, 27, 45, 0.06);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 400;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(79, 70, 229, 0.18);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:hover { background: #4338ca; box-shadow: 0 8px 20px rgba(79, 70, 229, 0.28); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn.ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; box-shadow: 0 8px 20px rgba(220, 38, 38, 0.25); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.soft:hover { background: #e0e3ff; box-shadow: none; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.13);
}
.field .hint { font-size: 12px; color: var(--muted); }
.field .row-inline { display: flex; gap: 10px; align-items: center; }

/* ---------- auth ---------- */

.auth {
  min-height: 100%;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--surface);
}

.auth-visual {
  position: relative;
  overflow: hidden;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.22), transparent 42%),
    radial-gradient(circle at 85% 78%, rgba(255, 255, 255, 0.16), transparent 46%),
    linear-gradient(150deg, #312e81 0%, #4f46e5 46%, #7c3aed 100%);
}

.auth-visual::after {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  right: -150px;
  bottom: -170px;
  border-radius: 50%;
  border: 60px solid rgba(255, 255, 255, 0.08);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
  z-index: 1;
}

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(6px);
}
.logo-mark svg { width: 21px; height: 21px; }

.auth-headline {
  max-width: 460px;
  z-index: 1;
}
.auth-headline h1 {
  font-size: clamp(30px, 3.4vw, 46px);
  line-height: 1.16;
  margin: 0 0 18px;
  letter-spacing: -0.02em;
}
.auth-headline p {
  margin: 0;
  font-size: 15px;
  line-height: 1.75;
  color: rgba(255, 255, 255, 0.82);
}

.auth-points { display: flex; flex-direction: column; gap: 12px; z-index: 1; }
.auth-point { display: flex; align-items: center; gap: 11px; font-size: 14px; color: rgba(255, 255, 255, 0.9); }
.auth-point .tick {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.18);
}
.auth-point .tick svg { width: 13px; height: 13px; }

.auth-form-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  background: var(--surface);
}

.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.01em; }
.auth-card .sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

.tabs {
  display: flex;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 22px;
}
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
}
.tabs button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

.form-error {
  background: var(--danger-soft);
  color: #991b1b;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.auth-foot { margin-top: 20px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-foot a { font-weight: 600; }

/* ---------- app shell ---------- */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  height: 62px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  z-index: 20;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
.icon-btn svg { width: 20px; height: 20px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: 0.01em; }
.brand .logo-mark {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  width: 34px; height: 34px; border-radius: 10px;
}
.brand .logo-mark svg { width: 19px; height: 19px; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0.04em; }

.topbar-center { flex: 1; display: flex; justify-content: center; min-width: 0; }

.announcement {
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px;
  border-radius: 999px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.announcement svg { width: 15px; height: 15px; flex-shrink: 0; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }
.dot.off { background: #9ca3af; box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.15); }
.dot.connecting { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); animation: dotBlink 1s ease-in-out infinite; }
@keyframes dotBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.conn { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.conn .dot { width: 7px; height: 7px; }

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

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

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px clamp(16px, 4vw, 56px) 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}
.empty-state .glyph {
  width: 66px; height: 66px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  margin: 0 auto 16px;
}
.empty-state .glyph svg { width: 30px; height: 30px; }
.empty-state h3 { margin: 0 0 6px; color: var(--ink); font-size: 17px; }
.empty-state p { margin: 0; font-size: 13px; }

.msg {
  display: flex;
  gap: 11px;
  padding: 6px 10px;
  border-radius: 12px;
  max-width: 100%;
}
.msg.incoming { animation: rise 0.22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }

.msg:hover { background: rgba(255, 255, 255, 0.72); }
.msg.self:hover { background: rgba(238, 240, 255, 0.8); }
.msg.self { flex-direction: row-reverse; }

.msg-avatar {
  width: 38px; height: 38px;
  border-radius: 11px;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  overflow: hidden;
  margin-top: 2px;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-body { min-width: 0; max-width: min(660px, 78%); }
.msg.self .msg-body { text-align: right; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
  font-size: 12px;
  color: var(--muted);
}
.msg.self .msg-meta { flex-direction: row-reverse; }
.msg-meta .name { font-weight: 700; color: #374151; font-size: 13px; }
.msg-meta .time { font-variant-numeric: tabular-nums; }

.msg-text {
  display: inline-block;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 9px 13px;
  border-radius: 14px;
  border-top-left-radius: 5px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.self .msg-text {
  background: linear-gradient(140deg, var(--accent), #5b52ea);
  border-color: transparent;
  color: #fff;
  border-radius: 14px;
  border-top-right-radius: 5px;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.24);
}

.msg-system {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  padding: 7px 15px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  max-width: 85%;
}
.msg-system svg { width: 14px; height: 14px; flex-shrink: 0; }

.msg-deleted .msg-text { color: var(--muted); font-style: italic; }
.msg-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
  padding: 1px 6px;
  border-radius: 5px;
  vertical-align: middle;
}

.composer {
  padding: 12px clamp(16px, 4vw, 56px) 22px;
  background: linear-gradient(to bottom, rgba(238, 241, 246, 0), var(--bg) 34%);
  flex-shrink: 0;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 9px 10px 9px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-inner:focus-within {
  border-color: rgba(79, 70, 229, 0.5);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1), var(--shadow-md);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  max-height: 140px;
  min-height: 28px;
  line-height: 1.6;
  font-size: 14.5px;
  padding: 5px 0;
}
.composer textarea::placeholder { color: #9ca3af; }

.send-btn {
  width: 42px; height: 42px;
  border-radius: 13px;
  border: none;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.send-btn:hover { box-shadow: 0 8px 18px rgba(79, 70, 229, 0.35); transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.45; transform: none; box-shadow: none; cursor: not-allowed; }
.send-btn svg { width: 19px; height: 19px; }

.composer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 6px 0;
  font-size: 11.5px;
  color: var(--muted);
}

.members {
  width: 268px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  padding: 22px 16px;
  overflow-y: auto;
  flex-shrink: 0;
}
.members h3 {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.members h3 span { font-size: 12px; color: #374151; background: var(--surface); border: 1px solid var(--line); padding: 1px 8px; border-radius: 999px; }
.member-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 11px;
  transition: background 0.15s ease;
}
.member:hover { background: var(--surface); box-shadow: var(--shadow-sm); }
.member-avatar {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px;
  overflow: visible;
}
.member-avatar .frame { width: 100%; height: 100%; border-radius: 10px; display: grid; place-items: center; overflow: hidden; }
.member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.member-avatar .presence-dot {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--surface);
}
.member-info { min-width: 0; }
.member-info .name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-info .status { font-size: 11px; color: var(--muted); }

.member-empty { padding: 18px 10px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- drawer ---------- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 35, 0.42);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.24s ease;
}
.drawer-overlay.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(370px, 88vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-102%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.drawer-title { font-weight: 700; font-size: 15px; }
.drawer-person { display: flex; align-items: center; gap: 13px; }
.drawer-avatar {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 21px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.drawer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.drawer-person .name { font-weight: 700; font-size: 16px; }
.drawer-person .handle { font-size: 12.5px; color: var(--muted); }

.drawer-tabs { display: flex; gap: 6px; padding: 14px 18px 0; }
.drawer-tabs button {
  flex: 1;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}
.drawer-tabs button.active { background: var(--accent-soft); color: var(--accent); }

.drawer-scroll { flex: 1; overflow-y: auto; padding: 18px 22px 26px; }

.avatar-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.avatar-preview {
  width: 76px; height: 76px;
  border-radius: 20px;
  overflow: hidden;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 28px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-actions { display: flex; flex-direction: column; gap: 6px; }
.file-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  width: fit-content;
}
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn svg { width: 15px; height: 15px; }
.link-btn { border: none; background: none; color: var(--muted); font-size: 12px; padding: 2px 0; text-align: left; }
.link-btn:hover { color: var(--danger); }

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 9px;
  border: 2px solid transparent;
  padding: 0;
  position: relative;
}
.color-swatch.active { border-color: var(--ink); box-shadow: 0 0 0 3px #fff inset; }

.drawer-foot {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.drawer-foot .btn { justify-content: flex-start; }

.drawer-members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.drawer-members .member { padding: 9px; }

/* ---------- fullscreen states ---------- */

.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(124, 58, 237, 0.14), transparent 45%),
    radial-gradient(circle at 84% 82%, rgba(79, 70, 229, 0.14), transparent 46%),
    var(--bg);
  overflow-y: auto;
}

.state-card {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: 24px;
  padding: 44px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.state-glyph {
  width: 76px; height: 76px;
  border-radius: 22px;
  display: grid; place-items: center;
  margin: 0 auto 22px;
  color: #fff;
}
.state-glyph svg { width: 36px; height: 36px; }
.state-glyph.warn { background: linear-gradient(140deg, #f59e0b, #d97706); box-shadow: 0 14px 30px rgba(217, 119, 6, 0.3); }
.state-glyph.danger { background: linear-gradient(140deg, #ef4444, #b91c1c); box-shadow: 0 14px 30px rgba(220, 38, 38, 0.3); }
.state-card h2 { margin: 0 0 10px; font-size: 24px; letter-spacing: -0.01em; }
.state-card p { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.state-detail {
  margin: 20px 0 26px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 13.5px;
  color: #374151;
  text-align: left;
}
.state-detail strong { color: var(--ink); }
.state-actions { display: flex; flex-direction: column; gap: 10px; }
.state-foot { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: #16181d;
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 500;
  max-width: min(440px, 88vw);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

/* ---------- admin ---------- */

.admin-body { background: #f1f3f8; }
.admin-auth { min-height: 100%; display: grid; place-items: center; padding: 32px 18px; }
.admin-auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 28px;
  border: 1px solid rgba(255, 255, 255, 0.8);
}
.admin-auth-head { text-align: center; margin-bottom: 24px; }
.admin-auth-head .logo-mark {
  width: 52px; height: 52px;
  margin: 0 auto 14px;
  border-radius: 15px;
  background: linear-gradient(140deg, #1f2937, #111827);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 12px 26px rgba(17, 24, 39, 0.28);
}
.admin-auth-head .logo-mark svg { width: 26px; height: 26px; }
.admin-auth-head h1 { margin: 0 0 6px; font-size: 21px; }
.admin-auth-head p { margin: 0; color: var(--muted); font-size: 13px; }

.admin-shell { display: flex; min-height: 100vh; }

.admin-side {
  width: 244px;
  background: #12141b;
  color: #cbd0dc;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.admin-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; color: #fff; font-weight: 700; font-size: 15px; }
.admin-brand .logo-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(140deg, #4f46e5, #7c3aed);
  display: grid; place-items: center; color: #fff;
}
.admin-brand .logo-mark svg { width: 18px; height: 18px; }
.admin-brand small { display: block; font-size: 10.5px; color: #8b93a7; font-weight: 500; letter-spacing: 0.08em; }

.admin-nav { display: flex; flex-direction: column; gap: 4px; }
.admin-nav button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: none;
  background: transparent;
  color: #aab1c2;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.admin-nav button svg { width: 17px; height: 17px; }
.admin-nav button:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.admin-nav button.active { background: rgba(79, 70, 229, 0.2); color: #c9c6ff; }

.admin-side-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.admin-who { display: flex; align-items: center; gap: 10px; padding: 8px 10px 12px; }
.admin-who .mini-avatar {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
}
.admin-who .name { color: #fff; font-size: 13px; font-weight: 600; }
.admin-who .role { font-size: 11px; color: #8b93a7; }
.admin-side-foot .btn { width: 100%; justify-content: center; }
.admin-side-foot .btn.ghost { color: #cbd0dc; border-color: rgba(255, 255, 255, 0.14); }
.admin-side-foot .btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }

.admin-main { flex: 1; min-width: 0; padding: 26px clamp(18px, 3vw, 38px) 40px; }
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.admin-top h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.admin-top p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.admin-top-actions { display: flex; align-items: center; gap: 10px; }

.live-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: #15803d; background: #dcfce7; padding: 5px 11px; border-radius: 999px; }
.live-badge .pulse { width: 7px; height: 7px; border-radius: 50%; background: #16a34a; animation: pulse 1.6s ease infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); } 50% { box-shadow: 0 0 0 5px rgba(22, 163, 74, 0); } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-card .label svg { width: 15px; height: 15px; color: var(--accent); }
.stat-card .value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-card .foot { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15.5px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.panel-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.toolbar input { min-width: 210px; flex: 1; max-width: 320px; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); background: #fff; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td { padding: 12px 10px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafbff; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.cell-user .mini-avatar { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; overflow: hidden; flex-shrink: 0; }
.cell-user .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cell-user .name { font-weight: 600; }
.cell-user .handle { font-size: 11.5px; color: var(--muted); }
.cell-sub { color: var(--muted); font-size: 12px; }

.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.tag.online { background: #dcfce7; color: #15803d; }
.tag.offline { background: #eef0f4; color: #6b7280; }
.tag.banned { background: #fee2e2; color: #b91c1c; }
.tag.role { background: #eef0ff; color: #4338ca; }
.tag.system { background: #e0f2fe; color: #0369a1; }
.tag.role-owner { background: #fef3c7; color: #b45309; }
.tag.role-admin { background: #eef0ff; color: #4338ca; }
.tag.role-mod { background: #dcfce7; color: #15803d; }
.tag.audit { background: #f3e8ff; color: #7e22ce; }
.ban-dur.active { background: var(--accent-soft); border-color: rgba(79, 70, 229, 0.5); color: var(--accent); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.empty-row { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.pager .btns { display: flex; gap: 6px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 0; border-bottom: 1px solid #f0f2f7; }
.switch-row:last-child { border-bottom: none; padding-bottom: 0; }
.switch-row:first-child { padding-top: 0; }
.switch-copy { min-width: 0; }
.switch-copy .title { font-size: 14px; font-weight: 600; }
.switch-copy .desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.55; }
.switch {
  position: relative;
  width: 48px; height: 27px;
  border-radius: 999px;
  border: none;
  background: #d6dae3;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}
.switch.on { background: var(--success); }
.switch.on::after { transform: translateX(21px); }
.switch.danger.on { background: var(--danger); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .settings-grid { grid-template-columns: 1fr; } }

.live-users { display: flex; flex-wrap: wrap; gap: 8px; }
.live-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  font-size: 12.5px;
  font-weight: 600;
}
.live-user .mini-avatar { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700; overflow: hidden; }
.live-user .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.live-user .green { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 35, 0.5);
  backdrop-filter: blur(3px);
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: min(430px, 100%);
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.18s ease;
}
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.admin-side-toggle { display: none; }

/* ---------- search / chat head / DM ---------- */

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 12px;
  max-width: 340px;
  width: min(340px, 100%);
}
.search-box svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13.5px;
}
.search-box input::placeholder { color: #9ca3af; }
.search-clear {
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 2px;
}
.search-clear svg { width: 14px; height: 14px; }
.search-clear:hover { color: var(--danger); }

.dm-btn { position: relative; }
.dm-btn.active { background: var(--accent-soft); border-color: rgba(79, 70, 229, 0.4); color: var(--accent); }
.badge-count {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
}

.dm-panel {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.dm-head h3 { margin: 0; font-size: 15px; }
.dm-tabs { display: flex; gap: 6px; padding: 8px 14px 0; }
.dm-tabs button {
  flex: 1;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 7px;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--muted);
}
.dm-tabs button.active { background: var(--accent-soft); color: var(--accent); }
.dm-scroll { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }
.dm-contact-search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12.5px;
  margin-bottom: 10px;
  outline: none;
}
.dm-contact-search:focus { border-color: var(--accent); background: #fff; }
.dm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.dm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.dm-item:hover { background: var(--surface); box-shadow: var(--shadow-sm); }
.dm-item.active { background: var(--accent-soft); }
.dm-item .member-avatar { width: 36px; height: 36px; }
.dm-item-body { flex: 1; min-width: 0; }
.dm-item-name { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-item-preview { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.dm-empty { padding: 22px 10px; font-size: 12.5px; color: var(--muted); text-align: center; }

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 56px) 0;
  flex-shrink: 0;
}
.chat-head-title .chat-title { font-size: 15px; font-weight: 700; }
.chat-head-title .chat-sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* ---------- message reply / attachments / reactions / actions ---------- */

.msg-quote {
  display: inline-block;
  max-width: 100%;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.msg.self .msg-quote { border-left-color: rgba(255, 255, 255, 0.6); background: rgba(255, 255, 255, 0.14); color: rgba(255, 255, 255, 0.85); }
.msg-quote .quote-name { display: block; font-weight: 700; color: var(--accent); }
.msg.self .msg-quote .quote-name { color: #fff; }
.msg-quote .quote-text { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mention { color: var(--accent); font-weight: 700; }
.msg.self .mention { color: #fff; }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.att-image {
  display: block;
  max-width: 260px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.att-image img { display: block; max-width: 100%; max-height: 260px; object-fit: cover; }
.att-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
}
.att-file:hover { border-color: var(--accent); }
.att-file svg { width: 16px; height: 16px; color: var(--accent); }
.att-file-name { font-weight: 600; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file-size { color: var(--muted); font-size: 11px; }

.msg-reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.react-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.react-chip:hover { border-color: var(--accent); }
.react-chip.mine { background: var(--accent-soft); border-color: rgba(79, 70, 229, 0.5); color: var(--accent); }
.react-chip .re-emoji { font-size: 13px; }
.react-chip .re-count { font-variant-numeric: tabular-nums; }

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 7px;
  border-radius: 7px;
}
.msg-action:hover { background: var(--surface-2); color: var(--accent); }
.msg-action svg { width: 13px; height: 13px; }
.msg.self .msg-actions { justify-content: flex-end; }
.msg.self .msg-action:hover { background: rgba(255, 255, 255, 0.14); }

.msg-text.deleted-note { color: var(--muted); font-style: italic; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 70, 229, 0.3);
  border-radius: 12px 12px 0 0;
  padding: 8px 12px;
  margin: 0 2px;
  font-size: 12.5px;
}
.reply-info { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 7px; }
.reply-label { font-weight: 700; color: var(--accent); flex-shrink: 0; }
.reply-text { color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-cancel {
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 2px;
}
.reply-cancel:hover { color: var(--danger); }
.reply-cancel svg { width: 15px; height: 15px; }

.attach-btn {
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 10px;
}
.attach-btn:hover { background: var(--surface-2); color: var(--accent); }
.attach-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.attach-btn svg { width: 19px; height: 19px; }

.attach-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 2px;
  width: 100%;
}
.att-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 28px 5px 8px;
  font-size: 12px;
}
.att-chip img { width: 34px; height: 34px; border-radius: 7px; object-fit: cover; }
.att-chip svg { width: 17px; height: 17px; color: var(--accent); }
.att-chip-name { max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.att-remove {
  position: absolute;
  top: 3px; right: 3px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 1px;
}
.att-remove:hover { color: var(--danger); }
.att-remove svg { width: 13px; height: 13px; }

.react-pop {
  position: fixed;
  z-index: 260;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: rise 0.15s ease;
}
.react-option {
  border: none;
  background: transparent;
  font-size: 20px;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.15s ease, transform 0.15s ease;
}
.react-option:hover { background: var(--accent-soft); transform: scale(1.18); }

.mention-pop {
  position: fixed;
  z-index: 260;
  width: 260px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  animation: rise 0.15s ease;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 7px 9px;
  border-radius: 9px;
  text-align: left;
}
.mention-item:hover { background: var(--surface-2); }
.mention-item .mini-avatar { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 11px; overflow: hidden; flex-shrink: 0; }
.mention-item .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mi-name { font-size: 13px; font-weight: 600; }
.mi-handle { font-size: 11.5px; color: var(--muted); }

.member.clickable { cursor: pointer; }

.user-modal-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 6px; }
.user-modal-actions .btn { flex: 1; min-width: 120px; }

.toast.mention { background: #4338ca; }

@media (max-width: 960px) {
  .auth { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .members { display: none; }
  .admin-side {
    position: fixed;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .admin-side.open { transform: translateX(0); }
  .admin-side-toggle { display: grid; }
  .admin-main { padding-top: 18px; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { height: 58px; padding: 0 12px; gap: 9px; }
  .brand small { display: none; }
  .topbar-center { display: none; }
  .conn { display: none; }
  .messages { padding: 14px 12px 8px; }
  .composer { padding: 10px 12px 16px; }
  .msg-body { max-width: 88%; }
  .msg-avatar { width: 34px; height: 34px; border-radius: 9px; font-size: 13px; }
  .state-card { padding: 34px 24px; }
  .admin-main { padding: 18px 14px 34px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-card .value { font-size: 23px; }
  .dm-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 86vw);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    z-index: 80;
  }
  .chat-head { padding: 10px 12px 0; }
  .chat-head-actions .btn { padding: 5px 9px; font-size: 11.5px; }
  .att-image { max-width: 180px; }
  .msg-actions { opacity: 1; }
  .react-pop { position: fixed; left: 12px !important; right: 12px; width: auto; top: auto !important; bottom: 84px; justify-content: center; flex-wrap: wrap; }
}
