/* BLAGO — склад зеркал. Мобильная вёрстка, крупный шрифт, работа одной рукой.
 * Строгий стиль: без градиентов и теней, ровные углы. Светлая и тёмная темы на переменных:
 * тёмная включается по настройке телефона или кнопкой в шапке (html[data-theme]). */
:root {
	color-scheme: light;
	--bg: #f4f5f7;
	--card: #ffffff;
	--card-alt: #f8f9fb;
	--text: #14171f;
	--muted: #5b6272;
	--line: #d9dce3;
	--line-strong: #b9bec9;
	--accent: #1f3a8a;
	--accent-dark: #172c69;
	--accent-soft: #e8ecf6;
	--on-accent: #ffffff;
	--focus: #9fb3e6;
	--top-bg: #12151c;
	--top-text: #ffffff;
	--th-bg: #eef0f4;
	--group-bg: #e3e6ec;
	--ok: #146c3c;
	--ok-bg: #e2f3e9;
	--err: #b42318;
	--err-bg: #fbe5e3;
	--warn: #8a5300;
	--warn-bg: #fdf0d8;
	--zero: #f6cfd2;
	--neg: #d92d20;
	--ship-before: #fbe3c4;
	--ship-ch: #fdf0e3;
	--ship-ch-cell: #fff8e8;
	--ship-after: #d3f0dc;
	--radius: 6px;
}

/* Тёмная тема: по настройке системы, если пользователь не выбрал светлую */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #0f1115;
		--card: #171a21;
		--card-alt: #1c2029;
		--text: #e7e9ee;
		--muted: #9aa1b0;
		--line: #2a2f3a;
		--line-strong: #3b4250;
		--accent: #4263eb;
		--accent-dark: #5c7cfa;
		--accent-soft: #1f2740;
		--on-accent: #ffffff;
		--focus: #3d5292;
		--top-bg: #0a0c10;
		--top-text: #e7e9ee;
		--th-bg: #1e222b;
		--group-bg: #252a35;
		--ok: #4cc38a;
		--ok-bg: #12301f;
		--err: #f97066;
		--err-bg: #3a1714;
		--warn: #f5b041;
		--warn-bg: #352610;
		--zero: #4a1f24;
		--neg: #b42318;
		--ship-before: #3a2c18;
		--ship-ch: #2f2618;
		--ship-ch-cell: #241f16;
		--ship-after: #173322;
	}
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #0f1115;
	--card: #171a21;
	--card-alt: #1c2029;
	--text: #e7e9ee;
	--muted: #9aa1b0;
	--line: #2a2f3a;
	--line-strong: #3b4250;
	--accent: #4263eb;
	--accent-dark: #5c7cfa;
	--accent-soft: #1f2740;
	--on-accent: #ffffff;
	--focus: #3d5292;
	--top-bg: #0a0c10;
	--top-text: #e7e9ee;
	--th-bg: #1e222b;
	--group-bg: #252a35;
	--ok: #4cc38a;
	--ok-bg: #12301f;
	--err: #f97066;
	--err-bg: #3a1714;
	--warn: #f5b041;
	--warn-bg: #352610;
	--zero: #4a1f24;
	--neg: #b42318;
	--ship-before: #3a2c18;
	--ship-ch: #2f2618;
	--ship-ch-cell: #241f16;
	--ship-after: #173322;
}

* { box-sizing: border-box; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 18px;
	line-height: 1.4;
	-webkit-tap-highlight-color: transparent;
	/* Ничто не должно растягивать страницу вбок на телефоне */
	overflow-x: clip;
}

a { color: var(--accent); }

