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

:root {
	--font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	--orange: #f97316;
	--orange-dim: rgba(249, 115, 22, 0.35);
	--orange-glow: rgba(249, 115, 22, 0.45);
	--radius: 14px;
	--radius-sm: 10px;
	--ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
	color-scheme: light;
	--bg-deep: #f4f4f5;
	--orb-a: rgba(249, 115, 22, 0.14);
	--orb-b: rgba(234, 88, 12, 0.1);
	--orb-c: rgba(251, 191, 36, 0.12);
	--text: #18181b;
	--text-muted: #52525b;
	--card: rgba(255, 255, 255, 0.72);
	--card-border: rgba(24, 24, 27, 0.08);
	--card-highlight: rgba(249, 115, 22, 0.06);
	--input-bg: rgba(255, 255, 255, 0.95);
	--input-border: rgba(24, 24, 27, 0.12);
	--input-focus: var(--orange);
	--shadow: 0 24px 48px -12px rgba(24, 24, 27, 0.12), 0 0 0 1px var(--card-border);
	--switch-bg: rgba(24, 24, 27, 0.06);
	--switch-border: rgba(24, 24, 27, 0.1);
	--switch-active: rgba(249, 115, 22, 0.18);
	--title-accent: linear-gradient(135deg, #ea580c 0%, #f97316 50%, #fb923c 100%);
}

[data-theme="dark"] {
	color-scheme: dark;
	--bg-deep: #0c0a09;
	--orb-a: rgba(249, 115, 22, 0.22);
	--orb-b: rgba(234, 88, 12, 0.14);
	--orb-c: rgba(251, 146, 60, 0.12);
	--text: #fafaf9;
	--text-muted: #a8a29e;
	--card: rgba(28, 25, 23, 0.65);
	--card-border: rgba(255, 255, 255, 0.08);
	--card-highlight: rgba(249, 115, 22, 0.08);
	--input-bg: rgba(12, 10, 9, 0.6);
	--input-border: rgba(255, 255, 255, 0.12);
	--input-focus: #fb923c;
	--shadow:
		0 24px 48px -12px rgba(0, 0, 0, 0.45),
		0 0 0 1px var(--card-border),
		0 0 80px -20px var(--orange-dim);
	--switch-bg: rgba(255, 255, 255, 0.06);
	--switch-border: rgba(255, 255, 255, 0.1);
	--switch-active: rgba(249, 115, 22, 0.25);
	--title-accent: linear-gradient(135deg, #fb923c 0%, #f97316 45%, #fdba74 100%);
}

html {
	font-family: var(--font);
	background: var(--bg-deep);
	transition: background-color 0.35s var(--ease);
	text-rendering: optimizeLegibility;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

body {
	margin: 0;
	min-height: 100vh;
	padding: 24px 16px 48px;
	color: var(--text);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	position: relative;
	overflow-x: hidden;
}

/* Animated mesh background */
.ambient {
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	overflow: hidden;
	background: var(--bg-deep);
	transition: background 0.35s var(--ease);
}

.ambient__orb {
	position: absolute;
	border-radius: 50%;
	filter: blur(80px);
	opacity: 0.85;
	will-change: transform;
}

.ambient__orb--1 {
	width: min(90vw, 520px);
	height: min(90vw, 520px);
	background: var(--orb-a);
	top: -12%;
	left: -18%;
	animation: drift-1 22s var(--ease) infinite;
}

.ambient__orb--2 {
	width: min(70vw, 420px);
	height: min(70vw, 420px);
	background: var(--orb-b);
	bottom: -15%;
	right: -20%;
	animation: drift-2 26s var(--ease) infinite;
}

.ambient__orb--3 {
	width: min(55vw, 340px);
	height: min(55vw, 340px);
	background: var(--orb-c);
	top: 38%;
	left: 50%;
	transform: translateX(-50%);
	animation: drift-3 18s var(--ease) infinite;
}

@keyframes drift-1 {
	0%,
	100% {
		transform: translate(0, 0) scale(1);
	}
	40% {
		transform: translate(8%, 12%) scale(1.06);
	}
	70% {
		transform: translate(4%, -6%) scale(0.96);
	}
}

@keyframes drift-2 {
	0%,
	100% {
		transform: translate(0, 0) scale(1);
	}
	45% {
		transform: translate(-10%, -8%) scale(1.08);
	}
	80% {
		transform: translate(-4%, 6%) scale(0.94);
	}
}

@keyframes drift-3 {
	0%,
	100% {
		transform: translateX(-50%) translateY(0) scale(1);
	}
	50% {
		transform: translateX(-48%) translateY(-14%) scale(1.12);
	}
}

/* Theme switch */
.theme-switch {
	position: fixed;
	top: 16px;
	right: 16px;
	z-index: 10;
	display: flex;
	gap: 4px;
	padding: 4px;
	border-radius: 999px;
	background: var(--switch-bg);
	border: 1px solid var(--switch-border);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	box-shadow: var(--shadow);
}

.theme-switch__btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: none;
	border-radius: 999px;
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
	transition:
		color 0.2s var(--ease),
		background 0.2s var(--ease),
		transform 0.15s var(--ease);
}

.theme-switch__btn:hover {
	color: var(--text);
	background: var(--card-highlight);
}

.theme-switch__btn:focus-visible {
	outline: 2px solid var(--orange);
	outline-offset: 2px;
}

.theme-switch__btn[aria-pressed="true"] {
	color: var(--orange);
	background: var(--switch-active);
}

.theme-switch__btn:active {
	transform: scale(0.94);
}

.theme-switch__icon {
	display: block;
	flex-shrink: 0;
}

.user-bar {
	position: fixed;
	top: 16px;
	left: 16px;
	z-index: 10;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 14px;
	border-radius: 999px;
	background: var(--switch-bg);
	border: 1px solid var(--switch-border);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	box-shadow: var(--shadow);
	font-size: 0.875rem;
}

.user-bar__label {
	color: var(--text-muted);
}

.user-bar__logout {
	color: var(--orange);
	background: none;
	border: none;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	padding: 0;
}

/* Main column */
.main {
	position: relative;
	z-index: 1;
	width: min(960px, calc(100vw - 32px));
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 18px;
}

.panel {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.panel__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.panel__title {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	color: var(--text);
}

.panel__head--sub {
	padding: 0 24px;
	margin-top: 8px;
}

.panel__subtitle {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--text);
}

.container--flush {
	padding-top: 16px;
	padding-bottom: 16px;
}

.title {
	font-size: clamp(1.75rem, 5vw, 2.125rem);
	font-weight: 700;
	letter-spacing: -0.03em;
	text-align: center;
	margin: 0 0 8px;
	color: var(--orange);
	background: var(--title-accent);
	-webkit-background-clip: text;
	background-clip: text;
	-webkit-text-fill-color: transparent;
}

.subtitle {
	font-size: 0.8125rem;
	color: var(--text-muted);
	text-align: center;
	margin: 0 0 18px;
	line-height: 1.5;
	max-width: 100%;
}

.subtitle a {
	color: var(--orange);
	text-decoration: none;
	font-weight: 500;
}

.subtitle a:hover {
	text-decoration: underline;
}

.container {
	background: var(--card);
	padding: 24px;
	border-radius: var(--radius);
	border: 1px solid var(--card-border);
	box-shadow: var(--shadow);
	backdrop-filter: blur(20px);
	-webkit-backdrop-filter: blur(20px);
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 12px;
	transition:
		background 0.35s var(--ease),
		border-color 0.35s var(--ease),
		box-shadow 0.35s var(--ease);
}

label {
	display: block;
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--text-muted);
}

.mode-fieldset {
	border: 1px solid var(--input-border);
	border-radius: var(--radius-sm);
	padding: 12px 14px 10px;
	margin: 0;
}

.mode-fieldset legend {
	padding: 0 6px;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--text);
}

