/**
 * 前台下载卡片样式。
 *
 * 设计要点：
 * 1. 所有可调外观都走 CSS 变量（--wpdbd-*），由 PHP 按后台设置注入，主题也可覆盖。
 * 2. 不使用 !important，靠类名组合的选择器权重覆盖主题与核心样式。
 * 3. 使用逻辑属性（margin-inline / padding-inline）以支持 RTL。
 * 4. 尊重 prefers-reduced-motion。
 */

/* -------------------------------------------------------------------------
 * 变量默认值（PHP 会用后台设置覆盖同名变量）
 * ---------------------------------------------------------------------- */
.wpdbd-download-card {
	--wpdbd-bg: #ffffff;
	--wpdbd-fg: #1f2937;
	--wpdbd-muted: #8a96a3;
	--wpdbd-border: #e5e7eb;
	--wpdbd-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
	--wpdbd-shadow-hover: 0 10px 24px rgba(15, 23, 42, 0.1);
	--wpdbd-btn-bg: var(--wpdbd-accent, #0265a8);
	--wpdbd-btn-fg: #ffffff;
	--wpdbd-btn-border: transparent;
	--wpdbd-tag-bg: rgba(2, 101, 168, 0.08);
	--wpdbd-tag-fg: #475569;
	--wpdbd-radius: 32px;
	--wpdbd-pad-y: 12px;
	--wpdbd-pad-x: 18px;
	--wpdbd-icon-size: 3em;
	--wpdbd-clamp: 2;
	--wpdbd-lift: -2px;
	--wpdbd-anim: 0.18s;
	--wpdbd-arrow: 1.4s;
	--wpdbd-accent: #0265a8;
}

/* -------------------------------------------------------------------------
 * 卡片主体
 * ---------------------------------------------------------------------- */
.wp-block-file.wpdbd-download-card,
.wpdbd-download-card {
	box-sizing: border-box;
	container-type: inline-size;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 14px;
	padding: var(--wpdbd-pad-y) var(--wpdbd-pad-x);
	border: 1px solid var(--wpdbd-border);
	border-radius: var(--wpdbd-radius);
	background: var(--wpdbd-bg);
	color: var(--wpdbd-fg);
	box-shadow: var(--wpdbd-shadow);
	transition: transform var(--wpdbd-anim) ease, box-shadow var(--wpdbd-anim) ease, border-color var(--wpdbd-anim) ease;
}

.wp-block-file.wpdbd-download-card {
	margin-block: 0;
}

.wpdbd-download-card:hover {
	transform: translateY(var(--wpdbd-lift));
	box-shadow: var(--wpdbd-shadow-hover);
	border-color: var(--wpdbd-border);
}

/* 文件链接 */
.wpdbd-download-card a.wpdbd-file-link {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: 1 1 auto;
	min-width: 0;
	color: inherit;
	text-decoration: none;
	box-shadow: none;
}

.wpdbd-download-card a.wpdbd-file-link:focus-visible {
	outline: 2px solid var(--wpdbd-accent);
	outline-offset: 3px;
	border-radius: 8px;
}

/* -------------------------------------------------------------------------
 * 图标：角标 / 线性图标 / 原色图标
 * ---------------------------------------------------------------------- */
.wpdbd-download-card .wpdbd-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: var(--wpdbd-icon-size);
	height: var(--wpdbd-icon-size);
	line-height: 1;
	transition: transform var(--wpdbd-anim) ease, filter var(--wpdbd-anim) ease;
}

.wpdbd-download-card .wpdbd-icon--svg {
	color: var(--wpdbd-accent);
}

.wpdbd-download-card .wpdbd-icon--svg svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wpdbd-download-card .wpdbd-icon--native img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.wpdbd-download-card .wpdbd-icon--mask {
	color: var(--wpdbd-accent);
}

.wpdbd-download-card .wpdbd-icon-mask {
	display: block;
	width: 100%;
	height: 100%;
	background-color: currentColor;
	-webkit-mask-image: var(--wpdbd-icon-url);
	mask-image: var(--wpdbd-icon-url);
	-webkit-mask-position: center;
	mask-position: center;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-size: contain;
	mask-size: contain;
}