header.top {
	position: sticky;
	top: 0;
	z-index: 20;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 16px;
	background: var(--top-bg);
	color: var(--top-text);
	border-bottom: 1px solid #000;
}
header.top a { color: var(--top-text); text-decoration: none; }
header.top .brand { display: flex; align-items: baseline; gap: 8px; }
header.top .brand b { font-size: 22px; font-weight: 800; letter-spacing: .18em; }
header.top .brand span { font-size: 13px; opacity: .6; letter-spacing: .04em; }
header.top .who { margin-left: auto; text-align: right; font-size: 15px; line-height: 1.2; }
header.top .who small { display: block; opacity: .6; }
header.top form { margin: 0; }
header.top button.exit, header.top button.theme {
	min-height: 38px; padding: 6px 12px; font-size: 15px; font-weight: 600;
	background: transparent; color: var(--top-text); border: 1px solid rgba(255, 255, 255, .3);
}
header.top button.exit:hover, header.top button.theme:hover { background: rgba(255, 255, 255, .1); }
header.top button.theme { min-width: 38px; padding: 6px 8px; font-size: 17px; }

nav.menu {
	display: flex; flex-wrap: wrap; gap: 6px;
	padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
nav.menu a {
	flex: 0 0 auto; display: inline-flex; align-items: center; padding: 8px 14px; min-height: 42px;
	border-radius: var(--radius); color: var(--text); text-decoration: none;
	border: 1px solid var(--line); font-size: 16px; font-weight: 600; white-space: nowrap;
}
nav.menu a:hover { background: var(--accent-soft); }
nav.menu a.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

main { padding: 14px; max-width: 1200px; margin: 0 auto; }

h1 { font-size: 24px; margin: 4px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 18px 0 10px; }
.card > h2:first-child, .card > .line:first-child h2 { margin-top: 0; }

.card {
	background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
	padding: 16px; margin-bottom: 12px;
	/* Широкая таблица прокручивается внутри карточки, а не растягивает страницу */
	overflow-x: auto;
}

label { display: block; margin: 10px 0 4px; font-weight: 600; }

input[type=text], input[type=number], input[type=password], input[type=search],
input[type=date], input[type=time], select, textarea {
	width: 100%; min-height: 48px; padding: 10px 12px; font-size: 18px;
	border: 1px solid var(--line-strong); border-radius: var(--radius);
	background: var(--card); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); border-color: var(--accent); }

button, .btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	min-height: 48px; padding: 10px 18px; font-size: 18px; font-weight: 600;
	border: 1px solid var(--accent); border-radius: var(--radius);
	background: var(--accent); color: var(--on-accent);
	cursor: pointer; text-decoration: none; transition: background .15s;
}
button:hover, .btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary { background: var(--card); color: var(--text); border-color: var(--line-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--accent-soft); }
button.danger, .btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
button.big, .btn.big { width: 100%; min-height: 68px; font-size: 21px; }
button.big.secondary, .btn.big.secondary { background: var(--card); }
button:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row > * { flex: 1 1 200px; }
.row.tight > * { flex: 0 0 auto; }

.muted { color: var(--muted); font-size: 15px; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 14px; }

