:root {
	color-scheme: light dark;
	--bg: #f4f5f7;
	--surface: #ffffff;
	--surface-2: #f0f2f5;
	--surface-3: #e6e9ee;
	--text: #1b1f24;
	--muted: #5c6470;
	--border: #dde1e6;
	--accent: #2458e6;
	--accent-soft: #e8edfb;
	--accent-text: #ffffff;
	--danger: #c0392b;
	--danger-bg: #fdecea;
	--ok: #1f8a4c;
	--ok-bg: #e7f6ec;
	--chip: #eef1f7;
	--chip-text: #2a3f7a;
	--shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
	--shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.18);
	--radius: 10px;
	--sidebar: 240px;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0e1116;
		--surface: #161a20;
		--surface-2: #1d222a;
		--surface-3: #262c36;
		--text: #e6e9ee;
		--muted: #97a1b2;
		--border: #2a313c;
		--accent: #7a9cff;
		--accent-soft: #1d2740;
		--accent-text: #0b1020;
		--danger: #ff7b6b;
		--danger-bg: #3a1d19;
		--ok: #5ed08a;
		--ok-bg: #16311f;
		--chip: #242c3b;
		--chip-text: #bccaff;
		--shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
		--shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
	}
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	padding: 0;
	height: 100%;
}

body {
	font-family:
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji",
		"Segoe UI Emoji";
	font-size: 14.5px;
	line-height: 1.45;
	color: var(--text);
	background: var(--bg);
	-webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
	margin: 0 0 0.4rem;
	line-height: 1.25;
	font-weight: 650;
}
h1 {
	font-size: 1.45rem;
}
h2 {
	font-size: 1.05rem;
}
h3 {
	font-size: 0.78rem;
	color: var(--muted);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	margin: 1.1rem 0 0.5rem;
}
h3:first-child {
	margin-top: 0;
}
p {
	margin: 0 0 0.6rem;
}

.muted {
	color: var(--muted);
}
.small {
	font-size: 0.84rem;
}
.strong {
	font-weight: 600;
}
.ellipsis {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
code,
pre,
.mono {
	font-family: var(--mono);
	font-size: 0.88em;
}
code {
	background: var(--surface-2);
	padding: 0.05rem 0.35rem;
	border-radius: 4px;
}
pre {
	margin: 0;
	padding: 0.7rem 0.8rem;
	border-radius: 8px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	overflow-x: auto;
	white-space: pre-wrap;
	word-break: break-all;
	line-height: 1.5;
}
pre code {
	background: none;
	padding: 0;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* ─── Sign-in ─────────────────────────────────────────────────────────── */
body.signin {
	display: grid;
	place-items: center;
	padding: 1rem;
}
.signin-card {
	width: 100%;
	max-width: 420px;
	text-align: center;
	padding: 2.25rem 2rem;
}
.signin-card h1 {
	margin-bottom: 0.75rem;
}
.signin-card .button {
	margin-top: 0.75rem;
	width: 100%;
}

/* ─── Shell ───────────────────────────────────────────────────────────── */
.shell {
	display: grid;
	grid-template-columns: var(--sidebar) minmax(0, 1fr);
	min-height: 100vh;
}
.sidebar {
	background: var(--surface);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	padding: 1rem 0.75rem;
	position: sticky;
	top: 0;
	height: 100vh;
}
.brand {
	font-weight: 700;
	font-size: 1rem;
	display: flex;
	align-items: center;
	gap: 0.55rem;
	padding: 0.35rem 0.6rem 1rem;
	color: var(--text);
}
.brand-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--accent), #8f5cff);
	display: inline-block;
	box-shadow: 0 0 0 3px var(--accent-soft);
}
.nav {
	display: flex;
	flex-direction: column;
	gap: 2px;
}
.nav a {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.5rem 0.65rem;
	border-radius: 7px;
	color: var(--muted);
	font-weight: 500;
}
.nav a:hover {
	text-decoration: none;
	background: var(--surface-2);
	color: var(--text);
}
.nav a.active {
	background: var(--accent-soft);
	color: var(--accent);
}
.nav-icon {
	width: 1.1rem;
	text-align: center;
	opacity: 0.8;
	font-size: 0.95rem;
}
.sidebar-foot {
	margin-top: auto;
	border-top: 1px solid var(--border);
	padding-top: 0.9rem;
	display: grid;
	gap: 0.6rem;
}
.identity {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	min-width: 0;
}
.identity-text {
	min-width: 0;
}
.identity-name {
	font-weight: 600;
	font-size: 0.9rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.avatar {
	flex: none;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: var(--accent-soft);
	color: var(--accent);
	font-weight: 700;
	display: grid;
	place-items: center;
}
.sidebar-foot form {
	margin: 0;
}

.main {
	min-width: 0;
	padding: 1.5rem 2rem 3rem;
	max-width: 1100px;
	width: 100%;
}
.page-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.25rem;
}
.page-head p {
	margin: 0;
}
.page-actions {
	display: flex;
	gap: 0.5rem;
	flex: none;
}
.content {
	display: grid;
	gap: 1.1rem;
}
.toolbar {
	display: flex;
	gap: 0.6rem;
	align-items: center;
}
.toolbar .search {
	max-width: 360px;
}
.grid-2 {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
	gap: 1.1rem;
	align-items: start;
}
.role-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
	gap: 1.1rem;
}

