/* ===== 主题变量 ===== */
:root {
	--radius: 12px;
	--radius-sm: 8px;
	--gap: 12px;
	--font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

:root,
:root[data-theme='light'] {
	color-scheme: light;
	--bg: #f5f6f8;
	--card: #ffffff;
	--text: #1f2328;
	--text-dim: #667085;
	--border: #e2e5ea;
	--accent: #2563eb;
	--accent-text: #ffffff;
	--accent-soft: #eff4ff;
	--danger: #d92d20;
	--shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.06);
	/* 下拉框箭头（颜色同 --text-dim，随主题切换） */
	--select-arrow: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%20fill='none'%20stroke='%23667085'%20stroke-width='1.75'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M4%206l4%204%204-4'/%3E%3C/svg%3E");
}

:root[data-theme='dark'] {
	color-scheme: dark;
	--bg: #0e1116;
	--card: #1b1f27;
	--text: #e7e9ee;
	--text-dim: #9aa3b2;
	--border: #2b313c;
	--accent: #5b8def;
	--accent-text: #ffffff;
	--accent-soft: #1d2b4a;
	--danger: #f97066;
	--shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
	--select-arrow: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%20fill='none'%20stroke='%239aa3b2'%20stroke-width='1.75'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M4%206l4%204%204-4'/%3E%3C/svg%3E");
}

/* ===== 基础 ===== */
* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	padding: 0;
}

body {
	font-family: var(--font);
	background: var(--bg);
	color: var(--text);
	line-height: 1.5;
	min-height: 100dvh;
	transition: background 0.2s ease, color 0.2s ease;
}

/* 未启用 JS 时的提示（用 class 而非内联样式，以便 CSP 不需要 style-src 'unsafe-inline'） */
.noscript-hint {
	text-align: center;
	padding: 2rem;
	margin: 0;
}

button {
	font: inherit;
	cursor: pointer;
}

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

.hidden {
	display: none !important;
}

.container {
	width: 100%;
	max-width: 980px;
	margin: 0 auto;
	padding: 0 16px;
}

/* ===== 顶部栏 ===== */
.topbar {
	background: var(--card);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 10;
}

.topbar-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 56px;
	flex-wrap: wrap;
	padding-top: 6px;
	padding-bottom: 6px;
}

.brand {
	font-weight: 700;
	font-size: 1.1rem;
	color: var(--text);
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.brand::before {
	content: '';
	width: 26px;
	height: 26px;
	border-radius: 7px;
	background: linear-gradient(135deg, var(--accent), #7c3aed);
	display: inline-block;
}

.topbar-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

.user-area {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 34px;
}

.user-chip {
	font-weight: 600;
	font-size: 0.9rem;
	color: var(--text);
	background: var(--accent-soft);
	border-radius: 999px;
	padding: 4px 12px;
	max-width: 180px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* 用户名可跳转用户中心（服务端配置了 OIDC_ACCOUNT_URL）时给出可点击的提示 */
.user-chip-link:hover {
	text-decoration: underline;
}

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

/* ===== 按钮 / 控件 ===== */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	padding: 7px 14px;
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--text);
	background: var(--card);
	transition: filter 0.15s ease, background 0.15s ease;
	white-space: nowrap;
}

.btn:hover {
	filter: brightness(1.06);
}

.btn:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.btn.primary {
	background: var(--accent);
	color: var(--accent-text);
}

.btn.ghost {
	background: transparent;
	border-color: var(--border);
	color: var(--text);
}

.btn.small {
	padding: 4px 10px;
	font-size: 0.82rem;
}

.icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: transparent;
	color: var(--text);
	font-size: 1rem;
	/* 也用于 <a>（GitHub 入口）：链接不显示下划线 */
	text-decoration: none;
}

.icon-btn:hover {
	background: var(--accent-soft);
	text-decoration: none;
}

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

/* 图标按钮内的 SVG：固定尺寸并跟随按钮文字颜色 */
.icon-btn svg {
	width: 18px;
	height: 18px;
	display: block;
	fill: currentColor;
}

.select {
	font: inherit;
	color: var(--text);
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 6px 10px;
	max-width: 100%;
	/*
	 * 自定义下拉箭头：原生箭头紧贴右内边距且间距不可调，改为背景图后
	 * 用 right 10px 让箭头右边距与文字左边距（padding-left）保持一致。
	 */
	appearance: none;
	background-image: var(--select-arrow);
	background-repeat: no-repeat;
	background-position: right 10px center;
	background-size: 14px 14px;
	/* 右侧留出箭头宽度 + 间距，避免文字与箭头重叠 */
	padding-right: 30px;
}

