:root {
	--canvas: #f5f7fa;
	--surface: #ffffff;
	--surface-muted: #eef2f6;
	--ink: #0a1530;
	--text: #182033;
	--muted: #697386;
	--line: #dce2e9;
	--line-strong: #bcc6d2;
	--accent: #087ec2;
	--accent-soft: #dff3fb;
	--green: #138564;
	--green-soft: #def4ea;
	--amber: #b96b0b;
	--amber-soft: #fff0d5;
	--danger: #c13d43;
	--danger-soft: #fce7e7;
	--shadow: 0 10px 28px rgba(10, 21, 48, 0.08);
}

* { box-sizing: border-box; }

html {
	min-width: 320px;
	min-height: 100%;
	background: var(--canvas);
	color-scheme: light;
}

body {
	min-width: 320px;
	min-height: 100vh;
	min-height: 100dvh;
	margin: 0;
	background: var(--canvas);
	color: var(--text);
	font-family: "Noto Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
	font-size: 14px;
	letter-spacing: 0;
	-webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
img { display: block; }
[hidden] { display: none !important; }

button:focus-visible, input:focus-visible, select:focus-visible {
	outline: 3px solid rgba(8, 126, 194, 0.2);
	outline-offset: 2px;
}

.app-shell { min-height: 100dvh; }

.sidebar {
	position: fixed;
	inset: 0 auto 0 0;
	z-index: 20;
	display: flex;
	width: 224px;
	flex-direction: column;
	padding: 20px 14px;
	border-right: 1px solid var(--line);
	background: #f0f3f6;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.brand-mark { width: 36px; height: 36px; flex: 0 0 36px; overflow: hidden; border-radius: 7px; background: #fff; box-shadow: 0 3px 10px rgba(10, 21, 48, 0.12); }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand strong { display: block; color: var(--ink); font-size: 14px; line-height: 1.3; }
.brand span, .service-state span { display: block; margin-top: 3px; color: var(--muted); font: 10px/1.2 Consolas, monospace; }

.side-nav { display: grid; gap: 4px; }
.nav-button, .bottom-nav-button {
	border: 0;
	background: transparent;
}
.nav-button {
	display: flex;
	min-height: 42px;
	align-items: center;
	gap: 11px;
	padding: 0 12px;
	border-radius: 6px;
	color: #4c586b;
	text-align: left;
}
.nav-button img { width: 18px; height: 18px; opacity: 0.72; }
.nav-button:hover { background: #e5eaf0; color: var(--ink); }
.nav-button.active { background: var(--ink); color: #fff; }
.nav-button.active img { filter: invert(1); opacity: 1; }

.service-state {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: auto;
	padding: 13px 10px;
	border-top: 1px solid var(--line);
}
.service-state strong { display: block; font-size: 12px; }

.status-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	flex: 0 0 8px;
	border-radius: 50%;
	background: #9aa5b3;
	box-shadow: 0 0 0 3px rgba(154, 165, 179, 0.14);
}
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(19, 133, 100, 0.15); }
.status-dot.error { background: #9aa5b3; }

.workspace { min-height: 100dvh; margin-left: 224px; }

.topbar {
	position: sticky;
	top: 0;
	z-index: 15;
	display: flex;
	min-height: 78px;
	align-items: center;
	justify-content: space-between;
	padding: 12px 28px;
	border-bottom: 1px solid var(--line);
	background: rgba(255, 255, 255, 0.96);
}

.mobile-brand { display: flex; align-items: center; gap: 11px; }
.mobile-brand > img { display: none; width: 36px; height: 36px; border-radius: 7px; box-shadow: 0 3px 10px rgba(10, 21, 48, 0.12); }
.context-label { margin: 0 0 4px; color: var(--accent); font: 700 10px/1.1 Consolas, monospace; }
.topbar h1 { margin: 0; color: var(--ink); font-size: 22px; line-height: 1.15; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.health-pill {
	display: inline-flex;
	height: 36px;
	align-items: center;
	gap: 8px;
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: 6px;
	background: #fff;
	color: var(--muted);
	font-size: 12px;
}

.icon-button, .primary-icon-button, .input-icon, .remove-file {
	display: inline-grid;
	place-items: center;
	border: 1px solid var(--line);
	border-radius: 6px;
	background: #fff;
}
.icon-button { width: 38px; height: 38px; }
.icon-button img, .input-icon img, .remove-file img { width: 17px; height: 17px; }
.icon-button:hover, .input-icon:hover { border-color: var(--line-strong); background: var(--surface-muted); }

.page {
	display: none;
	width: min(100%, 940px);
	margin: 0 auto;
	padding: 28px 28px 112px;
}
.page.active { display: block; animation: page-enter 180ms ease-out both; }

@keyframes page-enter {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}

.storage-band {
	display: grid;
	grid-template-columns: 44px 1fr auto;
	align-items: center;
	gap: 13px;
	min-height: 88px;
	margin-bottom: 14px;
	padding: 15px 16px;
	border-radius: 8px;
	background: var(--ink);
	color: #fff;
	box-shadow: var(--shadow);
}
.storage-icon {
	display: grid;
	width: 42px;
	height: 42px;
	place-items: center;
	border-radius: 7px;
	background: rgba(255, 255, 255, 0.12);
}
.storage-icon img { width: 21px; filter: invert(1); }
.storage-copy > span { display: block; color: #aab7d2; font-size: 11px; }
.storage-copy > div { display: flex; align-items: baseline; gap: 5px; margin-top: 2px; }
.storage-copy strong { font: 700 24px/1 Consolas, monospace; }
.storage-copy em { color: #d4dced; font-style: normal; font-size: 12px; }
.storage-copy small { display: block; margin-top: 5px; color: #8fe1ca; font-size: 11px; }
.band-action {
	height: 34px;
	padding: 0 12px;
	border: 1px solid rgba(255, 255, 255, 0.25);
	border-radius: 6px;
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
}

.search-bar {
	display: grid;
	grid-template-columns: 22px 1fr 46px;
	align-items: center;
	gap: 10px;
	height: 62px;
	padding: 7px 8px 7px 16px;
	border: 1px solid var(--line-strong);
	border-radius: 8px;
	background: #fff;
	box-shadow: 0 7px 22px rgba(10, 21, 48, 0.06);
}
.search-bar > img { width: 22px; opacity: 0.55; }
.search-bar input {
	min-width: 0;
	height: 44px;
	border: 0;
	outline: 0;
	background: transparent;
	color: var(--ink);
	font-size: 16px;
}
.search-bar input::placeholder { color: #8a95a5; }
.primary-icon-button {
	width: 46px;
	height: 46px;
	border-color: var(--accent);
	background: var(--accent);
}
.primary-icon-button img { width: 20px; filter: invert(1); }

.native-tools {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-top: 12px;
	padding: 13px 14px;
	border: 1px solid #bfe4d7;
	border-radius: 8px;
	background: var(--green-soft);
}
.native-tools > div { display: flex; align-items: center; gap: 10px; }
.native-tools strong, .native-tools span { display: block; }
.native-tools strong { color: #124d3d; font-size: 13px; }
.native-tools span { margin-top: 2px; color: #487567; font-size: 11px; }
.tool-icon { display: grid !important; width: 34px; height: 34px; place-items: center; margin: 0 !important; border-radius: 6px; background: #fff; }
.tool-icon img { width: 18px; }

.section-heading, .page-lead {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
}
.section-heading { margin: 26px 2px 12px; }
.section-heading h2, .page-lead h2, .band-heading h2 { margin: 0; color: var(--ink); font-size: 16px; line-height: 1.3; }
.section-heading p, .page-lead p, .band-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.page-lead { margin-bottom: 14px; }
.page-lead > div { display: flex; align-items: center; gap: 11px; }
.page-lead.separated { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); }
.lead-index {
	display: grid;
	width: 34px;
	height: 34px;
	place-items: center;
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	background: #fff;
	color: var(--accent);
	font: 700 11px/1 Consolas, monospace;
}

.result-list, .library-list { display: grid; gap: 9px; }
.result-item, .library-item {
	padding: 15px 16px;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: #fff;
	box-shadow: 0 4px 14px rgba(10, 21, 48, 0.04);
}
.result-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.result-type {
	display: inline-flex;
	min-height: 23px;
	align-items: center;
	padding: 0 8px;
	border-radius: 4px;
	background: var(--accent-soft);
	color: #096b9f;
	font-size: 11px;
	font-weight: 700;
}
.result-score { color: var(--muted); font: 11px/1 Consolas, monospace; }
.result-question { margin: 11px 0 12px; color: var(--ink); font-size: 14px; font-weight: 650; line-height: 1.7; }
.result-answer {
	padding: 10px 11px;
	border-left: 3px solid var(--green);
	background: #f2f9f6;
	color: #175b47;
	font-size: 13px;
	line-height: 1.6;
}
.library-item .result-topline > div { display: flex; align-items: center; gap: 8px; }
.library-delete { width: 32px; height: 32px; border-color: #f0c7c9; background: var(--danger-soft); }
.library-delete img { width: 15px; filter: invert(29%) sepia(47%) saturate(1740%) hue-rotate(312deg) brightness(92%); }

.empty-state {
	display: grid;
	min-height: 220px;
	place-items: center;
	align-content: center;
	gap: 8px;
	padding: 28px;
	border: 1px dashed var(--line-strong);
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.52);
	color: var(--muted);
	text-align: center;
}
.empty-state img { width: 30px; height: 30px; opacity: 0.56; }
.empty-state strong { color: #4f5b6d; font-size: 14px; }
.empty-state span { font-size: 12px; }
.empty-state.compact { min-height: 108px; }
.empty-state.loading img, button.loading img { animation: spin 800ms linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.upload-zone {
	display: grid;
	min-height: 184px;
	place-items: center;
	align-content: center;
	gap: 9px;
	border: 1px dashed #81b9d5;
	border-radius: 8px;
	background: #eff8fc;
	color: var(--muted);
	text-align: center;
	cursor: pointer;
}
.upload-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.upload-zone input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.upload-zone strong { color: var(--ink); font-size: 15px; }
.upload-zone > span { font-size: 12px; }
.upload-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 8px; background: var(--surface); box-shadow: 0 5px 16px rgba(8, 126, 194, 0.12); }
.upload-icon img { width: 23px; }

.file-list { display: grid; gap: 8px; margin-top: 12px; }
.file-item { display: grid; grid-template-columns: 52px 1fr 34px; align-items: center; gap: 11px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.file-preview { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; }
.file-meta { min-width: 0; }
.file-meta strong, .file-meta span { display: block; }
.file-meta strong { overflow: hidden; color: var(--ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.remove-file { width: 32px; height: 32px; }
.action-row { display: flex; justify-content: flex-end; margin-top: 12px; }

.primary-button, .secondary-button, .text-button {
	display: inline-flex;
	min-height: 38px;
	align-items: center;
	justify-content: center;
	gap: 7px;
	border-radius: 6px;
	padding: 0 13px;
	font-weight: 650;
}
.primary-button img, .secondary-button img, .text-button img img { width: 16px; height: 16px; }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.primary-button img { filter: invert(1); }
.secondary-button { border: 1px solid var(--line-strong); background: #fff; color: var(--text); }
.text-button { border: 0; background: transparent; color: var(--muted); }

.job-panel { min-height: 108px; }
.job-content { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.job-title { display: flex; align-items: center; justify-content: space-between; }
.job-title strong { color: var(--ink); }
.job-status { padding: 4px 8px; border-radius: 4px; background: var(--surface-muted); color: var(--muted); font-size: 11px; }
.job-status.completed { background: var(--green-soft); color: var(--green); }
.job-status.failed { background: var(--danger-soft); color: var(--danger); }
.job-status.processing, .job-status.pending_ocr { background: var(--accent-soft); color: var(--accent); }
.job-status.needs_review, .job-status.waiting_configuration { background: var(--amber-soft); color: var(--amber); }
.job-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--line); }
.job-metric { padding: 12px; background: #fff; text-align: center; }
.job-metric strong, .job-metric span { display: block; }
.job-metric strong { color: var(--ink); font: 700 20px/1 Consolas, monospace; }
.job-metric span { margin-top: 5px; color: var(--muted); font-size: 10px; }
.job-error { margin: 12px 0 0; color: var(--danger); font-size: 12px; line-height: 1.5; }

.library-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.settings-band { padding: 0 0 26px; }
.settings-band + .settings-band { padding-top: 24px; border-top: 1px solid var(--line); }
.band-heading { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 11px; margin-bottom: 16px; }
.band-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 7px; background: var(--accent-soft); }
.band-icon.vision { background: var(--amber-soft); }
.band-icon.guard { background: var(--green-soft); }
.band-icon img { width: 18px; }
.band-heading output { color: var(--green); font: 700 15px/1 Consolas, monospace; }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field-wide { grid-column: 1 / -1; }
.field > span { display: block; margin-bottom: 6px; color: #536074; font-size: 11px; font-weight: 700; }
.field input, .field select {
	width: 100%;
	height: 44px;
	border: 1px solid var(--line-strong);
	border-radius: 6px;
	background: #fff;
	color: var(--ink);
	padding: 0 12px;
	outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8, 126, 194, 0.1); }
.field input:disabled { background: var(--surface-muted); }
.input-with-action { position: relative; }
.input-with-action input { padding-right: 46px; }
.input-icon { position: absolute; top: 5px; right: 5px; width: 34px; height: 34px; border: 0; background: transparent; }

.model-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.model-option { max-width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 4px; background: #fff; padding: 6px 8px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.check-row, .range-row { display: flex; align-items: center; gap: 9px; margin-top: 14px; color: #4d596b; font-size: 12px; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.range-row { justify-content: space-between; }
.range-row input { width: min(70%, 420px); accent-color: var(--green); }
.switch { display: inline-flex; align-items: center; gap: 7px; }
.switch input { position: absolute; opacity: 0; }
.switch > span { position: relative; width: 38px; height: 22px; border-radius: 11px; background: #c8d0da; transition: background 160ms ease; }
.switch > span::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; content: ""; transition: transform 160ms ease; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch em { color: var(--muted); font-style: normal; font-size: 11px; }

.inline-actions { margin-top: 12px; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 20px; border-top: 1px solid var(--line); }
.form-footer > span { color: var(--muted); font-size: 11px; }

.bottom-nav { display: none; }

dialog {
	width: min(92vw, 480px);
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 21, 48, 0.52); }
.dialog-panel { display: grid; gap: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.dialog-heading, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-heading h2 { margin: 0; color: var(--ink); font-size: 18px; }
.dialog-actions { justify-content: flex-end; margin-top: 2px; }

.toast {
	position: fixed;
	z-index: 100;
	left: 50%;
	bottom: 24px;
	max-width: min(88vw, 460px);
	transform: translate(-50%, 16px);
	border-radius: 6px;
	background: var(--ink);
	color: #fff;
	padding: 11px 14px;
	font-size: 12px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: #8e2f35; }

@media (max-width: 720px) {
	.sidebar { display: none; }
	.workspace { margin-left: 0; }
	.topbar {
		min-height: 72px;
		padding: 10px 16px;
		background: #fff;
	}
	.mobile-brand > img { display: block; }
	.context-label { margin-bottom: 3px; font-size: 9px; }
	.topbar h1 { font-size: 18px; }
	.health-pill { width: 36px; padding: 0; justify-content: center; }
	.health-pill > span:last-child { display: none; }
	.page { width: 100%; padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
	.storage-band { min-height: 82px; padding: 13px 14px; }
	.search-bar { height: 58px; grid-template-columns: 20px 1fr 42px; padding-left: 14px; }
	.search-bar input { height: 42px; font-size: 15px; }
	.primary-icon-button { width: 42px; height: 42px; }
	.section-heading { margin-top: 22px; }
	.empty-state { min-height: 190px; }
	.upload-zone { min-height: 168px; }
	.field-grid { grid-template-columns: 1fr; }
	.field-wide { grid-column: auto; }
	.band-heading { grid-template-columns: 38px 1fr auto; }
	.band-heading .secondary-button { width: 38px; min-height: 36px; padding: 0; }
	.band-heading .secondary-button img { width: 16px; }
	.band-heading .secondary-button { font-size: 0; }
	.form-footer { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 5; margin: 0 -16px; padding: 12px 16px; background: rgba(245, 247, 250, 0.96); }
	.form-footer .primary-button { min-height: 42px; }
	.bottom-nav {
		position: fixed;
		z-index: 30;
		right: 0;
		bottom: 0;
		left: 0;
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		gap: 4px;
		padding: 7px 8px max(7px, env(safe-area-inset-bottom));
		border-top: 1px solid var(--line);
		background: rgba(255, 255, 255, 0.98);
	}
	.bottom-nav-button {
		display: grid;
		min-width: 0;
		height: 56px;
		place-items: center;
		align-content: center;
		gap: 4px;
		border-radius: 6px;
		color: #707b8b;
		font-size: 10px;
	}
	.bottom-nav-button img { width: 20px; height: 20px; opacity: 0.72; }
	.bottom-nav-button.active { background: var(--accent-soft); color: #075f91; font-weight: 700; }
	.bottom-nav-button.active img { opacity: 1; }
	dialog { width: calc(100vw - 24px); margin-bottom: calc(12px + env(safe-area-inset-bottom)); }
	.dialog-panel { padding: 18px; }
	.toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
	.topbar { padding-inline: 12px; }
	.page { padding-inline: 12px; }
	.storage-band { grid-template-columns: 40px 1fr auto; gap: 9px; padding-inline: 11px; }
	.storage-icon { width: 38px; height: 38px; }
	.native-tools { align-items: flex-start; }
	.library-actions { display: grid; grid-template-columns: 1fr 1fr; }
	.library-actions button { min-width: 0; padding-inline: 8px; font-size: 11px; }
}
