:root {
	--bg: #0f1220;
	--bg2: #171b2e;
	--bg3: #1f2438;
	--fg: #e8eaf2;
	--muted: #9aa0b5;
	--accent: #4f8dff;
	--accent2: #2f6feb;
	--danger: #e5484d;
	--border: #2a3050;
	--radius: 10px;
}

/* Light theme overrides (toggle keeps dark by default) */
[data-theme="light"] {
	--bg: #eef1f6;
	--bg2: #ffffff;
	--bg3: #f2f4f9;
	--fg: #1c2233;
	--muted: #5f6b85;
	--accent: #2f6feb;
	--accent2: #1d5bd0;
	--danger: #d6373c;
	--border: #d5dbe8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

.hidden { display: none !important; }

.view {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	background: var(--bg);
}
.view.active { display: flex; }

/* Auth */
.auth-card {
	width: 380px;
	max-width: 92vw;
	background: var(--bg2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 28px;
	text-align: center;
}
.auth-card h1 { margin-bottom: 4px; }
.auth-card .subtitle { color: var(--muted); margin-bottom: 20px; font-size: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
	flex: 1;
	padding: 9px;
	background: var(--bg3);
	border: 1px solid var(--border);
	color: var(--fg);
	border-radius: 8px;
	cursor: pointer;
}
.tab.active { background: var(--accent); border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
	padding: 11px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
	font-size: 15px;
}
.auth-form button {
	padding: 11px;
	border: none;
	border-radius: 8px;
	background: var(--accent);
	color: #fff;
	font-size: 15px;
	cursor: pointer;
}
.auth-form button:hover { background: var(--accent2); }
.form-err { color: var(--danger); font-size: 13px; min-height: 16px; }

/* Layout */
.layout { display: flex; width: 100%; height: 100%; }

.sidebar {
	width: 300px;
	min-width: 260px;
	background: var(--bg2);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	height: 100%;
}
.sidebar-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px;
	border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }
.header-avatar {
	flex: 0 0 30px;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--bg3);
	border: 1px solid var(--border);
}
.header-actions { display: flex; gap: 4px; align-items: center; }
.header-actions .icon-btn { font-size: 18px; }
.icon-btn {
	background: none;
	border: none;
	color: var(--muted);
	font-size: 20px;
	cursor: pointer;
	padding: 4px;
}
.icon-btn:hover { color: var(--fg); }
#logout-btn:hover { color: var(--danger); }
#theme-btn:hover { color: #f2c94c; }

.sidebar-tabs {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px 14px;
	border-bottom: 1px solid var(--border);
}
.sidebar-search {
	padding: 10px 14px 0;
}
.sidebar-search input {
	width: 100%;
	box-sizing: border-box;
	padding: 8px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
}
.side-tab {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 9px 12px;
	background: var(--bg3);
	border: 1px solid var(--border);
	color: var(--fg);
	border-radius: 8px;
	cursor: pointer;
	font-size: 14px;
	text-align: left;
}
.side-tab .sicon { flex: 0 0 20px; text-align: center; font-size: 16px; filter: grayscale(1) opacity(.75); }
.side-tab.active .sicon { filter: none; }
.side-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.side-section { flex: 1; overflow-y: auto; padding: 12px; }

.side-block {
	flex: 0 0 auto;
	max-height: 30%;
	overflow-y: auto;
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
}
.side-block-title {
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .5px;
	color: var(--muted);
	margin-bottom: 8px;
}
.users-list { gap: 4px; }
.users-list li { padding: 8px 10px; }
.users-list li:hover { border-color: var(--accent); }

.section-head { display: flex; gap: 8px; margin-bottom: 10px; }
.section-head input {
	flex: 1;
	padding: 8px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
}

