/* TRINITY MEET — single stylesheet for index.html and room.html.
   Near-black surfaces, one accent, system font stack, no external assets. */

:root {
  --bg: #0a0b0e;
  --surface: #14161b;
  --surface-2: #1c1f26;
  --border: #2a2e37;
  --text: #e6e8ec;
  --text-dim: #8b909a;
  --accent: #06b6d4;
  --accent-ink: #04222a;
  --danger: #e5484d;
  --ok: #3dd68c;
  --radius: 8px;
  --control-h: 40px;
  --focus: 0 0 0 3px rgba(6, 182, 212, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: var(--accent); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  min-height: var(--control-h);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}
button:hover { border-color: #3a3f4b; background: #232732; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: #22c5e0; border-color: #22c5e0; }

.btn-danger { color: var(--danger); border-color: rgba(229, 72, 77, 0.4); }
.btn-danger:hover { background: rgba(229, 72, 77, 0.12); }

.btn-small { min-height: 30px; padding: 0 10px; font-size: 13px; }

input[type="text"], select, textarea {
  min-height: var(--control-h);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:disabled, select:disabled { color: var(--text-dim); }

label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }

.field { margin-bottom: 14px; }

.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .brand { font-weight: 700; letter-spacing: 0.08em; font-size: 13px; color: var(--accent); }
.topbar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); margin-right: 6px; vertical-align: middle;
}
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: #e8b339; }
.status-dot.bad { background: var(--danger); }

/* ---------- index (lobby page) ---------- */

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h1, .card h2 { margin: 0 0 12px; font-size: 18px; }
.card h1 { font-size: 24px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input[type="text"] { flex: 1; min-width: 200px; }

.signin { text-align: center; padding: 60px 20px; }
.signin .brand-big { font-size: 34px; font-weight: 700; letter-spacing: 0.12em; color: var(--accent); margin-bottom: 8px; }
.signin p { color: var(--text-dim); margin-bottom: 24px; }
.signin a.btn-primary {
  display: inline-block; text-decoration: none; padding: 12px 22px; border-radius: var(--radius);
}

.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.room-list li:first-child { border-top: 0; }
.room-list .name { font-weight: 600; }
.room-list .meta { color: var(--text-dim); font-size: 13px; }
.room-list .live { margin-left: auto; font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.room-list .live.on { color: var(--ok); }
.empty { color: var(--text-dim); padding: 16px 0; }

/* ---------- room page frame ---------- */

.room-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.room-main { flex: 1; display: flex; min-height: 0; position: relative; }

/* pre-join */
.prejoin {
  margin: auto;
  width: min(920px, 100%);
  padding: 24px 20px;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
  gap: 24px;
}
.prejoin .preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.prejoin .preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.prejoin .preview .preview-off {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); background: var(--surface);
}
.prejoin .preview .preview-controls {
  position: absolute; left: 0; right: 0; bottom: 12px;
  display: flex; justify-content: center; gap: 10px;
}
.prejoin h1 { margin: 0 0 4px; font-size: 22px; }
.prejoin .sub { color: var(--text-dim); margin: 0 0 18px; }
.prejoin .join-btn { width: 100%; min-height: 46px; margin-top: 6px; }
.notice {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius);
  background: rgba(232, 179, 57, 0.12); border: 1px solid rgba(232, 179, 57, 0.4); font-size: 13px;
}
.notice.error { background: rgba(229, 72, 77, 0.12); border-color: rgba(229, 72, 77, 0.4); }

@media (max-width: 720px) {
  .prejoin { grid-template-columns: 1fr; }
}

/* call layout */
.call { flex: 1; display: flex; min-width: 0; min-height: 0; }
.media { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; gap: 12px; }

.stage {
  flex: 1; min-height: 0; position: relative;
  background: #000; border-radius: 12px; overflow: hidden; border: 1px solid var(--border);
}
.stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage .stage-label {
  position: absolute; left: 12px; bottom: 12px;
  padding: 4px 10px; border-radius: 6px; font-size: 13px;
  background: rgba(0, 0, 0, 0.6);
}

/* Tile size (--tw/--th) is computed by layoutTiles() in app.js: the largest 16:9 box such that
   all tiles fit the container. Flex-wrap + centering keeps the grid centred at any count. */