.mode-option {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	margin-top: 8px;
	font-size: 0.9375rem;
	color: var(--text);
}

.mode-option:first-of-type {
	margin-top: 4px;
}

.mode-option input {
	width: auto;
	margin-top: 2px;
}

.hint {
	margin: -4px 0 0;
	font-size: 0.8125rem;
	color: var(--text-muted);
	line-height: 1.45;
}

input,
select {
	width: 100%;
	padding: 11px 14px;
	font-family: inherit;
	font-size: 1rem;
	color: var(--text);
	background: var(--input-bg);
	border: 1px solid var(--input-border);
	border-radius: var(--radius-sm);
	transition:
		border-color 0.2s var(--ease),
		box-shadow 0.2s var(--ease),
		background 0.2s var(--ease);
}

input::placeholder {
	color: var(--text-muted);
	opacity: 0.7;
}

input:hover,
select:hover {
	border-color: var(--orange-dim);
}

input:focus,
select:focus {
	outline: none;
	border-color: var(--input-focus);
	box-shadow: 0 0 0 3px var(--orange-dim);
}

.autocomplete {
	position: relative;
	width: 100%;
}

.autocomplete__list {
	position: absolute;
	left: 0;
	right: 0;
	top: calc(100% + 4px);
	margin: 0;
	padding: 6px;
	list-style: none;
	max-height: min(280px, 45vh);
	overflow-y: auto;
	z-index: 30;
	background: var(--card);
	border: 1px solid var(--card-border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
}

.autocomplete__item {
	padding: 10px 12px;
	border-radius: 8px;
	font-size: 0.875rem;
	line-height: 1.35;
	cursor: pointer;
	color: var(--text);
	transition: background 0.15s var(--ease);
}

.autocomplete__item:hover:not(.autocomplete__item--muted) {
	background: var(--card-highlight);
}

.autocomplete__item--muted {
	color: var(--text-muted);
	cursor: default;
	font-size: 0.8125rem;
}

.btn-primary {
	font-family: inherit;
	font-size: 1rem;
	font-weight: 600;
	width: 100%;
	padding: 13px 18px;
	margin-top: 4px;
	border: none;
	border-radius: var(--radius-sm);
	cursor: pointer;
	color: #0c0a09;
	background: linear-gradient(135deg, #fb923c 0%, #f97316 40%, #ea580c 100%);
	box-shadow:
		0 4px 14px -3px var(--orange-glow),
		inset 0 1px 0 rgba(255, 255, 255, 0.25);
	transition:
		filter 0.2s var(--ease),
		transform 0.15s var(--ease),
		box-shadow 0.2s var(--ease);
}

.btn-primary:hover {
	filter: brightness(1.06);
	box-shadow:
		0 8px 24px -4px var(--orange-glow),
		inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-primary:active {
	transform: scale(0.99);
}

.btn-primary:focus-visible {
	outline: 2px solid var(--input-focus);
	outline-offset: 2px;
}

.btn-primary:disabled,
.btn-secondary:disabled {
	opacity: 0.65;
	cursor: not-allowed;
	filter: none;
	transform: none;
}

.actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin-top: 4px;
}

.btn-secondary {
	font-family: inherit;
	font-size: 0.9375rem;
	font-weight: 600;
	width: 100%;
	padding: 13px 14px;
	border: 1px solid var(--input-border);
	border-radius: var(--radius-sm);
	cursor: pointer;
	color: var(--text);
	background: var(--input-bg);
	transition:
		border-color 0.2s var(--ease),
		background 0.2s var(--ease),
		transform 0.15s var(--ease);
}

.btn-secondary:hover {
	border-color: var(--orange-dim);
	background: var(--card-highlight);
}

.btn-secondary:focus-visible {
	outline: 2px solid var(--input-focus);
	outline-offset: 2px;
}

.btn-ghost {
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--orange);
	background: none;
	border: 1px solid var(--switch-border);
	border-radius: 999px;
	padding: 6px 12px;
	cursor: pointer;
}

.btn-ghost:hover {
	background: var(--card-highlight);
}

.history-wrap {
	overflow-x: auto;
}

.history-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.875rem;
}