@media (max-width: 900px) {
	.shell {
		grid-template-columns: 1fr;
		grid-template-rows: auto 1fr;
	}
	.sidebar {
		position: static;
		height: auto;
		flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
		gap: 0.5rem;
		padding: 0.6rem 0.75rem;
		border-right: none;
		border-bottom: 1px solid var(--border);
	}
	.brand {
		padding: 0.25rem 0.4rem;
	}
	.nav {
		flex-direction: row;
		flex-wrap: wrap;
	}
	.nav a {
		padding: 0.35rem 0.55rem;
	}
	.sidebar-foot {
		margin-left: auto;
		margin-top: 0;
		border-top: none;
		padding-top: 0;
		grid-auto-flow: column;
		align-items: center;
	}
	.sidebar-foot .chips {
		display: none;
	}
	.main {
		padding: 1rem 1rem 2.5rem;
	}
	.page-head {
		flex-direction: column;
	}
}

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 1.1rem 1.25rem;
}
.card.flush {
	padding: 0;
	overflow: hidden;
}
.card-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.75rem;
}
.card-head h2 {
	margin: 0;
	display: flex;
	align-items: center;
	gap: 0.5rem;
}
.card-head p {
	margin: 0.15rem 0 0;
}
.card-head .actions {
	display: flex;
	gap: 0.4rem;
	flex: none;
}
.role-card {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
}
.role-foot {
	margin-top: auto;
	padding-top: 0.4rem;
}
.built-in {
	font-size: 0.68rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

/* ─── Buttons & forms ─────────────────────────────────────────────────── */
.button,
button {
	appearance: none;
	font: inherit;
	font-size: 0.88rem;
	font-weight: 500;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	padding: 0.45rem 0.85rem;
	border-radius: 7px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	line-height: 1.2;
	white-space: nowrap;
	transition: background 0.12s ease;
}
.button:hover,
button:hover {
	background: var(--surface-2);
	text-decoration: none;
}
.button.primary,
button.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}
.button.primary:hover,
button.primary:hover {
	filter: brightness(1.08);
	background: var(--accent);
}
button.danger {
	color: var(--danger);
}
button.danger:hover {
	background: var(--danger-bg);
	border-color: var(--danger);
}
button.small,
.button.small {
	padding: 0.25rem 0.6rem;
	font-size: 0.8rem;
}
button.full {
	width: 100%;
}
button.icon {
	padding: 0.2rem 0.55rem;
	font-size: 1.1rem;
	line-height: 1;
	border: none;
	background: transparent;
	color: var(--muted);
}
button:disabled {
	opacity: 0.55;
	cursor: default;
}
.button-row {
	display: flex;
	gap: 0.4rem;
	margin-top: 0.6rem;
	flex-wrap: wrap;
}