.tiles {
  flex: 1; min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-content: center;
  overflow: hidden;
}
.media:not(.staged) .tile { width: var(--tw, 320px); height: var(--th, 180px); flex: 0 0 auto; }
/* With a stage active the grid collapses to a horizontal strip. */
.media.staged .tiles {
  flex: 0 0 auto;
  height: 130px;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
}
.media.staged .tile { flex: 0 0 200px; height: 100%; }

.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
}
.tile.speaking { border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.tile.local video { transform: scaleX(-1); }
.tile.video-off video { visibility: hidden; }
.tile .avatar {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
}
.tile.video-off .avatar { display: flex; }
.tile .avatar span {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 24px; font-weight: 600; color: var(--text-dim);
}
.tile .label {
  position: absolute; left: 8px; bottom: 8px; right: 8px;
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500;
  pointer-events: none;
}
.tile .label .name {
  padding: 3px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.6);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .label .ind {
  display: none; padding: 3px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: var(--danger);
}
.tile .label .ind .icon { width: 16px; height: 16px; }
.tile.audio-muted .ind.ind-audio { display: inline-flex; }
.tile.video-off .ind.ind-video { display: inline-flex; }
.tile .role-badge {
  position: absolute; top: 8px; left: 8px; padding: 2px 6px; border-radius: 4px;
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  background: rgba(6, 182, 212, 0.2); color: var(--accent); display: none;
}
.tile.host .role-badge { display: block; }

/* side panel */
.panel {
  width: 320px; flex: 0 0 320px;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.panel .tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel .tabs button {
  flex: 1; border: 0; border-radius: 0; background: transparent; min-height: 44px; color: var(--text-dim);
}
.panel .tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.panel .tabs button .count { margin-left: 6px; color: var(--accent); }
.panel-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.plist { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.plist li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: var(--radius);
}
.plist li:hover { background: var(--surface-2); }
.plist .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .prole { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.plist .pind { color: var(--text-dim); display: inline-flex; }
.plist .pind.on { color: var(--danger); }
.plist .pind .icon { width: 16px; height: 16px; }
.plist .actions { display: flex; gap: 4px; }
.plist .actions button { min-height: 28px; padding: 0 6px; }
.plist .actions button .icon { width: 16px; height: 16px; }
.plist-head { padding: 10px 16px 4px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.lobby-list li { background: rgba(6, 182, 212, 0.06); }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg .from { font-size: 12px; color: var(--text-dim); }
.chat-msg .from .t { margin-left: 6px; }
.chat-msg .body { white-space: pre-wrap; word-break: break-word; }
.chat-msg.me .from { color: var(--accent); }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form textarea { resize: none; height: var(--control-h); }

/* bottom controls */
.controls {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.ctl {
  width: 48px; height: 48px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.ctl .icon { width: 22px; height: 22px; }
.ctl .off { display: none; }
.ctl[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl[aria-pressed="true"] .on { display: none; }
.ctl[aria-pressed="true"] .off { display: block; }
.ctl.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ctl .badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; display: none; align-items: center; justify-content: center;
}
.ctl .badge.show { display: inline-flex; }
.prejoin .preview .ctl { background: rgba(0, 0, 0, 0.55); border-color: rgba(255, 255, 255, 0.2); }
.prejoin .preview .ctl[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); }
.controls .sep { width: 1px; height: 28px; background: var(--border); margin: 0 6px; }
.controls .leave { background: var(--danger); border-color: var(--danger); color: #fff; }

/* banners / overlays */
.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  z-index: 5; display: flex; gap: 12px; align-items: center;
}
.overlay {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(10, 11, 14, 0.9);
  display: flex; align-items: center; justify-content: center;
}
.overlay .box {
  text-align: center; padding: 32px; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.overlay h2 { margin: 0 0 8px; }
.overlay p { color: var(--text-dim); margin: 0 0 18px; }
.overlay .row { justify-content: center; }

.toasts {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none;
}
.toast {
  padding: 10px 14px; border-radius: var(--radius); font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.toast.error { border-color: rgba(229, 72, 77, 0.6); }

dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog .row { margin-top: 10px; }

@media (max-width: 860px) {
  .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(320px, 100%); z-index: 6; }
  .controls { gap: 6px; }
  .controls .ctl { width: 44px; height: 44px; }
  .media.staged .tiles { height: 90px; }
  .media.staged .tile { flex-basis: 140px; }
}
