/*
** Copyright (C) 2021-2026 initMAX s.r.o.
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/

/* Chrome-only: inherits theme text colour, translucent greys for hovers/borders — one rule set works in both themes, no JS. */

.navigatormax {
	box-sizing: border-box;
	height: 100%;
	overflow: auto;
	font-size: 12px;
}

/* Our inline glyphs: drawn in the surrounding text colour, never shrink in a flex row. */
.navigatormax-icon {
	display: inline-block;
	vertical-align: middle;
	flex: 0 0 auto;
}

/* ---- List view: folder tree ------------------------------------------- */

.navigatormax-tree {
	margin: 0;
	padding: 0;
	list-style: none;
}

.navigatormax-tree .navigatormax-tree {
	padding-left: 16px;
}

.navigatormax .tree-folder-header {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 3px 4px;
	border-radius: 3px;
	cursor: pointer;
	user-select: none;
}

.navigatormax .tree-folder-header:hover {
	background: rgba(127, 127, 127, 0.12);
}

/* Tabler chevron; expanded = pointing down (rotated 90deg), collapsed = pointing right. */
.navigatormax .tree-folder-toggle {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	opacity: 0.65;
	transform: rotate(90deg);
	transition: transform 0.1s ease;
}

.navigatormax .tree-folder-toggle svg {
	width: 14px;
	height: 14px;
}

.navigatormax .tree-folder.collapsed > .tree-folder-header .tree-folder-toggle {
	transform: rotate(0deg);
}

.navigatormax .tree-folder.collapsed > .navigatormax-tree {
	display: none;
}

