/* Минимальные правки поверх Pico.css */

main.container {
	max-width: 100%;
	padding: 1rem;
}

header {
	margin-bottom: 1rem;
}

header h1 {
	margin-bottom: 0;
}

header small {
	color: var(--pico-muted-color);
}

.report-meta {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
	margin: 1rem 0;
	font-size: 0.9rem;
	color: var(--pico-muted-color);
}

.report-meta button {
	margin: 0;
	padding: 0.4rem 0.9rem;
	font-size: 0.85rem;
}

.filters {
	display: flex;
	gap: 0.75rem;
	align-items: center;
	flex-wrap: wrap;
	margin-bottom: 1rem;
}

.filters input[type="search"] {
	margin: 0;
	max-width: 240px;
}

.filters select {
	margin: 0;
	max-width: 200px;
}

.filters .chk {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	margin: 0;
	font-size: 0.9rem;
	cursor: pointer;
	white-space: nowrap;
}

.filters .chk input {
	margin: 0;
}

.filters button {
	margin: 0;
	padding: 0.4rem 0.9rem;
	font-size: 0.85rem;
}

/* === shadcn-style design tokens === */
:root {
	--app-bg: #fafafa;
	--surface: #ffffff;
	--surface-2: #f4f4f5;
	--border: #e4e4e7;
	--border-strong: #d4d4d8;
	--text: #18181b;
	--muted: #71717a;
	--primary: #2563eb;
	--primary-hover: #1d4ed8;
	--primary-bg: #eff6ff;
	--success: #16a34a;
	--warning: #d97706;
	--danger: #dc2626;
}
[data-theme="dark"] {
	--app-bg: #09090b;
	--surface: #18181b;
	--surface-2: #27272a;
	--border: #27272a;
	--border-strong: #3f3f46;
	--text: #fafafa;
	--muted: #a1a1aa;
	--primary: #60a5fa;
	--primary-hover: #3b82f6;
	--primary-bg: #1e3a8a40;
}
[data-theme="dark"] body { background: var(--app-bg); color: var(--text); }

html, body { margin: 0 !important; padding: 0 !important; }
body.body-anon { background: var(--app-bg); }
.auth-container { max-width: 420px; margin: 4rem auto; }

/* === Горизонтальный топбар + breadcrumbs-полоса === */
.app-shell {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	background: var(--app-bg);
}
.app-topbar {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 0.4rem 1rem;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	flex-wrap: wrap;
	/* НЕ sticky — топбар уезжает вверх при прокрутке страницы. */
}
.brand {
	font-weight: 700;
	font-size: 1.1rem;
	letter-spacing: -0.5px;
	color: var(--text);
	text-decoration: none;
	padding-right: 0.5rem;
	border-right: 1px solid var(--border);
	margin-right: 0.5rem;
}
.brand-mark { color: var(--primary); }
.brand-rest { color: var(--muted); font-weight: 500; }

.topnav {
	display: flex;
	gap: 0.15rem;
	flex-wrap: wrap;
}
.topnav a {
	padding: 0.3rem 0.55rem;
	border-radius: 6px;
	font-size: 0.85rem;
	color: var(--text);
	text-decoration: none;
}
.topnav a:hover { background: var(--surface-2); }
.topnav a.active { background: var(--primary-bg); color: var(--primary); font-weight: 500; }

.user-pill {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.8rem;
	color: var(--muted);
}
.user-pill strong { color: var(--text); }
.btn-logout {
	background: transparent;
	border: 1px solid var(--border-strong);
	color: var(--text);
	padding: 0.2rem 0.5rem;
	border-radius: 6px;
	font-size: 0.78rem;
	cursor: pointer;
}
.btn-logout:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }

/* Полоса под топбаром с breadcrumbs — НЕ sticky, уезжает при прокрутке. */
.breadcrumbs-bar {
	padding: 0.4rem 1rem;
	font-size: 0.85rem;
	color: var(--muted);
	background: var(--app-bg);
	border-bottom: 1px solid var(--border);
}
.breadcrumbs-bar:empty { display: none; }
.breadcrumbs-bar a { color: var(--text); text-decoration: none; }
.breadcrumbs-bar a:hover { color: var(--primary); }
.breadcrumbs-bar .sep { margin: 0 0.4rem; color: var(--muted); }
/* Старый класс .breadcrumbs (внутри страниц) — оставляем совместимым */
.breadcrumbs { font-size: 0.85rem; color: var(--muted); }
.breadcrumbs a { color: var(--text); text-decoration: none; }
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs .sep { margin: 0 0.4rem; color: var(--muted); }

.search-form { margin: 0; }
.search-input {
	width: 260px;
	padding: 0.3rem 0.6rem;
	border: 1px solid var(--border-strong);
	border-radius: 6px;
	background: var(--app-bg);
	color: var(--text);
	font-size: 0.85rem;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }

.theme-toggle {
	background: transparent;
	border: 1px solid var(--border-strong);
	border-radius: 6px;
	padding: 0.25rem 0.5rem;
	font-size: 1rem;
	cursor: pointer;
	line-height: 1;
	color: var(--text);
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

.app-content { padding: 1.25rem 1.5rem; min-width: 0; }

/* Картинки/кнопки от Pico — стили перекраиваем под shadcn для согласованности */
[data-theme="dark"] {
	--pico-color: var(--text);
	--pico-muted-color: var(--muted);
	--pico-background-color: var(--app-bg);
	--pico-card-background-color: var(--surface);
	--pico-card-sectioning-background-color: var(--surface-2);
	--pico-card-border-color: var(--border);
	--pico-primary: var(--primary);
}

.table-wrap {
	/* Топбар не sticky — уезжает при прокрутке. Таблица прилипает к самому верху
	   окна (top:0). Внутри — свой scroll-контекст для sticky-vc/thead/tfoot/pinned. */
	position: sticky;
	top: 0;
	max-height: 100vh;
	overflow-x: auto;
	overflow-y: auto;
}

#report-table {
	font-size: 0.9rem;
	width: auto;
	min-width: 100%;
	white-space: nowrap;
}

