/* ============================================
 *   Durable Chat – Modern UI
 *   Dark-first, glassmorphism, Linear/Discord vibes
 *   ============================================ */

:root {
	/* Dark theme (default) */
	--bg-primary: #0c0c0e;
	--bg-secondary: #141417;
	--bg-tertiary: #1c1c21;
	--bg-elevated: #222228;
	--bg-hover: #2a2a32;
	--bg-input: #18181c;

	--text-primary: #f4f4f5;
	--text-secondary: #a1a1aa;
	--text-muted: #71717a;
	--text-inverse: #09090b;

	--border: rgba(255, 255, 255, 0.06);
	--border-strong: rgba(255, 255, 255, 0.12);

	--accent: #6366f1;
	--accent-hover: #818cf8;
	--accent-muted: rgba(99, 102, 241, 0.15);
	--accent-glow: rgba(99, 102, 241, 0.25);

	--success: #22c55e;
	--danger: #ef4444;
	--warning: #f59e0b;

	--bubble-self: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
	--bubble-other: #1c1c21;

	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
	--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
	--shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
	--shadow-glow: 0 0 24px var(--accent-glow);

	--radius-sm: 8px;
	--radius-md: 12px;
	--radius-lg: 16px;
	--radius-xl: 20px;
	--radius-full: 9999px;

	--nav-height: 56px;
	--footer-height: 40px;
	--sidebar-width: 280px;
	--input-height: 56px;

	--font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
	Roboto, sans-serif;
	--mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;

	--transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light theme */
[data-theme="light"] {
	--bg-primary: #fafafa;
	--bg-secondary: #ffffff;
	--bg-tertiary: #f4f4f5;
	--bg-elevated: #ffffff;
	--bg-hover: #f0f0f2;
	--bg-input: #f4f4f5;

	--text-primary: #09090b;
	--text-secondary: #52525b;
	--text-muted: #a1a1aa;
	--text-inverse: #fafafa;

	--border: rgba(0, 0, 0, 0.06);
	--border-strong: rgba(0, 0, 0, 0.12);

	--accent: #4f46e5;
	--accent-hover: #4338ca;
	--accent-muted: rgba(79, 70, 229, 0.1);
	--accent-glow: rgba(79, 70, 229, 0.2);

	--bubble-self: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
	--bubble-other: #f0f0f2;

	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
	--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
	--shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
}

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

html,
body {
	height: 100%;
	font-family: var(--font);
	background: var(--bg-primary);
	color: var(--text-primary);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	overflow: hidden;
}

#root {
height: 100%;
display: flex;
flex-direction: column;
}

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

.app-body {
	display: flex;
	flex: 1;
	overflow: hidden;
	position: relative;
}

/* ========== Navbar ========== */
.navbar {
	height: var(--nav-height);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 16px;
	background: rgba(20, 20, 23, 0.72);
	backdrop-filter: blur(16px) saturate(180%);
	-webkit-backdrop-filter: blur(16px) saturate(180%);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 50;
	flex-shrink: 0;
}

[data-theme="light"] .navbar {
	background: rgba(255, 255, 255, 0.8);
}

.navbar-left {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.logo {
	width: 32px;
	height: 32px;
	border-radius: var(--radius-sm);
	background: linear-gradient(135deg, #6366f1, #a855f7);
	display: grid;
	place-items: center;
	font-size: 16px;
	flex-shrink: 0;
	box-shadow: var(--shadow-glow);
}

.logo-text {
	font-weight: 650;
	font-size: 15px;
	letter-spacing: -0.02em;
	white-space: nowrap;
}

.navbar-center {
	display: flex;
	align-items: center;
	gap: 8px;
}

.room-badge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px;
	background: var(--bg-tertiary);
	border: 1px solid var(--border);
	border-radius: var(--radius-full);
	font-size: 12px;
	font-family: var(--mono);
	color: var(--text-secondary);
	cursor: pointer;
	transition: all var(--transition);
	max-width: 180px;
}

.room-badge:hover {
	background: var(--bg-hover);
	border-color: var(--border-strong);
	color: var(--text-primary);
}

.room-badge svg {
	width: 12px;
	height: 12px;
	opacity: 0.6;
	flex-shrink: 0;
}

.room-id {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

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

/* Profile dropdown */
.profile-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 4px 8px 4px 4px;
	background: transparent;
	border: 1px solid transparent;
	border-radius: var(--radius-full);
	cursor: pointer;
	transition: all var(--transition);
	color: var(--text-primary);
}

.profile-btn:hover {
	background: var(--bg-hover);
	border-color: var(--border);
}

.avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--bg-tertiary);
	flex-shrink: 0;
}

.avatar-lg {
	width: 40px;
	height: 40px;
}

.avatar-xl {
	width: 64px;
	height: 64px;
}

.online-dot {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 10px;
	height: 10px;
	background: var(--success);
	border: 2px solid var(--bg-secondary);
	border-radius: 50%;
}

.avatar-wrap {
	position: relative;
	display: inline-flex;
}

