/* ==========================================================================
   Header 2026 — единая белая шапка ТехСтройМаркет
   Стили загружаются после template_styles и перекрывают старую шапку.
   ========================================================================== */

.tsm-header {
	--tsm-ink: #2b2f34;
	--tsm-ink-soft: #565d66;
	--tsm-muted: #838a93;
	--tsm-line: #e4e7ea;
	position: relative;
	z-index: 40;
	background: #fff;
	color: var(--tsm-ink);
}
.tsm-header *,
.tsm-header *::before,
.tsm-header *::after { box-sizing: border-box; }

.tsm-header .container {
	width: 100%;
	max-width: 1280px;
	margin: 0 auto;
	padding: 0 24px;
}

.tsm-header a { color: inherit; }
.tsm-header .tsm-icon { display: block; }

.tsm-visually-hidden {
	position: absolute !important;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Верхняя строка ------------------------------------------------- */

.tsm-header__top {
	background: #fff;
}
.tsm-header__top-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 24px;
	min-height: 38px;
}
.tsm-header__menu { min-width: 0; }

.tsm-header__contacts {
	position: relative;
	display: flex;
	align-items: center;
	gap: 18px;
	flex-shrink: 0;
}

.tsm-phone {
	display: inline-flex;
	align-items: center;
	gap: 2px;
}
.tsm-phone__number {
	display: inline-flex;
	align-items: center;
	min-height: 36px;
	padding: 2px 0;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.2;
	color: var(--tsm-ink);
	text-decoration: none;
	white-space: nowrap;
}
.tsm-phone__number:hover { color: var(--tsm-ink); }
.tsm-phone__number:focus-visible { outline: 2px solid var(--tsm-ink); outline-offset: 2px; border-radius: 4px; }
.tsm-phone__toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	min-height: 36px;
	padding: 0;
	background: none;
	border: 0;
	color: var(--tsm-muted);
	cursor: pointer;
}
.tsm-phone__toggle:focus-visible { outline: 2px solid var(--tsm-ink); outline-offset: 2px; border-radius: 4px; }
.tsm-phone__arrow { display: inline-flex; color: var(--tsm-muted); }
.tsm-phone__arrow .tsm-icon { width: 16px; height: 16px; transition: transform .18s ease; }
.tsm-phone__toggle[aria-expanded="true"] .tsm-phone__arrow .tsm-icon { transform: rotate(180deg); }

.tsm-header .tsm-header__callback {
	display: inline-flex;
	align-items: center;
	min-height: 36px;
	padding: 0;
	background: none;
	border: 0;
	font: inherit;
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1.2;
	color: #1b9fc6;
	text-decoration: none;
	white-space: nowrap;
}
.tsm-header .tsm-header__callback:hover {
	color: #147f9b;
	text-decoration: underline;
	text-underline-offset: 3px;
}
.tsm-header .tsm-header__callback:focus-visible {
	outline: 2px solid #1b9fc6;
	outline-offset: 3px;
	border-radius: 3px;
}

.tsm-contacts {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	z-index: 100;
	display: none;
	width: 320px;
	max-width: calc(100vw - 32px);
	margin-top: 0;
	padding: 16px 18px 16px;
	background: #fff;
	border: 1px solid var(--tsm-line);
	border-radius: 12px;
	box-shadow: 0 16px 40px rgba(20, 26, 33, .14);
}
.tsm-contacts.is-open { display: block; }

.tsm-contacts__inner {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
}
.tsm-contacts__head { display: none; }
.tsm-contacts__overlay { display: none; }
.tsm-contacts__phones {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
	width: 100%;
}
.tsm-contacts__phone {
	font-size: 15px;
	line-height: 1.6;
	text-decoration: none;
	color: var(--tsm-ink) !important;
}
.tsm-contacts__phone--main { margin-bottom: 4px; font-size: 18px; font-weight: 700; }
.tsm-contacts__phone:hover { color: var(--tsm-ink) !important; text-decoration: underline; }

.tsm-contacts__email {
	margin-top: 8px;
	font-size: 13px;
	line-height: 1.5;
	text-decoration: none;
	color: var(--tsm-ink-soft) !important;
}
.tsm-contacts__email:hover { color: var(--tsm-ink) !important; text-decoration: underline; }