#report-table th {
	position: sticky;
	top: 0;
	background: var(--pico-card-background-color);
	cursor: pointer;
	user-select: none;
}

#report-table th.sorted-asc::after  { content: " ▲"; opacity: 0.7; font-size: 0.8em; }
#report-table th.sorted-desc::after { content: " ▼"; opacity: 0.7; font-size: 0.8em; }

#report-table .audit-col   { width: 36px; text-align: center; cursor: default; }
#report-table .comment-col { min-width: 180px; cursor: text; }
#report-table .nm-link, #daily-table .nm-link, #op-pivot-table .nm-link { color: var(--pico-muted-color); font-size: 0.75em; text-decoration: none; }
#report-table .nm-link:hover, #daily-table .nm-link:hover, #op-pivot-table .nm-link:hover { color: var(--pico-primary); text-decoration: underline; }
#report-table .sticky-vc strong { font-size: 0.9rem; }
#daily-table .sticky-vc strong { font-size: 0.72rem; }

/* Daily pivot 14 дней */
#daily-table {
	font-size: 0.7rem;
	white-space: nowrap;
	/* separate (не collapse!) — иначе sticky-ячейки теряют общие границы
	   при «всплытии» над прокручиваемым телом. Границы рисуем явно на каждой ячейке. */
	border-collapse: separate;
	border-spacing: 0;
}
#daily-table th, #daily-table td {
	padding: 0.15rem 0.3rem;
	border-bottom: 1px solid var(--pico-card-border-color);
	border-right:  1px solid var(--pico-card-border-color);
}
/* Левый край таблицы — без двойной границы (sticky-vc сам нарисует right) */
#daily-table tr > *:first-child { border-left: 1px solid var(--pico-card-border-color); }
/* Верхняя граница только у первой строки шапки */
#daily-table thead tr:first-child th { border-top: 1px solid var(--pico-card-border-color); }
/* row 2 шапки — собственный border-top, чтобы линия между датой и шт/выр/рек/ПП
   оставалась видна при скролле (row 2 перекрывает row 1 на 1px ради устранения щели). */
#daily-table thead tr:nth-child(2) th { border-top: 1px solid var(--pico-card-border-color); }
#daily-table .sticky-vc {
	position: sticky; left: 0;
	background: var(--pico-card-background-color);
	min-width: 150px; max-width: 180px; width: 180px; z-index: 1;
	border-right: 2px solid var(--pico-card-border-color);
	/* Артикул всегда в ОДНУ строку; не влез — троеточие, полный текст в tooltip. */
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.2;
}
/* Сам vendor_code (strong) — обрезаем с троеточием */
#daily-table .sticky-vc strong {
	display: inline-block;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	vertical-align: bottom;
}
#daily-table thead .sticky-vc { z-index: 2; background: var(--pico-card-sectioning-background-color); }
#daily-table .day-group {
	text-align: center;
	border-left: 3px solid var(--pico-card-border-color);
	background: var(--pico-card-sectioning-background-color);
}
#daily-table .metric-sub {
	font-size: 0.58rem;
	font-weight: normal;
	color: var(--pico-muted-color);
	border-left: 1px solid var(--pico-card-border-color);
}
/* Разделитель между днями (первая ячейка дня в row 2 thead, tbody и tfoot).
   Должно идти ПОСЛЕ .metric-sub, иначе border-left:1px из .metric-sub перекроет. */
#daily-table .day-start { border-left: 3px solid var(--pico-card-border-color) !important; }
#daily-table tbody tr.row-even td { background: var(--pico-card-sectioning-background-color); }
#daily-table tbody tr.row-even td.sticky-vc { background: var(--pico-card-sectioning-background-color); }
#daily-table .empty-cell { color: var(--pico-muted-color); }
#daily-table td.pp-positive { color: #2e7d32; }
#daily-table td.pp-negative { color: #c62828; }
#daily-table .audit-extra {
	width: 75px;
	max-width: 75px;
	padding: 0.1rem 0.25rem;
	height: 1.4rem;
	font-size: 0.65rem;
}

/* Скрываемая колонка «Доп. заказ» */
#daily-table.hide-extra-order .extra-order-col { display: none; }

/* Закреплённый последний день — прилипает к левому краю после колонки «Артикул»
   при горизонтальном скролле. left-значение задаёт JS (daily_pin.js).
   Непрозрачный фон — иначе ячейки сзади просвечивают при скролле. */
#daily-table .pinned-day {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 1;
}
#daily-table thead .pinned-day { z-index: 4; }
#daily-table tfoot .pinned-day { z-index: 4; }
#daily-table tbody tr.row-even td.pinned-day,
#daily-table tbody tr.row-odd  td.pinned-day { background: #E5EFFA !important; }

/* Жёсткое правило для row 2 шапки и tfoot — самая высокая специфичность среди
   всех правил, обращающихся к этим ячейкам. Гарантирует sticky на them
   независимо от того, успел ли JS поставить класс .pinned-day. */
#daily-table thead tr:nth-child(2) th[data-day-idx="0"],
#daily-table tfoot tr.totals-row th[data-day-idx="0"] {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 5 !important;
}
#daily-table tbody tr td[data-day-idx="0"] {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 1 !important;
}
#daily-table thead .day-group[data-day-idx="0"] {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 5 !important;
}