.profile-name {
	font-size: 13px;
	font-weight: 500;
	max-width: 100px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

@media (max-width: 640px) {
	.profile-name {
		display: none;
	}
	.logo-text {
		display: none;
	}
}

.dropdown {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	min-width: 220px;
	background: var(--bg-elevated);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-lg);
	padding: 6px;
	z-index: 100;
	animation: dropdownIn 150ms ease;
}

@keyframes dropdownIn {
	from {
		opacity: 0;
		transform: translateY(-6px) scale(0.98);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.dropdown-header {
	padding: 10px 12px;
	border-bottom: 1px solid var(--border);
	margin-bottom: 4px;
}

.dropdown-header .name {
	font-weight: 600;
	font-size: 14px;
}

.dropdown-header .sub {
	font-size: 12px;
	color: var(--text-muted);
	margin-top: 2px;
}

.dropdown-item {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 9px 12px;
	background: transparent;
	border: none;
	border-radius: var(--radius-sm);
	color: var(--text-primary);
	font-size: 13px;
	font-family: inherit;
	cursor: pointer;
	transition: background var(--transition);
	text-align: left;
}

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

.dropdown-item svg {
	width: 16px;
	height: 16px;
	opacity: 0.7;
	flex-shrink: 0;
}

.dropdown-item.danger {
	color: var(--danger);
}

.dropdown-divider {
	height: 1px;
	background: var(--border);
	margin: 4px 0;
}

/* ========== Sidebar / Online Panel ========== */
.sidebar {
	width: var(--sidebar-width);
	background: var(--bg-secondary);
	border-left: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	transition: transform var(--transition), width var(--transition);
}

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

.sidebar-title {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
	display: flex;
	align-items: center;
	gap: 6px;
}

.online-count {
	background: var(--accent-muted);
	color: var(--accent);
	font-size: 11px;
	font-weight: 600;
	padding: 2px 7px;
	border-radius: var(--radius-full);
}

.sidebar-list {
	flex: 1;
	overflow-y: auto;
	padding: 8px;
}

.user-item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: var(--radius-md);
	transition: background var(--transition);
	animation: fadeSlideIn 250ms ease;
}

@keyframes fadeSlideIn {
	from {
		opacity: 0;
		transform: translateX(8px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

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

.user-item .name {
	font-size: 13px;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.user-item .you-badge {
	font-size: 10px;
	color: var(--accent);
	background: var(--accent-muted);
	padding: 1px 6px;
	border-radius: var(--radius-full);
	margin-left: 4px;
}

/* Mobile sidebar as drawer */
.sidebar-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 40;
	backdrop-filter: blur(2px);
}

.sidebar-toggle {
	display: none;
	background: transparent;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 6px;
	cursor: pointer;
	color: var(--text-secondary);
}

.sidebar-toggle:hover {
	background: var(--bg-hover);
	color: var(--text-primary);
}

@media (max-width: 900px) {
	.sidebar {
		position: fixed;
		top: var(--nav-height);
		right: 0;
		bottom: var(--footer-height);
		z-index: 45;
		transform: translateX(100%);
		box-shadow: var(--shadow-lg);
	}
	.sidebar.open {
		transform: translateX(0);
	}
	.sidebar-overlay.open {
		display: block;
	}
	.sidebar-toggle {
		display: grid;
		place-items: center;
	}
}

/* ========== Main Chat Area ========== */
.chat-main {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	background: var(--bg-primary);
}

.messages {
	flex: 1;
	overflow-y: auto;
	padding: 20px 16px 12px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
	width: 6px;
}
.messages::-webkit-scrollbar-track {
	background: transparent;
}
.messages::-webkit-scrollbar-thumb {
	background: var(--border-strong);
	border-radius: 3px;
}

.empty-state {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	color: var(--text-muted);
	text-align: center;
	padding: 40px 20px;
}

.empty-state .icon {
	width: 64px;
	height: 64px;
	border-radius: var(--radius-lg);
	background: var(--bg-tertiary);
	display: grid;
	place-items: center;
	font-size: 28px;
	margin-bottom: 8px;
}

.empty-state h3 {
	font-size: 16px;
	font-weight: 600;
	color: var(--text-secondary);
}

.empty-state p {
	font-size: 13px;
	max-width: 280px;
	line-height: 1.5;
}

/* Message bubbles */
.message-row {
	display: flex;
	gap: 10px;
	padding: 4px 0;
	animation: msgIn 200ms ease;
	max-width: 100%;
}

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

.message-row.self {
	flex-direction: row-reverse;
}

.message-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	flex-shrink: 0;
	margin-top: 18px;
}

.message-body {
	display: flex;
	flex-direction: column;
	max-width: min(70%, 520px);
	min-width: 0;
}

.message-row.self .message-body {
	align-items: flex-end;
}

.message-meta {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 3px;
	padding: 0 4px;
}

.message-row.self .message-meta {
	flex-direction: row-reverse;
}

.message-author {
	font-size: 12px;
	font-weight: 600;
	color: var(--text-secondary);
}

.message-time {
	font-size: 11px;
	color: var(--text-muted);
	white-space: nowrap;
	opacity: 0.85;
}

.bubble {
	padding: 10px 14px;
	border-radius: var(--radius-lg);
	font-size: 14px;
	line-height: 1.45;
	word-break: break-word;
	position: relative;
}

.message-row:not(.self) .bubble {
	background: var(--bubble-other);
	border: 1px solid var(--border);
	border-top-left-radius: 4px;
	color: var(--text-primary);
}

.message-row.self .bubble {
	background: var(--bubble-self);
	color: white;
	border-top-right-radius: 4px;
	box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* ========== Input Bar ========== */
.input-bar {
	padding: 12px 16px 16px;
	background: var(--bg-secondary);
	border-top: 1px solid var(--border);
	flex-shrink: 0;
}

.input-form {
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--bg-input);
	border: 1px solid var(--border);
	border-radius: var(--radius-xl);
	padding: 6px 6px 6px 16px;
	transition: border-color var(--transition), box-shadow var(--transition);
}

.input-form:focus-within {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-muted);
}

.input-form input {
	flex: 1;
	background: transparent;
	border: none;
	outline: none;
	color: var(--text-primary);
	font-size: 14px;
	font-family: inherit;
	min-width: 0;
}

.input-form input::placeholder {
	color: var(--text-muted);
}

.send-btn {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--accent);
	border: none;
	color: white;
	display: grid;
	place-items: center;
	cursor: pointer;
	transition: all var(--transition);
	flex-shrink: 0;
}

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

.send-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.send-btn svg {
	width: 18px;
	height: 18px;
}

/* ========== Footer ========== */
.footer {
	height: var(--footer-height);
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16px;
	background: var(--bg-secondary);
	border-top: 1px solid var(--border);
	font-size: 11px;
	color: var(--text-muted);
	flex-shrink: 0;
}

.footer a {
	color: var(--text-muted);
	text-decoration: none;
	transition: color var(--transition);
}

.footer a:hover {
	color: var(--text-secondary);
}

.footer-sep {
	opacity: 0.3;
}

/* ========== Join Modal ========== */
.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.65);
	backdrop-filter: blur(8px);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 200;
	padding: 20px;
	animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.modal {
	background: var(--bg-elevated);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-xl);
	width: 100%;
	max-width: 420px;
	padding: 28px;
	box-shadow: var(--shadow-lg);
	animation: modalIn 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
	from {
		opacity: 0;
		transform: scale(0.95) translateY(12px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.modal h2 {
	font-size: 20px;
	font-weight: 650;
	letter-spacing: -0.02em;
	margin-bottom: 6px;
}

.modal .subtitle {
	font-size: 13px;
	color: var(--text-secondary);
	margin-bottom: 24px;
}

.form-group {
	margin-bottom: 20px;
}

.form-group label {
	display: block;
	font-size: 12px;
	font-weight: 600;
	color: var(--text-secondary);
	margin-bottom: 8px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.form-group input {
	width: 100%;
	padding: 11px 14px;
	background: var(--bg-input);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	color: var(--text-primary);
	font-size: 14px;
	font-family: inherit;
	outline: none;
	transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-muted);
}

.avatar-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 10px;
}

.avatar-option {
	aspect-ratio: 1;
	border-radius: var(--radius-md);
	border: 2px solid transparent;
	background: var(--bg-tertiary);
	cursor: pointer;
	overflow: hidden;
	transition: all var(--transition);
	padding: 0;
}

.avatar-option img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.avatar-option:hover {
	border-color: var(--border-strong);
	transform: scale(1.04);
}

.avatar-option.selected {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-muted);
}