/* 角标：圆角方块 + 扩展名文字 */
.wpdbd-download-card .wpdbd-icon--badge {
	border-radius: calc(var(--wpdbd-icon-size) * 0.26);
	background: var(--wpdbd-tag-bg);
	color: var(--wpdbd-accent);
	box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

@supports (background: color-mix(in srgb, red 10%, transparent)) {
	.wpdbd-download-card .wpdbd-icon--badge {
		background: color-mix(in srgb, var(--wpdbd-accent) 13%, transparent);
	}
}

.wpdbd-download-card .wpdbd-icon-text {
	font-size: calc(var(--wpdbd-icon-size) * 0.28);
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1;
	text-transform: uppercase;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * 文本区
 * ---------------------------------------------------------------------- */
.wpdbd-download-card .wpdbd-file-text {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
	flex: 1 1 auto;
}

.wpdbd-download-card .wpdbd-file-name {
	display: -webkit-box;
	-webkit-line-clamp: var(--wpdbd-clamp);
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: 1.06em;
	font-weight: 600;
	line-height: 1.35;
	overflow-wrap: anywhere;
	transition: color var(--wpdbd-anim) ease;
}

.wpdbd-download-card .wpdbd-file-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	color: var(--wpdbd-muted);
	font-size: 0.86em;
	line-height: 1.35;
}

.wpdbd-download-card .wpdbd-meta-sep {
	opacity: 0.55;
}

.wpdbd-download-card .wpdbd-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-block-start: 1px;
}

.wpdbd-download-card .wpdbd-tag {
	display: inline-block;
	padding: 1px 8px;
	border-radius: 999px;
	background: var(--wpdbd-tag-bg);
	color: var(--wpdbd-tag-fg);
	font-size: 0.76em;
	line-height: 1.6;
	white-space: nowrap;
}

.wpdbd-download-card .wpdbd-note {
	color: var(--wpdbd-muted);
	font-size: 0.84em;
	line-height: 1.45;
}

/* -------------------------------------------------------------------------
 * 下载按钮
 * ---------------------------------------------------------------------- */
.wpdbd-download-card a.wpdbd-download-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	flex: 0 0 auto;
	margin-inline-start: auto;
	padding: 0.55em 1.15em;
	border: 1px solid var(--wpdbd-btn-border);
	border-radius: calc(var(--wpdbd-radius) / 1.6);
	background: var(--wpdbd-btn-bg);
	color: var(--wpdbd-btn-fg);
	font-size: 0.95em;
	font-weight: 600;
	line-height: 1.5;
	text-decoration: none;
	white-space: nowrap;
	box-shadow: none;
	transition: transform var(--wpdbd-anim) ease, box-shadow var(--wpdbd-anim) ease, filter var(--wpdbd-anim) ease;
}

.wpdbd-download-card a.wpdbd-download-link:hover {
	filter: brightness(1.06);
	box-shadow: 0 8px 16px rgba(15, 23, 42, 0.16);
	color: var(--wpdbd-btn-fg);
}

.wpdbd-download-card a.wpdbd-download-link:focus-visible {
	outline: 2px solid var(--wpdbd-accent);
	outline-offset: 3px;
}

.wpdbd-download-card .wpdbd-download-icon {
	display: inline-flex;
	flex: 0 0 auto;
	width: 1.25em;
	height: 1.25em;
	color: inherit;
}

.wpdbd-download-card .wpdbd-download-icon svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wpdbd-download-card .wpdbd-download-icon-arrow {
	transform-box: fill-box;
	transform-origin: center;
}

@media (prefers-reduced-motion: no-preference) {
	.wpdbd-download-card:hover .wpdbd-download-icon-arrow {
		animation: wpdbd-download-arrow var(--wpdbd-arrow) infinite ease-in-out;
	}

	.wpdbd-download-card:hover .wpdbd-icon {
		transform: translateY(-1px);
	}
}

@keyframes wpdbd-download-arrow {
	0% {
		transform: translateY(-4px);
		opacity: 0;
	}

	18% {
		transform: translateY(-1px);
		opacity: 1;
	}

	82% {
		transform: translateY(2px);
		opacity: 1;
	}

	100% {
		transform: translateY(4px);
		opacity: 0;
	}
}

/* -------------------------------------------------------------------------
 * 复制链接按钮（仅在 JS 可用时显示）
 * ---------------------------------------------------------------------- */
.wpdbd-download-card .wpdbd-copy {
	display: none;
	align-items: center;
	justify-content: center;
	gap: 5px;
	flex: 0 0 auto;
	width: 2.1em;
	height: 2.1em;
	padding: 0;
	border: 1px solid var(--wpdbd-border);
	border-radius: 50%;
	background: transparent;
	color: var(--wpdbd-muted);
	cursor: pointer;
	transition: color var(--wpdbd-anim) ease, border-color var(--wpdbd-anim) ease;
}

html.wpdbd-js .wpdbd-download-card .wpdbd-copy {
	display: inline-flex;
}

.wpdbd-download-card .wpdbd-copy svg {
	display: block;
	width: 1.05em;
	height: 1.05em;
}

.wpdbd-download-card .wpdbd-copy-text {
	display: none;
}

