/* ============================================================
 *   CSS Variables – Light / Dark
 *   ============================================================ */
:root,
[data-theme="light"] {
	--bg: #f0f2f5;
	--bg-elevated: #ffffff;
	--bg-input: #f0f2f5;
	--bg-hover: #e4e6eb;
	--text: #050505;
	--text-secondary: #65676b;
	--text-muted: #8a8d91;
	--border: #ced0d4;
	--accent: #0866ff;
	--accent-hover: #0750c7;
	--accent-soft: #e7f3ff;
	--bubble-me: #0866ff;
	--bubble-me-text: #ffffff;
	--bubble-other: #e4e6eb;
	--bubble-other-text: #050505;
	--bubble-admin: #fff3cd;
	--bubble-admin-text: #664d03;
	--system-bg: transparent;
	--system-text: #8a8d91;
	--shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
	--shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.12);
	--radius: 12px;
	--radius-sm: 8px;
	--radius-pill: 20px;
	--nav-height: 56px;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
	--bg: #0b0c0f;
	--bg-elevated: #18191a;
	--bg-input: #3a3b3c;
	--bg-hover: #3a3b3c;
	--text: #e4e6eb;
	--text-secondary: #b0b3b8;
	--text-muted: #8a8d91;
	--border: #3e4042;
	--accent: #4599ff;
	--accent-hover: #6aadff;
	--accent-soft: #1a2f4a;
	--bubble-me: #0866ff;
	--bubble-me-text: #ffffff;
	--bubble-other: #3a3b3c;
	--bubble-other-text: #e4e6eb;
	--bubble-admin: #3d3200;
	--bubble-admin-text: #ffecb3;
	--system-bg: transparent;
	--system-text: #8a8d91;
	--shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
	--shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ============================================================
 *   Reset & Base
 *   ============================================================ */
*,
*::before,
*::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

html,
body,
#root {
height: 100%;
width: 100%;
}

body {
	font-family: var(--font);
	background: var(--bg);
	color: var(--text);
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;
	overflow: hidden;
}

button {
	font-family: inherit;
	cursor: pointer;
	border: none;
	background: none;
	color: inherit;
}

input {
	font-family: inherit;
	color: inherit;
}

/* ============================================================
 *   Setup Screens (Profile + Room Selector)
 *   ============================================================ */
.setup-screen {
	min-height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: var(--bg);
}

.setup-card {
	background: var(--bg-elevated);
	border-radius: 20px;
	padding: 36px 32px;
	width: 100%;
	max-width: 420px;
	box-shadow: var(--shadow-lg);
	text-align: center;
}

.setup-card h1 {
	font-size: 1.75rem;
	font-weight: 700;
	margin-bottom: 6px;
}

.setup-subtitle {
	color: var(--text-secondary);
	margin-bottom: 28px;
	font-size: 0.95rem;
}

.avatar-preview {
	font-size: 4rem;
	line-height: 1;
	margin-bottom: 20px;
	filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
}

.avatar-grid {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 8px;
	margin-bottom: 28px;
	max-height: 180px;
	overflow-y: auto;
	padding: 4px;
}

.avatar-btn {
	font-size: 1.6rem;
	width: 44px;
	height: 44px;
	border-radius: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s, transform 0.1s;
}

.avatar-btn:hover {
	background: var(--bg-hover);
	transform: scale(1.08);
}

.avatar-btn.selected {
	background: var(--accent-soft);
	outline: 2px solid var(--accent);
}

