/* Portal — layar kiosk (TV). Video adalah kontennya; semua chrome tenang dan gelap.
   Satu elemen khas: pelat lokasi di tiap tile (bar status + nama site + status). */

:root {
  --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: 10px;
  --r-ctl: 8px;
  --gutter: 20px;

  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 ---------- */

.bar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 14px var(--gutter);
  border-bottom: 1px solid var(--line);
}

.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-size: 26px; font-weight: 500; letter-spacing: 0.01em; }
.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: var(--line); background: var(--surface); }
.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: 12px;
  padding: var(--gutter);
}

.tiles { display: grid; gap: 12px; min-height: 0; }

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

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

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

/* ---------- 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; }

/* 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, .tile[data-rot='270'] video {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--th);
  height: var(--tw);
  transform: translate(-50%, -50%) rotate(var(--rot));
}
.tile[data-rot='180'] video { 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 */
.plate {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  padding: 10px 16px 11px 18px;
  border-radius: 6px;
  background: rgba(22, 27, 34, 0.86);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-left: 4px solid var(--state);
}
.plate-name {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plate-status {
  margin-top: 2px;
  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: 8px; bottom: 8px; padding: 6px 10px 7px 12px; border-left-width: 3px; }
.strip .plate-name { font-size: 16px; }
.strip .plate-status { font-size: 12.5px; }
.strip .plate-hint { margin-top: 2px; font-size: 12px; }

/* Mode pilih conference */
.tile-check {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  display: none;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background: rgba(22, 27, 34, 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: 12px;
  top: 5px;
  width: 10px;
  height: 19px;
  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; }

@media (orientation: portrait) {
  main.has-pin { flex-direction: column; }
  main.has-pin .strip {
    flex: none;
    height: 24vh;
    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: 15vw;
  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; }

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: 13vw;
}

/* ---------- 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; }

/* ---------- 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: 92px;
  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: 18px; }
  .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; }
}
