/* Mail MCP: one stylesheet for the dashboard and the public pages (login, consent,
   password reset). System fonts only: the pages load nothing from other sites. */

:root {
	--bg: #f6f7fb;
	--surface: #ffffff;
	--surface-2: #f8fafc;
	--text: #0f172a;
	--muted: #64748b;
	--line: #e2e8f0;
	--line-strong: #cbd5e1;
	--accent: #4f46e5;
	--accent-hover: #4338ca;
	--accent-soft: #eef2ff;
	--accent-text: #ffffff;
	--danger: #dc2626;
	--danger-soft: #fef2f2;
	--ok: #047857;
	--ok-soft: #ecfdf5;
	--warn: #b45309;
	--warn-soft: #fffbeb;
	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 1px 2px rgb(15 23 42 / .05), 0 1px 3px rgb(15 23 42 / .04);
	--shadow-lg: 0 20px 40px -12px rgb(15 23 42 / .18);
	--sidebar-width: 248px;
	color-scheme: light;
}

/* Dark: when the system is dark and no light theme was chosen, or when dark was chosen
   (the theme button in theme.js sets data-theme on the html element). */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #0b1020;
		--surface: #111827;
		--surface-2: #0f172a;
		--text: #e5e7eb;
		--muted: #94a3b8;
		--line: #1f2937;
		--line-strong: #334155;
		--accent: #818cf8;
		--accent-hover: #a5b4fc;
		--accent-soft: rgb(129 140 248 / .14);
		--accent-text: #0b1020;
		--danger: #f87171;
		--danger-soft: rgb(248 113 113 / .12);
		--ok: #34d399;
		--ok-soft: rgb(52 211 153 / .12);
		--warn: #fbbf24;
		--warn-soft: rgb(251 191 36 / .12);
		--shadow: 0 1px 2px rgb(0 0 0 / .4);
		--shadow-lg: 0 20px 40px -12px rgb(0 0 0 / .6);
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #0b1020;
	--surface: #111827;
	--surface-2: #0f172a;
	--text: #e5e7eb;
	--muted: #94a3b8;
	--line: #1f2937;
	--line-strong: #334155;
	--accent: #818cf8;
	--accent-hover: #a5b4fc;
	--accent-soft: rgb(129 140 248 / .14);
	--accent-text: #0b1020;
	--danger: #f87171;
	--danger-soft: rgb(248 113 113 / .12);
	--ok: #34d399;
	--ok-soft: rgb(52 211 153 / .12);
	--warn: #fbbf24;
	--warn-soft: rgb(251 191 36 / .12);
	--shadow: 0 1px 2px rgb(0 0 0 / .4);
	--shadow-lg: 0 20px 40px -12px rgb(0 0 0 / .6);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; margin: 0 0 1.25rem; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin: 2rem 0 .75rem; }