.tsm-contacts__links {
	display: flex;
	flex-direction: column;
	gap: 3px;
	width: 100%;
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid #f0f1f3;
}
.tsm-contacts__link {
	font-size: 13px;
	line-height: 1.5;
	text-decoration: none;
	color: var(--tsm-ink-soft) !important;
}
.tsm-contacts__link:hover { color: var(--tsm-ink) !important; text-decoration: underline; }

.tsm-header .call-me { margin: 0; }
.tsm-header .call-me .callback-popup-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 42px;
	margin-top: 12px;
	padding: 8px 16px;
	border: 1px solid #cfd4d9;
	border-radius: 8px;
	background: #fff;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.2;
	color: var(--tsm-ink);
	text-decoration: none;
	transition: border-color .16s ease, background-color .16s ease;
}
.tsm-header .call-me .callback-popup-btn:hover {
	border-color: var(--tsm-ink);
	background: #f7f8f9;
	color: var(--tsm-ink);
}

/* ---------- Основная строка ------------------------------------------------ */

.tsm-header__main { position: relative; }

.tsm-header__main-inner {
	display: grid;
	grid-template-columns: auto auto minmax(260px, 1fr) auto;
	grid-template-areas: "logo catalog search personal";
	align-items: center;
	gap: 22px;
	padding: 12px 0 14px;
}

/* ---------- Строка категорий ----------------------------------------------- */

.tsm-header__cats {
	background: #fff;
	padding: 0 0 3px;
}
.tsm-header__cats-inner {
	display: flex;
	align-items: center;
	min-height: 29px;
}
.tsm-cats {
	display: flex;
	align-items: center;
	gap: 20px;
	min-width: 0;
	white-space: nowrap;
}
.tsm-cats__link {
	position: relative;
	display: inline-flex;
	align-items: center;
	min-height: 29px;
	font-size: 14px;
	line-height: 1.2;
	color: #3f454d;
	text-decoration: none;
	white-space: nowrap;
	transition: color .16s ease;
}
.tsm-cats__link:hover,
.tsm-cats__link:focus-visible {
	color: #1b9fc6;
	outline: none;
}
.tsm-cats__link.is-active {
	color: #1b9fc6;
}
.tsm-cats__link.is-active::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 2px;
	background: #1b9fc6;
	border-radius: 2px;
}

.tsm-header__logo { grid-area: logo; }
.tsm-catalog { grid-area: catalog; }
.tsm-header__search { grid-area: search; }
.tsm-header__personal { grid-area: personal; }

.tsm-header__logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; min-width: 0; }
.tsm-header__logo a { display: flex; align-items: center; text-decoration: none; }
.tsm-header__logo img {
	display: block;
	width: auto;
	max-width: 62px;
	max-height: 58px;
	height: auto;
}
.tsm-header__logo-text {
	display: flex;
	flex-direction: column;
	font-size: 17px;
	font-weight: 700;
	line-height: 1.15;
	letter-spacing: -.01em;
	color: var(--tsm-ink);
	white-space: nowrap;
}
.tsm-header__logo-text small {
	margin-top: 2px;
	font-size: 11px;
	font-weight: 400;
	letter-spacing: 0;
	color: var(--tsm-muted);
}

/* Поиск */
.tsm-header__search { min-width: 0; }