.navigatormax .tree-folder-label {
	font-weight: 600;
	color: inherit;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* List leaf: link row + optional page-picker caret sibling; hover highlight and tree indent live here, not on the link. */
.navigatormax .navigatormax-leaf {
	display: flex;
	align-items: center;
	gap: 4px;
	position: relative;
	padding-left: 20px;
	/* Badges are a leaf sibling, so the leaf's right padding keeps them off the widget edge/scrollbar. */
	padding-right: 8px;
	border-radius: 3px;
}

.navigatormax .navigatormax-leaf:hover {
	background: rgba(127, 127, 127, 0.12);
}

/* Link row: [bar][icon][name/desc]…[badges]. Inherits theme colour, never recolours on visit. */
.navigatormax .navigatormax-row,
.navigatormax .navigatormax-row:visited,
.navigatormax .navigatormax-row:hover,
.navigatormax .navigatormax-row:focus {
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 3px 6px;
	color: inherit;
	text-decoration: none;
	/* Zabbix draws link hover/focus underline as a blue border-bottom; drop it — leaf's grey hover suffices. */
	border-bottom: 0;
	min-width: 0;
}

/* Page-picker caret. A bare <button> gets Zabbix's blue skin in every state, so reset colour/background in all — scoped under .navigatormax to beat button:hover specificity. */
.navigatormax .navigatormax-row-caret,
.navigatormax .navigatormax-row-caret:hover,
.navigatormax .navigatormax-row-caret:focus,
.navigatormax .navigatormax-row-caret:active {
	color: inherit;
	background: transparent;
	box-shadow: none;
}

.navigatormax-row-caret {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	/* Undo Zabbix's fixed button box (min-width:24px; height:24px; line-height:22px) so the caret sizes to the chevron. */
	min-width: 0;
	width: auto;
	height: auto;
	line-height: 0;
	/* 1px transparent border reserved so showing it on hover adds no layout shift. */
	padding: 1px;
	cursor: pointer;
	border: 1px solid transparent;
	border-radius: 3px;
	opacity: 0.55;
}

.navigatormax .navigatormax-row-caret:hover,
.navigatormax .navigatormax-row-caret:focus {
	opacity: 1;
	border-color: currentColor;
}

.navigatormax-row-caret svg {
	width: 12px;
	height: 12px;
}

/* Native Zabbix popup chrome, heading, links, selected marker and theme colours. */
.navigatormax-row-menu.menu-popup {
	max-width: min(250px, calc(100vw - 8px));
	max-height: min(220px, calc(100vh - 20px));
}

.navigatormax-row-menu[hidden] {
	display: none;
}

/* Left colour bar; stands in for the tile's fill, only present when painted by a rule/problems. */
.navigatormax-row-bar {
	flex: 0 0 auto;
	align-self: stretch;
	width: 4px;
	min-height: 14px;
	border-radius: 2px;
}

.navigatormax-row-icon {
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	object-fit: contain;
}

/* Name (+ description) take the slack; the badges keep their room at the row end. */
.navigatormax-row-text {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.navigatormax-row-name {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-size: var(--navigatormax-font, 12px);
	line-height: 1.3;
}

.navigatormax-row-desc {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	opacity: 0.7;
	font-size: calc(var(--navigatormax-font, 12px) - 1px);
	line-height: 1.2;
}

/* Reuse the grid's badge pills at the row's end; undo the bottom-pin (margin-top:auto). */
.navigatormax-leaf .navigatormax-btn-badges {
	flex: 0 0 auto;
	margin: 0;
	padding-top: 0;
	justify-content: flex-end;
}

/* ---- Buttons view: grid of tiles -------------------------------------- */

/* Flex column: fixed cols×rows grid (set inline) fills the widget, pager sits under it; overflow paginated by class.widget.js. */
.navigatormax-buttons {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	/* padding is set inline (half the inter-tile gap). */
}

.navigatormax-matrix {
	flex: 1 1 auto;
	min-height: 0;
	display: grid;
	/* grid-template-columns / grid-auto-rows / gap are set inline by the controller. */
}

.navigatormax .navigatormax-btn {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	padding: calc(6px + var(--navigatormax-reserve-top, 0px)) 6px
		calc(6px + var(--navigatormax-reserve-bottom, 0px));
	min-width: 0;
	min-height: 0;
	border: 1px solid rgba(127, 127, 127, 0.55);
	border-radius: var(--navigatormax-radius, 6px);
	/* No fill by default; painted only when a Default or per-tile colour is set (inline). */
	background: transparent;
	text-align: center;
	text-decoration: none;
	overflow: hidden;
	transition: border-color 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

/* Beat legacy a:link/focus styles too: multi-page links inherit the wrapper's contrast colour. */
.navigatormax .navigatormax-btn,
.navigatormax .navigatormax-btn:visited,
.navigatormax .navigatormax-btn:hover,
.navigatormax .navigatormax-btn:focus,
.navigatormax .navigatormax-btn:active {
	color: inherit;
}

/* Hover uses shadow + brightness (not a bg swap) so it works over any custom tile fill. */
.navigatormax-btn:hover {
	border-color: rgba(127, 127, 127, 0.65);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
	filter: brightness(1.05);
}

/* Wrapper (the grid cell) lets the page caret be a sibling of the <a>, never nested; menu opens FIXED so overflow:hidden can't clip it. */
.navigatormax-tile {
	position: relative;
	display: flex;
	min-width: 0;
	min-height: 0;
}

.navigatormax-tile > .navigatormax-btn {
	flex: 1 1 auto;
	min-width: 0;
}

/* Top-right chevron, no chip (clashed on dark problem fills); stroke is currentColor so it reads on any fill. */
.navigatormax-tile > .navigatormax-row-caret {
	position: absolute;
	top: 3px;
	right: 3px;
	z-index: 2;
	background: transparent;
	opacity: 0.85;
}

.navigatormax-tile > .navigatormax-row-caret:hover {
	opacity: 1;
}

/* Icon and text form one centred group; measured footer room limits the icon height. */
.navigatormax-btn-icon {
	min-height: 0;
	max-width: 100%;
	max-height: var(--navigatormax-icon-room, 100%);
	object-fit: contain;
	width: var(--navigatormax-icon-size, auto);
	height: var(--navigatormax-icon-size, auto);
	flex: 0 1 auto;
}

/* Keep text inside its measured room, including when a tiny tile cannot fit a full line. */
.navigatormax-btn-text {
	flex: 0 0 auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	max-width: 100%;
	max-height: var(--navigatormax-content-room, none);
	overflow: hidden;
}

/* Font size and line count set by class.widget.js from measured tile height; overflow ends in an ellipsis. */
.navigatormax-btn-label {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: var(--navigatormax-lines, 3);
	overflow: hidden;
	font-size: var(--navigatormax-font, 12px);
	font-weight: 600;
	line-height: 1.25;
	word-break: break-word;
}

/* "host:" prefix dimmed + lighter so it reads as a separate part on both themes. */
.navigatormax-btn-host {
	opacity: 0.6;
	font-weight: 400;
}

/* A short, dimmed line under the name; clamped to two lines so it cannot dominate the tile. */
.navigatormax-btn-desc {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	opacity: 0.75;
	font-size: calc(var(--navigatormax-font, 12px) - 1px);
	font-weight: 400;
	line-height: 1.2;
	word-break: break-word;
	max-height: var(--navigatormax-description-room, none);
}

/* Problem badges = tile's bottom row; margin-top:auto pins them to the bottom edge. */
.navigatormax-btn-badges {
	flex: 0 0 auto;
	margin-top: auto;
	padding-top: 2px;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 3px;
	max-width: 100%;
}

/* One pill per firing severity (worst first): initial + count in that severity's colour; ring separates it from a same-coloured tile. */
.navigatormax-btn-badge {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	padding: 2px 4px;
	border-radius: 3px;
	font-size: 10px;
	/* line-height 1 hugs the digit so align-items:center puts glyph + number at the same optical
	   height (a taller line box drops its baseline, making the box-centred icon read low). */
	line-height: 1;
	font-variant-numeric: tabular-nums;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* Badges linking to Problems get their own pointer + hover lift, reading as a separate click target. */
.navigatormax-btn-badges[data-problems-url] {
	cursor: pointer;
}

.navigatormax-btn-badges[data-problems-url]:hover .navigatormax-btn-badge {
	filter: brightness(1.08);
}

/* The initial reads as a label, the count as the number. */
.navigatormax-btn-badge-sev {
	font-weight: 700;
	opacity: 0.85;
}

/* The severity glyph (solid fill): sized to the pill text, coloured by the pill (currentColor).
   display:block drops the inline-svg baseline gap so it centres cleanly against the number. */
.navigatormax-btn-badge-icon {
	display: block;
	width: 11px;
	height: 11px;
	opacity: 0.9;
}

.navigatormax-btn-badge-n {
	font-weight: 700;
}

/* Not enough height on THIS tile: drop the icon (class.widget.js sets it per tile), giving the room to the text. */
.navigatormax-btn--tiny .navigatormax-btn-icon {
	display: none;
}

/* Grid footer never pushes the centred icon/text group. List badges retain their row layout. */
.navigatormax-btn > .navigatormax-btn-badges {
	position: absolute;
	left: 6px;
	right: 6px;
	bottom: 6px;
	margin-top: 0;
	/* Keep each pill's ring and shadow inside the clipped footer. */
	padding: 2px 2px 3px;
	max-height: calc(100% - 12px);
	overflow: hidden;
}

.navigatormax-pager {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 4px 0 2px;
	font-variant-numeric: tabular-nums;
}

.navigatormax-pager-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	padding: 1px 6px;
	cursor: pointer;
	border: 1px solid rgba(127, 127, 127, 0.4);
	border-radius: 3px;
	background: rgba(127, 127, 127, 0.08);
	color: inherit;
}

.navigatormax-pager-btn:hover:not(:disabled) {
	background: rgba(127, 127, 127, 0.18);
}

.navigatormax-pager-btn:disabled {
	opacity: 0.4;
	cursor: default;
}

.navigatormax-truncated {
	margin-top: 6px;
	color: #768d99;
	font-size: 11px;
}

.navigatormax-state-warning {
	display: flex;
	gap: 5px;
	margin-top: 6px;
	font-size: 11px;
}
.navigatormax-state-warning-icon { color: #e07800; }
.navigatormax-state-unknown {
	background: #fff;
	color: #1f2c33;
	padding: 2px 5px;
	border-radius: 3px;
	font-size: 11px;
}

/* The widget owns its spacing. Core's bottom padding otherwise leaves an unpainted strip. */
.dashboard-widget-navigatormax .dashboard-grid-widget-body { padding: 0; }
.dashboard-grid-widget-contents.dashboard-widget-navigatormax { padding-bottom: 0; }

.navigatormax .navigatormax-pager-btn:is(:hover, :focus, :active) {
 color: inherit;
 background: rgba(127, 127, 127, .18);
}
.navigatormax :is(.navigatormax-pager-btn, .navigatormax-btn):focus-visible {
 outline: 2px solid currentColor;
 outline-offset: -3px;
}