.card h2 { margin-top: 0; }
p { margin: .45rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.bad-text { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Dashboard shell: sidebar and content ---------- */

.shell {
	display: grid;
	grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
	min-height: 100vh;
}
/* Signed out: no sidebar, the content takes the whole width. */
.shell:has(> .sidebar[hidden]) { grid-template-columns: minmax(0, 1fr); }

.sidebar {
	position: sticky;
	top: 0;
	display: flex;
	flex-direction: column;
	gap: 1rem;
	height: 100vh;
	padding: 1.1rem .85rem;
	background: var(--surface);
	border-right: 1px solid var(--line);
	overflow-y: auto;
}
.sidebar[hidden] { display: none; }

.brand {
	display: flex;
	align-items: center;
	gap: .6rem;
	padding: .2rem .45rem;
	font-size: 1.05rem;
	font-weight: 700;
	letter-spacing: -.01em;
	color: var(--text);
}
.logo {
	display: grid;
	place-items: center;
	flex: none;
	width: 32px;
	height: 32px;
	border-radius: 9px;
	background: linear-gradient(135deg, #6366f1, #8b5cf6);
	color: #fff;
	box-shadow: 0 4px 12px -4px rgb(99 102 241 / .6);
}
.logo svg { width: 18px; height: 18px; }

nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
	display: flex;
	align-items: center;
	gap: .65rem;
	padding: .5rem .65rem;
	border-radius: var(--radius-sm);
	color: var(--muted);
	font-weight: 500;
	text-decoration: none;
	white-space: nowrap;
}
nav a svg { width: 18px; height: 18px; flex: none; }
nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.badge {
	display: inline-grid;
	place-items: center;
	min-width: 1.35rem;
	height: 1.35rem;
	padding: 0 .4rem;
	margin-left: auto;
	border-radius: 999px;
	background: var(--accent);
	color: var(--accent-text);
	font-size: .72rem;
	font-weight: 700;
}

.sidebar-foot {
	margin-top: auto;
	display: flex;
	flex-direction: column;
	gap: .6rem;
	padding: .8rem .45rem 0;
	border-top: 1px solid var(--line);
}
#who { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
#logout { flex: 1; }
.sidebar-actions { display: flex; gap: .5rem; }

/* The theme button: an icon that cycles system, light and dark. */
.theme-toggle {
	flex: none;
	width: 38px;
	padding: 0;
	background: var(--surface);
	color: var(--muted);
	border-color: var(--line-strong);
}
.theme-toggle:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--muted); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-float { position: fixed; top: 1rem; right: 1rem; z-index: 30; }
.theme-switching *, .theme-switching *::before, .theme-switching *::after { transition: none !important; }
/* Inside the dashboard the sidebar has its own. */
.shell:has(> .sidebar:not([hidden])) ~ .theme-float { display: none; }

main { width: 100%; max-width: 1120px; margin: 0 auto; padding: 2rem 2.25rem 4rem; }

/* ---------- Cards, rows, notices ---------- */

.card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 1.25rem;
	margin-bottom: 1rem;
	box-shadow: var(--shadow);
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card > .card { margin-top: 1rem; box-shadow: none; background: var(--surface-2); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
main > .row { margin-bottom: 1rem; }
.spacer { flex: 1; }

.notice {
	padding: .75rem 1rem;
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	background: var(--surface-2);
}
.notice.bad { border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); color: var(--danger); }
.notice.ok { border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft); color: var(--ok); }
.notice ul { margin: .4rem 0; padding-left: 1.2rem; }
main .notice { margin-bottom: 1rem; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
/* A table fills its card edge to edge; the card's corners clip it. */
.card > .table-wrap { margin: -1.25rem; border-radius: var(--radius); }
.card > .table-wrap:not(:last-child) { margin-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
	background: var(--surface-2);
	color: var(--muted);
	font-size: .72rem;
	font-weight: 600;
	letter-spacing: .05em;
	text-transform: uppercase;
	white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td .row { gap: .4rem; }
/* The actions of a row stay on one line; the usage note goes under the tags. */
td:last-child > .row { flex-wrap: nowrap; justify-content: flex-end; }
td .row > .usage { order: 9; flex-basis: 100%; margin-top: 0; }
td .row button, td details.menu > summary { padding: .3rem .65rem; min-height: 32px; font-size: .88rem; }
.card > .table-wrap + .row { margin-top: 1rem; }
.usage { display: block; margin-top: .25rem; }

/* ---------- Forms ---------- */

label { display: block; font-size: .85rem; font-weight: 500; color: var(--muted); margin-bottom: .8rem; }
label.inline {
	display: flex;
	align-items: center;
	gap: .55rem;
	color: var(--text);
	font-size: .95rem;
	font-weight: 400;
}
input, select, textarea {
	display: block;
	width: 100%;
	min-height: 40px;
	margin-top: .3rem;
	padding: .5rem .7rem;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}
label.inline input { display: inline-block; width: 1rem; height: 1rem; min-height: 0; margin: 0; accent-color: var(--accent); }
textarea { min-height: 6rem; resize: vertical; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; align-items: end; }
/* Anything that is not a field (a button, say) sits on the same baseline as the inputs. */
.grid > div { margin-bottom: .8rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 1rem; padding: .9rem 1rem .2rem; }
legend { color: var(--muted); font-size: .8rem; font-weight: 600; padding: 0 .35rem; }

/* ---------- Buttons ---------- */

button, .button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .45rem;
	min-height: 38px;
	padding: .45rem .95rem;
	border: 1px solid var(--accent);
	border-radius: var(--radius-sm);
	background: var(--accent);
	color: var(--accent-text);
	font: inherit;
	font-weight: 600;
	font-size: .92rem;
	cursor: pointer;
	text-decoration: none;
	transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
button:hover:not(:disabled), .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button.quiet { background: var(--surface); color: var(--text); border-color: var(--line-strong); font-weight: 500; }
button.quiet:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
button.danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); font-weight: 500; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
button svg { width: 16px; height: 16px; }
button:focus-visible, a:focus-visible, summary:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* ---------- Code, copy boxes, tags ---------- */

code, pre { font-family: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace; font-size: .86rem; }
pre {
	margin: .6rem 0;
	padding: .8rem 1rem;
	background: var(--surface-2);
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	white-space: pre-wrap;
	word-break: break-word;
	max-height: 18rem;
	overflow: auto;
}
pre.email-body { font-family: inherit; font-size: .95rem; line-height: 1.6; background: var(--surface-2); }
.attachments { margin: 12px 0; }
.attachments input[type=file] { display: none; }
.attachments-title { margin: 0 0 4px; font-weight: 600; font-size: .85rem; color: var(--muted); }
.file-list { list-style: none; padding: 0; margin: 0 0 8px; }
.file-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 4px 0; overflow-wrap: anywhere; }
.file-list li + li { border-top: 1px solid var(--line); }
.file-list button { padding: 2px 10px; font-size: .8rem; min-height: 0; }
.copy { display: flex; gap: .5rem; align-items: center; margin: .6rem 0; }
.copy code {
	flex: 1;
	padding: .55rem .75rem;
	background: var(--surface-2);
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	overflow-x: auto;
	white-space: nowrap;
}

