/* Analytics Dashboard Styles */

:root {
	--bg: #f4f6fb;
	--card: #ffffff;
	--text: #172033;
	--muted: #5f6b7a;
	--accent-1: #0ea5e9;
	--accent-2: #22c55e;
	--accent-3: #f97316;
	--border: #d9e0ea;
}

[data-theme="dark"] {
	--bg: #0f172a;
	--card: #1e293b;
	--text: #f1f5f9;
	--muted: #94a3b8;
	--accent-1: #3b82f6;
	--accent-2: #10b981;
	--accent-3: #f59e0b;
	--border: #334155;
	--button-bg: #3b82f6;
	--button-hover: #2563eb;
	--tab-hover-bg: rgba(59, 130, 246, 0.1);
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	min-height: 100vh;
	font-family: "Segoe UI", Tahoma, sans-serif;
	color: var(--text);
	background:
		radial-gradient(circle at 10% 10%, rgba(59, 130, 246, 0.1) 0%, transparent 35%),
		radial-gradient(circle at 90% 0%, rgba(245, 158, 11, 0.08) 0%, transparent 40%),
		var(--bg);
	background-attachment: fixed;
}

[data-theme="light"] body {
	background:
		radial-gradient(circle at 10% 10%, #e7f5ff 0%, transparent 35%),
		radial-gradient(circle at 90% 0%, #fff2e8 0%, transparent 40%),
		var(--bg);
}

.container {
	max-width: 1100px;
	margin: 16px auto;
	padding: 0 12px;
}

.top {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	align-items: end;
	margin-bottom: 12px;
	padding: 12px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 10px;
}

[data-theme="dark"] .top {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.field {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

label {
	font-size: 13px;
	color: var(--muted);
}

input,
button {
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 13px;
}

input {
	background: var(--card);
	color: var(--text);
	transition: all 0.2s;
}

input:focus {
	outline: none;
	border-color: var(--accent-1);
	box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] input {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] input:focus {
	box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2), 0 1px 3px rgba(0, 0, 0, 0.3);
}

label {
	color: var(--text);
}

button {
	background: var(--button-bg, #3b82f6);
	color: white;
	border: none;
	cursor: pointer;
	transition: all 0.2s;
}

button:hover:not(:disabled) {
	background: var(--button-hover, #2563eb);
	transform: translateY(-1px);
	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.loading-state {
	display: none;
	align-items: center;
	gap: 8px;
	margin: 4px 0 12px;
	color: var(--muted);
	font-size: 13px;
}

.loading-state.active {
	display: flex;
}

.spinner {
	width: 14px;
	height: 14px;
	border: 2px solid var(--border);
	border-top-color: var(--accent-1);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

.cards {
	display: grid;
	grid-template-columns: repeat(4, minmax(140px, 1fr));
	gap: 8px;
	margin-bottom: 10px;
}

.card {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 10px;
	transition: all 0.2s;
}

[data-theme="dark"] .card {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .card:hover {
	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
	transform: translateY(-2px);
}

.card h3 {
	margin: 0;
	font-size: 12px;
	color: var(--muted);
	font-weight: 600;
}

.value {
	margin-top: 6px;
	font-size: 24px;
	font-weight: 700;
}

.chart-wrap {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 10px;
	margin-top: 8px;
}

[data-theme="dark"] .chart-wrap {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.charts-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 8px;
	margin-top: 8px;
	align-items: stretch;
}

.chart-wrap h3 {
	margin: 0 0 8px 0;
	font-size: 13px;
	font-weight: 600;
}

.chart-wrap-small {
	max-width: 300px;
	max-height: 300px;
	margin: 0 auto;
}

.table-wrap {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 16px;
	margin-top: 8px;
}

[data-theme="dark"] .table-wrap {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.table-wrap h3 {
	margin: 0 0 12px 0;
	font-size: 13px;
	font-weight: 600;
}

.table-container {
	max-height: 400px;
	overflow-y: auto;
	border: 1px solid var(--border);
	border-radius: 6px;
}

/* Стили для скроллбара */
.table-container::-webkit-scrollbar {
	width: 8px;
}

.table-container::-webkit-scrollbar-track {
	background: var(--bg);
	border-radius: 6px;
}

.table-container::-webkit-scrollbar-thumb {
	background: #64748b;
	border-radius: 6px;
	transition: background 0.2s;
}

.table-container::-webkit-scrollbar-thumb:hover {
	background: #475569;
}

[data-theme="dark"] .table-container::-webkit-scrollbar-thumb {
	background: #475569;
}

[data-theme="dark"] .table-container::-webkit-scrollbar-thumb:hover {
	background: #64748b;
}

.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.data-table thead {
	position: sticky;
	top: 0;
	background: var(--card);
	z-index: 10;
}

[data-theme="dark"] .data-table thead {
	background: #1e293b;
}

.data-table th {
	padding: 10px 12px;
	text-align: left;
	font-weight: 600;
	color: var(--muted);
	border-bottom: 2px solid var(--border);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.data-table th:last-child,
.data-table td:last-child {
	text-align: right;
}

.data-table tbody tr {
	border-bottom: 1px solid var(--border);
	transition: background-color 0.2s;
}

.data-table tbody tr:hover {
	background: var(--bg);
}

.data-table tbody tr:last-child {
	border-bottom: none;
}

.data-table td {
	padding: 10px 12px;
	color: var(--text);
}

.data-table .count-cell {
	font-weight: 600;
	color: var(--accent-1);
}

.data-table .duration-cell {
	color: var(--muted);
	font-variant-numeric: tabular-nums;
}

.data-table .no-data {
	color: var(--muted);
	font-style: italic;
}

/* Tooltip для детализации брака */
.product-tooltip {
	position: absolute;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 12px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	z-index: 1000;
	min-width: 250px;
	max-width: 400px;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s ease;
}

.product-tooltip.visible {
	opacity: 1;
}

.product-tooltip-title {
	font-weight: 600;
	margin-bottom: 8px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--border);
	color: var(--text);
	font-size: 13px;
}

.product-tooltip-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 4px 0;
	font-size: 12px;
	color: var(--text);
}

.product-tooltip-name {
	flex: 1;
	margin-right: 12px;
}

.product-tooltip-stats {
	display: flex;
	gap: 8px;
	font-variant-numeric: tabular-nums;
}

.product-tooltip-count {
	color: var(--muted);
}

.product-tooltip-percentage {
	font-weight: 500;
	color: var(--text);
}

.product-tooltip-empty {
	color: var(--muted);
	font-style: italic;
	font-size: 12px;
}

.product-row-with-tooltip {
	position: relative;
	cursor: help;
}

/* Стили для таблицы по периодам */
.period-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.period-table thead {
	background: var(--bg);
}

.period-table th {
	padding: 8px 12px;
	text-align: left;
	font-weight: 600;
	font-size: 11px;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	border-bottom: 1px solid var(--border);
}

.period-table th:nth-child(2),
.period-table th:nth-child(3),
.period-table th:nth-child(4) {
	text-align: center;
}

.period-table th:last-child {
	text-align: right;
}

.period-table tbody tr {
	border-bottom: 1px solid var(--border);
	transition: background-color 0.2s;
}

.period-table tbody tr:hover {
	background: var(--bg);
}

.period-table tbody tr:last-child {
	border-bottom: none;
}

.period-table td {
	padding: 12px;
	color: var(--text);
}

.period-table .date-cell {
	font-weight: 500;
	color: var(--text);
}

.period-table .number-cell {
	text-align: center;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.period-table .growth-cell {
	text-align: center;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.period-table .growth-positive {
	color: #10b981;
}

.period-table .growth-negative {
	color: #ef4444;
}

.period-table .time-cell {
	text-align: right;
	padding: 8px 12px;
	font-variant-numeric: tabular-nums;
}

.period-table .time-bar {
	display: inline-block;
	height: 24px;
	line-height: 24px;
	padding: 0 12px;
	border-radius: 4px;
	font-weight: 600;
	font-size: 12px;
	color: #fff;
}

.period-table .time-bar-low {
	background: linear-gradient(135deg, #10b981, #059669);
}

.period-table .time-bar-medium {
	background: linear-gradient(135deg, #f59e0b, #d97706);
}

.period-table .time-bar-high {
	background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Стили для сортируемых заголовков */
.period-table th.sortable {
	cursor: pointer;
	user-select: none;
	position: relative;
	padding-right: 20px;
}

.period-table th.sortable:hover {
	background: var(--bg);
}

.period-table th.sortable,
.data-table th.sortable {
	position: relative;
	cursor: pointer;
	user-select: none;
	padding-right: 24px;
}

.period-table th.sortable::after,
.data-table th.sortable::after {
	content: '⇅';
	position: absolute;
	right: 8px;
	opacity: 0.3;
	font-size: 10px;
}

.period-table th.sortable.asc::after,
.data-table th.sortable.asc::after {
	content: '↑';
	opacity: 1;
}

.period-table th.sortable.desc::after,
.data-table th.sortable.desc::after {
	content: '↓';
	opacity: 1;
}

/* Tooltip для hover */
.tovar-tooltip {
	position: absolute;
	background: rgba(30, 41, 59, 0.95);
	border: 1px solid rgba(71, 85, 105, 0.5);
	border-radius: 6px;
	padding: 12px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
	z-index: 1000;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s;
	font-size: 13px;
	min-width: 200px;
	backdrop-filter: blur(8px);
}

[data-theme="light"] .tovar-tooltip {
	background: rgba(255, 255, 255, 0.95);
	border: 1px solid rgba(226, 232, 240, 0.8);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tovar-tooltip.visible {
	opacity: 1;
}

.tovar-tooltip h4 {
	margin: 0 0 8px 0;
	font-size: 13px;
	font-weight: 600;
	color: var(--text);
}

.tovar-tooltip .stat-row {
	display: flex;
	justify-content: space-between;
	margin: 4px 0;
	color: var(--muted);
}

.tovar-tooltip .stat-row .label {
	font-weight: 500;
}

.tovar-tooltip .stat-row .value {
	font-weight: 600;
	color: var(--text);
}

.theme-toggle {
	position: fixed;
	top: 16px;
	right: 16px;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--card);
	border: 1px solid var(--border);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	z-index: 1000;
	transition: all 0.2s;
}

.theme-toggle:hover {
	transform: scale(1.1);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.logout-button {
	position: fixed;
	top: 16px;
	right: 72px;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--card);
	border: 1px solid var(--border);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	z-index: 1000;
	transition: all 0.2s;
	text-decoration: none;
	color: var(--text);
}

.logout-button:hover {
	transform: scale(1.1);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	background: rgba(239, 68, 68, 0.1);
	border-color: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .logout-button:hover {
	background: rgba(239, 68, 68, 0.15);
	border-color: rgba(239, 68, 68, 0.4);
}

.theme-toggle span {
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

.theme-toggle:hover {
	transform: scale(1.1);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.error {
	color: #dc2626;
	margin-top: 10px;
	min-height: 20px;
}

@media (max-width: 800px) {
	.cards {
		grid-template-columns: 1fr;
	}
}

/* Tabs */
.tabs-container {
	margin: 20px 0;
}

.tabs-nav {
	display: flex;
	gap: 4px;
	border-bottom: 2px solid var(--border);
	margin-bottom: 20px;
}

.tab-button {
	padding: 12px 24px;
	background: transparent;
	border: none;
	border-bottom: 3px solid transparent;
	color: var(--muted);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s;
	position: relative;
	bottom: -2px;
}

.tab-button:hover {
	color: var(--text);
	background: var(--tab-hover-bg, rgba(59, 130, 246, 0.1));
}

.tab-button.active {
	color: var(--accent-1);
	border-bottom-color: var(--accent-1);
	font-weight: 600;
}

[data-theme="dark"] .tab-button.active {
	color: #60a5fa;
	border-bottom-color: #60a5fa;
}

.tab-content {
	display: none;
}

.tab-content.active {
	display: block;
	animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Help Icon & Tooltip */
.help-icon {
	display: inline-block;
	width: 16px;
	height: 16px;
	line-height: 16px;
	text-align: center;
	border-radius: 50%;
	background: var(--border);
	color: var(--muted);
	font-size: 11px;
	font-weight: 600;
	cursor: help;
	margin-left: 6px;
	position: relative;
	vertical-align: middle;
	transition: all 0.2s;
}

.help-icon:hover {
	background: var(--accent-1);
	color: white;
	transform: scale(1.1);
}

[data-theme="dark"] .help-icon {
	background: #334155;
	color: #94a3b8;
}

[data-theme="dark"] .help-icon:hover {
	background: #3b82f6;
	color: white;
}

.help-icon::before {
	content: '?';
}

.help-icon::after {
	content: attr(data-tooltip);
	position: absolute;
	left: 50%;
	bottom: 100%;
	transform: translateX(-50%);
	margin-bottom: 8px;
	padding: 8px 12px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 6px;
	color: var(--text);
	font-size: 11px;
	line-height: 1.4;
	white-space: pre-line;
	max-width: 280px;
	width: max-content;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s, visibility 0.2s;
	pointer-events: none;
	z-index: 1000;
	font-weight: 400;
}

[data-theme="dark"] .help-icon::after {
	background: #1e293b;
	border-color: #475569;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.help-icon:hover::after {
	opacity: 1;
	visibility: visible;
	transition-delay: 0.3s;
}