/* Portal — layar kiosk (TV). Videonya adalah antarmukanya: video memenuhi layar, kontrol
   muncul saat disentuh lalu menyingkir. Satu elemen khas: pelat lokasi bergaya papan
   penunjuk arah (huruf condensed) di tiap tile. */

:root {
  --vw: 1vw; /* satuan layar; ditukar saat tampilan diputar ke potret */
  --vh: 1vh;
  --bg: #161b22;          /* graphite */
  --surface: #1f262f;
  --surface-2: #27303b;
  --line: #2e3742;
  --ink: #eef2f6;
  --ink-2: #9aa6b2;
  --accent: #2ba3ae;      /* petrol */
  --accent-ink: #062a2e;
  --live: #3fb871;
  --ring: #e2a33b;
  --busy: #7c8a9a;
  --danger: #e5534b;

  --r-tile: 8px;
  --r-ctl: 8px;
  --gutter: 20px;
  --seam: 6px; /* celah antar video */

  font-family: 'Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'tnum' 1;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

[hidden] { display: none !important; }

/* ---------- Header ---------- */

/* Header melayang di atas video; menyingkir setelah layar tidak disentuh (body.idle).
   Scrim gelap hanya untuk menjaga teks tetap terbaca di atas gambar. */
.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 7;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 18px calc(var(--gutter) + 4px) 44px;
  background: linear-gradient(to bottom, rgba(16, 20, 26, 0.9), rgba(16, 20, 26, 0.6) 55%, rgba(16, 20, 26, 0));
  transition: opacity 0.4s ease, transform 0.4s ease;
}
body.idle .bar { opacity: 0; transform: translateY(-14px); pointer-events: none; }

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 30px; height: 30px; color: var(--accent); flex: none; }
.wordmark { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.divider { width: 1px; height: 24px; background: var(--line); }
.site-name { font-size: 20px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Titik koneksi ke server: hijau = tersambung, merah = putus. */
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; }
.conn.ok { background: var(--live); }

.clock { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.clock-time { font-family: 'Plex Condensed', 'Plex Sans', sans-serif; font-size: 34px; font-weight: 500; letter-spacing: 0.02em; }
.clock-date { font-size: 13px; color: var(--ink-2); }

.bar-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Tombol ---------- */

.btn {
  font: inherit;
  font-size: 17px;
  font-weight: 500;
  min-height: 48px;
  padding: 0 20px;
  border-radius: var(--r-ctl);
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost { border-color: rgba(255, 255, 255, 0.14); background: rgba(31, 38, 47, 0.82); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.btn.ghost:active { background: var(--surface-2); }
.btn.ghost.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:active { filter: brightness(1.1); }
.btn.danger { background: var(--danger); color: #fff; font-weight: 600; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Area video ---------- */

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--seam);
  padding: var(--seam);
}

.tiles { display: grid; gap: var(--seam); min-height: 0; }

#stage {
  flex: 1;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  grid-auto-rows: 1fr;
}

.strip {
  flex: none;
  height: calc(var(--vh) * 22);
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, calc(var(--vh) * 30));
  justify-content: start;
}

body:has(.callbar:not([hidden])) main { padding-bottom: 94px; }

/* ---------- Tile ---------- */

.tile {
  --state: var(--busy);
  position: relative;
  min-height: 0;
  border-radius: var(--r-tile);
  overflow: hidden;
  background: var(--surface);
  outline: 0 solid var(--state);
  outline-offset: -3px;
  cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.contain video { object-fit: contain; background: transparent; }
.tile .tile-backdrop {
  position: absolute;
  inset: -40px;
  width: calc(100% + 80px);
  height: calc(100% + 80px);
  display: none;
  object-fit: cover;
  filter: blur(28px) brightness(0.45) saturate(1.2);
}
.tile.contain video.tile-backdrop { display: block; object-fit: cover; }
.tile.contain video:not(.tile-backdrop) { background: transparent; }
.tile video:not(.tile-backdrop) { position: relative; }

/* Putar kamera (diatur admin per site). Untuk 90°, elemen video ditukar ukurannya
   lalu diputar di tengah tile. */
.tile[data-rot='90'], .self-view[data-rot='90'] { --rot: 90deg; }
.tile[data-rot='270'], .self-view[data-rot='270'] { --rot: -90deg; }
.tile[data-rot='90'] video:not(.tile-backdrop), .tile[data-rot='270'] video:not(.tile-backdrop) {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--th);
  height: var(--tw);
  transform: translate(-50%, -50%) rotate(var(--rot));
}
.tile[data-rot='180'] video:not(.tile-backdrop) { transform: rotate(180deg); }

.tile.available { --state: var(--live); }
.tile.talking { --state: var(--accent); outline-width: 3px; }
.tile.ringing { --state: var(--ring); outline-width: 3px; }
.tile.busy, .tile.connecting { --state: var(--busy); }
.tile.offline { --state: #4a5563; cursor: default; }
.tile.offline video, .tile.privacy video { opacity: 0.12; }

/* Pelat lokasi: papan penunjuk arah. Bar warna = status, nama besar condensed. */
.plate {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: calc(100% - 36px);
  padding: 12px 20px 13px 20px;
  border-radius: 4px;
  background: rgba(16, 20, 26, 0.84);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-left: 5px solid var(--state);
}
.plate-name {
  font-family: 'Plex Condensed', 'Plex Sans', sans-serif;
  font-size: 34px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plate-status {
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.3;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plate-hint { margin-top: 4px; font-size: 14px; font-weight: 500; color: var(--state); }
.tile.privacy .plate-hint { color: var(--ring); }

.tile.ringing .plate { animation: plate-pulse 1.4s ease-in-out infinite; }
@keyframes plate-pulse { 50% { border-left-color: transparent; } }

.strip .plate { left: 10px; bottom: 10px; padding: 7px 12px 8px 12px; border-left-width: 3px; }
.strip .plate-name { font-size: 20px; }
.strip .plate-status { font-size: 12.5px; }
.strip .plate-hint { margin-top: 2px; font-size: 12px; }

/* Mode pilih conference: kotak centang di dalam pelat, di depan nama site. */
.plate { display: grid; grid-template-columns: auto; column-gap: 14px; }
.tile.selectable .plate { grid-template-columns: auto 1fr; }
.tile.selectable .plate > :not(.tile-check) { grid-column: 2; }
.tile-check {
  position: relative;
  grid-column: 1;
  grid-row: 1 / span 3;
  align-self: center;
  width: 34px;
  height: 34px;
  display: none;
  border-radius: 6px;
  border: 2px solid var(--ink);
  background: rgba(16, 20, 26, 0.6);
}
.tile.selectable .tile-check { display: block; }
.tile.selected { --state: var(--accent); outline-width: 3px; }
.tile.selected .tile-check { background: var(--accent); border-color: var(--accent); }
.tile.selected .tile-check::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 3px;
  width: 9px;
  height: 17px;
  border: solid var(--accent-ink);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}
.tile.selectable.disabled { opacity: 0.35; }

/* ---------- Pin (diatur admin) ---------- */

main.has-pin { flex-direction: row; }
main.has-pin #stage { flex: 7; }
main.has-pin .strip {
  flex: 3;
  height: auto;
  min-width: 0;
  grid-auto-flow: row;
  grid-template-columns: repeat(var(--side-cols, 1), 1fr);
  grid-auto-rows: 1fr;
  grid-auto-columns: auto;
}
main.has-pin #stage .plate-name { font-size: 30px; }

/* Layar potret (TV tegak, atau tampilan diputar dari admin): tile samping pindah ke bawah. */
html.portrait main.has-pin { flex-direction: column; }
html.portrait main.has-pin .strip {
  flex: none;
  height: calc(var(--vh) * 24);
  grid-auto-flow: column;
  grid-template-columns: none;
  grid-auto-columns: minmax(0, 1fr);
  grid-template-rows: 1fr;
}

/* ---------- Kamera sendiri ---------- */

.self-view {
  position: fixed;
  right: 32px;
  bottom: 32px;
  z-index: 5;
  width: calc(var(--vw) * 15);
  min-width: 160px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #000;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.self-view video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.self-view[data-rot='180'] video { transform: rotate(180deg) scaleX(-1); }
.self-view[data-rot='90'] video, .self-view[data-rot='270'] video {
  /* Kotak preview 16:9; elemen video ditukar ukurannya (9:16) lalu diputar. */
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56.25%;
  height: 177.78%;
  object-fit: cover;
  transform: translate(-50%, -50%) rotate(var(--rot)) scaleX(-1);
}
.self-label, .self-privacy {
  position: absolute;
  bottom: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: rgba(22, 27, 34, 0.8);
}
.self-label { left: 6px; }
.self-privacy { right: 6px; background: var(--ring); color: #241703; }
.self-sharing {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-ink);
}

body:has(.callbar:not([hidden])) .self-view { bottom: 112px; }

body:has(main.has-pin) .self-view,
body:has(main.has-pin):has(.callbar:not([hidden])) .self-view {
  top: 104px;
  left: 36px;
  right: auto;
  bottom: auto;
  width: calc(var(--vw) * 13);
}

/* ---------- Bar call & bar pilih ---------- */

.callbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  height: 88px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 var(--gutter);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.callbar-status {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-dot { width: 12px; height: 12px; flex: none; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(43, 163, 174, 0.22); }
.callbar.waiting .live-dot { background: var(--ring); box-shadow: 0 0 0 4px rgba(226, 163, 59, 0.22); }
.callbar .btn { min-width: 150px; min-height: 56px; }
.callbar .btn.ghost.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Dialog ---------- */

.overlay, .fatal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 13, 17, 0.72);
}
.fatal { z-index: 20; background: var(--bg); text-align: center; }
.fatal .dialog-sub { max-width: 720px; margin: 0 auto; overflow-wrap: anywhere; }

.dialog {
  width: min(560px, 100%);
  padding: 32px 36px 28px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.overlay[data-kind='ring'] .dialog,
.overlay[data-kind='join'] .dialog { border-top-color: var(--ring); }

.dialog-title { margin: 0 0 6px; font-size: 30px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.dialog-sub { margin: 0 0 28px; font-size: 18px; line-height: 1.45; color: var(--ink-2); }
.dialog-sub:empty { display: none; }
.dialog-title:has(+ .dialog-sub:empty) { margin-bottom: 28px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; }
.dialog-actions .btn { min-width: 150px; min-height: 60px; font-size: 19px; }
.dialog-actions .btn.ghost { background: transparent; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 108px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 12px 20px;
  border-radius: var(--r-ctl);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  font-size: 17px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ---------- Layar kecil (uji di laptop/HP) ---------- */

@media (max-width: 760px) {
  :root { --gutter: 12px; }
  .bar { grid-template-columns: 1fr auto; gap: 12px; }
  .clock, .wordmark, .divider { display: none; }
  .btn { font-size: 15px; min-height: 44px; padding: 0 14px; }
  .plate-name { font-size: 24px; }
  .dialog-title { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.ringing .plate { animation: none; }
  .btn { transition: none; }
}

/* ---------- Pendaftaran perangkat ---------- */

.register { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.register-card { width: min(560px, 100%); }
.register-mark { width: 44px; height: 44px; margin-bottom: 28px; color: var(--accent); }
.register-step { display: flex; flex-direction: column; gap: 12px; }
.register h1 { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.register-lede { margin: 0 0 16px; font-size: 18px; line-height: 1.5; color: var(--ink-2); max-width: 46ch; }
.register label { font-size: 15px; font-weight: 500; color: var(--ink-2); }
.register input {
  font: inherit;
  font-size: 22px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  padding: 14px 16px;
  -webkit-user-select: text;
  user-select: text;
}
.register input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.register .btn { align-self: flex-start; min-height: 56px; padding: 0 28px; font-size: 18px; margin-top: 8px; }
.register-error { margin: 0; color: var(--danger); font-size: 16px; }

.pair-code {
  margin: 8px 0 4px;
  font-size: 88px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  color: var(--ink);
}
.register-meta { margin: 0; font-size: 15px; color: var(--ink-2); }

@media (max-width: 760px) {
  .register h1 { font-size: 26px; }
  .pair-code { font-size: 56px; }
}

/* ---------- Orientasi layar (diatur admin per site) ----------
   Untuk TV yang dipasang tegak tapi PC tetap mengeluarkan gambar lanskap: seluruh tampilan
   diputar 90°, dan ukuran layar (lebar/tinggi) ditukar. */
html.screen-90, html.screen-270 { --vw: 1vh; --vh: 1vw; }
html.screen-90 body, html.screen-270 body {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vh;
  height: 100vw;
  transform-origin: top left;
}
html.screen-90 body { transform: translateX(100vw) rotate(90deg); }
html.screen-270 body { transform: translateY(100vh) rotate(-90deg); }

@media (prefers-reduced-motion: reduce) {
  .bar { transition: none; }
}
