:root {
  --bg: #0f1412;
  --panel: #18201c;
  --panel-2: #212b26;
  --line: #2c3832;
  --text: #eef3ef;
  --muted: #9aa8a0;
  --brand: #2e9e5b;
  --brand-2: #3cc46f;
  --danger: #e5484d;
  --warn: #f5b83d;
  --hover: #2a3630;
  --err: #ff8a8d;
  --radius: 14px;
  color-scheme: dark;
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
}
/* ---------- giao diện sáng (chọn bằng nút Sáng/Tối, lưu trên từng máy) ---------- */
:root[data-theme="light"] {
  --bg: #f2f5f3;
  --panel: #ffffff;
  --panel-2: #e6ece8;
  --line: #d2dbd5;
  --text: #15201a;
  --muted: #5b6961;
  --brand: #1f8f4d;
  --brand-2: #17803f;
  --danger: #d6363c;
  --hover: #d7e0da;
  --err: #c81e2a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input { font: inherit; color: inherit; }
a { color: var(--brand-2); }

.btn {
  border: 0; border-radius: 10px; padding: 11px 18px; cursor: pointer;
  background: var(--panel-2); font-weight: 600; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); color: #fff; }
:root[data-theme="light"] .btn.primary:hover { background: #17733a; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); }
.field input[type=text], .field input[type=password] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; outline: none;
}
.field input:focus { border-color: var(--brand); }
.select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; color: var(--text); width: 100%; min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 14px; cursor: pointer; }
.error { color: var(--err); font-size: 14px; min-height: 20px; }
.hidden { display: none !important; }