.lang-select {
	min-width: 110px;
}

/* ===== 主区域 ===== */
main.container {
	padding-top: 28px;
	padding-bottom: 48px;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.page-title {
	font-size: 1.6rem;
	margin: 4px 0 2px;
}

.page-tagline {
	color: var(--text-dim);
	margin: 0 0 20px;
}

.card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	width: 100%;
	padding: 18px;
}

.config-error {
	color: var(--danger);
	text-align: center;
	padding: 2rem 1rem;
}

/* ===== 标签页 ===== */
.tabs {
	display: flex;
	gap: 4px;
	margin-bottom: 16px;
	border-bottom: 1px solid var(--border);
}

.tab {
	appearance: none;
	border: none;
	background: transparent;
	color: var(--text-dim);
	padding: 9px 14px;
	font-weight: 600;
	font-size: 0.95rem;
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
}

.tab.active {
	color: var(--accent);
	border-bottom-color: var(--accent);
}

/* ===== 语言行 ===== */
.lang-row {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	gap: 10px;
	align-items: end;
	margin-bottom: 14px;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 0;
}

.field-label {
	font-size: 0.8rem;
	color: var(--text-dim);
}

.field .select {
	width: 100%;
}

.swap-btn {
	width: 40px;
	height: 36px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: transparent;
	color: var(--accent);
	font-size: 1.15rem;
	margin-bottom: 0;
}

.swap-btn:hover {
	background: var(--accent-soft);
}

/* ===== 翻译面板 ===== */
.io-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--gap);
}

.io-box {
	border: 1px solid var(--border);
	border-radius: var(--radius);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--card);
}

.io-top {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	border-bottom: 1px solid var(--border);
	min-height: 38px;
}

.io-top .spacer {
	flex: 1;
}

.io-textarea {
	/*
	 * 不使用 flex 尺寸：flex-basis 会覆盖浏览器原生 resize 写入的 height，
	 * 导致右下角拖拽把手拖不动。高度由 JS 拖拽逻辑维护并持久化。
	 */
	flex: none;
	width: 100%;
	height: 190px;
	min-height: 120px;
	border: none;
	outline: none;
	resize: vertical;
	padding: 12px;
	font: inherit;
	font-size: 1rem;
	line-height: 1.6;
	background: transparent;
	color: var(--text);
}

.io-textarea::placeholder {
	color: var(--text-dim);
}

.detected {
	font-size: 0.8rem;
	color: var(--text-dim);
	min-height: 1em;
}

.output-label {
	font-weight: 600;
	font-size: 0.9rem;
	color: var(--accent);
}

.char-count {
	font-size: 0.78rem;
	color: var(--text-dim);
	font-variant-numeric: tabular-nums;
}

.char-count.over {
	color: var(--danger);
}

.status-line {
	font-size: 0.82rem;
	color: var(--danger);
	min-height: 1.2em;
	margin-top: 10px;
	padding-left: 2px;
}