.setup-form {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.name-input {
	padding: 12px 16px;
	border-radius: var(--radius-pill);
	border: 1.5px solid var(--border);
	background: var(--bg-input);
	font-size: 1rem;
	outline: none;
	transition: border-color 0.15s;
}

.name-input:focus {
	border-color: var(--accent);
}

.primary-btn {
	padding: 12px 24px;
	border-radius: var(--radius-pill);
	background: var(--accent);
	color: #fff;
	font-weight: 600;
	font-size: 1rem;
	transition: background 0.15s, opacity 0.15s;
}

.primary-btn:hover:not(:disabled) {
	background: var(--accent-hover);
}

.primary-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

/* Profile chip on room selector */
.profile-chip {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	background: var(--bg-input);
	padding: 6px 12px 6px 6px;
	border-radius: var(--radius-pill);
	margin-bottom: 24px;
}

.chip-avatar {
	font-size: 1.4rem;
}

.chip-name {
	font-weight: 600;
	font-size: 0.9rem;
}

.text-btn {
	color: var(--accent);
	font-size: 0.8rem;
	font-weight: 600;
	padding: 2px 6px;
}

.text-btn:hover {
	text-decoration: underline;
}

/* Room options */
.room-options {
	display: flex;
	flex-direction: column;
	gap: 12px;
	text-align: left;
}

.room-option {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 16px;
	border-radius: var(--radius);
	background: var(--bg-input);
	border: 1.5px solid transparent;
	transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.room-option:hover {
	border-color: var(--accent);
	background: var(--accent-soft);
	transform: translateY(-1px);
}

.room-option.admin:hover {
	border-color: #f0ad4e;
	background: #fff8e6;
}

[data-theme="dark"] .room-option.admin:hover {
	background: #3d3200;
}

.room-icon {
	font-size: 1.8rem;
	flex-shrink: 0;
}

.room-option strong {
	display: block;
	font-size: 1rem;
	margin-bottom: 2px;
}

.room-option span:last-child {
	font-size: 0.82rem;
	color: var(--text-secondary);
}

/* ============================================================
 *   Chat App Layout
 *   ============================================================ */
.chat-app {
	display: flex;
	flex-direction: column;
	height: 100%;
	background: var(--bg);
}

/* Top Nav */
.top-nav {
	height: var(--nav-height);
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	background: var(--bg-elevated);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow);
	z-index: 20;
}

.nav-left {
	display: flex;
	align-items: center;
	gap: 10px;
}

.nav-logo {
	font-size: 1.4rem;
}

.nav-room {
	font-weight: 650;
	font-size: 1rem;
}

.nav-right {
	display: flex;
	align-items: center;
	gap: 14px;
}

.online-badge {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.8rem;
	color: var(--text-secondary);
	font-weight: 500;
}

.online-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #31a24c;
	box-shadow: 0 0 0 2px rgba(49, 162, 76, 0.25);
}

/* Dropdown menu */
.menu-wrapper {
	position: relative;
}

.menu-trigger {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 4px 8px 4px 4px;
	border-radius: var(--radius-pill);
	transition: background 0.15s;
}

.menu-trigger:hover {
	background: var(--bg-hover);
}

.menu-avatar {
	font-size: 1.3rem;
}

