:root {
  color-scheme: dark;
  --bg: #0b1c30;
  --ink: #eaf1ff;
  --muted: #b5c8df;
  --accent: #1a6b4a;
  --line: #36485b;
  --panel: #213145;
  --danger: #ffb3b3;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
a { color: #8ad6ae; }
[hidden] { display: none !important; }
.site-toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 10px;
  background: #2b2b2b;
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}
.site-toast.ok { background: #1a6b4a; }
.site-toast.err { background: #b42318; }
.site-toast[hidden] { display: none !important; }
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: #213145;
  border-bottom: 1px solid var(--line);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  text-decoration: none;
  color: #8ad6ae;
  font-size: 22px;
}
.logo img { width: 28px; height: 28px; display: block; border-radius: 6px; }
nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.studio-toggle {
  margin-left: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}
.studio-toggle.active { color: #fff; }
#btn-studio[hidden] { display: none !important; }
body.studio-on [data-studio]:not(.webk-host):not(.is-parked) {
  outline: 1px dashed rgba(82, 136, 193, 0.55);
  outline-offset: -1px;
}
#studio-box {
  position: fixed;
  z-index: 80;
  pointer-events: auto;
  cursor: move;
  border: 1px solid #5288c1;
}
#studio-box[hidden] { display: none !important; }
#studio-box .studio-box-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22px;
  background: rgba(82, 136, 193, 0.85);
  cursor: move;
  pointer-events: auto;
  z-index: 1;
}
#studio-box .studio-box-bar-s {
  top: auto;
  bottom: 0;
}
#studio-box.is-lock .studio-box-bar,
#studio-box.is-lock .studio-handle { display: none; }
.studio-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #5288c1;
  border: 1px solid #fff;
  pointer-events: auto;
  padding: 0;
  z-index: 2;
}
.studio-handle.n { top: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.studio-handle.s { bottom: -5px; left: 50%; margin-left: -5px; cursor: ns-resize; }
.studio-handle.e { right: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.studio-handle.w { left: -5px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.studio-handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
#studio-panel {
  position: fixed;
  right: 16px;
  top: 72px;
  bottom: auto;
  z-index: 85;
  width: 280px;
  max-height: min(70vh, 560px);
  overflow: auto;
  background: #0b1c30;
  color: #eaf1ff;
  border: 1px solid #36485b;
  border-radius: 10px;
  padding: 12px;
}
#studio-panel[hidden] { display: none !important; }
#studio-panel header { font-weight: 700; margin: 0 0 8px; }
#studio-panel .studio-hint { margin: 0 0 8px; font-size: 11px; color: var(--muted); }
#studio-panel label { display: block; font-size: 11px; margin: 0 0 6px; }
#studio-panel select,
#studio-panel input[type="number"] {
  width: 100%;
  background: #152033;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
#studio-panel input[type="color"] { width: 100%; height: 28px; border: 1px solid var(--line); }
#studio-panel .studio-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#studio-panel .studio-actions { display: flex; gap: 8px; margin-top: 10px; }
#studio-panel .studio-actions button {
  flex: 1;
  background: var(--panel);
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 6px;
  cursor: pointer;
  font: inherit;
}
nav a { text-decoration: none; color: var(--muted); }
#link-workspace {
  text-decoration: none;
  color: #fff;
}
#who { color: var(--muted); font-size: 13px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: 0;
  cursor: pointer;
  font: inherit;
  border-radius: 8px;
  padding: 7px 14px;
  font-weight: 650;
}
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #753134; }
main { max-width: 1440px; margin: 0 auto; padding: 24px 32px 48px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}
.panel h1 { margin: 0; font-size: 22px; }
.lead, .err { color: var(--muted); margin: 0; }
.err { color: var(--danger); min-height: 1.2em; }
label { font-size: 13px; color: var(--muted); }
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: #152033;
  color: var(--ink);
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat b { display: block; font-size: 26px; line-height: 1.2; color: #a5f3c9; }
.stat span { color: var(--muted); font-size: 13px; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}
.toolbar input { max-width: 280px; flex: 1 1 180px; }
.toolbar select {
  max-width: 220px;
  flex: 1 1 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: #152033;
  color: var(--ink);
}
.th-sort {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.th-sort.is-on { color: #a5f3c9; }
.th-sort.is-on::after { content: " ▼"; font-size: 11px; }
.th-sort.is-on[aria-sort="ascending"]::after { content: " ▲"; }
.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { font-size: 12px; color: var(--muted); font-weight: 650; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
.user { font-weight: 700; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 650;
  background: #152033;
  color: var(--muted);
}
.pill.ok { background: rgba(26, 107, 74, 0.28); color: #8ad6ae; }
.pill.admin { background: #1a6b4a; color: #fff; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; }
.acts .btn { padding: 5px 10px; font-size: 12px; }
.admin-tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
}
.admin-tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.admin-tabs button.is-on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  background: #152033;
  color: var(--ink);
}
.chat-chip.is-channel { background: rgba(82, 136, 193, 0.22); }
.chat-chip .kind { color: var(--muted); font-size: 11px; }
.chat-chip .role { color: #8ad6ae; font-size: 11px; }
.people-who-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.people-av {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a6b4a;
  color: #c8f5dc;
  font-weight: 700;
  font-size: 14px;
}
.people-av::before { content: attr(data-letter); }
.people-av.has-photo::before { content: none; }
.people-av img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}
.people-av.has-photo img { opacity: 1; }
.people-who {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.people-who a.people-handle {
  color: #4ea1ff;
  text-decoration: none;
}
.people-who a.people-handle:hover { text-decoration: underline; }
.people-seen { color: var(--muted); white-space: nowrap; }
.people-seen.is-on { color: #8ad6ae; }
.people-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.people-caret {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transition: transform 0.15s ease;
}
.people-toggle[aria-expanded="true"] .people-caret { transform: rotate(180deg); }
@media (max-width: 800px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .nav { padding: 0 16px; }
}
