:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e3e8f0;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; }
.logo { font-size: 20px; color: var(--accent); }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.online { font-size: 12px; color: var(--muted); }
.user-chip { font-size: 13px; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1280px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 8px;
}
.card-head h2 { margin: 0; font-size: 15px; }

.chat-card { display: flex; flex-direction: column; height: calc(100vh - 120px); min-height: 420px; }
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg { font-size: 14px; line-height: 1.55; }
.chat-msg .who { font-weight: 600; color: #4b5563; margin-right: 6px; }
.chat-msg .time { font-size: 11px; color: #9ca3af; margin-left: 6px; }
.chat-msg.mine .who { color: var(--accent); }
.chat-empty { color: var(--muted); font-size: 13px; text-align: center; margin-top: 30px; }
.chat-form { display: flex; gap: 8px; padding: 12px 16px 16px; }
.chat-form input { flex: 1; }

input, select, textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.screen-card { display: flex; flex-direction: column; }
.screen-stage {
  position: relative;
  margin: 0 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #0f1116;
  min-height: 300px;
  display: grid;
  place-items: center;
}
#screen-video { width: 100%; max-height: 62vh; display: block; background: #0f1116; }
.screen-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #9ca3af; font-size: 14px; }
.screen-empty[hidden] { display: none; }

.sound-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 9px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.82);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.sound-btn:hover { background: rgba(17, 24, 39, 0.95); }
.sound-btn[hidden] { display: none; }

.mic-select {
  max-width: 170px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}
.mic-select[hidden] { display: none; }
.screen-controls { display: flex; gap: 10px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status { font-size: 12px; color: var(--muted); }
.status.live { color: var(--ok); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #eef2ff, #ecfdf5);
  display: grid;
  place-items: center;
  z-index: 50;
}

.auth-overlay[hidden] {
  display: none;
}
.auth-card {
  width: min(360px, 92vw);
  background: #fff;
  border-radius: 18px;
  padding: 26px 24px;
  box-shadow: 0 20px 60px rgba(30, 41, 59, 0.18);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-sub { margin: 0 0 6px; color: var(--muted); font-size: 13px; }

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 40;
}
.dialog-overlay[hidden] { display: none; }
.dialog {
  width: min(560px, 94vw);
  max-height: 80vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  padding: 16px 18px;
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dialog-head h3 { margin: 0; font-size: 16px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.inline-form input { flex: 1 1 120px; }
.user-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; }
.user-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.user-list li:last-child { border-bottom: 0; }
.user-list .u-meta { color: var(--muted); font-size: 12px; }

.dialog-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.dialog-section h4 { margin: 0 0 8px; font-size: 13px; color: #4b5563; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 60;
  max-width: 80vw;
}
.toast[hidden] { display: none; }
.toast.bad { background: #b91c1c; }
.toast.ok { background: #15803d; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
  .chat-card { height: 46vh; min-height: 300px; }
}