.menu-name {
	font-weight: 600;
	font-size: 0.88rem;
	max-width: 100px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.chevron {
	font-size: 0.7rem;
	color: var(--text-muted);
}

.dropdown-menu {
	position: absolute;
	top: calc(100% + 6px);
	right: 0;
	min-width: 210px;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow-lg);
	padding: 6px;
	z-index: 50;
	animation: fadeIn 0.12s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(-4px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.dropdown-item {
	display: block;
	width: 100%;
	text-align: left;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	font-size: 0.9rem;
	transition: background 0.12s;
}

.dropdown-item:hover {
	background: var(--bg-hover);
}

/* Chat body: messages + participants */
.chat-body {
	flex: 1;
	display: flex;
	min-height: 0;
}

.chat-main {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

/* Message list */
.message-list {
	flex: 1;
	overflow-y: auto;
	padding: 20px 16px 12px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}

/* Individual messages */
.msg {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	max-width: 75%;
	animation: msgIn 0.18s ease;
}

@keyframes msgIn {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.msg.me {
	align-self: flex-end;
	flex-direction: row;
}

.msg.other {
	align-self: flex-start;
}

.msg.system {
	align-self: center;
	max-width: 90%;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	margin: 4px 0;
}

.system-text {
	font-size: 0.78rem;
	color: var(--system-text);
	background: var(--bg-hover);
	padding: 4px 12px;
	border-radius: var(--radius-pill);
}

.msg-avatar {
	font-size: 1.5rem;
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: var(--bg-input);
}

.msg-body {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

.msg.me .msg-body {
	align-items: flex-end;
}

.msg-meta {
	display: flex;
	align-items: baseline;
	gap: 8px;
	padding: 0 4px;
}

.msg-author {
	font-size: 0.78rem;
	font-weight: 600;
	color: var(--text-secondary);
}

.msg-time {
	font-size: 0.7rem;
	color: var(--text-muted);
}

.msg-bubble {
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 0.95rem;
	line-height: 1.4;
	word-break: break-word;
	white-space: pre-wrap;
}

.msg.me .msg-bubble {
	background: var(--bubble-me);
	color: var(--bubble-me-text);
	border-bottom-right-radius: 4px;
}

.msg.other .msg-bubble {
	background: var(--bubble-other);
	color: var(--bubble-other-text);
	border-bottom-left-radius: 4px;
}

.msg.admin .msg-bubble {
	background: var(--bubble-admin);
	color: var(--bubble-admin-text);
}

/* Composer */
.composer {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	background: var(--bg-elevated);
	border-top: 1px solid var(--border);
}

.composer input {
	flex: 1;
	padding: 12px 18px;
	border-radius: var(--radius-pill);
	border: 1.5px solid var(--border);
	background: var(--bg-input);
	font-size: 0.95rem;
	outline: none;
	transition: border-color 0.15s;
}

.composer input:focus {
	border-color: var(--accent);
}

.composer button {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--accent);
	color: #fff;
	font-size: 1.1rem;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.composer button:hover:not(:disabled) {
	background: var(--accent-hover);
	transform: scale(1.05);
}

.composer button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* Participants sidebar */
.participants {
	width: 220px;
	flex-shrink: 0;
	background: var(--bg-elevated);
	border-left: 1px solid var(--border);
	padding: 16px 12px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
}

.participants h3 {
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	margin-bottom: 12px;
	display: flex;
	align-items: center;
	gap: 6px;
}

.participants .count {
	background: var(--bg-hover);
	padding: 1px 7px;
	border-radius: 10px;
	font-size: 0.75rem;
	color: var(--text-secondary);
}

.empty-hint {
	font-size: 0.82rem;
	color: var(--text-muted);
}

.participant-list {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.participant {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 8px;
	border-radius: var(--radius-sm);
	transition: background 0.12s;
}

.participant:hover {
	background: var(--bg-hover);
}

.p-avatar {
	font-size: 1.35rem;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: var(--bg-input);
	flex-shrink: 0;
}

.p-name {
	font-size: 0.88rem;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* ============================================================
 *   Responsive
 *   ============================================================ */
@media (max-width: 720px) {
	.participants {
		display: none;
	}

	.msg {
		max-width: 88%;
	}

	.menu-name {
		display: none;
	}

	.setup-card {
		padding: 28px 20px;
	}

	.avatar-grid {
		grid-template-columns: repeat(5, 1fr);
	}
}

@media (max-width: 400px) {
	.online-badge {
		display: none;
	}
}

/* ============================================================
 *   Admin Dashboard
 *   ============================================================ */
.admin-link {
	margin-top: 20px;
	font-size: 0.85rem;
	opacity: 0.7;
}

.admin-link:hover {
	opacity: 1;
}

.admin-error {
	color: #e74c3c;
	font-size: 0.9rem;
	margin: 0;
}

.admin-app {
	display: flex;
	flex-direction: column;
	height: 100%;
	background: var(--bg);
}

.admin-header {
	height: var(--nav-height);
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	background: var(--bg-elevated);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow);
}

.admin-header-left {
	display: flex;
	align-items: center;
	gap: 10px;
}

.admin-header-right {
	display: flex;
	align-items: center;
	gap: 8px;
}

.admin-btn {
	padding: 7px 14px;
	border-radius: var(--radius-sm);
	background: var(--accent);
	color: #fff;
	font-size: 0.85rem;
	font-weight: 600;
	transition: background 0.15s, opacity 0.15s;
}

.admin-btn:hover {
	background: var(--accent-hover);
}

.admin-btn.ghost {
	background: transparent;
	color: var(--text-secondary);
	border: 1px solid var(--border);
}

.admin-btn.ghost:hover {
	background: var(--bg-hover);
	color: var(--text);
}

.admin-btn.danger {
	background: #e74c3c;
}

.admin-btn.danger:hover {
	background: #c0392b;
}

.admin-banner {
	padding: 10px 16px;
	font-size: 0.9rem;
	text-align: center;
}

.admin-banner.error {
	background: #fdecea;
	color: #c0392b;
}

[data-theme="dark"] .admin-banner.error {
	background: #3d1f1f;
	color: #ff8a80;
}

.admin-body {
	flex: 1;
	display: flex;
	min-height: 0;
}

.admin-sidebar {
	width: 300px;
	flex-shrink: 0;
	background: var(--bg-elevated);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.admin-sidebar-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px;
	border-bottom: 1px solid var(--border);
}

.admin-sidebar-head h2 {
	font-size: 0.95rem;
	font-weight: 650;
}

.admin-count {
	background: var(--bg-hover);
	padding: 2px 8px;
	border-radius: 10px;
	font-size: 0.8rem;
	color: var(--text-secondary);
}

.admin-room-list {
	list-style: none;
	overflow-y: auto;
	flex: 1;
	padding: 8px;
}

.admin-room-item {
	width: 100%;
	text-align: left;
	padding: 12px;
	border-radius: var(--radius-sm);
	transition: background 0.12s;
	margin-bottom: 4px;
}

.admin-room-item:hover {
	background: var(--bg-hover);
}

.admin-room-item.active {
	background: var(--accent-soft);
	outline: 1px solid var(--accent);
}

.admin-room-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 4px;
}

.admin-room-label {
	font-weight: 600;
	font-size: 0.9rem;
}

.admin-live {
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: 0.78rem;
	color: var(--text-secondary);
	font-weight: 500;
}

.admin-room-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	font-size: 0.75rem;
	color: var(--text-muted);
}

.admin-kind {
	text-transform: uppercase;
	font-weight: 600;
	letter-spacing: 0.03em;
}

.admin-kind.public {
	color: #31a24c;
}

.admin-kind.admin {
	color: #f0ad4e;
}

.admin-kind.private {
	color: var(--accent);
}

.admin-main {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	overflow: hidden;
}

.admin-empty {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text-muted);
}

.admin-detail-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	padding: 16px 20px;
	border-bottom: 1px solid var(--border);
	background: var(--bg-elevated);
}

.admin-detail-head h2 {
	font-size: 1.15rem;
	margin-bottom: 4px;
}

.admin-detail-sub {
	font-size: 0.82rem;
	color: var(--text-muted);
}

.admin-detail-sub code {
	background: var(--bg-input);
	padding: 1px 6px;
	border-radius: 4px;
	font-size: 0.78rem;
}

.admin-participants {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 12px 20px;
	border-bottom: 1px solid var(--border);
	background: var(--bg-elevated);
}

.admin-participant-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px 4px 6px;
	background: var(--bg-input);
	border-radius: var(--radius-pill);
	font-size: 0.85rem;
	font-weight: 500;
}

.admin-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.admin-msg {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	background: var(--bg-elevated);
	border: 1px solid var(--border);
}

.admin-msg.system {
	opacity: 0.7;
}

.admin-msg-avatar {
	font-size: 1.4rem;
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: var(--bg-input);
}

.admin-msg-body {
	flex: 1;
	min-width: 0;
}

.admin-msg-meta {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 3px;
	font-size: 0.78rem;
	color: var(--text-muted);
}

.admin-msg-meta strong {
	color: var(--text);
	font-size: 0.85rem;
}

.admin-msg-role {
	text-transform: uppercase;
	font-size: 0.7rem;
	letter-spacing: 0.04em;
}

.admin-msg-content {
	font-size: 0.92rem;
	word-break: break-word;
	white-space: pre-wrap;
}

.admin-msg-delete {
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	border-radius: 6px;
	color: var(--text-muted);
	font-size: 0.85rem;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.12s, color 0.12s;
}

.admin-msg-delete:hover {
	background: #fdecea;
	color: #c0392b;
}

[data-theme="dark"] .admin-msg-delete:hover {
	background: #3d1f1f;
	color: #ff8a80;
}

@media (max-width: 720px) {
	.admin-body {
		flex-direction: column;
	}

	.admin-sidebar {
		width: 100%;
		max-height: 40%;
		border-right: none;
		border-bottom: 1px solid var(--border);
	}
}