/* ===== 多版本译文 ===== */
.alts {
	border-top: 1px dashed var(--border);
	padding: 10px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.alts-title {
	font-size: 0.8rem;
	color: var(--text-dim);
}

.alts-list {
	display: flex;
	flex-direction: column;
	gap: 6px;
	max-height: 150px;
	overflow-y: auto;
}

.alt-item {
	text-align: left;
	font: inherit;
	font-size: 0.9rem;
	line-height: 1.5;
	color: var(--text);
	background: var(--accent-soft);
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	padding: 6px 10px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.alt-item:hover {
	border-color: var(--accent);
}

.alt-item.active {
	border-color: var(--accent);
	background: var(--card);
}

/* ===== 文件翻译 ===== */
.file-picker {
	border: 2px dashed var(--border);
	border-radius: var(--radius);
	padding: 28px 16px;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s ease;
}

.file-picker:hover {
	border-color: var(--accent);
}

.file-icon {
	font-size: 2rem;
	margin-bottom: 6px;
}

.file-title {
	font-weight: 600;
}

.file-hint {
	font-size: 0.8rem;
	color: var(--text-dim);
	margin-top: 4px;
	word-break: break-all;
}

.file-meta {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
}

.file-name {
	font-weight: 600;
	max-width: 70%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.file-actions {
	margin-top: 14px;
	text-align: center;
}

/* ===== 页脚 ===== */
.footer {
	padding: 18px 16px 32px;
	color: var(--text-dim);
	font-size: 0.82rem;
	text-align: center;
}

.footer a {
	color: var(--text-dim);
	text-decoration: none;
	border-bottom: 1px dotted var(--border);
	transition: color 0.15s ease, border-color 0.15s ease;
}

.footer a:hover {
	color: var(--accent);
	border-bottom-color: var(--accent);
}

/* ===== 登录弹窗 ===== */
.modal-overlay {
	position: fixed;
	inset: 0;
	z-index: 200;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(16, 24, 40, 0.45);
	animation: modal-fade-in 0.15s ease;
}

.modal-dialog {
	display: flex;
	flex-direction: column;
	gap: 10px;
	/*
	 * 宽度跟随内容：默认 360px 会把较长的 SSO 提供商名挤成两行。
	 * 用 max-content 让弹框随按钮文字伸展，再由 max-width 兜住视口宽度
	 * （遮罩左右各有 16px 内边距）。
	 */
	width: max-content;
	min-width: min(92vw, 280px);
	max-width: calc(100vw - 32px);
	padding: 28px 24px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	animation: modal-pop-in 0.18s ease;
}

.modal-text {
	margin: 0 0 4px;
	text-align: center;
	font-size: 0.95rem;
	color: var(--text);
}

.modal-action {
	/* 由父级 flex 拉伸到弹框宽度，配合 max-content 弹框不会形成循环依赖 */
	align-self: stretch;
	padding: 11px 18px;
	font-size: 0.95rem;
	/*
	 * 弹框宽度是 max-content（受 max-width 限制），因此按钮文案只有在
	 * 超过视口上限时才会换行；正常情况下始终单行。
	 * overflow-wrap: anywhere 让没有空格的超长串也能在视口内断开。
	 */
	white-space: normal;
	overflow-wrap: anywhere;
	text-align: center;
}

body.modal-open {
	overflow: hidden;
}

@keyframes modal-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

@keyframes modal-pop-in {
	from {
		opacity: 0;
		transform: translateY(8px) scale(0.98);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* ===== Toast ===== */
.toast-box {
	position: fixed;
	bottom: 20px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	z-index: 100;
	width: min(92vw, 460px);
	pointer-events: none;
}

.toast {
	background: var(--card);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow);
	padding: 10px 16px;
	font-size: 0.9rem;
	max-width: 100%;
	animation: toast-in 0.18s ease;
}

.toast-error {
	border-left: 3px solid var(--danger);
}

.toast-success {
	border-left: 3px solid #12b76a;
}

@keyframes toast-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ===== 移动端适配 ===== */
@media (max-width: 720px) {
	.io-grid {
		grid-template-columns: 1fr;
	}

	.lang-row {
		grid-template-columns: 1fr auto 1fr;
	}

	.topbar-inner {
		flex-direction: column;
		align-items: stretch;
		padding-top: 10px;
		padding-bottom: 10px;
	}

	.topbar-actions {
		justify-content: space-between;
		flex-wrap: wrap;
	}

	.user-area {
		margin-left: auto;
	}
}

@media (max-width: 420px) {
	.lang-row {
		grid-template-columns: 1fr;
		align-items: stretch;
	}

	.swap-btn {
		width: 100%;
		height: 32px;
	}

	.card {
		padding: 14px;
	}
}

/*
 * 小屏滚动时收起顶栏
 *
 * 由 `src/frontend/scroll-chrome.ts` 给顶栏加 `.chrome-hidden`；断点必须与该模块
 * 导出的 MOBILE_QUERY 一致。
 *
 * 用 transform 而不是高度或 display：顶栏是 sticky，仍然占据布局中自身的空间，
 * 页面不会重排，正文也不会跳动。页脚是普通文档流内容，无需处理。
 */
@media (max-width: 720px) {
	.topbar {
		transition: transform 0.25s ease;
	}

	.topbar.chrome-hidden {
		transform: translateY(-100%);
	}
}

/* 用户要求减少动效时，收起/展开直接切换而不是滑出（避免前庭不适） */
@media (prefers-reduced-motion: reduce) {
	* {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}
