/* Aplikasi komuniti: deretan server | saluran | chat | ahli */
.app { display: grid; grid-template-columns: 72px 240px 1fr 220px; height: 100vh; height: 100dvh; overflow: hidden; }
.app.no-members { grid-template-columns: 72px 240px 1fr; }

/* Deretan server */
.rail { background: #110f18; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow-y: auto; }
.rail a, .rail button {
  position: relative; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none;
  color: #fff; font-weight: 800; font-size: 1.05rem; text-decoration: none; border: 0; cursor: pointer; transition: border-radius .15s, transform .1s;
}
.rail a:hover, .rail a.on, .rail button:hover { border-radius: 16px; }
.rail a.on::before { content: ''; position: absolute; left: -12px; width: 4px; height: 36px; border-radius: 0 4px 4px 0; background: #fff; }
.rail .home { background: var(--brand); }
.rail .add { background: var(--panel); color: var(--ok); font-size: 1.6rem; }
.rail .sep { width: 32px; height: 2px; background: var(--line); border-radius: 2px; flex: none; }
.rail .dot { position: absolute; right: -2px; bottom: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); border: 3px solid #110f18; font-size: .65rem; display: flex; align-items: center; justify-content: center; }

/* Senarai saluran / DM */
.side { background: var(--bg2); display: flex; flex-direction: column; min-width: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px; height: 52px; border-bottom: 1px solid var(--line); font-weight: 800; flex: none; }
.side-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-body { flex: 1; overflow-y: auto; padding: 10px 8px; }
.side-label { display: flex; align-items: center; justify-content: space-between; color: var(--dim); font-size: .72rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; padding: 12px 8px 4px; }
.side-label button { background: none; border: 0; color: var(--dim); font-size: 1.1rem; cursor: pointer; padding: 0 4px; }
.ch { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; cursor: pointer; }
.ch:hover { background: var(--panel); color: var(--text); }
.ch.on { background: var(--panel2); color: #fff; }
.ch.unread { color: #fff; }
.ch.unread::after { content: ''; margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.ch .ic { width: 18px; text-align: center; opacity: .8; flex: none; }
.ch .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #19162a; flex: none; }
.me-bar .nm { flex: 1; min-width: 0; font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-bar .nm small { display: block; color: var(--dim); font-weight: 600; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-family: inherit; font-weight: 700; font-size: 1.05rem; padding: 6px; border-radius: 8px; line-height: 1; position: relative; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn .dot { position: absolute; top: 0; right: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }

/* Ruang chat */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.main-head { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 52px; border-bottom: 1px solid var(--line); font-weight: 800; flex: none; }
.main-head .back { display: none; }
.main-head .ttl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 0 6px; overscroll-behavior: contain; }
.msg { display: grid; grid-template-columns: 40px 1fr auto; gap: 0 12px; padding: 2px 16px; position: relative; }
.msg:hover { background: rgba(255, 255, 255, .03); }
.msg.first { margin-top: 12px; }
.msg .avatar { width: 40px; height: 40px; font-size: .95rem; grid-row: span 2; }
.msg:not(.first) .avatar { visibility: hidden; height: 0; }
.msg .who { font-weight: 800; }
.msg .who time { color: var(--dim); font-weight: 500; font-size: .76rem; margin-left: 8px; }
.msg:not(.first) .who { display: none; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; grid-column: 2; }
.msg .body .edited { color: var(--dim); font-size: .72rem; margin-left: 4px; }
.msg .body.deleted { color: var(--dim); font-style: italic; }
.msg.mention { background: rgba(245, 176, 65, .08); box-shadow: inset 3px 0 0 var(--warn); }
.msg .mtools { grid-column: 3; grid-row: 1; display: none; gap: 2px; align-self: start; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px; position: absolute; right: 16px; top: -14px; }
.msg:hover .mtools, .msg:focus-within .mtools { display: flex; }
.mtools button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: .9rem; }
.mtools button:hover { background: var(--panel2); color: var(--text); }
.at { color: #c9b8ff; background: rgba(124, 92, 255, .18); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.more { display: block; margin: 6px auto 10px; }
.empty-ch { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty-ch b { display: block; font-size: 1.4rem; color: var(--text); margin-bottom: 6px; }

.composer { padding: 0 16px 14px; flex: none; }
.composer form { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border-radius: 12px; padding: 8px 8px 8px 14px; }
.composer textarea { flex: 1; background: none; border: 0; min-height: 24px; max-height: 160px; padding: 6px 0; resize: none; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer .meta { display: flex; justify-content: space-between; gap: 8px; min-height: 20px; font-size: .78rem; color: var(--dim); padding: 4px 4px 0; }
.composer .limit { background: rgba(239, 83, 80, .12); border: 1px solid rgba(239, 83, 80, .4); color: #ffb4b2; border-radius: 12px; padding: 12px 14px; font-weight: 600; }

/* Ahli */
.members { background: var(--bg2); overflow-y: auto; padding: 12px 8px; }
.mem { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.mem:hover { background: var(--panel); }
.mem .avatar { width: 32px; height: 32px; font-size: .8rem; position: relative; }
.mem .avatar::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--bg2); background: #5d5a74; }
.mem.on .avatar::after { background: var(--ok); }
.mem:not(.on) { opacity: .55; }
.mem .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: .92rem; }
.mem .role { font-size: .7rem; color: var(--warn); }

/* Kotak dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(92vw, 460px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin-top: 0; }
.notif { padding: 10px; border-radius: 10px; background: var(--bg2); margin-bottom: 8px; cursor: pointer; }
.notif.new { box-shadow: inset 3px 0 0 var(--warn); }
.voice-ph { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--muted); }
.voice-ph b { font-size: 3rem; }
.invite-box { display: flex; gap: 8px; }
.invite-box input { font-family: ui-monospace, Consolas, monospace; }

/* Panggilan: peserta di bawah saluran suara, bar panggilan, pentas & butang kawalan */
.vp { display: flex; align-items: center; gap: 8px; padding: 3px 10px 3px 34px; font-size: .85rem; color: var(--muted); }
.vp .avatar { width: 22px; height: 22px; font-size: .62rem; }
.call-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: rgba(47, 191, 113, .12); border-top: 1px solid rgba(47, 191, 113, .35); flex: none; }
.call-bar div { flex: 1; min-width: 0; font-size: .85rem; }
.call-bar b { color: #7fe3ad; display: block; }
.call-bar small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-bar .icon-btn { background: var(--bad); color: #fff; transform: rotate(135deg); }
.callwrap { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #0d0b14; }
.callwrap.dm { flex: none; height: 46%; border-bottom: 1px solid var(--line); }
.stage { flex: 1; min-height: 0; display: grid; gap: 10px; padding: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); grid-auto-rows: minmax(140px, 1fr); overflow-y: auto; }
.stage.has-screen { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); grid-auto-rows: 120px; }
.stage.has-screen .tile.screen { grid-column: 1 / -1; grid-row: span 3; }
.tile { position: relative; border-radius: 14px; background: var(--panel); display: flex; align-items: center; justify-content: center; overflow: hidden; outline: 3px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--ok); }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.screen video { object-fit: contain; background: #000; }
.tile video.mirror { transform: scaleX(-1); }
.tile .avatar { width: 72px; height: 72px; font-size: 1.8rem; }
.tile .tname { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); padding: 3px 8px; border-radius: 8px; font-size: .8rem; font-weight: 700; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctrl { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; padding: 10px 12px 14px; flex: none; }
.ctrl #call-left { min-width: 120px; }
.cbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; padding: 8px 10px; border: 0; border-radius: 14px; background: var(--panel2); color: var(--text); font-family: inherit; font-weight: 700; font-size: 1.2rem; cursor: pointer; }
.cbtn span { font-size: .68rem; color: var(--muted); }
.cbtn:hover { filter: brightness(1.15); }
.cbtn.off { background: #4a2633; }
.cbtn.live { background: var(--ok); } .cbtn.live span { color: #fff; }
.cbtn.leave { background: var(--bad); } .cbtn.leave span { color: #fff; }
.cbtn.leave { font-size: 1.1rem; }

/* Telefon: satu panel pada satu masa */
@media (max-width: 900px) {
  .app, .app.no-members { grid-template-columns: 64px 1fr; }
  .members { display: none; }
  .rail a, .rail button { width: 44px; height: 44px; }
  .app .main { display: none; }
  .app.show-main { grid-template-columns: 1fr; }
  .app.show-main .rail, .app.show-main .side { display: none; }
  .app.show-main .main { display: flex; }
  .main-head .back { display: inline-flex; }
  .msg { padding: 2px 10px; } .msg .mtools { right: 10px; }
  .composer { padding: 0 10px 10px; }
  .ctrl #call-left { width: 100%; text-align: center; min-width: 0; }
  .cbtn { min-width: 58px; }
}