.modal-actions {
	display: flex;
	gap: 10px;
	margin-top: 8px;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 11px 18px;
	border-radius: var(--radius-md);
	font-size: 14px;
	font-weight: 550;
	font-family: inherit;
	cursor: pointer;
	border: none;
	transition: all var(--transition);
}

.btn-primary {
	background: var(--accent);
	color: white;
	flex: 1;
}

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

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

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

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

/* Toast / copy feedback */
.toast {
	position: fixed;
	bottom: 80px;
	left: 50%;
	transform: translateX(-50%);
	background: var(--bg-elevated);
	border: 1px solid var(--border-strong);
	color: var(--text-primary);
	padding: 10px 18px;
	border-radius: var(--radius-full);
	font-size: 13px;
	font-weight: 500;
	box-shadow: var(--shadow-md);
	z-index: 300;
	animation: toastIn 200ms ease;
}

@keyframes toastIn {
	from {
		opacity: 0;
		transform: translateX(-50%) translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateX(-50%);
	}
}

/* Connection status */
.connection-status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 11px;
	color: var(--text-muted);
	padding: 0 4px;
}

.status-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--text-muted);
}

.status-dot.connected {
	background: var(--success);
	box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-dot.connecting {
	background: var(--warning);
	animation: pulse 1.2s infinite;
}

@keyframes pulse {
	0%,
	100% {
		opacity: 1;
	}
	50% {
		opacity: 0.4;
	}
}

/* Utility */
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	border: 0;
}
