/*
Theme Name: MyERPSea
Description: 软海网（erpsea.com）子主题。基于 Twenty Twenty-Five，针对中文技术内容站做了三点改造：中英混排字体与行高、企业级可信配色、以及适合实操笔记的表格／卡片／代码样式。
Author: 软海网
Template: twentytwentyfive
Version: 1.9.5
Requires at least: 6.7
Requires PHP: 7.2
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: myerpsea
Tags: one-column, custom-colors, custom-menu, custom-logo, editor-style, featured-images, full-site-editing, block-patterns, rtl-language-support, sticky-post, threaded-comments, translation-ready, wide-blocks, block-styles, accessibility-ready, blog
*/

/*
 * 设计令牌（配色 / 字号 / 按钮 / 表格基础）都在 theme.json 里，
 * 因为块主题的 theme.json 同时作用于前台和编辑器，不会出现两套样式。
 * 这里只放 theme.json 表达不了的、针对中文排版的补充。
 */

/*
 * --- 宽度标准（只有两档，改宽度只认这两个值）-------------------------
 *   主网格 1280px  → theme.json settings.layout.wideSize，header / footer /
 *                    首页与 xakd 页的 hero 与各版块（contentSize 1280px）
 *   正文列 760px   → hero 内部 .hero-copy、列表条目、关于页（单行约 44 个汉字）
 * 新增或改版块时对齐上面两档，不要另造宽度。
 */

/* --- 中英混排：避开标点挤压与断行事故 ------------------------------- */
:where(p, li, dd, dt, figcaption, blockquote, td, th) {
	/* 中文标点不做压缩，混排时更稳定 */
	text-spacing-trim: normal;
	/* 长英文串、URL、代码片段不撑破容器 */
	overflow-wrap: anywhere;
	/* 现代浏览器下避免最后一行只剩一两个字 */
	text-wrap: pretty;
}

/* 标题不要 anywhere 断行，会拆坏词 */
:where(h1, h2, h3, h4, h5, h6) {
	overflow-wrap: break-word;
	hanging-punctuation: allow-end;
	text-wrap: balance;
}

/* --- 正文节奏 -------------------------------------------------------- */
/* 中文段落比英文更需要段间距，但主题默认块间距偏大，这里收一点 */
.wp-block-post-content > p + p {
	margin-top: 1.1em;
}

/* 正文里的列表与前后段落拉开呼吸 */
.wp-block-post-content > p + :where(ul, ol) {
	margin-top: 1.2em;
}

/* --- 表格：版本对比表在这个站是高频内容 ------------------------------ */
/* 窄屏下横向滚动，而不是把表格压变形 */
.wp-block-table {
	overflow-x: auto;
}

.wp-block-table table {
	min-width: 480px;
	border-collapse: collapse;
}

/* --- 代码：实操笔记里会贴快捷键、路径、命令 -------------------------- */
.wp-block-code code {
	white-space: pre-wrap;
	word-break: break-word;
}

/* --- 选中与焦点 ------------------------------------------------------ */
::selection {
	background-color: var(--wp--preset--color--accent-2);
	color: var(--wp--preset--color--contrast);
}

:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
	outline: 2px solid var(--wp--preset--color--accent-1);
	outline-offset: 3px;
	border-radius: 4px;
}

/* --- 动效 ------------------------------------------------------------ */
.wp-block-button__link,
.wp-block-navigation a,
.wp-block-post-title a,
.wp-block-latest-posts a {
	transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-button__link,
	.wp-block-navigation a,
	.wp-block-post-title a,
	.wp-block-latest-posts a {
		transition: none;
	}
}

/* --- 文章列表（首页列表 / 栏目归档） ---------------------------------- */
/* 标题是列表页唯一的主要可点区域：不加下划线，hover 才给颜色反馈，避免整页都是线。 */
.wp-block-post-title a {
	text-decoration: none;
}

.wp-block-post-title a:hover,
.wp-block-post-title a:focus-visible {
	color: var(--wp--preset--color--accent-1);
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 4px;
}

/* 分类名是次要信息，默认下划线太重 */
.wp-block-post-terms a {
	text-decoration: none;
}