input,
textarea,
select {
	font: inherit;
	font-size: 0.92rem;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 7px;
	padding: 0.45rem 0.65rem;
	width: 100%;
}
input[readonly] {
	background: var(--surface-2);
	color: var(--muted);
}
textarea {
	min-height: 4.5rem;
	resize: vertical;
	line-height: 1.5;
}
textarea.masked {
	-webkit-text-security: disc;
}
input:focus,
textarea:focus,
select:focus {
	outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
	outline-offset: 0;
	border-color: var(--accent);
}
label {
	display: block;
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--muted);
	margin-bottom: 0.3rem;
}
label.check {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	font-weight: 500;
	margin: -0.3rem 0 0.8rem;
}
label.check input {
	width: auto;
}
.field {
	margin-bottom: 0.85rem;
}
.hint {
	font-size: 0.8rem;
	color: var(--muted);
	margin-top: 0.3rem;
	line-height: 1.45;
}
.row {
	display: flex;
	gap: 0.6rem;
	align-items: flex-end;
	flex-wrap: wrap;
}
.row > * {
	flex: 1 1 200px;
}
.row > .field {
	margin-bottom: 0;
}
.row > button,
.row > .button {
	flex: 0 0 auto;
}
form.inline {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex-wrap: wrap;
	margin-top: 0.6rem;
}
form.inline select {
	width: auto;
	min-width: 180px;
	flex: 1;
}
.form-error {
	margin: 0 1.25rem;
	padding: 0.55rem 0.8rem;
	border-radius: 7px;
	background: var(--danger-bg);
	color: var(--danger);
	font-size: 0.88rem;
}

/* ─── Tables ──────────────────────────────────────────────────────────── */
.table-wrap {
	overflow-x: auto;
}
table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.9rem;
}
th,
td {
	text-align: left;
	padding: 0.65rem 0.9rem;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
}
th {
	font-size: 0.74rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
	font-weight: 600;
	background: var(--surface-2);
}
tbody tr:hover td {
	background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}
tr:last-child td {
	border-bottom: none;
}
td.actions {
	white-space: nowrap;
	text-align: right;
}
td.actions button {
	margin-left: 0.3rem;
}
.empty-state {
	padding: 2.25rem 1rem;
	text-align: center;
	color: var(--muted);
}
.empty-state strong {
	display: block;
	color: var(--text);
	margin-bottom: 0.25rem;
}
.empty-state p {
	margin: 0;
}
.loading {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	color: var(--muted);
	padding: 1.25rem;
	justify-content: center;
}
.spinner {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	animation: spin 0.8s linear infinite;
}
@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* ─── Chips ───────────────────────────────────────────────────────────── */
.chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
}
.chip {
	display: inline-block;
	padding: 0.1rem 0.55rem;
	border-radius: 999px;
	background: var(--chip);
	color: var(--chip-text);
	font-size: 0.78rem;
	font-family: var(--mono);
	line-height: 1.6;
	white-space: nowrap;
}
.chip.ok {
	background: var(--ok-bg);
	color: var(--ok);
}
.chip.danger {
	background: var(--danger-bg);
	color: var(--danger);
}
.chip.plain {
	font-family: inherit;
}
.chip-button {
	padding: 0.15rem 0.6rem;
	border-radius: 999px;
	font-size: 0.78rem;
	font-family: var(--mono);
	background: var(--surface);
	border: 1px dashed var(--border);
	color: var(--muted);
}
.chip-button:hover {
	border-style: solid;
	color: var(--text);
}
.chip-button.on {
	background: var(--accent-soft);
	border: 1px solid var(--accent);
	color: var(--accent);
}
.quick-add {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
	align-items: center;
	margin-top: 0.5rem;
}

/* ─── Alerts & toasts ─────────────────────────────────────────────────── */
.alert {
	padding: 0.65rem 0.85rem;
	border-radius: 8px;
	border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
	background: var(--danger-bg);
	color: var(--danger);
	font-size: 0.9rem;
	text-align: left;
	margin-bottom: 0.75rem;
}
.alert.info {
	border-color: var(--border);
	background: var(--surface-2);
	color: var(--muted);
}
.toasts {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	display: grid;
	gap: 0.5rem;
	z-index: 1000;
	max-width: min(420px, calc(100vw - 2rem));
}
.toast {
	background: var(--text);
	color: var(--bg);
	padding: 0.65rem 0.9rem;
	border-radius: 8px;
	box-shadow: var(--shadow-lg);
	display: flex;
	gap: 0.75rem;
	align-items: flex-start;
	justify-content: space-between;
	font-size: 0.9rem;
	animation: rise 0.18s ease-out;
}
.toast.error {
	background: var(--danger);
	color: #fff;
}
.toast.ok {
	background: var(--ok);
	color: #fff;
}
.toast button {
	background: transparent;
	border: none;
	color: inherit;
	padding: 0 0.2rem;
	font-size: 1.05rem;
	line-height: 1;
}
@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
}