.history-table th,
.history-table td {
	padding: 10px 8px;
	text-align: left;
	vertical-align: middle;
}

.history-table tbody td {
	border-bottom: 1px solid var(--card-border);
}

.history-table tbody tr:last-child td {
	border-bottom: none;
}

.history-table thead th {
	border-bottom: 1px solid var(--card-border);
}

.history-table th {
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-muted);
	white-space: nowrap;
}

.history-name {
	display: block;
	font-weight: 600;
	color: var(--text);
}

.history-meta {
	display: block;
	margin-top: 2px;
	font-size: 0.75rem;
	color: var(--text-muted);
}

.history-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	min-width: 210px;
}

.btn-split {
	position: relative;
	display: inline-grid;
	grid-template-columns: 1fr;
	grid-template-rows: 1fr;
	min-width: 5.75rem;
	height: 2rem;
	border-radius: 999px;
	border: 1px solid var(--input-border);
	background: var(--input-bg);
	overflow: hidden;
	isolation: isolate;
}

.btn-split__label,
.btn-split__actions {
	grid-area: 1 / 1;
}

.btn-split__label {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 10px;
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--text);
	transition:
		opacity 0.2s var(--ease),
		transform 0.25s var(--ease);
	pointer-events: none;
	user-select: none;
}

.btn-split__actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	width: 100%;
	height: 100%;
	opacity: 0;
	transform: scaleX(0.35);
	transition:
		opacity 0.2s var(--ease),
		transform 0.25s var(--ease);
}