.tag {
	display: inline-flex;
	align-items: center;
	padding: .1rem .55rem;
	border-radius: 999px;
	background: var(--surface-2);
	border: 1px solid var(--line);
	color: var(--muted);
	font-size: .76rem;
	font-weight: 600;
	white-space: nowrap;
	vertical-align: middle;
}
.tag.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.tag.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.tag.bad { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

/* ---------- Toast ---------- */

#toast {
	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	z-index: 50;
	max-width: min(92vw, 28rem);
	padding: .75rem 1rem;
	border-radius: var(--radius-sm);
	background: #0f172a;
	color: #f8fafc;
	box-shadow: var(--shadow-lg);
	font-size: .92rem;
}
#toast.error { background: #b91c1c; }

/* ---------- Dialogs and menus ---------- */

dialog.panel {
	width: min(40rem, calc(100vw - 2rem));
	max-height: calc(100vh - 2rem);
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--text);
	overflow: auto;
}
dialog.panel::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(2px); }
dialog.panel > .card { margin: 0; box-shadow: var(--shadow-lg); }

details.menu { display: inline-block; }
details.menu > summary {
	display: inline-flex;
	align-items: center;
	min-height: 38px;
	padding: .45rem .95rem;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	list-style: none;
	cursor: pointer;
	font-size: .92rem;
	font-weight: 500;
	user-select: none;
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover { background: var(--surface-2); }
details.menu > .menu-items {
	position: fixed;
	z-index: 20;
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 13rem;
	padding: .35rem;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-lg);
}
details.menu > .menu-items button { width: 100%; justify-content: flex-start; border-color: transparent; }

iframe.preview {
	display: block;
	width: 100%;
	min-height: 9rem;
	margin-bottom: .8rem;
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	background: #fff;
}
.card img {
	display: block;
	margin: .6rem 0;
	padding: .5rem;
	max-width: 100%;
	height: auto;
	background: #fff;
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
}

/* ---------- First steps ---------- */