/* Сортировка по «Дней хватит» */
#daily-table .sortable-days {
	cursor: pointer;
	user-select: none;
	text-decoration: underline dotted;
	text-underline-offset: 3px;
}
#daily-table .sortable-days:hover { background: #E5EFFA; }
#daily-table .sortable-days .sort-arrow { color: var(--pico-primary); font-weight: bold; }
#daily-table .sortable-days .sort-idle { color: var(--pico-muted-color); opacity: 0.7; }
#toggle-extra-order.active {
	background: var(--pico-primary);
	color: #fff;
	border-color: var(--pico-primary);
}

#daily-table tfoot .totals-row th {
	background: var(--pico-card-sectioning-background-color);
	font-weight: 600;
	border-top: 2px solid var(--pico-primary);
	position: sticky;
	bottom: 0;
	z-index: 2;
}
#daily-table tfoot .totals-row .sticky-vc {
	z-index: 3;  /* пересечение sticky-vc + sticky-bottom */
}

/* Sticky thead для всех таблиц */
#daily-table thead th,
#report-table thead th,
#op-pivot-table thead th {
	position: sticky;
	top: 0;
	z-index: 2;
	background: var(--pico-card-sectioning-background-color);
}
#daily-table thead .sticky-vc,
#report-table thead .sticky-vc,
#op-pivot-table thead .sticky-vc { z-index: 4; }

/* Двухстрочный заголовок: высота первого ряда зафиксирована жёстко, второй
   ряд прилипает ровно на эту высоту — иначе ряды разъезжаются и первый
   (с датами) уходит под скролл. */
#daily-table thead tr:first-child th,
#op-pivot-table thead tr:first-child th {
	height: 34px;
	box-sizing: border-box;
}
#daily-table thead tr:nth-child(2) th { top: 34px; z-index: 2; }
#op-pivot-table thead tr:nth-child(2) th { top: 34px; z-index: 2; }

/* Дневные комментарии */
#daily-table .comment-cell {
	cursor: pointer;
	text-align: center;
	width: 28px;
	padding: 0 4px;
	border-right: 1px solid var(--pico-card-border-color);
}
#daily-table .comment-cell:hover {
	background: var(--pico-card-sectioning-background-color);
}
#daily-table .comment-cell.has-comment {
	background: rgba(255, 213, 79, 0.45) !important;
}
#daily-table .ds-bg-1 { background: rgba(198, 40, 40, 0.25)  !important; }
#daily-table .ds-bg-2 { background: rgba(253, 216, 53, 0.30) !important; }
#daily-table .ds-bg-3 { background: rgba(102, 187, 106, 0.25) !important; }
#daily-table .ds-bg-4 { background: rgba(255, 167, 38, 0.30) !important; }
#daily-table .ds-bg-5 { background: rgba(239, 83, 80, 0.30) !important; }

#report-table .audit-extra {
	width: 100%;
	max-width: 60px;
	padding: 0.2rem 0.3rem;
	margin: 0;
	height: 1.6rem;
	font-size: 0.85rem;
	text-align: right;
}

/* Sticky vendor_code колонка слева */
#report-table .sticky-vc {
	position: sticky;
	left: 36px;  /* после audit-col */
	background: var(--pico-card-background-color);
	z-index: 1;
}
#report-table thead .sticky-vc { z-index: 2; }

/* Зебра */
#report-table tbody tr.row-even td { background: var(--pico-card-sectioning-background-color); }
#report-table tbody tr.row-even td.sticky-vc { background: var(--pico-card-sectioning-background-color); }

/* Цветовые шкалы — days_of_stock (приглушённые, !important перебивает зебру) */
#report-table td.ds-bg-1 { background: rgba(198, 40, 40, 0.25)  !important; }  /* <40 — критично, бордовый */
#report-table td.ds-bg-2 { background: rgba(253, 216, 53, 0.30) !important; }  /* 40-70 — жёлтый */
#report-table td.ds-bg-3 { background: rgba(102, 187, 106, 0.25) !important; } /* 71-110 — норм, зелёный */
#report-table td.ds-bg-4 { background: rgba(255, 167, 38, 0.30) !important; }  /* 111-130 — оранжевый */
#report-table td.ds-bg-5 { background: rgba(239, 83, 80, 0.30) !important; }   /* >130 — красный (залежавшиеся) */