.btn-split:hover .btn-split__label,
.btn-split:focus-within .btn-split__label {
	opacity: 0;
	transform: scale(0.88);
}

.btn-split:hover .btn-split__actions,
.btn-split:focus-within .btn-split__actions {
	opacity: 1;
	transform: scaleX(1);
}

.btn-split__action {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 0;
	border: none;
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
	transition:
		background 0.15s var(--ease),
		color 0.15s var(--ease);
}

.btn-split__action + .btn-split__action {
	border-left: 1px solid var(--input-border);
}

.btn-split__action:hover {
	background: var(--card-highlight);
	color: var(--orange);
}

.btn-split__action:focus-visible {
	outline: 2px solid var(--input-focus);
	outline-offset: -2px;
	z-index: 1;
}

.btn-split:hover,
.btn-split:focus-within {
	border-color: var(--orange-dim);
	background: var(--card-highlight);
}

.btn-split__icon {
	display: block;
	flex-shrink: 0;
}

.btn-chip {
	font: inherit;
	font-size: 0.75rem;
	font-weight: 600;
	padding: 6px 10px;
	border-radius: 999px;
	border: 1px solid var(--input-border);
	background: var(--input-bg);
	color: var(--text);
	cursor: pointer;
	white-space: nowrap;
}

.btn-chip:hover {
	border-color: var(--orange-dim);
	background: var(--card-highlight);
}

.btn-icon-delete {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	margin-left: auto;
	padding: 0;
	border-radius: 999px;
	border: 1px solid var(--input-border);
	background: var(--input-bg);
	color: var(--text-muted);
	cursor: pointer;
	flex-shrink: 0;
	transition:
		border-color 0.15s var(--ease),
		background 0.15s var(--ease),
		color 0.15s var(--ease);
}

.btn-icon-delete:hover {
	border-color: rgba(239, 68, 68, 0.45);
	background: rgba(239, 68, 68, 0.12);
	color: #dc2626;
}

.btn-icon-delete:focus-visible {
	outline: 2px solid #ef4444;
	outline-offset: 2px;
}

.btn-icon-delete__icon {
	display: block;
	flex-shrink: 0;
}

.grade-pill {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2rem;
	padding: 4px 8px;
	border-radius: 999px;
	font-weight: 700;
	font-size: 0.8125rem;
}

.grade-pill--a {
	background: rgba(34, 197, 94, 0.18);
	color: #16a34a;
}

.grade-pill--b {
	background: rgba(234, 179, 8, 0.18);
	color: #ca8a04;
}

.grade-pill--c {
	background: rgba(239, 68, 68, 0.18);
	color: #dc2626;
}

.grade-pill--muted {
	background: var(--switch-bg);
	color: var(--text-muted);
}

.history-empty {
	margin: 0;
	text-align: center;
	color: var(--text-muted);
	font-size: 0.9375rem;
}

.status {
	margin: 0;
	font-size: 0.9375rem;
	text-align: center;
	color: var(--text-muted);
	min-height: 1.4em;
}

.status--loading {
	color: var(--orange);
	font-weight: 500;
}

.job-progress {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-top: 4px;
}

.job-progress__bar {
	height: 8px;
	border-radius: 999px;
	background: var(--switch-bg);
	overflow: hidden;
}

.job-progress__fill {
	height: 100%;
	width: 0%;
	border-radius: inherit;
	background: var(--orange);
	transition: width 0.25s ease;
}

.job-progress__label {
	margin: 0;
	font-size: 0.875rem;
	color: var(--text-muted);
	text-align: center;
}

.status-pill {
	display: inline-flex;
	align-items: center;
	padding: 0.2em 0.65em;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.02em;
}

.status-pill--pending,
.status-pill--running {
	background: color-mix(in srgb, var(--orange) 18%, transparent);
	color: var(--orange);
}

.status-pill--done {
	background: color-mix(in srgb, #16a34a 18%, transparent);
	color: #16a34a;
}

.status-pill--failed {
	background: color-mix(in srgb, #dc2626 18%, transparent);
	color: #dc2626;
}

.is-hidden {
	display: none !important;
}

@media (max-width: 720px) {
	.actions {
		grid-template-columns: 1fr;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ambient__orb--1,
	.ambient__orb--2 {
		animation: none;
	}

	.ambient__orb--3 {
		animation: none;
		transform: translateX(-50%);
	}

	.btn-split__label,
	.btn-split__actions {
		transition: none;
	}
}

@media (hover: none) {
	.btn-split__label {
		display: none;
	}

	.btn-split__actions {
		opacity: 1;
		transform: none;
	}
}