.wpdbd-download-card .wpdbd-copy:hover,
.wpdbd-download-card .wpdbd-copy:focus-visible {
	color: var(--wpdbd-accent);
	border-color: var(--wpdbd-accent);
	outline: none;
}

.wpdbd-download-card .wpdbd-copy[data-wpdbd-copied] {
	color: #16a34a;
	border-color: #16a34a;
}

/* -------------------------------------------------------------------------
 * 无下载按钮形态
 * ---------------------------------------------------------------------- */
.wpdbd-download-card.wpdbd-no-download-button {
	container-type: normal;
	display: inline-flex;
	align-items: center;
	width: auto;
	max-width: 100%;
}

.wpdbd-download-card.wpdbd-no-download-button a.wpdbd-file-link {
	flex: none;
	width: auto;
	max-width: 100%;
}

.wpdbd-download-card.wpdbd-no-download-button .wpdbd-file-name {
	display: block;
	-webkit-line-clamp: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* -------------------------------------------------------------------------
 * 失效状态
 * ---------------------------------------------------------------------- */
.wpdbd-download-card.wpdbd-dead {
	opacity: 0.72;
}

.wpdbd-download-card.wpdbd-dead a.wpdbd-download-link {
	background: transparent;
	color: var(--wpdbd-muted);
	border: 1px dashed var(--wpdbd-border);
	cursor: not-allowed;
	filter: none;
	box-shadow: none;
}

/* -------------------------------------------------------------------------
 * 风格预设
 * ---------------------------------------------------------------------- */
.wpdbd-download-card.wpdbd-preset-minimal,
.wpdbd-download-card.is-style-wpdbd-minimal {
	padding-inline: 2px;
	padding-block: 10px;
	border: 0;
	border-bottom: 1px solid var(--wpdbd-border);
	border-radius: 0;
	background: transparent;
	box-shadow: none;
}

.wpdbd-download-card.wpdbd-preset-minimal:hover,
.wpdbd-download-card.is-style-wpdbd-minimal:hover {
	transform: none;
	box-shadow: none;
}

.wpdbd-download-card.wpdbd-preset-minimal a.wpdbd-download-link,
.wpdbd-download-card.is-style-wpdbd-minimal a.wpdbd-download-link {
	background: transparent;
	color: var(--wpdbd-accent);
	border: 0;
	padding-inline: 0;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.wpdbd-download-card.wpdbd-preset-minimal a.wpdbd-download-link:hover,
.wpdbd-download-card.is-style-wpdbd-minimal a.wpdbd-download-link:hover {
	filter: none;
	box-shadow: none;
}

.wpdbd-download-card.wpdbd-preset-pill,
.wpdbd-download-card.is-style-wpdbd-pill {
	border-radius: 999px;
	padding-block: calc(var(--wpdbd-pad-y) * 0.7);
}

.wpdbd-download-card.wpdbd-preset-pill a.wpdbd-download-link,
.wpdbd-download-card.is-style-wpdbd-pill a.wpdbd-download-link {
	border-radius: 999px;
}

/* -------------------------------------------------------------------------
 * 窄容器自适应
 * ---------------------------------------------------------------------- */
@container (max-width: 520px) {
	.wpdbd-download-card:not(.wpdbd-no-download-button) a.wpdbd-file-link {
		flex: 0 0 100%;
	}

	.wpdbd-download-card:not(.wpdbd-no-download-button) a.wpdbd-download-link {
		margin-inline: auto;
	}
}

@media (max-width: 640px) {
	.wpdbd-download-card {
		align-items: flex-start;
	}

	.wpdbd-download-card a.wpdbd-download-link {
		width: 100%;
	}

	.wpdbd-download-card .wpdbd-copy {
		display: none;
	}
}

/* -------------------------------------------------------------------------
 * 附件链接（可选功能）
 * ---------------------------------------------------------------------- */
.wpdbd-attachment-link {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	line-height: 1.2;
	color: inherit;
	text-decoration: none;
}

.wpdbd-attachment-link .wpdbd-file-text {
	display: inline-flex;
	flex-direction: column;
	gap: 2px;
}

.wpdbd-attachment-link .wpdbd-icon {
	width: 1.6em;
	height: 1.6em;
}

.wpdbd-attachment-link .wpdbd-file-name {
	font-size: 1.06em;
}

/* -------------------------------------------------------------------------
 * 弹窗
 * ---------------------------------------------------------------------- */
.wpdbd-modal[hidden] {
	display: none;
}

.wpdbd-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

.wpdbd-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(15, 23, 42, 0.55);
	backdrop-filter: blur(2px);
}

.wpdbd-modal-dialog {
	position: relative;
	width: min(420px, 100%);
	max-height: 90vh;
	overflow: auto;
	padding: 22px;
	border-radius: 18px;
	background: #ffffff;
	color: #1f2937;
	box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
	text-align: start;
}

.wpdbd-modal-close {
	position: absolute;
	inset-block-start: 8px;
	inset-inline-end: 10px;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #8a96a3;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
}

.wpdbd-modal-close:hover {
	background: rgba(15, 23, 42, 0.06);
	color: #1f2937;
}

.wpdbd-modal-title {
	margin: 0 0 14px;
	font-size: 1.02em;
	font-weight: 600;
	line-height: 1.4;
	overflow-wrap: anywhere;
}

.wpdbd-modal-field {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-block-end: 10px;
	padding: 10px 12px;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	background: #f8fafc;
}

.wpdbd-modal-field[hidden] {
	display: none;
}

.wpdbd-modal-label {
	flex: 0 0 auto;
	color: #64748b;
	font-size: 0.86em;
}

.wpdbd-modal-value {
	flex: 1 1 auto;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 1.02em;
	font-weight: 600;
	letter-spacing: 0.04em;
	overflow-wrap: anywhere;
}

.wpdbd-modal-copy {
	flex: 0 0 auto;
	padding: 4px 10px;
	border: 1px solid #cbd5e1;
	border-radius: 7px;
	background: #ffffff;
	color: #334155;
	font-size: 0.82em;
	cursor: pointer;
}

.wpdbd-modal-copy:hover {
	border-color: #0265a8;
	color: #0265a8;
}

.wpdbd-modal-qr {
	text-align: center;
	margin-block: 6px 14px;
}

.wpdbd-modal-qr[hidden] {
	display: none;
}

.wpdbd-modal-qr-canvas {
	display: inline-block;
	max-width: 100%;
	padding: 10px;
	border-radius: 12px;
	background: #ffffff;
}

.wpdbd-modal-qr-canvas svg,
.wpdbd-modal-qr-canvas img,
.wpdbd-modal-qr-canvas canvas {
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
}

.wpdbd-modal-qr-tip {
	margin: 8px 0 0;
	color: #64748b;
	font-size: 0.82em;
}

.wpdbd-modal-go {
	display: block;
	padding: 11px 16px;
	border-radius: 10px;
	background: #0265a8;
	color: #ffffff;
	font-weight: 600;
	text-align: center;
	text-decoration: none;
}

.wpdbd-modal-go:hover {
	filter: brightness(1.06);
	color: #ffffff;
}

/* 复制成功提示 */
.wpdbd-toast {
	position: fixed;
	inset-block-end: 24px;
	inset-inline: 0;
	margin-inline: auto;
	width: fit-content;
	max-width: calc(100% - 32px);
	padding: 9px 16px;
	border-radius: 999px;
	background: rgba(15, 23, 42, 0.88);
	color: #ffffff;
	font-size: 0.86em;
	z-index: 100001;
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
}

.wpdbd-toast.is-visible {
	opacity: 1;
	transform: translateY(0);
}

/* 深色模式下的弹窗（由 JS 依据卡片实际背景色决定是否加类） */
body.wpdbd-dark-modal .wpdbd-modal-dialog {
	background: #2b2b2b;
	color: #ededed;
}

body.wpdbd-dark-modal .wpdbd-modal-field {
	border-color: #3f3f3f;
	background: #333333;
}

body.wpdbd-dark-modal .wpdbd-modal-copy {
	border-color: #555555;
	background: #3a3a3a;
	color: #ededed;
}

body.wpdbd-dark-modal .wpdbd-modal-label,
body.wpdbd-dark-modal .wpdbd-modal-qr-tip {
	color: #a8a8a8;
}

body.wpdbd-dark-modal .wpdbd-modal-close {
	color: #a8a8a8;
}

/* -------------------------------------------------------------------------
 * 无障碍
 * ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.wpdbd-download-card,
	.wpdbd-download-card * {
		transition: none;
		animation: none;
	}

	.wpdbd-download-card:hover {
		transform: none;
	}
}

.wpdbd-download-card .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * 编辑器内容区近似预览
 *
 * 本文件通过 wp_enqueue_block_style() 注册，会被注入区块编辑器 iframe，
 * 因此这里的 .editor-styles-wrapper 规则只在编辑器内生效。
 * 编辑器中的区块是核心 file 区块的静态标记，没有卡片类名，
 * 这里用近似样式让作者大致看到前台效果（图标与信息行由前台渲染）。
 * ---------------------------------------------------------------------- */
.editor-styles-wrapper .wp-block-file {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 14px;
	padding: 12px 18px;
	border: 1px solid #e5e7eb;
	border-radius: 32px;
	background: #fff;
	box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.editor-styles-wrapper .wp-block-file .wp-block-file__button {
	border-radius: 20px;
}