.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: .8rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps .mark {
	flex: none;
	display: grid;
	place-items: center;
	width: 1.7rem;
	height: 1.7rem;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
	color: var(--muted);
	font-size: .82rem;
	font-weight: 600;
}
.steps .title { font-weight: 600; }
.steps a.title { color: var(--accent); }
.steps li.done .mark { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.steps li.done .title { color: var(--muted); font-weight: 400; }

/* ---------- Public pages: login, consent, password reset, start ---------- */

body.public, .shell:has(> .sidebar[hidden]) {
	background:
		radial-gradient(60rem 30rem at 15% -10%, rgb(99 102 241 / .14), transparent 60%),
		radial-gradient(50rem 30rem at 110% 10%, rgb(139 92 246 / .12), transparent 60%),
		var(--bg);
}
body.public main, .shell:has(> .sidebar[hidden]) main { max-width: none; padding: 0; }

.auth {
	display: flex;
	flex-direction: column;
	justify-content: center;
	width: min(26rem, calc(100vw - 2rem));
	min-height: 100vh;
	margin: 0 auto;
	padding: 2.5rem 0;
}
.auth.wide { width: min(36rem, calc(100vw - 2rem)); }
.auth-brand {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: .6rem;
	margin-bottom: 1.5rem;
	color: var(--text);
	font-size: 1.15rem;
	font-weight: 700;
}
.auth-brand:hover { text-decoration: none; }
.auth .card { padding: 1.75rem; box-shadow: var(--shadow-lg); }
.auth h1 { font-size: 1.35rem; margin: 0 0 .35rem; text-align: center; }
.auth .lead { margin: 0 0 1.5rem; color: var(--muted); text-align: center; }
.auth form button[type="submit"] { width: 100%; margin-top: .4rem; }
.auth .notice { margin-bottom: 1rem; }
.auth-foot { margin-top: 1.25rem; text-align: center; font-size: .88rem; color: var(--muted); }
.auth label.inline { align-items: flex-start; margin-bottom: .8rem; }
.auth label.inline input { margin-top: .25rem; }
.code-input { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 1.35rem; letter-spacing: .3em; text-align: center; }

/* Consent: each permission is a selectable row. */
.client { display: flex; align-items: center; justify-content: center; gap: .5rem; margin-bottom: 1.25rem; }
.client .chip {
	padding: .3rem .75rem;
	border-radius: 999px;
	background: var(--accent-soft);
	color: var(--accent);
	font-weight: 600;
}
.scope-option {
	display: flex;
	align-items: flex-start;
	gap: .7rem;
	padding: .75rem .85rem;
	margin-bottom: .5rem;
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	color: var(--text);
	font-size: .92rem;
	font-weight: 400;
	cursor: pointer;
	transition: border-color .15s, background .15s;
}
.scope-option:hover { border-color: var(--line-strong); }
.scope-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.scope-option input { width: 1rem; height: 1rem; min-height: 0; margin: .2rem 0 0; flex: none; accent-color: var(--accent); }
.workspace-option { width: 100%; justify-content: space-between; margin-bottom: .5rem; }

/* Start page for visitors: a short pitch beside the way in. */
.landing {
	display: grid;
	grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
	gap: 3rem;
	align-items: center;
	width: min(68rem, calc(100vw - 2rem));
	min-height: 100vh;
	margin: 0 auto;
	padding: 3rem 0;
}
.landing .pitch h1 { font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1.1; letter-spacing: -.03em; margin: 1rem 0; }
.landing .pitch .lead { font-size: 1.1rem; color: var(--muted); max-width: 32rem; }
.features { list-style: none; margin: 1.75rem 0 0; padding: 0; display: grid; gap: .9rem; }
.features li { display: flex; gap: .75rem; align-items: flex-start; }
.features .icon {
	display: grid;
	place-items: center;
	flex: none;
	width: 2.1rem;
	height: 2.1rem;
	border-radius: 9px;
	background: var(--accent-soft);
	color: var(--accent);
}
.features .icon svg { width: 18px; height: 18px; }
.features strong { display: block; }
.landing .card { box-shadow: var(--shadow-lg); }
.landing .card .button, .landing .card button[type="submit"] { width: 100%; }

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
	.shell { grid-template-columns: minmax(0, 1fr); }
	.sidebar {
		position: sticky;
		z-index: 10;
		height: auto;
		flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
		gap: .5rem .75rem;
		padding: .6rem .9rem;
		border-right: 0;
		border-bottom: 1px solid var(--line);
		overflow: visible;
	}
	.sidebar nav {
		order: 3;
		width: 100%;
		flex-direction: row;
		overflow-x: auto;
		scrollbar-width: none;
	}
	nav a { padding: .4rem .6rem; }
	nav a svg { display: none; }
	.badge { margin-left: .3rem; }
	.sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; border: 0; }
	#who { max-width: 40vw; }
	#logout { flex: none; width: auto; }
	main { padding: 1.25rem 1rem 3rem; }
	.landing { grid-template-columns: minmax(0, 1fr); gap: 2rem; padding: 2rem 0; min-height: 0; }
}

@media (max-width: 640px) {
	h1 { font-size: 1.35rem; }
	/* On a phone the bar keeps only the brand, the tabs and the way out. */
	#who { display: none; }
	.card > .table-wrap { margin: -1rem; }
	.card > .table-wrap:not(:last-child) { margin-bottom: 0; }
	.card { padding: 1rem; }
	.table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
	.table-wrap thead { display: none; }
	.table-wrap tr { padding: .65rem 1rem; border-bottom: 1px solid var(--line); }
	.table-wrap tr:last-child { border-bottom: 0; }
	.table-wrap td { padding: .15rem 0; border: 0; }
	.table-wrap td:empty { display: none; }
	.table-wrap td[data-label]::before {
		content: attr(data-label);
		display: block;
		color: var(--muted);
		font-size: .72rem;
		font-weight: 600;
		letter-spacing: .04em;
		text-transform: uppercase;
	}
	tbody tr:hover td { background: transparent; }
	.card > .row > button, .card > .row > .button { flex: 1 1 auto; }
	.copy { flex-wrap: wrap; }
	.copy code { flex-basis: 100%; }
	pre { max-height: 12rem; }
	.auth .card { padding: 1.25rem; }
}