/* Цветовые шкалы — discount % */
#report-table td.dr-bg-1 { background: rgba(102, 187, 106, 0.4); }  /* 0-12 — зелёный лёгкий */
#report-table td.dr-bg-2 { background: rgba(255, 235, 59, 0.5); }   /* 12-20 — жёлтый */
#report-table td.dr-bg-3 { background: rgba(255, 152, 0, 0.5); }    /* 20-35 — оранжевый */
#report-table td.dr-bg-4 { background: rgba(229, 57, 53, 0.55); color: #fff; }  /* >35 — красный */
#report-table .audit-check { transform: scale(1.2); margin: 0; }
#report-table .audit-comment {
	margin: 0;
	padding: 0.2rem 0.4rem;
	font-size: 0.85rem;
	border: 1px solid transparent;
	background: transparent;
	width: 100%;
	min-height: unset;
	height: 1.6rem;
}
#report-table .audit-comment:focus {
	border-color: var(--pico-primary);
	background: var(--pico-card-background-color);
}
.audit-saving { outline: 2px solid #ffd54f; }
.audit-saved  { outline: 2px solid #66bb6a; transition: outline 0.4s; }
.audit-error  { outline: 2px solid #e53935; }

/* Tabs Daily / OP */
.group-tabs {
	display: flex;
	gap: 0.5rem;
	margin: 1rem 0;
	border-bottom: 1px solid var(--pico-card-border-color);
}
.group-tabs a {
	padding: 0.5rem 1rem;
	text-decoration: none;
	color: var(--pico-muted-color);
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
}
.group-tabs a:hover { color: inherit; }
.group-tabs a.active {
	color: inherit;
	border-bottom-color: var(--pico-primary);
	font-weight: 500;
}

/* Settings form (group_settings.html) */
.settings-form {
	max-width: 800px;
	margin-top: 1rem;
}
.settings-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
	gap: 1rem;
	margin-bottom: 1rem;
}
.settings-form label { font-size: 0.9rem; margin-bottom: 0.2rem; }
.settings-form small { color: var(--pico-muted-color); font-size: 0.75rem; display: block; margin-top: -0.4rem; }
.settings-form pre   { font-size: 0.8rem; line-height: 1.4; padding: 0.6rem; background: var(--pico-card-sectioning-background-color); border-radius: 0.4rem; }

/* Summary table */
#summary-table .rnp-divider td { border-top: 2px solid var(--pico-primary); }
#summary-table .pp-positive { color: #2e7d32; font-weight: 500; }
#summary-table .pp-negative { color: #c62828; font-weight: 500; }
#summary-table .warn-link   { color: #ef6c00; }

/* Admin dashboard */
/* Ссылки на рекламу в настройках группы */
.ad-links-block { margin: 1rem 0; }
.ad-links-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.ad-links-table th, .ad-links-table td {
	border: 1px solid var(--pico-card-border-color);
	padding: 0.3rem 0.5rem;
	text-align: left;
}
.ad-links-table input { margin: 0; width: 100%; }
.ad-links-table thead th { background: var(--pico-card-sectioning-background-color); }

/* Кнопка-стрелочка «ссылка на рекламу» рядом с артикулом */
.ad-link-arrow {
	text-decoration: none;
	font-size: 0.85rem;
	margin-left: 0.2rem;
}

/* Страница «Не попали в фильтры» — группировка по шаблонам */
.unmatched-pat { margin: 0.4rem 0; border: 1px solid var(--pico-card-border-color); border-radius: 0.4rem; }
.unmatched-pat summary {
	padding: 0.5rem 0.8rem;
	cursor: pointer;
	font-size: 0.9rem;
}
.unmatched-pat summary code { font-weight: 600; }
.unmatched-cnt {
	margin-left: 0.5rem;
	font-size: 0.78rem;
	color: var(--pico-muted-color);
	background: var(--pico-card-sectioning-background-color);
	padding: 0.1rem 0.5rem;
	border-radius: 999px;
}
.unmatched-pat .ad-links-table { margin: 0 0.8rem 0.8rem; width: calc(100% - 1.6rem); }

/* История действий */
.activity-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.activity-table th, .activity-table td {
	border: 1px solid var(--pico-card-border-color);
	padding: 0.35rem 0.6rem;
	text-align: left;
	vertical-align: top;
}
.activity-table thead th { background: var(--pico-card-sectioning-background-color); }
.activity-table tbody tr:hover { background: var(--pico-card-sectioning-background-color); }
.act-when { white-space: nowrap; color: var(--pico-muted-color); }
.act-tag { white-space: nowrap; font-size: 0.78rem; }
.act-comment  { color: #2563eb; }
.act-audit    { color: #16a34a; }
.act-settings { color: #ea580c; }

/* Режим просмотра (impersonation) */
.impersonate-bar {
	display: flex;
	align-items: center;
	gap: 0.7rem;
	padding: 0.4rem 1rem;
	background: #fff3cd;
	border-bottom: 1px solid #e0a800;
	font-size: 0.85rem;
	color: #7d5a00;
}
.imp-back-btn {
	width: auto;
	margin: 0;
	padding: 0.2rem 0.7rem;
	background: #e0a800;
	border: 0;
	border-radius: 0.3rem;
	font-size: 0.8rem;
	color: #fff;
	cursor: pointer;
}
.imp-view-btn {
	width: auto;
	margin: 0;
	padding: 0.15rem 0.5rem;
	background: none;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.3rem;
	font-size: 0.75rem;
	cursor: pointer;
}
.imp-view-btn:hover { border-color: #2563eb; color: #2563eb; }

/* Колонка «Сегодня» (комментарий) в дневной таблице */
#daily-table .today-col {
	background: rgba(37, 99, 235, 0.07);
	border-left: 2px solid #2563eb;
	text-align: center;
}

/* Кнопка «Назад» в шапке */
.nav-back {
	margin: 0 0.4rem 0 0;
	width: auto;
	padding: 0.25rem 0.7rem;
	background: none;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.35rem;
	font-size: 0.8rem;
	color: var(--pico-muted-color);
	cursor: pointer;
	white-space: nowrap;
}
.nav-back:hover { border-color: var(--pico-primary); color: var(--pico-primary); }

/* Кнопка выхода — компактная, в углу шапки */
.logout-form { margin: 0 0 0 auto; }
.logout-btn {
	margin: 0;
	width: auto;
	padding: 0.25rem 0.7rem;
	background: none;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.35rem;
	font-size: 0.8rem;
	color: var(--pico-muted-color);
	cursor: pointer;
}
.logout-btn:hover { border-color: #c62828; color: #c62828; }

/* Плашка свежести данных — единая на всех страницах */
.freshness-bar {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem 1.4rem;
	padding: 0.4rem 1rem;
	background: var(--pico-card-sectioning-background-color);
	border-bottom: 1px solid var(--pico-card-border-color);
	font-size: 0.78rem;
	color: var(--pico-muted-color);
}
.freshness-bar b { color: var(--pico-color); font-weight: 600; }

/* === Дашборд === */
.dash-section-title {
	font-size: 0.85rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--pico-muted-color);
	margin: 1.6rem 0 0.6rem;
}

.kpi-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
	gap: 0.9rem;
	margin: 0.6rem 0 0.5rem;
}
.kpi-card {
	padding: 0.85rem 1rem 0.9rem 1.05rem;
	border: 1px solid var(--pico-card-border-color);
	border-left: 4px solid var(--pico-muted-color);
	border-radius: 0.55rem;
	background: var(--pico-card-background-color);
	transition: transform 0.1s, box-shadow 0.1s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08); }
.kpi-card.acc-red    { border-left-color: #c62828; }
.kpi-card.acc-orange { border-left-color: #ef6c00; }
.kpi-card.acc-green  { border-left-color: #16a34a; }
.kpi-card.acc-blue   { border-left-color: #2563eb; }
.kpi-label {
	font-size: 0.72rem;
	color: var(--pico-muted-color);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.kpi-value {
	font-size: 1.35rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	margin-top: 0.35rem;
	line-height: 1.15;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.kpi-value.alert { color: #c62828; }
.kpi-value.warn  { color: #ef6c00; }
.kpi-value-small {
	font-size: 0.95rem;
	font-weight: 600;
	margin-top: 0.5rem;
	color: var(--pico-muted-color);
}

.chart-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 1rem;
	margin: 0.4rem 0 1rem;
}
.chart-card {
	padding: 1rem 1.1rem 1.2rem;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.55rem;
	background: var(--pico-card-background-color);
}
.chart-card h3 { margin: 0 0 0.7rem; font-size: 0.95rem; }
.chart-card .chart-box { position: relative; height: 260px; }
.chart-wide { grid-column: span 2; }
@media (max-width: 800px) {
	.chart-grid { grid-template-columns: 1fr; }
	.chart-wide { grid-column: span 1; }
}

/* OP pivot — те же приёмы что в daily: separate borders, узкий шрифт,
   sticky-vc с эллипсисом, толстые разделители между неделями. */
#op-pivot-table {
	font-size: 0.7rem;
	white-space: nowrap;
	border-collapse: separate;
	border-spacing: 0;
}
#op-pivot-table th, #op-pivot-table td {
	padding: 0.15rem 0.3rem;
	border-bottom: 1px solid var(--pico-card-border-color);
	border-right:  1px solid var(--pico-card-border-color);
}
#op-pivot-table tr > *:first-child { border-left: 1px solid var(--pico-card-border-color); }
#op-pivot-table thead tr:first-child th { border-top: 1px solid var(--pico-card-border-color); }
#op-pivot-table thead tr:nth-child(2) th { border-top: 1px solid var(--pico-card-border-color); }

#op-pivot-table .sticky-vc {
	position: sticky; left: 0;
	background: var(--pico-card-background-color);
	min-width: 150px; max-width: 180px; width: 180px; z-index: 1;
	border-right: 2px solid var(--pico-card-border-color);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.2;
}
#op-pivot-table .sticky-vc strong {
	display: inline-block;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	vertical-align: bottom;
	font-size: 0.72rem;
}
#op-pivot-table thead .sticky-vc { z-index: 2; background: var(--pico-card-sectioning-background-color); }
#op-pivot-table tbody tr.row-even td.sticky-vc { background: var(--pico-card-sectioning-background-color); }

#op-pivot-table .week-group {
	text-align: center;
	border-left: 3px solid var(--pico-card-border-color);
	background: var(--pico-card-sectioning-background-color);
}
#op-pivot-table .metric-sub {
	font-size: 0.58rem;
	font-weight: normal;
	color: var(--pico-muted-color);
	border-left: 1px solid var(--pico-card-border-color);
}
/* Разделитель между неделями (первая ячейка недели в row 2 thead, tbody, tfoot) */
#op-pivot-table .week-start { border-left: 3px solid var(--pico-card-border-color) !important; }

#op-pivot-table tbody tr.row-even td { background: var(--pico-card-sectioning-background-color); }
#op-pivot-table .op-negative { color: #c62828; }

/* Сортировка по ОП последней (закреплённой) недели — 3-фазная кнопка */
#op-pivot-table .sortable-op {
	cursor: pointer;
	user-select: none;
	text-decoration: underline dotted;
	text-underline-offset: 2px;
}
#op-pivot-table .sortable-op:hover { background: #E5EFFA; }
#op-pivot-table .sortable-op .sort-arrow { color: var(--pico-primary); font-weight: bold; }
#op-pivot-table .sortable-op .sort-idle { color: var(--pico-muted-color); opacity: 0.7; }

/* Comment-cell для OP — те же стили что в daily */
#op-pivot-table .comment-cell {
	cursor: pointer;
	text-align: center;
	width: 28px;
}
#op-pivot-table .comment-cell.has-comment {
	background: rgba(255, 213, 79, 0.45) !important;
}

/* Кнопка комментария — «+» / 💬 в кружочке (daily + op) */
.daily-comment-btn {
	background: transparent;
	border: 1px solid var(--pico-muted-border-color, #ccc);
	border-radius: 50%;
	width: 20px;
	height: 20px;
	padding: 0;
	margin: 0;
	font-size: 0.72rem;
	line-height: 1;
	color: var(--pico-muted-color);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.comment-cell:hover .daily-comment-btn {
	border-color: var(--pico-primary);
	color: var(--pico-primary);
}
.comment-cell.has-comment .daily-comment-btn { border-color: var(--pico-primary); }

/* Закреплённая «новейшая» неделя — sticky слева сразу за Артикул. left задаёт JS. */
#op-pivot-table .pinned-week {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 1;
}
#op-pivot-table thead .pinned-week,
#op-pivot-table tfoot .pinned-week { z-index: 4; }
#op-pivot-table tbody tr.row-even td.pinned-week,
#op-pivot-table tbody tr.row-odd  td.pinned-week { background: #E5EFFA !important; }
#op-pivot-table thead tr:nth-child(2) th[data-week-idx="0"],
#op-pivot-table tfoot tr.totals-row th[data-week-idx="0"],
#op-pivot-table thead .week-group[data-week-idx="0"] {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 5 !important;
}
#op-pivot-table tbody tr td[data-week-idx="0"] {
	position: sticky !important;
	background: #E5EFFA !important;
	z-index: 1 !important;
}