/* ---------- trang chủ ---------- */
.home { min-height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 18px 24px; }
.logo { width: 38px; height: 38px; border-radius: 10px; background: #fff; padding: 3px; object-fit: contain; flex: none; box-shadow: 0 0 0 1px var(--line); }
.logo.mini { width: 22px; height: 22px; border-radius: 6px; padding: 2px; }
.hero-logo { grid-column: 1 / -1; width: 120px; height: auto; background: #fff; border-radius: 18px; padding: 10px; box-shadow: 0 0 0 1px var(--line); }
.theme-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.theme-btn:hover { background: var(--hover); }
.brand-name { font-weight: 800; letter-spacing: .5px; }
.brand-name span { color: var(--brand-2); }
.hero { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; max-width: 900px; margin: 0 auto; padding: 24px 16px; width: 100%; align-content: center; }
.hero h1 { grid-column: 1 / -1; margin: 0 0 6px; font-size: clamp(26px, 4vw, 38px); }
.hero p.sub { grid-column: 1 / -1; margin: 0 0 10px; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h2 { margin: 0 0 16px; font-size: 19px; }
.created { margin-top: 12px; background: var(--bg); border-radius: 10px; padding: 12px; font-size: 14px; word-break: break-all; }
.created b { font-size: 20px; letter-spacing: 1px; }

/* ---------- màn hình trước khi vào ---------- */
.prejoin { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.prejoin-box { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; max-width: 980px; width: 100%; }
@media (max-width: 760px) { .prejoin-box { grid-template-columns: 1fr; } }
.preview { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview .off { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa8a0; }
.preview-controls { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 10px; }
.round { width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(40,50,45,.85); color: #fff; cursor: pointer; display: grid; place-items: center; }
.round.off-state { background: var(--danger); }
.round svg { width: 22px; height: 22px; }
.waiting { text-align: center; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--brand-2); border-radius: 50%; animation: spin 1s linear infinite; margin: 10px auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- phòng họp ---------- */
.meeting { height: 100%; display: flex; flex-direction: column; }
.meet-top { display: flex; align-items: center; justify-content: space-between; padding: 3px 12px; gap: 10px; font-size: 13px; color: var(--muted); }
.meet-top .btn { padding: 3px 10px; font-size: 12px; }
.meet-top .title { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meet-body { flex: 1; display: flex; min-height: 0; }
.stage-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 0 4px 4px; gap: 6px; }

.grid { flex: 1; display: grid; gap: 8px; min-height: 0; align-content: center; justify-content: center; }
.tile { position: relative; background: #1d2622; color: #fff; border-radius: 12px; overflow: hidden; aspect-ratio: 16/9; min-width: 0; outline: 3px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--brand-2); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.local:not(.screen) video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; }
.tile .avatar span { width: 30%; max-width: 96px; aspect-ratio: 1; border-radius: 50%; background: var(--brand); display: grid; place-items: center; font-size: clamp(14px, 3vw, 34px); font-weight: 700; }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 6px; font-size: 13px; display: flex; gap: 6px; align-items: center; max-width: calc(100% - 16px); }
.tile .label .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .hand { position: absolute; top: 8px; left: 8px; font-size: 22px; background: var(--warn); border-radius: 8px; padding: 0 6px; }
.tile .mic-off { color: var(--danger); }
.tile .hidden-tag { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.65); font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.tile:has(.hidden-tag:not(.hidden)) video, .tile:has(.hidden-tag:not(.hidden)) .avatar { opacity: .45; }
.host-settings + .host-settings { margin-top: 8px; }

.layout-share { display: flex; gap: 8px; flex: 1; min-height: 0; }
.layout-share .main-share { flex: 1; min-width: 0; display: flex; position: relative; }
/* nút xem toàn màn hình */
.fs-btn { position: absolute; top: 10px; right: 10px; z-index: 7; display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  background: rgba(0,0,0,.62); color: #fff; border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; font-weight: 600; opacity: .8; transition: opacity .15s, background .15s; }
.fs-btn:hover, .fs-btn:focus-visible { opacity: 1; background: rgba(0,0,0,.88); }
@media (max-width: 760px) { .fs-btn span { display: none; } .fs-btn { padding: 7px; } }
/* thanh mic / giơ tay chỉ hiện khi toàn màn hình */
.fs-bar { display: none; position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 7; gap: 10px; padding: 8px 10px;
  background: rgba(0,0,0,.55); border-radius: 14px; opacity: .7; transition: opacity .15s; }
.fs-bar:hover, .fs-bar:focus-within { opacity: 1; }
@media (hover: none) { .fs-bar { opacity: .92; } }
.main-share:fullscreen .fs-bar, .main-share:-webkit-full-screen .fs-bar, .main-share.fs-fake .fs-bar { display: flex; }
.fs-bar button { display: inline-flex; align-items: center; gap: 7px; border: 0; cursor: pointer; border-radius: 10px; padding: 9px 13px;
  background: rgba(255,255,255,.16); color: #fff; font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; }
.fs-bar button:hover { background: rgba(255,255,255,.28); }
.fs-bar button svg { width: 19px; height: 19px; flex: none; }
.fs-bar button.off { background: var(--danger); }
.fs-bar button.active { background: var(--brand); }
.main-share:fullscreen { background: #000; width: 100vw; height: 100vh; }
.main-share:-webkit-full-screen { background: #000; width: 100vw; height: 100vh; }
.main-share.fs-fake { position: fixed; inset: 0; z-index: 1000; background: #000; }
.main-share:fullscreen > .tile, .main-share:-webkit-full-screen > .tile, .main-share.fs-fake > .tile { border-radius: 0; border: 0; }
/* camera của cô nổi trong vùng chia sẻ */
.pip { position: absolute; z-index: 6; width: clamp(90px, 11%, 160px); right: 12px; bottom: 12px; touch-action: none; }
.pip.custom { right: auto; bottom: auto; }
.pip-open { position: relative; cursor: grab; }
.pip.dragging .pip-open { cursor: grabbing; }
.pip.dragging .tile { box-shadow: 0 12px 32px rgba(0,0,0,.7); }
.pip-resize { position: absolute; width: 16px; height: 16px; right: -4px; bottom: -4px; cursor: nwse-resize; border-radius: 4px;
  background: linear-gradient(135deg, transparent 45%, rgba(255,255,255,.8) 45% 55%, transparent 55% 70%, rgba(255,255,255,.8) 70% 80%, transparent 80%); opacity: 0; transition: opacity .15s; }
.pip:hover .pip-resize { opacity: 1; }
@media (hover: none) { .pip-resize { opacity: 1; } }
.pip-box .tile { width: 100%; aspect-ratio: 16/9; box-shadow: 0 8px 24px rgba(0,0,0,.55); border: 2px solid rgba(255,255,255,.15); }
.pip-box .tile .label { font-size: 13px; font-weight: 700; left: 5px; bottom: 5px; padding: 2px 7px; max-width: calc(100% - 10px); }
.pip-box .tile .label svg { width: 12px; height: 12px; }
/* bố cục Người đang nói: ô lớn hiện đủ khuôn mặt */
.speaker-layout .main-share > .tile:not(.screen) video { object-fit: contain; }
.speaker-layout .main-share > .tile .label { font-size: 15px; }
.pip-box .tile .avatar span { width: 44%; max-width: 72px; font-size: clamp(11px, 2vw, 22px); }
.pip-ctrl { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.pip:hover .pip-ctrl, .pip:focus-within .pip-ctrl { opacity: 1; }
@media (hover: none) { .pip-ctrl { opacity: 1; } }
.pip-ctrl button, .pip-pill { border: 0; cursor: pointer; background: rgba(0,0,0,.7); color: #fff; border-radius: 8px; font-size: 13px; padding: 4px 8px; }
.pip-ctrl button:hover, .pip-pill:hover { background: rgba(0,0,0,.9); }
.pip-pill { display: none; padding: 5px 12px 5px 5px; font-weight: 600; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.5);
  border-radius: 999px !important; align-items: center; gap: 8px; cursor: grab; touch-action: none; }
.pip.dragging .pip-pill { cursor: grabbing; }
.pip-av { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; border: 2px solid rgba(255,255,255,.85); }
.pip-nm { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.pip-exp { opacity: .8; font-size: 14px; }
.pip.collapsed { width: auto; }
.pip.collapsed .pip-open { display: none; }
.pip.collapsed .pip-pill { display: inline-flex; }
@media (max-width: 760px) { .pip:not(.sized) { width: 18%; min-width: 80px; } }
.layout-share .main-share > .tile { flex: 1; aspect-ratio: auto; }
.layout-share .strip { width: 220px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.layout-share .strip .tile { flex: none; }
@media (max-width: 760px) {
  .layout-share { flex-direction: column; }
  .layout-share .strip { width: 100%; flex-direction: row; overflow-x: auto; height: 100px; }
  .layout-share .strip .tile { height: 100%; width: auto; }
}
.pager { display: flex; justify-content: center; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }

.toolbar { display: flex; justify-content: center; align-items: center; gap: 4px; padding: 3px 8px; background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap; }
.tool { position: relative; border: 0; background: transparent; border-radius: 8px; padding: 3px 8px; min-width: 62px; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; font-size: 11px; line-height: 1.25; color: var(--text); }
.tool:hover { background: var(--panel-2); }
.tool svg { width: 20px; height: 20px; }
.tool.off svg { color: var(--danger); }
.tool.active { color: var(--brand-2); }
.tool .badge { position: absolute; top: 2px; right: 12px; background: var(--danger); color: #fff; font-size: 11px; border-radius: 9px; padding: 0 5px; min-width: 18px; }
.tool.leave { background: var(--danger); color: #fff; padding: 7px 16px; margin-left: 8px; font-size: 12px; }
@media (max-width: 760px) { .tool { min-width: 52px; font-size: 10px; padding: 5px; } .tool span.t { display: none; } }

.side { width: 340px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
@media (max-width: 760px) { .side { position: fixed; inset: 0; width: 100%; z-index: 20; } }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.side-head button { background: none; border: 0; cursor: pointer; font-size: 22px; line-height: 1; }
.side-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.chat-msg { margin-bottom: 12px; font-size: 14px; }
.chat-msg .who { font-weight: 700; font-size: 13px; }
.chat-msg .who time { color: var(--muted); font-weight: 400; margin-left: 6px; }
.chat-msg .txt { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.chat-msg.me .who { color: var(--brand-2); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; outline: none; }

.section-title { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; letter-spacing: .5px; }
.person { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.person .av { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.person .nm { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .nm small { color: var(--muted); }
.person .acts { display: flex; gap: 4px; }
.host-settings { background: var(--bg); border-radius: 10px; padding: 12px; margin-bottom: 6px; }
.host-settings .check { margin-bottom: 8px; }

.toast-wrap { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); pointer-events: auto; display: flex; gap: 10px; align-items: center; }

.reaction { position: fixed; bottom: 90px; font-size: 40px; animation: floatUp 3s ease-out forwards; pointer-events: none; z-index: 40; }
@keyframes floatUp { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-320px); opacity: 0; } }
.react-menu { position: absolute; bottom: 64px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; gap: 4px; }
.react-menu button { background: none; border: 0; font-size: 26px; cursor: pointer; border-radius: 8px; padding: 2px 6px; }
.react-menu button:hover { background: var(--line); }

.rec-badge { background: var(--danger); color: #fff; font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 6px; animation: recBlink 1.6s ease-in-out infinite; }
@keyframes recBlink { 50% { opacity: .55; } }
.tool.recording { color: var(--danger); }
.muted { color: var(--muted); }
.small-note { font-size: 12px; margin: 6px 0 0; line-height: 1.45; }
.pop-menu { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; z-index: 30; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.rec-menu { width: 340px; max-width: calc(100vw - 24px); }
.rec-title { font-weight: 700; margin-bottom: 8px; }
.rec-dir { font-size: 14px; margin-bottom: 10px; word-break: break-word; }
.rec-actions { display: flex; gap: 8px; }
.rec-actions .btn { flex: 1; }
.devices { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.devices .field { margin: 0; }
.devices .dev-mic { grid-column: 1 / -1; }
.side-body.devices { display: block; margin-top: 0; }
.side-body.devices .field { margin-bottom: 18px; gap: 8px; }
.dev-row { display: flex; gap: 6px; }
.dev-row .select { flex: 1; }
.dev-row .btn { flex: none; white-space: nowrap; }
.level { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.level > div { height: 100%; width: 0; background: var(--brand-2); transition: width .08s; }
.tool-group { position: relative; display: flex; align-items: stretch; }
.caret { border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; padding: 0 6px; font-size: 14px; margin-left: -6px; }
.caret:hover { background: var(--panel-2); color: var(--text); }
.dev-menu { width: 300px; left: 0; transform: none; padding: 8px; max-height: 60vh; overflow-y: auto; }
.dev-menu .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 8px 8px 4px; }
.dev-menu .item { display: flex; gap: 8px; align-items: center; width: 100%; border: 0; background: none; color: var(--text); text-align: left; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.dev-menu .item:hover { background: var(--line); }
.dev-menu .item .ck { width: 16px; flex: none; color: var(--brand-2); }
.dev-menu .item .lb { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
@media (max-width: 760px) { .dev-menu { position: fixed; left: 8px; right: 8px; bottom: 76px; width: auto; } }
.app-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(420px, 92vw); line-height: 1.5; }
.app-dialog::backdrop { background: rgba(0,0,0,.6); }
.audio-warn { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 60; width: min(760px, calc(100vw - 24px));
  background: #c81e2a; color: #fff; border-radius: 12px; padding: 12px 16px; font-size: 16px; line-height: 1.45; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); border: 2px solid #ff6b74; animation: warnPulse 1.4s ease-in-out infinite; }
.audio-warn.small { font-size: 14px; padding: 8px 40px 8px 14px; animation: none; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.audio-warn.small .btn { background: #fff; color: #c81e2a; }
.audio-warn-x { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: #fff; font-size: 16px; cursor: pointer; }
@keyframes warnPulse { 50% { box-shadow: 0 0 0 6px rgba(200,30,42,.35), 0 10px 30px rgba(0,0,0,.5); } }
.btn.testing { background: var(--danger); color: #fff; }
@media (max-width: 760px) { .devices { grid-template-columns: 1fr; } }

.ended { height: 100%; display: grid; place-items: center; text-align: center; padding: 16px; }
