/* Courtbridge design tokens and shared components, used by the app page and the popup. */
@import url("./fonts/fonts.css");

:root {
	color-scheme: light;
	--ground: #e9eef4;
	--surface: #ffffff;
	--surface-2: #f4f7fa;
	--surface-3: #e2e8ef;
	--ink: #13233a;
	--ink-2: #46566c;
	--ink-3: #66758a;
	--line: #d6dde6;
	--line-strong: #b8c3d1;
	--select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5l3.5 3.5 3.5-3.5' fill='none' stroke='%2366758a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	--accent: #1d5fa6;
	--accent-ink: #ffffff;
	--accent-soft: #e3edf8;
	--bridge: #c24a22;
	--ok: #1b7446;
	--ok-soft: #ddf1e5;
	--warn: #8a5600;
	--warn-soft: #fdf1d6;
	--warn-line: #dfa82f;
	--bad: #b3261e;
	--bad-soft: #fbe4e2;
	--knob: #ffffff;
	--shadow: 0 1px 2px rgba(19, 35, 58, 0.06), 0 10px 28px rgba(19, 35, 58, 0.12);
	--font-display: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
	--font-body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	--font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
	:root {
		color-scheme: dark;
		--ground: #0b121c;
		--surface: #121c2a;
		--surface-2: #172334;
		--surface-3: #1f2d41;
		--ink: #e3eaf2;
		--ink-2: #a9b6c6;
		--ink-3: #8898ac;
		--line: #243347;
		--line-strong: #34475f;
		--select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5l3.5 3.5 3.5-3.5' fill='none' stroke='%238898ac' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
		--accent: #74aef0;
		--accent-ink: #0b121c;
		--accent-soft: #182c45;
		--bridge: #f08257;
		--ok: #62cf98;
		--ok-soft: #12301f;
		--warn: #f1c057;
		--warn-soft: #33280f;
		--warn-line: #a97c22;
		--bad: #f38e85;
		--bad-soft: #3a1a18;
		--knob: #f4f7fa;
		--shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.5);
	}
}

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

body {
	margin: 0;
	background: var(--ground);
	color: var(--ink);
	font: 400 14px/1.45 var(--font-body);
	-webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.icon {
	flex: none;
	width: 16px;
	height: 16px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.6;
	stroke-linecap: round;
	stroke-linejoin: round;
}

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

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 34px;
	padding: 7px 14px;
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	background: var(--surface);
	color: var(--ink);
	font: 600 13.5px/1.1 var(--font-body);
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--accent); }
.btn.quiet:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Pills ---------- */

.pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 3px 9px 3px 8px;
	border-radius: 999px;
	background: var(--surface-3);
	color: var(--ink-2);
	font: 600 12px/1.25 var(--font-body);
	white-space: nowrap;
}
.pill::before {
	content: "";
	flex: none;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: currentColor;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.run { background: var(--accent-soft); color: var(--accent); }
.pill.run::before { animation: courtbridge-blink 1s ease-in-out infinite; }

@keyframes courtbridge-blink { 50% { opacity: 0.25; } }

/* ---------- Switch ---------- */

.switch {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font: 500 12.5px/1.2 var(--font-body);
	cursor: pointer;
}
.switch input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	opacity: 0;
}
.switch .track {
	position: relative;
	flex: none;
	width: 30px;
	height: 18px;
	border-radius: 9px;
	background: var(--line-strong);
	transition: background-color 0.15s ease;
}
.switch .track::after {
	content: "";
	position: absolute;
	top: 2px;
	left: 2px;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--knob);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
	transition: transform 0.15s ease;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }

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

.input,
.select {
	height: 34px;
	padding: 6px 10px;
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	background: var(--surface);
	color: var(--ink);
	font: 400 13.5px/1.2 var(--font-body);
}
/* The browser's own arrow sits flush against the edge while the text is
   inset, so the select draws its own, inset as far as the text is. */
.select {
	appearance: none;
	-webkit-appearance: none;
	padding-right: 30px;
	background-image: var(--select-arrow);
	background-repeat: no-repeat;
	background-position: right 10px center;
	background-size: 12px 12px;
}
.input::placeholder { color: var(--ink-3); }
.input:disabled,
.select:disabled { opacity: 0.6; cursor: not-allowed; }

.field { display: grid; align-content: start; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; }
.field .input,
.field .select { width: 100%; }
.help { color: var(--ink-3); font-size: 12px; }
.help.ok { color: var(--ok); }
.help.warn { color: var(--warn); }

.form-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 14px 18px;
}

/* ---------- Callouts and progress ---------- */

.callout {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px 16px;
	padding: 12px 14px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--surface-2);
}
.callout p { max-width: 72ch; margin: 0; }
.callout.warn { border-color: var(--warn-line); background: var(--warn-soft); }
.callout.bad { border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: var(--bad-soft); }
.callout.ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }

.progress {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 14px;
	padding: 10px 14px;
	border-radius: 8px;
	background: var(--accent-soft);
	font-size: 13px;
}
.progress .bar {
	position: relative;
	flex: 0 1 180px;
	height: 6px;
	overflow: hidden;
	border-radius: 3px;
	background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.progress .bar::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	width: 40%;
	border-radius: 3px;
	background: var(--accent);
	animation: courtbridge-sweep 1.4s ease-in-out infinite;
}

@keyframes courtbridge-sweep {
	from { left: -40%; }
	to { left: 100%; }
}

/* ---------- Key/value lists ---------- */

.kv {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 5px 12px;
	margin: 0;
	font-size: 13px;
}
.kv dt { color: var(--ink-2); }
.kv dd {
	margin: 0;
	font: 500 12.5px/1.45 var(--font-mono);
	font-variant-numeric: tabular-nums;
	text-align: right;
}

/* ---------- Code output ---------- */

.code-wrap { position: relative; min-width: 0; }
.json {
	max-height: 420px;
	margin: 0;
	padding: 12px 14px;
	overflow: auto;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--surface-2);
	color: var(--ink);
	font: 400 12px/1.55 var(--font-mono);
	white-space: pre;
}
.code-wrap .copy {
	position: absolute;
	top: 6px;
	right: 6px;
	min-height: 28px;
	padding: 4px 10px;
	font-size: 12px;
}

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

.toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 80;
	max-width: calc(100vw - 32px);
	padding: 10px 16px;
	border-radius: 8px;
	background: var(--ink);
	color: var(--surface);
	font: 500 13.5px/1.35 var(--font-body);
	box-shadow: var(--shadow);
	transform: translateX(-50%);
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}