/* ДРР цветовые шкалы — только отклонения (жёлтый/оранжевый/красный).
   Нормальный ДРР (<12%) не подсвечивается. */
#op-pivot-table td.drr-bg-2 { background: rgba(255, 235, 59, 0.5)   !important; }      /* 12-20 — жёлтый */
#op-pivot-table td.drr-bg-3 { background: rgba(255, 152, 0, 0.5)    !important; }       /* 20-35 — оранжевый */
#op-pivot-table td.drr-bg-4 { background: rgba(229, 57, 53, 0.55)   !important; color: #fff; }  /* >35 — красный */
/* Закреплённая неделя — ДРР-цвет должен побеждать голубую sticky-подсветку.
   Специфичность выше базовой `.pinned-week` зебры, поэтому ДРР виден и в pinned. */
#op-pivot-table tbody tr td.pinned-week.drr-bg-2 { background: rgba(255, 235, 59, 0.5) !important; }
#op-pivot-table tbody tr td.pinned-week.drr-bg-3 { background: rgba(255, 152, 0, 0.5) !important; }
#op-pivot-table tbody tr td.pinned-week.drr-bg-4 { background: rgba(229, 57, 53, 0.55) !important; color: #fff; }

/* Totals row */
#report-table tfoot .totals-row th,
#op-pivot-table tfoot .totals-row th {
	background: var(--pico-card-sectioning-background-color);
	font-weight: 600;
	border-top: 2px solid var(--pico-primary);
	position: sticky;
	bottom: 0;
}
#report-table tfoot .totals-row .pp-positive,
#op-pivot-table tfoot .totals-row .pp-positive { color: #2e7d32; }
#report-table tfoot .totals-row .pp-negative,
#op-pivot-table tfoot .totals-row .pp-negative { color: #c62828; }