.msg { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px; font-weight: 600; border-left: 4px solid currentColor; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.err { background: var(--err-bg); color: var(--err); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--th-bg); font-size: 14px; font-weight: 700; position: sticky; top: 0; z-index: 2; }
tr.header-row td { font-weight: 700; background: var(--group-bg); text-transform: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.zero { background: var(--zero); }
/* Строки с цветом подгруппы из TOP — цвета светлые, текст на них всегда тёмный */
/* В строке с цветом подгруппы ячейки всегда в светлых цветах, как в гугл-таблице, и в тёмной теме тоже */
tr[style*="background"], td[style*="background"] {
	color: #14171f;
	--zero: #f6cfd2; --ship-ch-cell: #fff8e8; --neg: #d92d20; --accent: #1f3a8a;
}

.badge {
	display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 4px;
	font-size: 14px; font-weight: 600; background: var(--group-bg); color: var(--text);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* Экран сканирования */
.scan-result { padding: 20px 18px 20px 62px; border-radius: var(--radius); font-size: 22px; font-weight: 700; margin-bottom: 12px; position: relative; }
.scan-result:empty { display: none; }
.scan-result.ok { background: var(--ok-bg); color: var(--ok); border: 2px solid var(--ok); }
.scan-result.err { background: var(--err-bg); color: var(--err); border: 2px solid var(--err); }
.scan-result.ok::before, .scan-result.err::before {
	position: absolute; left: 16px; top: 18px; width: 32px; height: 32px; border-radius: 4px;
	display: flex; align-items: center; justify-content: center; color: var(--card); font-size: 20px;
}
.scan-result.ok::before { content: "✓"; background: var(--ok); }
.scan-result.err::before { content: "✕"; background: var(--err); }
.scan-result .sub { font-size: 17px; font-weight: 500; margin-top: 6px; }
.scan-input { font-size: 22px; min-height: 56px; }
.scan-history { list-style: none; padding: 0; margin: 0; }
.scan-history li { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 16px; }
.scan-history li.ok { border-left: 4px solid var(--ok); }
.scan-history li.err { border-left: 4px solid var(--err); }

/* Прогресс задач */
.progress { height: 10px; background: var(--group-bg); border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); }

.task { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: var(--card-alt); }
.task.done { background: var(--ok-bg); border-color: var(--ok); }
.task .line, .line { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.task .name { font-weight: 700; font-size: 19px; }

/* Камера */
#camera-box { width: 100%; max-width: 420px; margin: 0 auto; }
#camera-box .camera-frame { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; }
#camera-box video { display: block; width: 100%; }
/* Прицел совпадает с полосой кадра, которая уходит в распознавание (15% сверху и снизу отрезаются) */
#camera-box .camera-aim {
	position: absolute; left: 4%; right: 4%; top: 15%; bottom: 15%;
	border: 3px solid rgba(255, 255, 255, .9); border-radius: 4px;
	box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); pointer-events: none;
}
#camera-box .camera-aim::after {
	content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: #e53935;
}

.table-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table { min-width: 560px; }
.table-wrap td.sticky, .table-wrap th.sticky {
	position: sticky; left: 0; background: var(--card); z-index: 3; box-shadow: 1px 0 0 var(--line);
}
.table-wrap th.sticky { z-index: 4; background: var(--th-bg); }
.dense td, .dense th { padding: 1px 8px; font-size: 13px; line-height: 1.3; }
.dense tr.header-row td { padding: 3px 8px; }
.table-wrap .mini { min-height: 26px; padding: 2px 8px; font-size: 13px; font-weight: 600; }
.table-wrap thead th { padding: 4px 8px; font-size: 13px; }
.stock-controls .card { padding: 10px; }

.hint { font-size: 15px; color: var(--muted); margin-top: 4px; }

/* Компактная форма закрытия смены прямо в табло */
.inline-form input, .inline-form select { min-height: 34px; font-size: 14px; padding: 4px 8px; }
.inline-form button { min-height: 34px; font-size: 14px; padding: 4px 10px; }
a.card { display: block; color: inherit; text-decoration: none; transition: border-color .15s; }
a.card:hover { border-color: var(--accent); }
a.card h2 { color: var(--text); margin-top: 0; }
a.card.tile { border-left: 4px solid var(--accent); }

