:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --line: #e3e6ec;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d93a3a;
  --ok: #1f9d55;
  --radius: 12px;
  --room-bg: #14171d;
  --tile-bg: #232833;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }
[hidden] { display: none !important; }
a { color: var(--accent); }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 9px 16px; border-radius: 9px; display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #c9ced8; }
button:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #255fd6; border-color: #255fd6; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,111,237,.35); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin-top: 8px; }

/* ---------- centered pages (home, login, prejoin, messages) ---------- */
.center-page { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.narrow { width: 100%; max-width: 420px; }
.brand { font-weight: 700; font-size: 18px; margin-bottom: 4px; }

/* ---------- prejoin ---------- */
.prejoin { width: 100%; max-width: 900px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 760px) { .prejoin { grid-template-columns: 1fr; } }
.preview {
  position: relative; background: var(--room-bg); border-radius: var(--radius); aspect-ratio: 16 / 9;
  overflow: hidden; display: flex; align-items: center; justify-content: center; color: #aab1c0;
}
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview .preview-off { position: absolute; }
.preview-controls { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 12px; }
.meter { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.meter > div { height: 100%; width: 0; background: var(--ok); transition: width .08s linear; }
.row { display: flex; gap: 8px; align-items: center; }
.row > select { flex: 1; min-width: 0; }

/* round control buttons (prejoin + room) */
.ctl {
  width: 52px; height: 52px; border-radius: 50%; padding: 0; justify-content: center;
  background: #3a4150; border: 0; color: #fff;
}
.ctl:hover { background: #4a5263; }
.ctl.off { background: var(--danger); }
.ctl.off:hover { background: #c22f2f; }
.ctl.leave { background: var(--danger); width: 64px; border-radius: 26px; }
.ctl svg { width: 24px; height: 24px; }

/* ---------- room ---------- */
body.in-room { background: var(--room-bg); color: #e8ebf1; overflow: hidden; }
.room { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 48px; }
.topbar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .count { color: #9aa3b5; font-size: 14px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar button { background: #2b313d; border-color: #2b313d; color: #e8ebf1; }

.stage { flex: 1; min-height: 0; padding: 0 12px; display: flex; align-items: center; justify-content: center; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 1), var(--tile-w, 1fr)); grid-auto-rows: var(--tile-h, auto); justify-content: center; align-content: center; }
.tile {
  position: relative; background: var(--tile-bg); border-radius: 12px; overflow: hidden;
  outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s;
}
.tile.speaking { outline-color: #3ccf7a; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile.local video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.tile .avatar span {
  width: 30%; max-width: 110px; aspect-ratio: 1; border-radius: 50%; background: #3d4658; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: clamp(18px, 4vw, 40px); font-weight: 600;
}
.tile .label {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); padding: 3px 9px; border-radius: 7px; font-size: 13px;
}
.tile .label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .label svg { width: 15px; height: 15px; flex: none; }
.tile .mic-off { color: #ff6b6b; }
.tile .bad-net { color: #ffb84d; }
.tile .kick {
  position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.55); border: 0; color: #fff;
  font-size: 12px; padding: 4px 9px; opacity: 0; transition: opacity .15s;
}
.tile:hover .kick { opacity: 1; }
@media (hover: none) { .tile .kick { opacity: .8; } }

.controls { display: flex; justify-content: center; gap: 14px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); }

.banner {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #ffb84d; color: #1c2230; padding: 8px 16px; border-radius: 9px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.banner.info { background: #2f6fed; color: #fff; }
.banner button { margin-left: 10px; }

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: #2b313d; color: #fff; padding: 10px 16px; border-radius: 9px; max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
body:not(.in-room) .toast { bottom: 24px; }

/* device popover in room */
.popover {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%); z-index: 25; width: min(360px, calc(100vw - 32px));
  background: #232833; border: 1px solid #343b49; border-radius: 12px; padding: 6px 16px 16px; color: #e8ebf1;
  box-shadow: 0 8px 28px rgba(0,0,0,.4);
}
.popover label { color: #9aa3b5; }
.popover select { background: #14171d; color: #e8ebf1; border-color: #343b49; }

/* ---------- admin ---------- */
.admin-wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-head h1 { font-size: 22px; margin: 0; flex: 1; }
.meetings { display: grid; gap: 12px; }
.meeting { padding: 16px 18px; }
.meeting-top { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.meeting-info { flex: 1; min-width: 220px; }
.meeting-title { font-weight: 600; font-size: 16px; }
.meeting-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.meeting-link { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); margin-top: 6px; word-break: break-all; }
.meeting-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #e9edf5; color: var(--muted); margin-left: 6px; vertical-align: 2px; }
.badge.live { background: #dcf5e6; color: var(--ok); }
.meeting.archived { opacity: .6; }
.details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 14px; }
.details table { width: 100%; border-collapse: collapse; }
.details td, .details th { text-align: left; padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.details th { font-weight: 500; color: var(--muted); font-size: 13px; }
.call { margin-bottom: 14px; }
.call-head { font-weight: 500; margin-bottom: 4px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

.modal-bg { position: fixed; inset: 0; background: rgba(15,20,30,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- screen share ---------- */
.ctl.active { background: var(--accent); }
.ctl.active:hover { background: #255fd6; }
.stage.sharing { gap: 10px; align-items: stretch; padding-bottom: 4px; }
.screen-main { flex: 1; min-width: 0; min-height: 0; display: flex; }
.screen-main > .tile { flex: 1; }
.stage.sharing .grid {
  flex: none; width: 220px; overflow-y: auto; align-content: start;
  grid-template-columns: 1fr; grid-auto-rows: 124px;
}
@media (max-aspect-ratio: 1/1) {
  .stage.sharing { flex-direction: column; }
  .stage.sharing .grid {
    width: auto; height: 96px; overflow-x: auto; overflow-y: hidden;
    grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 160px; grid-auto-rows: 90px;
  }
}
.tile.screen-tile video { background: #0b0d11; }
.tile .fs { right: 8px; }
.tile:fullscreen { border-radius: 0; }
.self-share { display: flex; flex-direction: column; align-items: center; gap: 12px; color: #c5cbd8; text-align: center; padding: 12px; }