/* ПП колонка в Daily */
#report-table td.pp-positive { color: #2e7d32; font-weight: 500; }
#report-table td.pp-negative { color: #c62828; font-weight: 500; }

/* Settings-ссылка в вкладках */
.group-tabs .settings-link {
	margin-left: auto;
	font-size: 0.85rem;
	color: var(--pico-muted-color);
}

#report-table td.num,
#report-table th.num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

#report-table tbody tr:hover {
	background: var(--pico-card-sectioning-background-color);
}

.empty-state {
	text-align: center;
	padding: 2rem;
}

.auth-card {
	max-width: 400px;
	margin: 2rem auto;
	padding: 2rem;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.5rem;
}

.flash {
	padding: 0.6rem 0.9rem;
	border-radius: 0.4rem;
	margin-bottom: 1rem;
	font-size: 0.9rem;
}
.flash-error   { background: #fde6e6; color: #8c1d1d; }
.flash-warning { background: #fff5d6; color: #7d5a00; }
.flash-success { background: #e0f5d8; color: #2a5d11; }

.error {
	color: #b21f1f;
	display: block;
	margin: -0.4rem 0 0.6rem 0;
}

.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 1rem;
	gap: 1rem;
	flex-wrap: wrap;
}

.user-menu {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.user-menu small {
	color: var(--pico-muted-color);
}

button.small,
.user-menu button {
	margin: 0;
	padding: 0.3rem 0.7rem;
	font-size: 0.8rem;
}

.breadcrumbs a {
	color: var(--pico-muted-color);
	text-decoration: none;
	font-size: 0.9rem;
}
.breadcrumbs a:hover { text-decoration: underline; }

/* === Раздел «Таблицы» === */

/* Цвет РНП-категории — наследуется детьми через var(--rnp) */
[data-rnp="CARDS"] { --rnp: #2563eb; }
[data-rnp="CASES"] { --rnp: #7c3aed; }
[data-rnp="RINGS"] { --rnp: #0891b2; }
[data-rnp="ARMOR"] { --rnp: #ea580c; }
[data-rnp="BCA"]   { --rnp: #16a34a; }
[data-rnp="BOOKS"] { --rnp: #db2777; }
[data-rnp="CASE"]  { --rnp: #475569; }

.tables-head {
	display: flex;
	align-items: baseline;
	gap: 0.75rem;
	flex-wrap: wrap;
	margin-bottom: 0.25rem;
}
.tables-period { color: var(--pico-muted-color); font-size: 0.85rem; }

.rnp-section { margin-bottom: 1.5rem; }
.rnp-section-title {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 1.1rem 0 0.6rem;
	font-size: 0.95rem;
	font-weight: 600;
	letter-spacing: 0.5px;
}
.rnp-section-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--rnp, var(--pico-muted-color));
}
.rnp-section-count {
	font-size: 0.72rem;
	font-weight: 500;
	color: var(--pico-muted-color);
	background: var(--pico-card-sectioning-background-color);
	padding: 0.05rem 0.5rem;
	border-radius: 999px;
}

.group-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
	gap: 0.75rem;
}

.group-card {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding: 0.85rem 1rem;
	border: 1px solid var(--pico-card-border-color);
	border-left: 3px solid var(--rnp, var(--pico-muted-color));
	border-radius: 0.5rem;
	text-decoration: none;
	color: inherit;
	background: var(--pico-card-background-color);
	transition: transform 0.1s, box-shadow 0.1s;
}
.group-card:hover {
	transform: translateY(-2px);
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
	text-decoration: none;
}
.rnp-tag {
	align-self: flex-start;
	display: inline-block;
	padding: 0.1rem 0.45rem;
	background: var(--rnp, var(--pico-muted-color));
	border-radius: 0.3rem;
	font-size: 0.68rem;
	font-weight: 600;
	letter-spacing: 0.5px;
	color: #fff;
}
.group-card-name {
	margin: 0;
	font-size: 1.05rem;
	line-height: 1.25;
}
.card-metrics {
	display: flex;
	flex-wrap: wrap;
	gap: 0.15rem 0.7rem;
	margin-top: auto;
	padding-top: 0.2rem;
	font-size: 0.8rem;
	color: var(--pico-muted-color);
}
.card-metrics .metric b { color: var(--pico-color); font-weight: 600; }
.metric-pos b { color: #16a34a; }
.metric-neg b { color: #c0392b; }

.group-card-warning {
	border-color: #ef6c00;
	border-left-color: #ef6c00;
	background: rgba(255, 152, 0, 0.05);
}
.group-card-warning .rnp-tag { background: #ef6c00; }

/* Секция «Менеджеры» (admin view на /my-tables) */
.section-title {
	margin: 1rem 0 0.5rem;
	font-size: 1rem;
	color: var(--pico-muted-color);
	text-transform: uppercase;
	letter-spacing: 0.5px;
}
.managers-block { margin-bottom: 1.5rem; }
.manager-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 0.75rem;
}
.manager-card {
	margin: 0;
	padding: 0.75rem 1rem;
	background: var(--pico-card-background-color);
	border: 1px solid var(--pico-card-border-color);
	border-radius: 6px;
}
.manager-card header {
	margin: 0 0 0.4rem;
	padding: 0;
	border: 0;
	background: transparent;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}
.manager-card header strong { font-size: 0.95rem; }
.manager-meta { color: var(--pico-muted-color); font-size: 0.8rem; }
.manager-group-list {
	list-style: none;
	margin: 0;
	padding: 0;
}
.manager-group-list li {
	padding: 0.15rem 0;
	font-size: 0.85rem;
	display: flex;
	gap: 0.25rem;
	align-items: baseline;
}
.manager-group-list a {
	color: var(--pico-color);
	text-decoration: none;
	flex: 1;
}
.manager-group-list a:hover { color: var(--pico-primary); text-decoration: underline; }
.manager-group-list small { color: var(--pico-muted-color); }
.rnp-tag-inline {
	display: inline-block;
	font-size: 0.6rem;
	font-weight: 600;
	padding: 1px 5px;
	background: var(--rnp, var(--pico-muted-color));
	border-radius: 3px;
	color: #fff;
	margin-right: 0.25rem;
	letter-spacing: 0.5px;
}
.empty-hint {
	margin: 0.25rem 0;
	color: var(--pico-muted-color);
	font-size: 0.85rem;
}

/* Поиск артикула */
.search-results {
	list-style: none;
	padding: 0;
	margin: 0.75rem 0;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}
.search-result {
	padding: 0.75rem 1rem;
	border: 1px solid var(--border, var(--pico-card-border-color));
	border-radius: 6px;
	background: var(--surface, var(--pico-card-background-color));
}
.search-result-head { display: flex; gap: 0.5rem; align-items: baseline; }
.search-result-head strong { font-size: 1rem; }
.search-result-meta { color: var(--muted, var(--pico-muted-color)); margin: 0.25rem 0; }
.search-result-groups { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.search-result-groups a { font-size: 0.7rem; text-decoration: none; }

/* === Drill-down по артикулу (модалка истории заказов) === */
.vc-drill {
	background: none;
	border: 0;
	padding: 0;
	margin: 0;
	max-width: 100%;
	display: inline-block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	vertical-align: bottom;
	font: inherit;
	font-size: 0.62rem;
	font-weight: 700;
	color: var(--pico-primary);
	cursor: pointer;
	text-align: left;
}
.vc-drill:hover { text-decoration: underline; }

.ah-modal { position: fixed; inset: 0; z-index: 1000; }
.ah-modal[hidden] { display: none; }
.ah-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.ah-modal-box {
	position: relative;
	background: var(--pico-background-color);
	max-width: 95vw;
	max-height: 90vh;
	margin: 4vh auto;
	padding: 1rem 1.25rem;
	border-radius: 0.6rem;
	display: flex;
	flex-direction: column;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.ah-modal-close {
	position: absolute;
	top: 0.3rem;
	right: 0.5rem;
	width: auto;
	margin: 0;
	padding: 0.1rem 0.5rem;
	background: none;
	border: 0;
	font-size: 1.7rem;
	line-height: 1;
	color: var(--pico-muted-color);
	cursor: pointer;
}
.ah-modal-body { overflow: auto; }

.ah-head { display: flex; gap: 0.6rem; align-items: baseline; margin-bottom: 0.6rem; }
.ah-head strong { font-size: 1.1rem; }
.ah-scroll { overflow: auto; max-height: 72vh; }

.ah-table { border-collapse: collapse; font-size: 0.8rem; }
.ah-table th,
.ah-table td {
	border: 1px solid var(--pico-card-border-color);
	padding: 0.2rem 0.45rem;
	white-space: nowrap;
}
.ah-table .num { text-align: right; }
.ah-table thead th {
	position: sticky;
	background: var(--pico-card-sectioning-background-color);
	z-index: 2;
}
/* Двухрядная шапка: высота первого ряда зафиксирована, второй ряд прилипает
   ровно под ним. Первый ряд — «Неделя N» + дата в 2 строки. */
.ah-table thead tr:first-child th { top: 0; height: 44px; box-sizing: border-box; }
.ah-table thead tr:nth-child(2) th { top: 44px; }
.ah-sticky {
	position: sticky;
	left: 0;
	background: var(--pico-card-background-color);
	z-index: 3;
	text-align: left;
}
.ah-table thead .ah-sticky { z-index: 4; }
.ah-week { text-align: center; }
.ah-week small { display: block; font-weight: normal; color: var(--pico-muted-color); }
.ah-wk-start { border-left: 2px solid var(--pico-muted-color); }
.ah-dow { font-weight: 600; }
.ah-future {
	background: repeating-linear-gradient(45deg, #f3f3f3, #f3f3f3 4px, #fff 4px, #fff 8px);
}
.ah-total td,
.ah-total th { background: #eef3fb; }
.ah-sub td,
.ah-sub th { background: #f4f4f4; color: var(--pico-muted-color); }
.ah-stock td,
.ah-stock th { background: #fffbe6; }
.ah-turn td,
.ah-turn th { background: #fdeee6; }
.ah-note { margin-top: 0.5rem; color: var(--pico-muted-color); }
.ah-loading { padding: 2rem; text-align: center; color: var(--pico-muted-color); }

/* === Сводная по группам === */
.sum-section { margin-bottom: 1.5rem; }
.sum-table {
	width: 100%;
	border-collapse: collapse;
	table-layout: fixed;
	font-size: 0.78rem;
}
.sum-table th, .sum-table td {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.sum-table th,
.sum-table td {
	border: 1px solid var(--pico-card-border-color);
	padding: 0.3rem 0.6rem;
}
.sum-table thead th {
	background: var(--pico-card-sectioning-background-color);
	text-align: left;
	font-size: 0.78rem;
}
.sum-table .num { text-align: right; }
.sum-table tbody tr:hover { background: var(--pico-card-sectioning-background-color); }
.sum-table a { text-decoration: none; }
.sum-table a:hover { text-decoration: underline; }
.warn-link { color: #e8540c; }

.sum-subtotal th,
.sum-subtotal td {
	background: var(--pico-card-sectioning-background-color);
	font-weight: 600;
	border-top: 2px solid var(--rnp, var(--pico-muted-color));
}
.sum-grand { margin-top: 0.5rem; }
.sum-grand-row th,
.sum-grand-row td {
	background: #1f3a5f;
	color: #fff;
	font-weight: 700;
	font-size: 0.9rem;
	padding: 0.45rem 0.6rem;
	border: 1px solid #1f3a5f;
}
.sum-grand-row .pp-negative { color: #ff9b9b; }
.sum-grand-row .pp-positive { color: #9be79b; }
/* Блоки колонок «Продажи» / «Заказы» */
.sum-table .blk-sales  { background: rgba(37, 99, 235, 0.10); text-align: center; }
.sum-table .blk-orders { background: rgba(234, 88, 12, 0.10); text-align: center; }
.sum-table .blk-start  { border-left: 2px solid var(--pico-muted-color); }
.sum-period {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem 1.2rem;
	margin: 0.25rem 0 1rem;
	font-size: 0.82rem;
	color: var(--pico-muted-color);
}

/* Переключатель периода 7/14/30 */
.period-switch {
	display: inline-flex;
	gap: 0;
	margin: 0.5rem 0;
	border: 1px solid var(--pico-card-border-color);
	border-radius: 0.4rem;
	overflow: hidden;
}
.period-switch a {
	padding: 0.35rem 0.9rem;
	font-size: 0.85rem;
	text-decoration: none;
	color: var(--pico-color);
	border-right: 1px solid var(--pico-card-border-color);
}
.period-switch a:last-child { border-right: 0; }
.period-switch a:hover { background: var(--pico-card-sectioning-background-color); }
.period-switch a.active {
	background: var(--pico-primary, #2563eb);
	color: #fff;
	font-weight: 600;
}
/* Маркер «есть комментарий» в drill-down — уголок (ячейки узкие, кнопка не влезает) */
.ah-table td.ah-has-cmt {
	position: relative;
	cursor: pointer;
}
.ah-table td.ah-has-cmt::after {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	border: 5px solid transparent;
	border-top-color: #e8540c;
	border-right-color: #e8540c;
}
.ah-table td.ah-has-cmt:hover { outline: 1px solid #e8540c; }
/* Сегодняшняя ячейка — редактируемый комментарий */
.ah-table td.ah-cmt-today {
	cursor: pointer;
	box-shadow: inset 0 0 0 2px var(--pico-primary, #2563eb);
}

/* Топ-10 убыточных по ОП — таблица на дашборде */
.loss-table {
	border-collapse: collapse;
	font-size: 0.9rem;
	margin-top: 0.5rem;
}
.loss-table th,
.loss-table td {
	border: 1px solid var(--pico-card-border-color);
	padding: 0.35rem 0.7rem;
	text-align: left;
}
.loss-table .num { text-align: right; }
.loss-table thead th { background: var(--pico-card-sectioning-background-color); }
.loss-table tbody tr:hover { background: var(--pico-card-sectioning-background-color); }
.loss-table .pp-negative { color: #c62828; }

.chart-period { font-weight: 400; font-size: 0.78rem; color: var(--pico-muted-color); }