.btn {
	padding: 9px 14px;
	border: none;
	border-radius: 8px;
	background: var(--accent);
	color: #fff;
	cursor: pointer;
	font-size: 14px;
	white-space: nowrap;
}
.btn:hover { background: var(--accent2); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.tiny { padding: 3px 8px; font-size: 12px; border-radius: 6px; background: var(--bg1); color: inherit; border: 1px solid var(--border); }
.btn.tiny:hover { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #c33c41; }

.admin-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.stat-card {
	flex: 1 1 130px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 12px 14px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: 10px;
}
.stat-val { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.admin-tabs .btn.active { background: var(--accent); }
.admin-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: 10px;
	overflow: hidden;
}
.admin-table th, .admin-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table th { background: var(--bg2); white-space: nowrap; }
.admin-table tr.row-blocked td { opacity: .55; }
.admin-table .row-actions { white-space: nowrap; }
.badge-ok { color: #2e7d32; }
.badge-bad { color: var(--danger); }

.list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.list li {
	position: relative;
	padding: 11px 12px;
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	gap: 2px;
}
.list li:hover { border-color: var(--accent); }
.sect-label { background: none; border: none; cursor: default; color: var(--accent); font-weight: 700; }
.sect-label:hover { border: none; }
.badge-live {
	position: absolute;
	top: 8px;
	right: 8px;
	font-size: 11px;
	padding: 2px 7px;
	border-radius: 20px;
	background: rgba(222, 57, 61, .15);
	color: var(--accent);
	border: 1px solid var(--accent);
}
.list li.active { border-color: var(--accent); background: var(--bg2); }
.list .name { font-weight: 600; }
.list .sub { font-size: 12px; color: var(--muted); }

/* Online / offline presence indicators */
.dot {
	flex: 0 0 10px;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	display: inline-block;
}
.dot.online { background: #2ecc71; box-shadow: 0 0 4px rgba(46, 204, 113, 0.7); }
.dot.offline { background: #9aa0a6; }

/* green flag for active subscribers */
.flag {
	flex: 0 0 12px;
	width: 12px;
	height: 12px;
	display: inline-block;
	background: #2ecc71;
	clip-path: polygon(0 0, 0 100%, 4px 100%, 4px 3px, 12px 3px, 12px 9px, 4px 9px);
	filter: drop-shadow(0 0 2px rgba(46, 204, 113, 0.8));
}

/* chat with new incoming messages */
.list li.unread { border-color: #2ecc71; }
.list li.unread .name { color: #2ecc71; }
.badge-new {
	position: absolute;
	top: 8px;
	right: 8px;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 9px;
	background: #2ecc71;
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
}

/* Main */
.main { flex: 1; display: flex; flex-direction: column; height: 100%; }
.panel { display: flex; flex-direction: column; height: 100%; flex: 1; }
.panel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px 20px;
	border-bottom: 1px solid var(--border);
}
.panel-actions { display: flex; gap: 8px; }

.messages {
	flex: 1;
	overflow-y: auto;
	padding: 18px 20px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.msg {
	max-width: 70%;
	padding: 9px 13px;
	border-radius: 12px;
	background: var(--bg3);
	align-self: flex-start;
}
.msg.mine { align-self: flex-end; background: var(--accent); }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.mine .meta { color: #cfe0ff; }
.msg .attachment { margin: -2px 0 4px; }
.msg .attachment img,
.msg .attachment video {
	max-width: 320px;
	max-height: 260px;
	width: auto;
	display: block;
	border-radius: 8px;
	cursor: pointer;
	background: #000;
}
.msg .caption { margin-top: 4px; word-break: break-word; }
.msg .caption:empty { display: none; }

/* Emoji panel */
.emoji-panel {
	display: flex;
	flex-wrap: wrap;
	gap: 2px;
	padding: 8px 12px;
	max-height: 160px;
	overflow-y: auto;
	border-top: 1px solid var(--border);
	background: var(--bg2);
}
.emoji-cell {
	background: none;
	border: none;
	font-size: 20px;
	line-height: 1;
	padding: 4px;
	cursor: pointer;
	border-radius: 6px;
}
.emoji-cell:hover { background: var(--bg3); }

.composer {
	display: flex;
	gap: 8px;
	padding: 14px 20px;
	border-top: 1px solid var(--border);
	align-items: center;
}
.composer input[type="text"] {
	flex: 1;
	padding: 11px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
	font-size: 15px;
	min-width: 0;
}
.composer .icon-btn { font-size: 22px; }

/* Settings modal */
.overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 60;
}
.modal {
	width: 360px;
	max-width: 92vw;
	background: var(--bg2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 24px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: 90vh;
	overflow-y: auto;
}
.modal h3 { margin-bottom: 4px; }
.modal input {
	padding: 10px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
	font-size: 15px;
	width: 100%;
}
.modal .f-label { font-size: 13px; color: var(--muted); }
.modal .hint { font-size: 12px; color: var(--muted); }
.avatar-row { display: flex; gap: 12px; align-items: center; }
.settings-avatar {
	width: 64px;
	height: 64px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--bg3);
	border: 1px solid var(--border);
}
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

.empty-state {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--muted);
	font-size: 16px;
}

/* Rooms */
.rooms-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 14px;
	padding: 20px;
	overflow-y: auto;
}
.room-card {
	background: var(--bg3);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 18px;
	text-align: center;
}
.room-card .room-name { font-weight: 600; margin-bottom: 10px; }
.room-select {
	display: flex;
	gap: 10px;
	padding: 20px;
	align-items: center;
}
.room-select input {
	flex: 1;
	padding: 10px;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg3);
	color: var(--fg);
}

/* Call view */
#call-view { flex-direction: column; align-items: stretch; }
.call-layout { display: flex; flex-direction: column; height: 100%; }
.call-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 14px 20px;
	background: var(--bg2);
	border-bottom: 1px solid var(--border);
}
.call-controls { display: flex; gap: 8px; }
.video-grid {
	flex: 1;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap: 12px;
	padding: 16px;
	overflow-y: auto;
	background: var(--bg);
}
.video-tile {
	position: relative;
	background: #000;
	border-radius: 10px;
	overflow: hidden;
	min-height: 220px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.video-tile video { width: 100%; height: 100%; object-fit: cover; }
.video-tile .label {
	position: absolute;
	bottom: 8px;
	left: 8px;
	background: rgba(0,0,0,0.55);
	padding: 4px 9px;
	border-radius: 6px;
	font-size: 12px;
}
.video-tile .screen-label {
	position: absolute;
	top: 8px;
	right: 8px;
	background: var(--danger);
	padding: 3px 8px;
	border-radius: 5px;
	font-size: 11px;
}

/* Presentation fullscreen */
#presentation-view { flex-direction: column; align-items: stretch; background: #000; }
.presentation-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 12px 20px;
	background: var(--bg2);
}
#presentation-video { flex: 1; width: 100%; object-fit: contain; }

/* Masterclass */
#mc-view { flex-direction: column; align-items: stretch; }
.mc-layout { display: flex; flex-direction: column; height: 100%; }
.mc-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 10px;
	padding: 14px 20px;
	background: var(--bg2);
	border-bottom: 1px solid var(--border);
}
.mc-role {
	font-size: 13px;
	color: var(--muted);
	background: var(--bg3);
	border: 1px solid var(--border);
	padding: 5px 10px;
	border-radius: 14px;
}
.mc-controls { display: flex; gap: 8px; }
.mc-body { flex: 1; display: flex; min-height: 0; }
.mc-stage {
	flex: 1;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #000;
	min-width: 0;
}
#mc-main-video { width: 100%; height: 100%; object-fit: contain; }
.mc-label {
	position: absolute;
	bottom: 10px;
	left: 10px;
	background: rgba(0,0,0,0.6);
	padding: 4px 10px;
	border-radius: 6px;
	font-size: 13px;
	color: #fff;
}
#mc-main-label { position: absolute; top: 10px; bottom: auto; left: 10px; }
.mc-question {
	position: absolute;
	bottom: 14px;
	left: 14px;
	width: 300px;
	max-width: 45%;
	aspect-ratio: 16/9;
	background: #000;
	border: 1px solid var(--accent);
	border-radius: 10px;
	overflow: hidden;
	box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.mc-question video { width: 100%; height: 100%; object-fit: cover; }
.mc-question-head {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: linear-gradient(rgba(0,0,0,.7), transparent);
	padding: 6px 8px;
	font-size: 12px;
	color: #fff;
}
.mc-question-head button { padding: 2px 8px; font-size: 12px; }
.mc-pip {
	position: absolute;
	bottom: 14px;
	right: 14px;
	width: 180px;
	aspect-ratio: 4/3;
	background: #111;
	border: 1px solid var(--border);
	border-radius: 10px;
	overflow: hidden;
	box-shadow: 0 6px 24px rgba(0,0,0,.6);
}
.mc-pip video { width: 100%; height: 100%; object-fit: cover; }
.mc-side {
	width: 300px;
	min-width: 240px;
	max-height: 100%;
	background: var(--bg2);
	border-left: 1px solid var(--border);
	overflow-y: auto;
	padding: 14px;
}
.mc-side-title {
	font-size: 13px;
	color: var(--muted);
	margin-bottom: 10px;
}
.mc-pers { display: flex; flex-direction: column; gap: 4px; }
.mc-pers .mc-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; }
.mc-pers .btn.small { white-space: normal; }

/* Masterclass list cards: stats and action buttons */
.room-card .mc-meta {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 10px;
	margin-top: 8px;
	font-size: 13px;
	color: var(--muted);
	flex-wrap: wrap;
}
.room-card .mc-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	margin-top: 10px;
}
.room-card .mc-actions .btn { white-space: nowrap; }
.room-card .rec-live { color: var(--danger); font-weight: 700; }
.room-card .mc-watched { border-color: var(--accent); color: var(--accent); }

/* Recording player modal */
.modal-wide { width: min(720px, 92vw); }
#rec-video {
	width: 100%;
	max-height: 60vh;
	border-radius: 8px;
	background: #000;
	margin-top: 10px;
}

@media (max-width: 720px) {
	.sidebar { width: 220px; min-width: 180px; }
	.video-grid { grid-template-columns: 1fr; }
	.mc-side { width: 220px; min-width: 180px; }
	.mc-question { width: 220px; }
	.mc-pip { width: 130px; }
}
