:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232732;
  --text: #e7eaf0;
  --muted: #9aa2b1;
  --primary: #4f8cff;
  --danger: #ef5f5f;
  --ok: #34c759;
  --warn: #f5b800;
  --gray: #6b7280;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1.2rem;
  background: var(--panel);
  border-bottom: 1px solid #2b2f3a;
}
.topbar .brand {
  color: var(--primary); text-decoration: none;
  display: inline-flex; align-items: center; gap: .6rem;
  line-height: 1;
}
.topbar .brand-logo {
  /* logo height = name+sub combined height, so the two visually balance */
  height: 36px; width: 36px; object-fit: contain; display: block;
}
.topbar .brand-text {
  display: inline-flex; flex-direction: column; justify-content: center;
  gap: 2px;
}
.topbar .brand-name {
  font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; line-height: 1;
}
.topbar .brand-sub {
  font-size: .75rem; font-weight: 500; color: var(--muted);
  letter-spacing: .08em; line-height: 1;
}
.topnav { display: flex; gap: 1rem; align-items: center; }
.topnav a, .topnav .who { color: var(--muted); text-decoration: none; }
.topnav small { opacity: .7; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; text-decoration: underline; padding: 0; }

main { max-width: 1100px; margin: 1.4rem auto; padding: 0 1rem; }

.card {
  background: var(--panel);
  border: 1px solid #2b2f3a;
  border-radius: 10px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.2rem;
}
.card.narrow { max-width: 420px; margin-inline: auto; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: .6rem; }
.wrap { flex-wrap: wrap; gap: .6rem; }

h1, h2 { margin: 0 0 .8rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.err { color: var(--danger); }

.form { display: flex; flex-direction: column; gap: .8rem; margin-top: .8rem; }
.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
input, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2b2f3a;
  border-radius: 6px;
  padding: .55rem .7rem;
  font-size: .95rem;
}
input:focus, select:focus { outline: 2px solid var(--primary); }

button {
  border: 0; border-radius: 6px;
  padding: .55rem 1rem; font-weight: 600;
  cursor: pointer; font-size: .9rem;
}
button.primary { background: var(--primary); color: white; }
button.primary:hover { filter: brightness(1.1); }
button.danger { background: var(--danger); color: white; }
button.ghost  { background: var(--panel-2); color: var(--text); border: 1px solid #333a48; }
button:disabled { opacity: .5; cursor: not-allowed; }

.rooms { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .55rem; }
.rooms li.room {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel-2); padding: .8rem 1rem;
  border-radius: 8px; border: 1px solid #2b2f3a;
}
.rooms .meta { display: flex; flex-direction: column; gap: .15rem; }

.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .55rem; border-radius: 999px; font-size: .8rem;
  background: var(--gray); color: white;
}
.badge.green  { background: var(--ok); }
.badge.yellow { background: var(--warn); color: #1a1a1a; }
.badge.gray   { background: var(--gray); }
.badge.red    { background: var(--danger); }

.video-grid {
  display: grid; gap: .6rem; margin-top: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.video-tile {
  background: #000; border-radius: 8px; overflow: hidden; position: relative;
  aspect-ratio: 16 / 9;
}
.video-tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.video-tile .label {
  position: absolute; left: .5rem; bottom: .5rem;
  background: rgba(0,0,0,.55); padding: .15rem .55rem;
  border-radius: 4px; font-size: .8rem;
}

.rec-list { list-style: none; padding: 0; margin: .8rem 0 0; display: flex; flex-direction: column; gap: .6rem; }
.rec-list li.rec {
  background: var(--panel-2); padding: .8rem 1rem;
  border-radius: 8px; border: 1px solid #2b2f3a;
}
.rec-list .rec-head { display: flex; justify-content: space-between; align-items: center; }
.rec-list details { margin-top: .5rem; }
.rec-list pre { white-space: pre-wrap; background: #11141a; padding: .6rem; border-radius: 6px; max-height: 240px; overflow: auto; }
.rec-audio {
  display: block;
  width: 100%;
  margin: .5rem 0;
  border-radius: 6px;
}
.live-transcript {
  background: #11141a;
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  padding: .6rem .8rem;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  margin-top: .3rem;
}

.chat-log {
  background: var(--panel-2); border: 1px solid #2b2f3a;
  border-radius: 6px; padding: .6rem; height: 180px;
  overflow-y: auto; margin-bottom: .6rem; font-size: .9rem;
}
.chat-log .msg { margin-bottom: .25rem; }
.chat-log .from { color: var(--primary); font-weight: 600; margin-right: .3rem; }

#chat-form { gap: .5rem; }
#chat-input { flex: 1; }

code { background: #11141a; padding: .1rem .35rem; border-radius: 4px; font-size: .85rem; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid #2b2f3a;
  border-radius: 10px;
  padding: 1.4rem 1.6rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.modal h2 { margin-top: 0; }
.modal p { margin: .4rem 0; }

.prejoin-modal { max-width: 460px; }
.prejoin-preview {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin: .6rem 0 .4rem;
  aspect-ratio: 4 / 3;
}
.prejoin-preview video {
  width: 100%; height: 100%; object-fit: cover;
  background: #000;
  transform: scaleX(-1); /* mirror like a selfie cam */
}
.prejoin-cam-off {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #11141a;
  color: var(--muted);
  font-size: .95rem;
}
.prejoin-cam-off[hidden] { display: none; }
.prejoin-meter { margin: .4rem 0 .2rem; }
.prejoin-meter-label { font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.prejoin-meter-track {
  width: 100%; height: 8px;
  background: #11141a;
  border-radius: 999px;
  overflow: hidden;
}
.prejoin-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #34c759 0%, #f5b800 70%, #ef5f5f 100%);
  transition: width .06s linear;
  border-radius: 999px;
}

/* Admin dashboard */
.adm-table { width: 100%; border-collapse: collapse; margin-top: .6rem; }
.adm-table th, .adm-table td {
  padding: .5rem .6rem; border-bottom: 1px solid #2b2f3a;
  text-align: left; vertical-align: middle;
}
.adm-table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.adm-table tr:last-child td { border-bottom: 0; }
.adm-table form.inline { display: inline-flex; }
.small-btn { padding: .3rem .6rem; font-size: .8rem; }
.adm-pwd summary {
  display: inline-block; cursor: pointer; list-style: none;
  background: var(--panel-2); border: 1px solid #333a48;
  padding: .3rem .6rem; border-radius: 6px; font-size: .8rem;
}
.adm-pwd summary::-webkit-details-marker { display: none; }
.flash { padding: .6rem .8rem; border-radius: 6px; margin: .6rem 0; font-size: .9rem; }
.flash.ok { background: rgba(52,199,89,.15); color: #34c759; border: 1px solid #34c75955; }
.flash.err { background: rgba(239,95,95,.15); color: var(--danger); border: 1px solid #ef5f5f55; }
.test-result {
  margin-top: .8rem;
  padding: .7rem .9rem;
  border-radius: 8px;
  border: 1px solid #2b2f3a;
  background: var(--panel-2);
  font-size: .9rem;
}
.test-result[hidden] { display: none; }
.test-result.ok  { background: rgba(52,199,89,.10);  border-color: #34c75955; }
.test-result.err { background: rgba(239,95,95,.10);  border-color: #ef5f5f55; }
.test-result.running { background: rgba(245,184,0,.10); border-color: #f5b80055; }
.test-result pre {
  white-space: pre-wrap; word-break: break-word;
  background: #11141a; padding: .5rem; border-radius: 6px;
  margin-top: .4rem; max-height: 220px; overflow: auto;
  font-size: .8rem;
}
