:root {
	--bg: #0b0d10;
	--panel: #14181d;
	--panel-2: #1a2028;
	--border: #262d36;
	--text: #e8ecf1;
	--muted: #8a93a0;
	--accent: #4f9cf9;
	--accent-2: #2f6fd0;
	--danger: #e5534b;
	--ok: #3fb950;
}

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

body {
	background: var(--bg);
	color: var(--text);
	font-family:
		"Segoe UI",
		system-ui,
		-apple-system,
		sans-serif;
	min-height: 100vh;
}

.hidden {
	display: none !important;
}
.muted {
	color: var(--muted);
}
.center {
	text-align: center;
	margin-top: 3rem;
}
.clickable {
	cursor: pointer;
}

.error {
	color: var(--danger);
	margin: 0.75rem 0;
	font-size: 0.9rem;
}

.brand {
	font-size: 1.35rem;
	font-weight: 700;
	letter-spacing: -0.02em;
}
.brand span {
	color: var(--accent);
}

button {
	background: var(--accent-2);
	border: none;
	color: #fff;
	padding: 0.55rem 1.1rem;
	border-radius: 8px;
	font-size: 0.95rem;
	cursor: pointer;
	transition: background 0.15s;
}
button:hover {
	background: var(--accent);
}
button.ghost {
	background: transparent;
	border: 1px solid var(--border);
	color: var(--muted);
}
button.ghost:hover {
	color: var(--text);
	border-color: var(--muted);
	background: transparent;
}

input {
	background: var(--panel-2);
	border: 1px solid var(--border);
	color: var(--text);
	padding: 0.55rem 0.8rem;
	border-radius: 8px;
	font-size: 0.95rem;
	outline: none;
}
input:focus {
	border-color: var(--accent);
}

/* ---- login ---- */
#view-login {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
}
.login-box {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 2.5rem;
	width: min(400px, 90vw);
	text-align: center;
}
.login-box .muted {
	margin: 0.5rem 0 1.5rem;
}
#login-form {
	display: flex;
	gap: 0.5rem;
}
#login-form input {
	flex: 1;
	text-align: center;
	letter-spacing: 0.15em;
}

/* ---- app shell ---- */
.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.9rem 1.5rem;
	border-bottom: 1px solid var(--border);
	background: var(--panel);
	position: sticky;
	top: 0;
	z-index: 5;
}
.topbar-right {
	display: flex;
	align-items: center;
	gap: 0.6rem;
}

.online-users {
	font-size: 0.78rem;
	line-height: 1;
	color: var(--text);
	background: color-mix(in srgb, var(--panel-2) 75%, transparent);
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 0.33rem 0.6rem;
	letter-spacing: 0.01em;
	min-width: 0;
}

.ws-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--danger);
	display: inline-block;
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 28%, transparent);
	transition:
		background 0.2s,
		box-shadow 0.2s;
}
.ws-dot.connected {
	background: var(--ok);
	box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 30%, transparent);
}

main {
	max-width: 900px;
	margin: 0 auto;
	padding: 1.5rem;
}

.section-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.25rem;
	flex-wrap: wrap;
}
.section-head h2 {
	font-size: 1.15rem;
	font-weight: 600;
}

#create-form {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}
.addr-input {
	display: flex;
	align-items: center;
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: 8px;
	overflow: hidden;
}
.addr-input:focus-within {
	border-color: var(--accent);
}
.addr-input input {
	border: none;
	background: transparent;
	border-radius: 0;
	min-width: 10rem;
}
.addr-domain {
	color: var(--muted);
	padding-right: 0.7rem;
	font-size: 0.95rem;
	user-select: none;
}

/* ---- dashboard grid ---- */
.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 0.9rem;
}
.account-card {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1rem 1.1rem;
	cursor: pointer;
	transition:
		border-color 0.15s,
		transform 0.1s;
	position: relative;
}
.account-card:hover {
	border-color: var(--accent);
	transform: translateY(-1px);
}
.account-card .addr {
	font-weight: 600;
	word-break: break-all;
}
.account-card .meta {
	color: var(--muted);
	font-size: 0.83rem;
	margin-top: 0.45rem;
}
.account-card.can-delete .meta {
	padding-right: 4.8rem;
}
.delete-mailbox-btn {
	position: absolute;
	right: 0.7rem;
	bottom: 0.65rem;
	padding: 0.28rem 0.55rem;
	font-size: 0.75rem;
	line-height: 1;
}
.badge {
	position: absolute;
	top: 0.85rem;
	right: 0.9rem;
	background: var(--accent-2);
	color: #fff;
	font-size: 0.75rem;
	font-weight: 700;
	border-radius: 999px;
	padding: 0.15rem 0.55rem;
}

/* ---- inbox list ---- */
.email-list {
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
}
.email-row {
	display: flex;
	align-items: baseline;
	gap: 0.9rem;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.8rem 1rem;
	cursor: pointer;
	transition: border-color 0.15s;
}
.email-row:hover {
	border-color: var(--accent);
}
.email-row .sender {
	flex: 0 0 220px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--muted);
}
.email-row .subject {
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.email-row .date {
	color: var(--muted);
	font-size: 0.82rem;
	white-space: nowrap;
}
.email-row.unread {
	border-left: 3px solid var(--accent);
}
.email-row.unread .sender,
.email-row.unread .subject {
	color: var(--text);
	font-weight: 600;
}

/* ---- reader ---- */
.email-head {
	margin-bottom: 1rem;
}
.email-head h2 {
	margin-bottom: 0.3rem;
	word-break: break-word;
}
#email-frame {
	width: 100%;
	height: calc(100vh - 260px);
	min-height: 320px;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: #fff;
}

#email-fallback {
	width: 100%;
	height: calc(100vh - 260px);
	min-height: 320px;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: #fff;
	color: #111;
	padding: 16px;
	overflow: auto;
	word-wrap: break-word;
}

#email-fallback img {
	max-width: 100%;
}

/* ---- toast ---- */
.toast {
	position: fixed;
	bottom: 1.4rem;
	right: 1.4rem;
	background: var(--panel-2);
	border: 1px solid var(--accent);
	color: var(--text);
	padding: 0.75rem 1.1rem;
	border-radius: 10px;
	font-size: 0.9rem;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
	z-index: 50;
}

.loading-overlay {
	position: fixed;
	inset: 0;
	background: rgba(6, 8, 11, 0.66);
	backdrop-filter: blur(2px);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
}

.loading-card {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1rem 1.15rem;
	min-width: 220px;
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.loading-spinner {
	width: 18px;
	height: 18px;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

#loading-text {
	color: var(--text);
	font-size: 0.92rem;
}

@keyframes spin {
	from {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(360deg);
	}
}

@media (max-width: 640px) {
	.email-row .sender {
		flex-basis: 110px;
	}
	#create-form {
		width: 100%;
	}
	.addr-input {
		flex: 1;
	}
	.addr-input input {
		min-width: 0;
		width: 100%;
	}
}