/* Погрузка: плитки каналов и выбор машины */
.channel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.channel-grid form { margin: 0; }
.channel-btn { width: 100%; min-height: 92px; font-size: 24px; font-weight: 800; letter-spacing: .03em; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.choice {
	display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 14px 18px; min-height: 56px;
	border: 2px solid var(--line); border-radius: var(--radius); font-size: 20px; cursor: pointer; background: var(--card);
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: 22px; height: 22px; }
.counter { font-size: 20px; }
.counter b { font-size: 30px; color: var(--text); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 320px; margin: 10px auto; }
.pinpad button { min-height: 60px; font-size: 24px; background: var(--card); color: var(--text); border: 1px solid var(--line-strong); }
.pinpad button:hover { background: var(--accent-soft); }
.pin-dots { font-size: 32px; letter-spacing: 8px; text-align: center; min-height: 44px; }
@media (max-width: 600px) {
	main { padding: 10px; }
	/* На телефоне меню — одна строка с прокруткой пальцем */
	nav.menu { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 6px; padding: 8px 12px; }
	nav.menu::-webkit-scrollbar { display: none; }
	nav.menu a { padding: 9px 14px; min-height: 44px; font-size: 16px; }
	header.top .who { font-size: 14px; }
}


/* Экран входа */
.login-hero {
	max-width: 460px; margin: 6px auto 12px; padding: 22px 20px; border-radius: var(--radius);
	text-align: center; color: #fff; background: var(--top-bg);
}
.login-logo { font-size: 40px; font-weight: 800; letter-spacing: .22em; padding-left: .22em; }
.login-hero p { margin: 4px 0 0; opacity: .7; }
.login-card { max-width: 460px; margin: 0 auto; }
.login-theme { max-width: 460px; margin: 10px auto 0; text-align: center; }

/* Таблицы на телефоне: компактнее, текст ячеек не ломается по буквам */
@media (max-width: 600px) {
	th, td { padding: 6px 8px; font-size: 15px; }
	th { white-space: nowrap; }
}

/* Табло: закрытие забытой смены спрятано, чтобы строки оставались короткими */
details.close-shift summary {
	cursor: pointer; color: var(--accent); font-weight: 600; font-size: 15px; white-space: nowrap;
	list-style: none;
}
details.close-shift summary::-webkit-details-marker { display: none; }
details.close-shift .inline-form { display: grid; gap: 6px; margin-top: 6px; min-width: 200px; }
#board-table td { white-space: nowrap; }

/* Кабинет администратора: действия по ролям */
.admin-section { margin-bottom: 22px; }
.admin-section h1, .admin-section h2 { display: flex; align-items: center; gap: 10px; }
.admin-section h1::before, .admin-section h2::before { content: ""; width: 4px; height: 24px; background: var(--accent); }
.admin-section.keeper h1::before, .admin-section.keeper h2::before { background: #c27a00; }
.admin-section.assembler h1::before, .admin-section.assembler h2::before { background: #0f8a7c; }
.admin-section.loader h1::before, .admin-section.loader h2::before { background: #2b6cd9; }
.admin-section.returns h1::before, .admin-section.returns h2::before { background: #c2255c; }
.admin-section.admin h1::before, .admin-section.admin h2::before { background: var(--muted); }
.admin-section.later h1::before, .admin-section.later h2::before { background: var(--line-strong); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.grid3 .card { margin: 0; padding: 12px 14px; }
.grid3 h3 { margin: 0 0 4px; font-size: 17px; color: var(--text); }
.grid3 p { margin: 0; }

/* Отгрузка: группы столбцов как в гугл-таблице */
.shipments th.group { text-align: center; font-size: 13px; }
.shipments th.group.before { background: var(--ship-before); }
.shipments th.group.ch { background: var(--ship-ch); }
.shipments th.group.after { background: var(--ship-after); }
.shipments td.ch { background: var(--ship-ch-cell); }
.shipments td.neg { background: var(--neg); color: #fff; font-weight: 700; }
.shipments tr.totals th { background: var(--th-bg); font-size: 13px; }
/* Шапка из трёх строк закреплена целиком: при прокрутке видно, что за столбец */
.shipments thead { position: sticky; top: 0; z-index: 5; }
.shipments thead th { position: static; }
.shipments thead th.sticky { position: sticky; left: 0; z-index: 6; }
/* В закреплённой шапке рамки рисуем тенью: у border-collapse они при прокрутке пропадают */
.shipments thead tr:last-child th { box-shadow: inset 0 -2px 0 var(--line-strong); }

/* Вкладки раздела «Склад» */
.subtabs { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; margin: 0 0 12px; border-bottom: 1px solid var(--line); }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs a {
	flex: 0 0 auto; padding: 8px 14px; text-decoration: none; white-space: nowrap;
	color: var(--muted); font-weight: 600; font-size: 15px;
	border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.subtabs a:hover { color: var(--text); }
.subtabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* Отгрузка: сетка по клеточкам, как в гугл-таблице */
.shipments { border-collapse: collapse; }
.shipments th, .shipments td { border: 1px solid var(--line-strong); }
.shipments td.num, .shipments th.num { min-width: 46px; }
.shipments tr.header-row td { border-left: 1px solid var(--line-strong); }

/* Маленькая кнопка «Закончить смену» — чтобы не нажать случайно */
button.small-btn { min-height: 36px; padding: 6px 12px; font-size: 14px; font-weight: 600; }

/* Выбор артикула: поиск + выпадающий список */
.article-picker { position: relative; flex: 1 1 260px; min-width: 220px; }
.article-picker .ap-input { padding-right: 36px; }
.article-picker.chosen .ap-input { border-color: var(--ok); background: var(--ok-bg); font-weight: 600; }
.article-picker.chosen::after {
	content: "✓"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
	color: var(--ok); font-weight: 800; pointer-events: none;
}
.article-picker.error .ap-input { border-color: var(--err); outline: 3px solid var(--err-bg); }
.ap-list {
	position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px);
	max-height: 280px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
	background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius);
	box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
}
.ap-list li { padding: 10px 12px; border-radius: 4px; cursor: pointer; font-size: 17px; }
.ap-list li.active, .ap-list li:hover { background: var(--accent-soft); color: var(--text); }
.ap-list li.ap-empty { color: var(--muted); cursor: default; background: none; }
/* Форма новой задачи */
.task-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; margin-top: 10px; }
.task-add .qty { width: 110px; flex: 0 0 110px; }
.task-add button { flex: 0 0 auto; }
.card:has(.article-picker) { overflow: visible; }

/* Задачи в «Отгрузке»: при наведении (или нажатии на телефоне) — кто делает */
.shipments td.who { position: relative; cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
/* Подсказка: мышью — при наведении, на телефоне — по нажатию, убирается нажатием в любое место */
@media (hover: hover) {
	.shipments td.who:hover::after { content: attr(data-who); }
}
.shipments td.who.show::after { content: attr(data-who); }
.shipments td.who:hover::after, .shipments td.who.show::after {
	position: absolute; z-index: 40; right: 0; top: 100%; margin-top: 4px;
	white-space: nowrap; padding: 6px 10px; border-radius: 4px; font-size: 13px; font-weight: 600;
	background: var(--top-bg); color: #fff; border: 1px solid var(--line-strong);
}

.channel-btn.site-btn { font-size: 20px; padding: 10px 8px; overflow-wrap: anywhere; }
.row.tight > * { max-width: 100%; }
.row.tight > button, .row.tight > form > button { white-space: normal; text-align: center; }

/* Переключатель «Сканер / Камера» над полем скана */
.scan-mode { display: inline-flex; gap: 0; margin: 0 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.scan-mode button {
	min-height: 38px; padding: 6px 16px; font-size: 15px; border-radius: 0; border: 0;
	background: var(--card); color: var(--text);
}
.scan-mode button.active { background: var(--accent); color: var(--on-accent); }
.scan-mode button:hover { background: var(--accent-soft); }
.scan-mode button.active:hover { background: var(--accent); }

/* Название группы в широкой таблице остаётся слева при прокрутке вбок */
tr.header-row .group-name { position: sticky; left: 8px; }
.shipments thead { background: var(--th-bg); }
/* Отгрузка: рамки без border-collapse, чтобы под закреплённой шапкой не просвечивали строки */
table.shipments { border-collapse: separate; border-spacing: 0; }
.shipments th, .shipments td { border: 0; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.shipments tr.header-row td { border-left: 0; }
.shipments thead tr:last-child th { box-shadow: none; border-bottom: 2px solid var(--line-strong); }

/* Погрузка: открытый канал площадки выделен, под названием — сколько уже загружено */
.channel-btn { flex-direction: column; gap: 2px; }
.channel-btn small { font-size: 14px; font-weight: 600; letter-spacing: 0; }
.channel-btn.secondary { color: var(--text); }