/* ─── Dialogs & drawers ───────────────────────────────────────────────── */
dialog {
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	padding: 0;
	box-shadow: var(--shadow-lg);
}
dialog::backdrop {
	background: rgba(10, 14, 22, 0.45);
	backdrop-filter: blur(2px);
}
.dialog {
	border-radius: 12px;
	width: min(480px, calc(100vw - 2rem));
}
.dialog.wide {
	width: min(680px, calc(100vw - 2rem));
}
.dialog-form {
	display: grid;
	gap: 0.6rem;
	margin: 0;
}
.dialog-head {
	padding: 1.25rem 1.25rem 0;
}
.dialog-head h2 {
	margin-bottom: 0.2rem;
}
.dialog-head p {
	margin: 0;
	font-size: 0.88rem;
}
.dialog-body {
	padding: 0.5rem 1.25rem 0;
}
.dialog-body .field:last-child {
	margin-bottom: 0;
}
.dialog-actions {
	display: flex;
	justify-content: flex-end;
	gap: 0.5rem;
	padding: 0.75rem 1.25rem 1.25rem;
	border-top: 1px solid var(--border);
	margin-top: 0.5rem;
}
.dialog-actions button.danger {
	background: var(--danger);
	border-color: var(--danger);
	color: #fff;
}
.dialog-actions button.danger:hover {
	filter: brightness(1.08);
}
.drawer {
	margin: 0 0 0 auto;
	height: 100vh;
	max-height: 100vh;
	width: min(520px, 100vw);
	border-radius: 0;
	border-width: 0 0 0 1px;
}
.drawer-inner {
	display: flex;
	flex-direction: column;
	height: 100%;
}
.drawer-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 1rem;
	padding: 1.1rem 1.25rem 0.9rem;
	border-bottom: 1px solid var(--border);
}
.drawer-head h2 {
	margin: 0;
	word-break: break-all;
}
.drawer-head p {
	margin: 0.1rem 0 0;
}
.drawer-body {
	padding: 1rem 1.25rem 2rem;
	overflow-y: auto;
	display: grid;
	gap: 1.25rem;
	align-content: start;
}
.drawer-body section {
	padding-bottom: 1.1rem;
	border-bottom: 1px solid var(--border);
}
.drawer-body section:last-child {
	border-bottom: none;
}
.binding-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 0.35rem;
}
.binding-list li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.35rem 0.5rem;
	border-radius: 6px;
	background: var(--surface-2);
	font-size: 0.9rem;
	word-break: break-all;
}
.picker-wrap {
	position: relative;
	margin-top: 0.6rem;
}
.picker {
	display: grid;
	gap: 2px;
	margin-top: 0.3rem;
}
.picker-item {
	justify-content: space-between;
	width: 100%;
	text-align: left;
	font-weight: 400;
	padding: 0.4rem 0.6rem;
}

/* ─── Misc ────────────────────────────────────────────────────────────── */
.kv {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 0.4rem 1rem;
	font-size: 0.92rem;
	margin: 0;
}
.kv dt {
	color: var(--muted);
}
.kv dd {
	margin: 0;
	min-width: 0;
}
.snippet {
	position: relative;
	margin-top: 0.3rem;
}
.snippet pre {
	padding-right: 4.5rem;
}
.snippet .copy {
	position: absolute;
	top: 0.4rem;
	right: 0.4rem;
}
.token-reveal {
	margin-bottom: 1rem;
	padding: 1rem;
	border: 1px dashed var(--accent);
	border-radius: 8px;
	background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}
.reveal {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	flex-wrap: wrap;
}
.secret-value {
	max-width: 320px;
	overflow-wrap: anywhere;
}
.details-json {
	max-width: 420px;
	font-size: 0.76rem;
	margin-top: 0.3rem;
}
details summary {
	cursor: pointer;
	color: var(--accent);
	font-size: 0.85rem;
}
.subtle-list {
	margin: 0.25rem 0 0;
	padding-left: 1.1rem;
}
.answer {
	margin-top: 0.75rem;
}
.answer pre {
	word-break: break-word;
}
.citations {
	margin-top: 0.6rem;
	font-size: 0.88rem;
}
.perm-editor textarea {
	min-height: 7rem;
}
