:root {
  --bg: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --primary: #0b57d0;
  --primary-hover: #0842a0;
  --danger: #dc362e;
  --border: #dadce0;
  --meet-bg: #202124;
  --tile-bg: #3c4043;
  --ctrl-bg: #3c4043;
  --ctrl-hover: #4a4e51;
  --panel-bg: #ffffff;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

input[type="text"] {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  min-width: 0;
}
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-text { background: transparent; color: var(--primary); }
.btn-text:hover:not(:disabled) { background: #e8f0fe; }
.btn-text:disabled { color: var(--muted); }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--border); }

.muted { color: var(--muted); }
.form-error { color: var(--danger); font-size: 14px; }

/* ---------- Beranda ---------- */

.home-header { padding: 16px 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 22px; color: var(--muted); }
.brand-logo { font-size: 28px; }

.home-main {
  display: flex;
  align-items: center;
  min-height: calc(100vh - 80px);
  padding: 0 16px;
}
.home-hero { max-width: 620px; margin: 0 auto 10vh; }
.home-hero h1 { font-size: clamp(32px, 5vw, 44px); font-weight: 400; margin: 0 0 16px; line-height: 1.2; }
.home-hero > p { font-size: 18px; color: var(--muted); margin: 0 0 36px; line-height: 1.5; }

.home-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.join-form { display: flex; gap: 4px; flex: 1; min-width: 240px; }
.join-form input { flex: 1; }

/* ---------- Lobby ---------- */

.lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  min-height: 100vh;
  padding: 24px 16px;
  flex-wrap: wrap;
}
.lobby-preview { width: min(720px, 100%); }
.lobby-join { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; width: min(320px, 100%); }
.lobby-join h2 { font-weight: 400; font-size: 28px; margin: 0; }
.lobby-join p { margin: 0; }
#lobby-form { display: flex; flex-direction: column; gap: 12px; width: 100%; }

.tile-large { aspect-ratio: 16 / 9; }
.tile-large video { transform: scaleX(-1); }
.tile-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 2;
}
.tile-controls .ctrl { border: 1px solid rgba(255,255,255,0.6); background: rgba(0,0,0,0.2); }

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

.tile {
  position: relative;
  background: var(--tile-bg);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile video.mirror { transform: scaleX(-1); }

.tile-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg);
}
.tile-avatar span {
  width: clamp(56px, 22%, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #5f6368;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 4vw, 44px);
}

.tile-name {
  position: absolute;
  left: 12px;
  bottom: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  max-width: calc(100% - 24px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-muted { font-size: 13px; background: rgba(0,0,0,0.5); border-radius: 50%; padding: 3px; line-height: 1; }

.tile.connecting::after {
  content: 'Menghubungkan…';
  position: absolute;
  top: 10px;
  right: 12px;
  color: #fff;
  font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 4px 8px;
  border-radius: 999px;
}

/* ---------- Meeting ---------- */

body.room:has(#meeting:not([hidden])) { background: var(--meet-bg); }

.meeting {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--meet-bg);
  color: #e8eaed;
}
.meeting-body { flex: 1; display: flex; gap: 16px; padding: 16px 16px 0; min-height: 0; }

.video-grid {
  --cols: 1;
  --rows: 1;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

/* Chat */
.chat-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel-bg);
  color: var(--text);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0 24px; }
.chat-header h3 { font-size: 18px; font-weight: 400; margin: 0; }
.chat-note { margin: 12px; padding: 12px; background: #f1f3f4; border-radius: 8px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.4; }

.chat-messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0 24px 12px; }
.chat-message { margin-top: 4px; }
.chat-message .chat-meta { display: flex; gap: 8px; align-items: baseline; margin-top: 14px; font-size: 13px; }
.chat-message .chat-meta span { color: var(--muted); font-size: 12px; }
.chat-message p { margin: 2px 0 0; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }

.chat-form { display: flex; gap: 4px; margin: 12px; padding: 4px 4px 4px 16px; background: #f1f3f4; border-radius: 999px; }
.chat-form input { flex: 1; border: none; background: transparent; padding: 10px 0; box-shadow: none !important; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); }
.chat-form .icon-btn { color: var(--primary); }

/* Toolbar */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 80px;
}
.toolbar-left { display: flex; gap: 10px; align-items: center; font-size: 15px; min-width: 0; }
.toolbar-center { display: flex; gap: 10px; }
.toolbar-right { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.divider { color: #5f6368; }
.meeting-code { background: none; border: none; color: inherit; padding: 4px; border-radius: 6px; font-size: 15px; }
.meeting-code:hover { background: rgba(255,255,255,0.08); }
.participant-count { font-size: 14px; padding: 0 8px; white-space: nowrap; }

.ctrl {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--ctrl-bg);
  color: #fff;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.ctrl:hover:not(:disabled) { background: var(--ctrl-hover); }
.ctrl.off { background: var(--danger) !important; }
.ctrl.off::after {
  /* garis coret untuk ikon yang dimatikan */
  content: '';
  position: absolute;
  width: 26px;
  height: 2px;
  background: #fff;
  transform: rotate(-45deg);
  border-radius: 2px;
}
.ctrl-danger { background: var(--danger); width: 64px; border-radius: 999px; }
.ctrl-danger:hover { background: #b3261e !important; }
.ctrl-flat { background: transparent; }
.ctrl-flat.active { background: #a8c7fa33; }

.badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #8ab4f8;
  color: #202124;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Layar setelah keluar */
.left-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; gap: 16px; padding: 16px; text-align: center; }
.left-screen h2 { font-weight: 400; font-size: 32px; }
.left-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  bottom: 96px;
  max-width: calc(100vw - 32px);
  background: #323232;
  color: #fff;
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 100;
}

/* ---------- Responsif ---------- */

@media (max-width: 720px) {
  .toolbar { grid-template-columns: auto 1fr; }
  .toolbar-left { display: none; }
  .toolbar-center { justify-content: flex-start; }
  .ctrl { width: 44px; height: 44px; font-size: 18px; }

  .chat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    border-radius: 0;
    z-index: 50;
  }

  .video-grid { grid-template-columns: repeat(min(var(--cols), 2), minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: minmax(0, 1fr); }
}