.wp-block-post-terms a:hover {
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* 窄屏时「分类 + 日期」这一行可能挤在一起，让日期不换行、分类可换行 */
.wp-block-post-template .wp-block-group.is-layout-flex > .wp-block-post-date {
	flex-shrink: 0;
	white-space: nowrap;
}

/* 列表条目的分隔线在最后一条会多出一条，去掉收尾感 */
.wp-block-post-template > .wp-block-group:last-child {
	border-bottom-width: 0 !important;
}

/* --- 微信二维码折叠卡（「关于」版块联系方式） -------------------------- */
/* 用原生 <details> 实现，无 JS：点击展开、再点收起，键盘和读屏器都能用。 */
.wp-block-details.qr-toggle {
	margin-top: var(--wp--preset--spacing--30);
	border: 1px solid var(--wp--preset--color--accent-6);
	border-radius: 10px;
	background: var(--wp--preset--color--accent-5);
	overflow: hidden;
}

.wp-block-details.qr-toggle > summary {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	font-weight: 600;
	cursor: pointer;
	list-style: none;
	user-select: none;
	transition: background-color 0.15s ease;
}

.wp-block-details.qr-toggle > summary:hover {
	background: var(--wp--preset--color--accent-2);
}

/* 去掉 Safari 的默认三角 */
.wp-block-details.qr-toggle > summary::-webkit-details-marker {
	display: none;
}

/* 微信绿图标：内联 SVG，不用引外部图标文件 */
.wp-block-details.qr-toggle > summary::before {
	content: "";
	width: 22px;
	height: 22px;
	flex: 0 0 22px;
	border-radius: 6px;
	background-color: #07C160;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M9.6 4.5c-3.5 0-6.3 2.2-6.3 5 0 1.6.9 3 2.3 3.9l-.6 2 2.2-1.2c.8.2 1.6.4 2.4.4h.5a5.5 5.5 0 0 1-.2-1.5c0-2.7 2.5-4.9 5.6-4.9h.3c-.6-2.1-3-3.7-6.2-3.7z'/%3E%3Ccircle cx='7.4' cy='8' r='.8' fill='%2307C160'/%3E%3Ccircle cx='11.6' cy='8' r='.8' fill='%2307C160'/%3E%3Cpath fill='%23fff' d='M20.7 12.9c0-2.2-2.2-4-4.9-4s-4.9 1.8-4.9 4 2.2 4 4.9 4c.6 0 1.2-.1 1.7-.2l1.9 1-.5-1.6c1.1-.7 1.8-1.9 1.8-3.2z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 15px;
}

/* 展开指示箭头 */
.wp-block-details.qr-toggle > summary::after {
	content: "▾";
	margin-left: auto;
	font-size: 12px;
	color: var(--wp--preset--color--accent-4);
	transition: transform 0.15s ease;
}

.wp-block-details.qr-toggle[open] > summary {
	border-bottom: 1px solid var(--wp--preset--color--accent-6);
}

.wp-block-details.qr-toggle[open] > summary::after {
	transform: rotate(180deg);
}

/* 展开内容的呼吸感：左右留白与图上方间距 */
.wp-block-details.qr-toggle > summary + * {
	margin-top: var(--wp--preset--spacing--30);
}

.wp-block-details.qr-toggle > :not(summary) {
	padding-left: 16px;
	padding-right: 16px;
}

.wp-block-details.qr-toggle > :last-child {
	padding-bottom: 16px;
	margin-bottom: 0;
}

.wp-block-details.qr-toggle .wp-block-image img {
	border: 1px solid var(--wp--preset--color--accent-6);
	border-radius: 8px;
	/* 展开后二维码在卡片内水平居中 */
	display: block;
	margin-left: auto;
	margin-right: auto;
}

/* --- PC 端导航吸顶 ---------------------------------------------------- */
/*
 * 只在 ≥782px（WordPress 的移动端断点）生效：桌面屏高足够，导航常驻有用；
 * 手机上吸顶会吃掉约 10% 的可视高度，得不偿失，所以小屏让它跟随滚动。
 * 用 sticky 而不是 fixed：不脱离文档流，不会遮住首屏内容、也不会引起布局跳动。
 */
@media (min-width: 782px) {
	header.wp-block-template-part {
		position: sticky;
		top: 0;
		z-index: 100;
		/* 必须有实底，否则滚动时下面的文字会从导航里透出来 */
		background-color: var(--wp--preset--color--base, #fff);
		border-bottom: 1px solid var(--wp--preset--color--accent-6, rgba(20, 32, 46, .12));
	}

	/* 登录状态下 WordPress 有一条 32px 的固定管理条，吸顶要避开它 */
	body.admin-bar header.wp-block-template-part {
		top: 32px;
	}
}

/* 页内锚点（#某段）跳转时，标题不要被吸顶导航压住 */
:where(h1, h2, h3, h4):target,
:where(h1, h2, h3, h4)[id] {
	scroll-margin-top: 96px;
}

/*
 * 滚动后才出现投影，静止时不加——吸顶导航一直带阴影会显得页面脏。
 * 用滚动驱动动画实现，零 JS；不支持的浏览器（Safari/Firefox 旧版）
 * 只是没有投影，功能不受影响。
 */
@supports (animation-timeline: scroll()) {
	@media (min-width: 782px) and (prefers-reduced-motion: no-preference) {
		header.wp-block-template-part {
			animation: myerpsea-header-lift linear both;
			animation-timeline: scroll();
			animation-range: 0 90px;
		}
	}
}

@keyframes myerpsea-header-lift {
	from {
		box-shadow: 0 0 0 rgba(20, 32, 46, 0);
	}
	to {
		box-shadow: 0 1px 0 rgba(20, 32, 46, .05), 0 10px 28px rgba(20, 32, 46, .07);
	}
}

/* --- 收紧导航栏的上下留白 ---------------------------------------------- */
/*
 * 线上 header 的导航行带有 spacing-30（约 24px）的上下内边距，且是内联样式
 * （存在数据库里），普通选择器压不过，必须 !important。
 * 结构：header > group(alignfull) > group(has-global-padding) > group(导航行)
 * 收紧到 10px，导航更紧凑，首屏内容上移。
 */
header.wp-block-template-part :is(div, nav, figure).wp-block-group {
	padding-top: 0 !important;
	padding-bottom: 0 !important;
}

header.wp-block-template-part
	> .wp-block-group
	> .wp-block-group
	> .wp-block-group {
	padding-top: 10px !important;
	padding-bottom: 10px !important;
}

/* --- 导航与首屏之间零空隙 ---------------------------------------------- */
/*
 * 截图红框：导航下缘与首屏 hero 背景之间的一条白缝。
 * 来源有两处，这里一起封死：
 * 1) 父主题的 root padding / 模板根节点的多余 margin；
 * 2) 首个内容区（main 或 hero）被父主题样式附加的顶部间距。
 * 三条选择器各封一层结构，只影响"紧跟 header 的第一个块"。
 */
.wp-site-blocks {
	padding-top: 0 !important;
}

body {
	--wp--style--root--padding-top: 0px;
}

.wp-site-blocks > header.wp-block-template-part + *,
.wp-site-blocks > main.wp-block-group > .wp-block-group:first-child,
main .is-style-hero.alignfull:first-child {
	margin-top: 0 !important;
}

/* --- 页脚（parts/footer.html）配套样式 ---------------------------------- */
/*
 * 与整站统一：浅蓝底 + 1280 网格；站名与导航同款图标；
 * 链接默认无下划线、悬停变主题蓝，弱化灰用于说明文字。
 */
/* 站名 + 图标：导航栏与页脚共用同一套（图标相对本样式表取 assets/brand/） */
:is(header, footer).wp-block-template-part .wp-block-site-title {
	display: inline-flex;
	align-items: center;
	gap: 10px;
}

:is(header, footer).wp-block-template-part .wp-block-site-title::before {
	content: "";
	flex: 0 0 auto;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	background: url("assets/brand/icon-192.png") center / contain no-repeat;
}

footer.wp-block-template-part a {
	text-decoration: none;
}

footer.wp-block-template-part a:hover {
	color: var(--wp--preset--color--accent-1);
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.25em;
}

/* 列内间距收紧：链接项、眉题到链接、品牌区各行都更紧凑 */
footer.wp-block-template-part .wp-block-column > * + * {
	margin-top: 0.5rem !important;
}

/* 两个导航列整体推到页脚右侧，与品牌区形成左右两极 */
footer.wp-block-template-part .footer-nav > .wp-block-column:nth-child(2) {
	margin-left: auto !important;
}

/* --- 图片防变形与坏标记兜底 ---------------------------------------------- */
/*
 * 即使 img 被编辑器/转换工具写入残缺的 style（如 aspect-ratio/width 拼错），
 * 浏览器会丢弃无效样式；这里保证：任何图片都不会超出容器、
 * 不会被固定高度拉伸变形（width/height 属性 + height:auto = 自动保比例）。
 */
.wp-block-image img {
	height: auto;
	max-width: 100%;
}

/* --- 产品区宽度兜底 ------------------------------------------------------ */
/*
 * 若 xakd 页面曾在编辑器里保存过，pattern 会被"固化"进数据库，
 * 内联的旧宽度（如 1120px）会压过主题文件。这里用 !important
 * 把产品区容器强制拉回 1280 主网格，无论数据库存的是什么。
 */
main .is-products-section {
	max-width: 1280px !important;
	margin-left: auto !important;
	margin-right: auto !important;
}

/* --- hero 文案与主网格左缘对齐 ------------------------------------------ */
/*
 * hero 容器是 1280 网格（与下方卡片同宽），内部 .hero-copy 限宽 760 保证
 * 长文可读性；constrained 嵌套默认居中，这里强制靠左，
 * 使眉题/标题/按钮的左缘与下方区块的左缘完全重合。
 */
main .is-style-hero > .hero-copy {
	margin-left: 0 !important;
	margin-right: auto !important;
}

/* --- 关于页双卡对称 ------------------------------------------------------ */
/*
 * 两张卡各占一半宽度；列改为纵向 flex，卡片 flex:1 拉伸，
 * 内容少的一侧也撑满同高，左右边缘完全对齐。
 */
.wp-block-columns.is-even-cards > .wp-block-column {
	flex-basis: 50% !important;
	width: 50% !important;
	display: flex;
	flex-direction: column;
}

.wp-block-columns.is-even-cards > .wp-block-column > .wp-block-group.is-style-card {
	flex: 1 1 auto;
}

/* 小屏单列时恢复自然高度 */
@media (max-width: 781px) {
	.wp-block-columns.is-even-cards > .wp-block-column {
		flex-basis: auto !important;
		width: auto !important;
	}
}
