:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2129;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #3b6cf6;
  --accent-text: #ffffff;
  --mine: #e8efff;
  --danger: #d93a3a;
  --admin: #b45309;
  --admin-bg: #fff3e0;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --panel: #1e2128;
    --text: #e6e8eb;
    --muted: #9198a3;
    --border: #2e323b;
    --accent: #5b86ff;
    --mine: #233154;
    --danger: #f06464;
    --admin: #f0a54a;
    --admin-bg: #3a2a14;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; }
.hint { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn-status { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn-status.ok { background: #22a35a; }
.conn-status.bad { background: var(--danger); }

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

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; box-shadow: var(--shadow);
}
.lobby {
  width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 16px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start;
}
@media (max-width: 680px) { .lobby { grid-template-columns: 1fr; } }
.join-card h1, .rooms-card h2 { margin: 0 0 12px; font-size: 18px; }
.join-card label, .admin-dialog label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.join-card input, .admin-dialog input:not([type=file]) {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.field-label { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.admin-dialog label.key-drop {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
  padding: 14px; border: 1.5px dashed var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.admin-dialog .key-drop:hover, .admin-dialog .key-drop.dragover, .admin-dialog .key-drop:focus-within { border-color: var(--accent); }
.admin-dialog .key-drop.dragover { background: var(--mine); }
.admin-dialog .key-drop.selected { border-style: solid; border-color: var(--accent); background: var(--mine); }
.key-icon { width: 28px; height: 28px; flex: none; fill: var(--muted); }
.key-drop.selected .key-icon, .key-drop:hover .key-icon { fill: var(--accent); }
.key-drop-text { display: flex; flex-direction: column; min-width: 0; }
.key-drop-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-drop-sub { font-size: 12px; color: var(--muted); }
button { cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .6; cursor: default; }
.join-card button.primary { width: 100%; }
.link-btn { border: none; background: none; padding: 4px 6px; color: var(--accent); }
.danger-btn { color: var(--danger); border-color: var(--danger); background: none; padding: 4px 10px; }

.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li {
  display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.room-list li:last-child { border-bottom: none; }
.room-list .room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-list button { padding: 3px 10px; font-size: 13px; }

.room { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 980px; margin: 0 auto; }
.room-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.room-title { margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.room-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.room-body { flex: 1; min-height: 0; display: flex; }
.messages { flex: 1; min-width: 0; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.members { width: 200px; border-left: 1px solid var(--border); padding: 12px; overflow-y: auto; }
.members h2 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.members ul { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.members li .nick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members li button { padding: 1px 8px; font-size: 12px; color: var(--danger); border-color: var(--danger); background: none; }
#members-toggle { display: none; }
@media (max-width: 680px) {
  #members-toggle { display: inline-block; }
  .members { display: none; position: absolute; right: 0; top: 0; bottom: 0; background: var(--panel); z-index: 5; }
  .members.open { display: block; }
  .room-body { position: relative; }
}

.msg { max-width: 80%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-bubble {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 11px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.mine .msg-bubble { background: var(--mine); }
.msg.admin .msg-bubble { border-color: var(--admin); }
.msg-meta button { border: none; background: none; padding: 0 2px; font-size: 12px; color: var(--muted); }
.msg-meta button:hover { color: var(--danger); }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.badge.admin { color: var(--admin); background: var(--admin-bg); }
.system-note { align-self: center; font-size: 12px; color: var(--muted); }

.send-form { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.send-form textarea {
  flex: 1; resize: none; max-height: 140px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel);
}

.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: rgba(20, 20, 20, .88); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px; z-index: 20;
  max-width: calc(100% - 32px);
}

.admin-dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text);
  width: min(420px, calc(100% - 32px)); padding: 20px;
}
.admin-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.admin-dialog h2 { margin: 0 0 6px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
