:root {
	--bg: #1b1c20;
	--panel: #24262c;
	--panel-2: #2c2f36;
	--panel-3: #33373f;
	--border: #383b44;
	--text: #e8e9ec;
	--muted: #969ca8;
	--accent: #4c8bf5;
	--accent-soft: rgba(76, 139, 245, 0.16);
	--danger: #e5484d;
	--radius: 8px;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Top loading bar shown during any htmx request. */
#progress {
	position: fixed;
	top: 0; left: 0;
	height: 3px;
	width: 100%;
	background: linear-gradient(90deg, transparent, var(--accent), transparent);
	background-size: 40% 100%;
	background-repeat: no-repeat;
	opacity: 0;
	transition: opacity .2s ease;
	z-index: 100;
	animation: slide 1s linear infinite;
}
#progress.htmx-request { opacity: 1; }
@keyframes slide {
	0%   { background-position: -40% 0; }
	100% { background-position: 140% 0; }
}

#app {
	display: flex;
	height: 100vh;
	overflow: hidden;
}

#left   { width: 288px; min-width: 240px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
#middle { width: 400px; min-width: 280px; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
#right  { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Brand / header */
.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--border);
}
.brand .logo {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px; height: 28px;
	border-radius: 7px;
	background: var(--accent);
	color: #fff;
	font-size: 15px;
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.brand-user .username {
	max-width: 110px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--muted);
	font-size: 13px;
}
.brand-user .logout {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px; height: 26px;
	border-radius: 6px;
	color: var(--muted);
	text-decoration: none;
	font-size: 15px;
}
.brand-user .logout:hover { background: var(--panel-3); color: #fff; }

.pane-header { padding: 12px; }
.pane-title {
	padding: 14px 16px;
	font-weight: 600;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: .06em;
	font-size: 12px;
	border-bottom: 1px solid var(--border);
}

.scroll { overflow: auto; flex: 1; }
.list-wrap { padding: 6px; }

/* Custom scrollbars */
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
.scroll::-webkit-scrollbar-thumb:hover { background: #454a54; background-clip: content-box; }

input[type=search], textarea {
	width: 100%;
	padding: 9px 11px;
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	color: var(--text);
	font: inherit;
}
input[type=search]::placeholder, textarea::placeholder { color: var(--muted); }
input[type=search]:focus, textarea:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}

.list { list-style: none; margin: 0; padding: 0; }

.item {
	position: relative;
	padding: 10px 12px;
	border-radius: var(--radius);
	cursor: pointer;
	border: 1px solid transparent;
	transition: background .12s ease;
}
.item + .item { margin-top: 2px; }
.item:hover { background: var(--panel-2); }
.item.htmx-request { opacity: .55; }

/* Selected state — clear accent highlight + left bar */
.item.active {
	background: var(--accent-soft);
	border-color: rgba(76, 139, 245, 0.35);
}
.item.active::before {
	content: "";
	position: absolute;
	left: 0; top: 8px; bottom: 8px;
	width: 3px;
	border-radius: 3px;
	background: var(--accent);
}

.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.account .email { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account.active .email { color: #fff; font-weight: 600; }

.acct-del {
	flex: 0 0 auto;
	width: 22px; height: 22px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	color: var(--muted);
	border-radius: 6px;
	font-size: 17px;
	line-height: 1;
	opacity: 0;
	transition: opacity .12s ease, background .12s ease, color .12s ease;
}
.account:hover .acct-del,
.account.active .acct-del,
.acct-del:focus-visible { opacity: 1; }
.acct-del:hover { background: var(--danger); color: #fff; filter: none; }

.message .subject { font-weight: 600; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message.active .subject { color: #fff; }
.message .meta, .mail-head .meta { color: var(--muted); font-size: 12px; word-break: break-all; }

.hint { color: var(--muted); padding: 18px; }
.notice { color: #f5c04c; padding: 8px 12px; font-size: 12px; }
.error { color: var(--danger); padding: 18px; }

/* Buttons */
button {
	padding: 8px 13px;
	background: var(--accent);
	color: #fff;
	border: none;
	border-radius: var(--radius);
	cursor: pointer;
	font: inherit;
	font-weight: 500;
	transition: filter .12s ease, background .12s ease;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--panel-3); }
button.danger { background: var(--danger); }
button.block { width: 100%; }

.left-footer { padding: 12px; border-top: 1px solid var(--border); }

/* Message view */
.mail { display: flex; flex-direction: column; height: 100%; }
.mail-head { padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--panel); }
.mail-head h2 { margin: 10px 0 8px; font-size: 17px; line-height: 1.3; }
.mail-head button.danger { float: right; }

.mailframe { flex: 1; width: 100%; border: 0; background: #fff; }
.mailtext {
	flex: 1;
	margin: 0;
	padding: 18px;
	white-space: pre-wrap;
	word-break: break-word;
	overflow: auto;
	font-family: ui-monospace, Consolas, monospace;
	font-size: 13px;
}

/* Modal dialog */
dialog.modal {
	border: none;
	background: transparent;
	padding: 0;
	max-width: 90vw;
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
.modal-card {
	width: 520px;
	max-width: 90vw;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 22px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-help { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.modal-help code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.modal-card textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Login page */
.login-body {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	padding: 20px;
}
.login-card {
	width: 360px;
	max-width: 100%;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 28px;
	box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.brand-center {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 6px;
}
.brand-center .logo { width: 34px; height: 34px; font-size: 18px; }
.brand-center h1 { margin: 0; font-size: 20px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 4px 0 20px; }
.login-error { padding: 10px 12px; background: rgba(229, 72, 77, 0.12); border-radius: 8px; margin-bottom: 16px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.field input {
	width: 100%;
	padding: 10px 12px;
	background: var(--panel-2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	color: var(--text);
	font: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button.block { margin-top: 6px; }