.tsm-header__search .search { width: 100%; max-width: none; min-width: 0; }
.tsm-header__search .search form {
	display: flex;
	align-items: center;
	width: 100%;
	min-width: 0;
	height: 54px;
	padding: 0;
	background: #fff;
	border: 1.5px solid #d5d9de;
	border-radius: 10px;
	transition: border-color .18s ease, box-shadow .18s ease;
}
.tsm-header__search .search form:focus-within {
	border-color: var(--tsm-ink);
	box-shadow: 0 0 0 3px rgba(43, 47, 52, .07);
}
.tsm-header__search .search input {
	flex: 1 1 auto;
	width: auto;
	min-width: 0;
	height: 100%;
	padding: 0 14px 0 16px;
	background: transparent;
	border: 0;
	border-radius: 10px 0 0 10px;
	font-size: 15px;
	line-height: 1.3;
	color: var(--tsm-ink);
	box-shadow: none;
	outline: none;
}
.tsm-header__search .search input::placeholder { color: #8a9199; opacity: 1; }
.tsm-header__search .search button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 54px;
	height: 100%;
	min-width: 54px;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 0;
	border-left: 1px solid #eef0f2;
	border-radius: 0 10px 10px 0;
	color: var(--tsm-ink);
	cursor: pointer;
}
.tsm-header__search .search button:hover { background: #f4f6f7; }
.tsm-header__search .search button:focus-visible { outline: 2px solid var(--tsm-ink); outline-offset: -3px; }
.tsm-header__search .search button::before { content: none; }
.tsm-search-icon { width: 20px; height: 20px; display: block; }

/* Личные разделы */
.tsm-header__personal {
	display: flex;
	align-items: center;
	gap: 2px;
	flex-shrink: 0;
}

.tsm-pitem {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	min-width: 64px;
	min-height: 54px;
	padding: 6px 8px;
	border-radius: 8px;
	font-size: 11px;
	line-height: 1.15;
	color: var(--tsm-ink-soft);
	text-decoration: none;
	white-space: nowrap;
	transition: color .16s ease, background-color .16s ease;
}
.tsm-pitem:hover,
.tsm-pitem:focus-visible { color: var(--tsm-ink); background: #f5f6f8; }
.tsm-pitem:focus-visible { outline: 2px solid var(--tsm-ink); outline-offset: 2px; }
.tsm-pitem__icon { position: relative; display: inline-flex; color: currentColor; }
.tsm-pitem__icon .tsm-icon { width: 22px; height: 22px; }
.tsm-pitem__label {
	display: block;
	max-width: 100px;
	overflow: hidden;
	text-overflow: ellipsis;
}
.tsm-pitem__label--short { display: none; }

/* Корзина внутри шапки */
.tsm-header .tsm-pitem--basket,
.tsm-header .tsm-pitem--basket .basket-container,
.tsm-header .tsm-pitem--basket .basket-container-items { display: contents; }

.tsm-header .basket-link.tsm-pitem {
	width: auto;
	height: auto;
	min-width: 64px;
	background: none;
	border-radius: 8px;
	font-size: 11px;
	color: var(--tsm-ink);
}
.tsm-header .basket-link.tsm-pitem:hover,
.tsm-header .basket-link.tsm-pitem:focus-visible {
	background: #f5f6f8;
	color: var(--tsm-ink);
}
.tsm-header .basket-link.tsm-pitem::before { content: none; }
.tsm-header .basket-link.tsm-pitem .basket-text { margin: 0; }
.tsm-header .basket-link.tsm-pitem .basket-text .name {
	font-size: 11px;
	line-height: 1.15;
	color: inherit;
}
.tsm-header .basket-link.tsm-pitem .basket-text .sum { display: none; }

.tsm-header .basket-link.tsm-pitem .items-counter {
	position: absolute;
	top: -6px;
	right: -14px;
	display: block;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	background: #1b9fc6;
	border-radius: 9px;
	box-shadow: 0 0 0 2px #fff;
	font-size: 10px;
	font-weight: 700;
	line-height: 18px;
	color: #fff;
	text-align: center;
}

/* ---------- Меню верхней строки ------------------------------------------- */

.tsm-header__tools { display: contents; }

.tsm-burger {
	display: none;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 6px 4px;
	background: none;
	border: 0;
	font: inherit;
	font-size: 14px;
	font-weight: 600;
	color: var(--tsm-ink);
	cursor: pointer;
}
.tsm-header__main-inner > .tsm-burger { grid-area: menu; justify-self: end; }
.tsm-burger .tsm-icon { width: 22px; height: 22px; }

.tsm-header .content-menu {
	width: auto;
	padding: 0;
	overflow: visible;
}
.tsm-header .content-menu > ul {
	display: flex;
	align-items: center;
	gap: 24px;
	font-size: 13.5px;
	letter-spacing: 0;
}
.tsm-header .content-menu > ul > .item {
	margin: 0;
	padding: 0;
}
.tsm-header .content-menu > ul > .item > a {
	position: relative;
	display: inline-block;
	padding: 7px 0 8px;
	font-size: 13.5px;
	color: #6b727b;
	text-decoration: none;
	white-space: nowrap;
	transition: color .16s ease;
}
.tsm-header .content-menu > ul > .item > a:hover,
.tsm-header .content-menu > ul > .item > a:focus-visible { color: var(--tsm-ink); }
.tsm-header .content-menu > ul > .item.active > a {
	color: var(--tsm-ink);
	font-weight: 500;
	box-shadow: none;
}
.tsm-header .content-menu > ul > .item.active > a::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 7px;
	height: 2px;
	background: #1b9fc6;
	border-radius: 2px;
}
.tsm-header .content-menu .sub-menu {
	display: none;
	position: absolute;
	top: 100%;
	left: -14px;
	min-width: 220px;
	padding: 6px 0;
	background: #fff;
	border: 1px solid var(--tsm-line);
	border-radius: 10px;
	box-shadow: 0 14px 32px rgba(20, 26, 33, .12);
	z-index: 50;
}
.tsm-header .content-menu .item:hover > .sub-menu,
.tsm-header .content-menu .item:focus-within > .sub-menu { display: block; }
.tsm-header .content-menu .sub-menu > .item { margin: 0; padding: 0; border: 0; }
.tsm-header .content-menu .sub-menu > .item > a {
	display: block;
	padding: 9px 16px;
	font-size: 14px;
	color: var(--tsm-ink-soft);
	text-decoration: none;
	white-space: nowrap;
}
.tsm-header .content-menu .sub-menu > .item > a:hover { background: #f5f6f8; color: var(--tsm-ink); }
.tsm-header .content-menu .sub-menu .sub-menu { top: -7px; left: 100%; }

/* Прокрутка каталога: шапка остаётся на месте */
.header_fixed {
	position: sticky;
	top: 0;
	left: auto;
	width: auto;
	z-index: 40;
}

/* ---------- Адаптив --------------------------------------------------------- */

@media (max-width: 1024px) {
	.tsm-header .container { padding: 0 20px; }
	.tsm-header__cats { display: none; }

	.tsm-header__main-inner {
		grid-template-columns: auto auto minmax(180px, 1fr) auto;
		grid-template-areas:
			"logo catalog search menu"
			"personal personal personal personal";
		row-gap: 10px;
	}
	.tsm-header__logo { grid-area: logo; }
	.tsm-header__search { grid-area: search; }
	.tsm-header__personal {
		grid-area: personal;
		width: 100%;
		justify-content: space-between;
		gap: 0;
		padding-top: 2px;
		border-top: 1px solid #f0f1f3;
	}
	.tsm-pitem { flex: 1 1 0; min-width: 0; }
	.tsm-pitem__label { max-width: 100%; }

	.tsm-burger { display: inline-flex; }
	.tsm-header__tools {
		display: flex;
		grid-area: menu;
		align-items: center;
		justify-self: end;
		gap: 10px;
	}
	.tsm-header__top {
		height: 0;
		min-height: 0;
		border: 0;
		overflow: visible;
	}
	.tsm-header__top-inner {
		height: 0;
		min-height: 0;
		padding: 0;
	}
	.tsm-header__top .tsm-header__contacts {
		position: static;
		margin: 0;
		padding: 0;
		border: 0;
	}
	.tsm-header__top .tsm-phone,
	.tsm-header__top .tsm-header__callback { display: none; }

	.tsm-header .content-menu {
		display: none;
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		z-index: 55;
		max-height: calc(100vh - 56px);
		overflow-y: auto;
		padding: 4px 20px 16px;
		background: #fff;
		border-top: 1px solid var(--tsm-line);
		box-shadow: 0 18px 32px rgba(20, 26, 33, .12);
	}
	.tsm-header.tsm-nav-open .content-menu { display: block; }
	.tsm-header .content-menu > ul {
		flex-direction: column;
		align-items: stretch;
		gap: 0;
	}
	.tsm-header .content-menu > ul > .item { border-bottom: 1px solid #f0f1f3; }
	.tsm-header .content-menu > ul > .item > a {
		display: block;
		padding: 14px 0;
		font-size: 16px;
	}
	.tsm-header .content-menu > ul > .item.active > a { font-weight: 600; }
	.tsm-header .content-menu > ul > .item.active > a::after { display: none; }
	.tsm-header .content-menu > ul .item .sub-menu {
		position: static;
		display: block;
		min-width: 0;
		padding: 0 0 10px 14px;
		background: none;
		border: 0;
		border-radius: 0;
		box-shadow: none;
	}
	.tsm-header .content-menu > ul .item .sub-menu > .item > a { padding: 8px 0; font-size: 14px; }
	.tsm-header .content-menu > ul .item .sub-menu .sub-menu { padding-left: 14px; }
}

@media (max-width: 767px) {
	.tsm-header .container { padding: 0 16px; }

	.tsm-header__top-inner { height: 0; min-height: 0; padding: 0; }
	.tsm-header__menu { display: none; }
	.tsm-phone { font-size: 14px; }

	.tsm-header__main-inner {
		grid-template-columns: auto minmax(0, 1fr) auto;
		grid-template-areas:
			"logo logo menu"
			"catalog search search"
			"personal personal personal";
		gap: 10px;
		padding: 6px 0 10px;
	}
	.tsm-header__logo { min-width: 0; }
	.tsm-header__logo img { max-height: 46px; max-width: 50px; }
	.tsm-header__logo-text { min-width: 0; font-size: 16px; }

	.tsm-header__search .search form { height: 52px; }
	.tsm-header__search .search input { font-size: 16px; }

	.tsm-header__personal { padding-top: 6px; }
	.tsm-pitem { min-height: 56px; padding: 6px 4px; font-size: 11px; }
	.tsm-pitem__label { max-width: 100%; font-size: 11px; }
	.tsm-pitem__label--full { display: none; }
	.tsm-pitem__label--short { display: block; }
	.tsm-header .basket-link.tsm-pitem,
	.tsm-header .basket-link.tsm-pitem .basket-text .name { font-size: 11px; }

	.tsm-header .content-menu { padding: 4px 16px 16px; }

	/* Контакты: нижняя панель поверх затемнённой страницы */
	.tsm-contacts {
		position: fixed;
		top: auto;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 210;
		display: none;
		width: auto;
		max-width: none;
		max-height: min(82vh, 640px);
		margin: 0;
		padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
		background: #fff;
		border: 0;
		border-radius: 16px 16px 0 0;
		box-shadow: 0 -14px 44px rgba(20, 26, 33, .28);
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
	}
	.tsm-contacts.is-open { display: block; }
	.tsm-contacts__overlay {
		position: fixed;
		inset: 0;
		z-index: 200;
		background: rgba(20, 26, 33, .5);
	}
	.tsm-contacts__overlay.is-open { display: block; }
	.tsm-contacts__head {
		position: sticky;
		top: 0;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		margin: 0 -16px 4px;
		padding: 6px 10px 6px 16px;
		background: #fff;
		border-bottom: 1px solid #eef0f2;
	}
	.tsm-contacts__head-title { font-size: 16px; font-weight: 700; color: var(--tsm-ink); }
	.tsm-contacts__close {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
		background: none;
		border: 0;
		border-radius: 8px;
		font-size: 28px;
		line-height: 1;
		color: var(--tsm-ink-soft);
		cursor: pointer;
	}
	.tsm-contacts__close:hover { background: #f2f4f6; color: var(--tsm-ink); }
	.tsm-contacts__inner { gap: 4px; padding: 8px 0 4px; }
	.tsm-contacts__phone { font-size: 17px; line-height: 1.5; padding: 2px 0; }
	.tsm-contacts__phone--main { margin-bottom: 8px; font-size: 22px; }
	.tsm-contacts__email { margin-top: 10px; font-size: 15px; }
	.tsm-contacts__links { margin-top: 12px; padding-top: 12px; }
	.tsm-contacts__link { font-size: 15px; line-height: 1.4; padding: 6px 0; }
	.tsm-header .call-me { width: 100%; }
	.tsm-header .call-me .callback-popup-btn {
		width: 100%;
		min-height: 48px;
		margin-top: 16px;
		font-size: 15px;
	}
}

@media (max-width: 359px) {
	.tsm-pitem__label,
	.tsm-header .basket-link.tsm-pitem .basket-text .name { font-size: 10px; }
}

body.tsm-contacts-lock {
	position: fixed;
	left: 0;
	right: 0;
	width: 100%;
	overflow: hidden;
}

@media (min-width: 1025px) {
	.tsm-header .tsm-header__main-inner {
		padding: 6px 24px 5px;
	}
}

/* Ноутбуки: верхняя строка остаётся в одну линию без «...» */
@media (min-width: 1025px) and (max-width: 1199px) {
	.tsm-header__top-inner { gap: 16px; }
	.tsm-header__contacts { gap: 12px; }
	.tsm-header .content-menu > ul { gap: 16px; }
	.tsm-header .content-menu > ul > .item > a { font-size: 13px; }
	.tsm-header .tsm-header__callback { font-size: 13px; }
	.tsm-cats { gap: 16px; }
	.tsm-cats__link { font-size: 13.5px; }
}
