/* Modul Cloud — the MODUL Workspace navigation rail
   ---------------------------------------------------------------------------
   Global navigation as a vertical column on the left, the way a corporate
   portal is built: the applications are always visible, always in the same
   place, and getting to one of them never costs a menu.

   The layout is driven from three variables set in the preset and in the
   generated per-user stylesheet — --mt-rail-display, --mt-rail-width and
   --mt-appmenu-display — so the shell is already in rail mode on the first
   paint. The rail's own markup is built by js/shell-rail.js a moment later and
   drops into space that has been reserved for it, so nothing reflows.

   Three widths, and the browser picks between them: expanded (labels),
   compact (icons, the default) and overlay (narrow windows, where the rail
   slides over the content instead of pushing it). */

#mt-rail {
	display: var(--mt-rail-display);
	position: fixed;
	inset-block: 0;
	inset-inline-start: 0;
	z-index: 2100; /* above the Nextcloud header (2000) */
	flex-direction: column;
	width: var(--mt-rail-width);
	background: var(--mt-rail-bg);
	/* Колонка умеет быть полупрозрачной, и тогда за ней нужно размытие: без
	   него фотография читается сквозь значки. Оба значения приходят из
	   настроек, при непрозрачной колонке фильтр вырождается в blur(0). */
	backdrop-filter: var(--mt-glass-rail);
	-webkit-backdrop-filter: var(--mt-glass-rail);
	border-inline-end: var(--mt-rail-border-width) solid var(--mt-rail-border);
	color: var(--mt-rail-text);
	overflow: hidden;
	transition: width var(--mt-duration-panel) var(--mt-ease);
}

/* The shell steps aside in css/shell.css, which insets #header and
   #content-vue rather than adding a margin — see the note there. Only the
   transition belongs to the rail, so the two move together. */
#header,
#content,
#content-vue {
	transition: inset-inline-start var(--mt-duration-panel) var(--mt-ease);
}

/* Core's app *switcher* is redundant once every app is one click away — but
   the current application's name is not, so only the waffle goes. Hiding the
   whole .app-menu took the page title with it. */
.app-menu > .v-popper {
	display: var(--mt-appmenu-display) !important;
}

/* ---------------------------------------------------------------- brand -- */

.mt-rail__brand {
	display: flex;
	align-items: center;
	gap: var(--mt-space-2);
	height: var(--mt-header-height);
	min-height: var(--mt-header-height);
	padding-inline: 14px;
	border-bottom: 1px solid var(--mt-rail-border);
	color: inherit;
	text-decoration: none;
	flex-shrink: 0;
}

.mt-rail__mark {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	min-width: 30px;
	border-radius: var(--mt-radius-sm);
	background: var(--mt-rail-brand-bg);
	color: var(--mt-rail-brand-text);
	font-size: 15px;
	font-weight: 700;
	letter-spacing: -0.02em;
	flex-shrink: 0;
}

.mt-rail__wordmark {
	font-size: var(--mt-text-ui);
	font-weight: var(--mt-weight-semibold);
	letter-spacing: var(--mt-tracking-tight);
	white-space: nowrap;
	opacity: 0;
	transition: opacity var(--mt-duration) var(--mt-ease);
}

/* ----------------------------------------------------------------- list -- */

.mt-rail__scroll {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: var(--mt-space-2) var(--mt-space-15);
	scrollbar-width: none;
}
.mt-rail__scroll::-webkit-scrollbar { width: 0; }

.mt-rail__foot {
	flex: 0 0 auto;
	padding: var(--mt-space-15) var(--mt-space-15) var(--mt-space-2);
	border-top: 1px solid var(--mt-rail-border);
}

.mt-rail__group {
	display: flex;
	flex-direction: column;
	gap: 2px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.mt-rail__sep {
	height: 1px;
	margin: var(--mt-space-15) 8px;
	background: var(--mt-rail-border);
	border: 0;
}

/* ----------------------------------------------------------------- item -- */

.mt-rail__item {
	position: relative;
	display: flex;
	align-items: center;
	gap: 10px;
	height: 38px;
	padding-inline: 8px;
	border: 0;
	border-radius: var(--mt-radius-control);
	background: transparent;
	color: var(--mt-rail-text-muted);
	font: inherit;
	font-size: var(--mt-text-compact);
	font-weight: var(--mt-weight-medium);
	text-align: start;
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
	transition:
		background-color var(--mt-duration-fast) var(--mt-ease),
		color var(--mt-duration-fast) var(--mt-ease);
}

.mt-rail__item:hover {
	background: var(--mt-rail-hover);
	color: var(--mt-rail-text);
}

.mt-rail__item:focus-visible {
	outline: 2px solid var(--mt-primary);
	outline-offset: -2px;
}

/* The selected state is deliberately louder than hover — a marker on the
   leading edge plus a filled row — because on a rail of fifteen identical
   icons a background tint alone is not an answer to "where am I". */
.mt-rail__item[aria-current='page'] {
	background: var(--mt-rail-active-bg);
	color: var(--mt-rail-active-text);
}

/* The marker sits inside the item, not in the gutter: the scroller clips its
   overflow, so a bar hanging off the leading edge was simply invisible. */
.mt-rail__item[aria-current='page']::before {
	content: '';
	position: absolute;
	inset-inline-start: 0;
	top: var(--mt-rail-marker-top);
	bottom: var(--mt-rail-marker-bottom);
	height: var(--mt-rail-marker-height);
	width: var(--mt-rail-marker-width);
	margin-top: var(--mt-rail-marker-shift);
	border-radius: var(--mt-radius-pill);
	background: var(--mt-primary);
}

.mt-rail__icon {
	display: grid;
	place-items: center;
	width: var(--mt-rail-icon-box);
	min-width: var(--mt-rail-icon-box);
	height: var(--mt-rail-icon-box);
	flex-shrink: 0;
}

.mt-rail__icon svg,
.mt-rail__icon img {
	width: var(--mt-rail-icon);
	height: var(--mt-rail-icon);
	display: block;
	flex: none;
}

/* Belt and braces: any icon that escapes the wrapper still cannot claim the
   whole row. */
.mt-rail__item > svg {
	width: var(--mt-rail-icon);
	height: var(--mt-rail-icon);
	flex: none;
}

/* App icons ship as dark SVGs. On a graphite rail they have to be inverted,
   and the mask keeps a single-colour icon following the row's text colour
   through hover and selection instead of staying stubbornly black. */
.mt-rail__icon--mask {
	background-color: currentColor;
	-webkit-mask-position: center;
	mask-position: center;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-size: var(--mt-rail-icon) var(--mt-rail-icon);
	mask-size: var(--mt-rail-icon) var(--mt-rail-icon);
}

.mt-rail__label {
	flex: 1 1 auto;
	overflow: hidden;
	text-overflow: ellipsis;
	opacity: 0;
	transition: opacity var(--mt-duration) var(--mt-ease);
}

/* ---------------------------------------------------------------- badge -- */

.mt-rail__badge {
	display: none;
	min-width: 17px;
	height: 17px;
	padding-inline: 5px;
	border-radius: var(--mt-radius-pill);
	background: var(--mt-danger);
	color: #fff;
	font-size: var(--mt-text-meta);
	font-weight: var(--mt-weight-semibold);
	font-variant-numeric: tabular-nums;
	line-height: 17px;
	text-align: center;
	flex-shrink: 0;
}

.mt-rail__item[data-badge]:not([data-badge='0']) .mt-rail__badge { display: block; }

/* Compact rail has no room for a counter next to the label, so the badge
   becomes a dot pinned to the icon — same information, no truncation. */
.mt-rail__item[data-badge]:not([data-badge='0']) .mt-rail__icon::after {
	content: '';
	position: absolute;
	top: 6px;
	inset-inline-start: 24px;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--mt-danger);
	box-shadow: 0 0 0 2px var(--mt-rail-bg);
}

/* --------------------------------------------------------------- states -- */

.mt-rail__item.mt-rail__item--dragging {
	opacity: 0.4;
}

.mt-rail__item.mt-rail__item--dropbefore::after,
.mt-rail__item.mt-rail__item--dropafter::after {
	content: '';
	position: absolute;
	inset-inline: 4px;
	height: 2px;
	border-radius: 2px;
	background: var(--mt-primary);
}
.mt-rail__item--dropbefore::after { top: -2px; }
.mt-rail__item--dropafter::after { bottom: -2px; }

/* ================================================ подписи под значками == */
/*
 * A compact rail with a caption under each icon. Wider than icons alone and
 * far narrower than the labelled list, and it removes the guessing that an
 * icon-only column always involves — which is the trade every corporate portal
 * has to make somewhere.
 */
html[data-mt-rail-labels='true'] .mt-rail__item {
	flex-direction: column;
	gap: 2px;
	height: 54px;
	padding-inline: 2px;
	justify-content: center;
}

/* Names .mt-rail__item as well, to get one class ahead of the compact rule
   below that clips labels out of the layout — at equal specificity that rule
   wins on source order and the captions never appeared. */
html[data-mt-rail-labels='true'] .mt-rail__item .mt-rail__label {
	position: static;
	width: auto;
	height: auto;
	clip-path: none;
	opacity: 1;
	flex: none;
	max-width: 100%;
	font-size: 10px;
	line-height: 1.15;
	font-weight: var(--mt-weight-medium);
	text-align: center;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

html[data-mt-rail-labels='true'] .mt-rail__icon {
	width: 20px;
	min-width: 20px;
	height: 20px;
}

html[data-mt-rail-labels='true'] .mt-rail__icon svg,
html[data-mt-rail-labels='true'] .mt-rail__icon img {
	width: 18px;
	height: 18px;
}

html[data-mt-rail-labels='true'] .mt-rail__icon--mask {
	-webkit-mask-size: 18px 18px;
	mask-size: 18px 18px;
}

/* The dot moves with the icon rather than staying where the row used to be. */
html[data-mt-rail-labels='true'] .mt-rail__item[data-badge]:not([data-badge='0']) .mt-rail__icon::after {
	top: 2px;
	inset-inline-start: 22px;
}

html[data-mt-rail-labels='true'] .mt-rail__item[aria-current='page']::before {
	inset-block: 6px;
}

html[data-mt-rail-labels='true'] .mt-rail__brand .mt-rail__wordmark {
	position: static;
	width: auto;
	height: auto;
	clip-path: none;
	opacity: 1;
	font-size: 11px;
}

html[data-mt-rail-labels='true'] .mt-rail__brand {
	flex-direction: column;
	gap: 2px;
	height: auto;
	min-height: var(--mt-header-height);
	padding-block: var(--mt-space-15);
}

/* ================================================== expanded / compact == */

/* Compact is the default and needs nothing: the labels are already at opacity
   zero and the rail is already at its narrow width. Expanded turns them on. */
/*
 * Ширины здесь больше нет, и это исправление, а не упрощение. Правило
 * `html[data-mt-rail='expanded']` весит (0,1,1) и перебивало `:root` из
 * сгенерированного листа, поэтому, во-первых, ширину нельзя было настроить, а
 * во-вторых, при классической раскладке с сохранённым `rail: expanded`
 * содержимое отодвигалось на 216px от колонки, которой на экране нет.
 *
 * Ширину целиком считает генератор: он один знает и раскладку, и подписи, и
 * настройку пользователя, и отдаёт 0, когда колонки быть не должно.
 */

html[data-mt-rail='expanded'] .mt-rail__label,
html[data-mt-rail='expanded'] .mt-rail__wordmark {
	opacity: 1;
}

html[data-mt-rail='expanded'] .mt-rail__item[data-badge]:not([data-badge='0']) .mt-rail__icon::after {
	display: none;
}

/* In compact mode the labels are still in the DOM (screen readers need them)
   but must not claim width or the icons stop being centred. */
html:not([data-mt-rail='expanded']) .mt-rail__label,
html:not([data-mt-rail='expanded']) .mt-rail__wordmark {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
}

html:not([data-mt-rail='expanded']) .mt-rail__item {
	justify-content: center;
	padding-inline: 0;
}

html:not([data-mt-rail='expanded']) .mt-rail__brand {
	justify-content: center;
	padding-inline: 0;
}

html:not([data-mt-rail='expanded']) .mt-rail__badge { display: none !important; }

/* -------------------------------------------------------------- tooltip -- */
/* Only compact needs one, and it is a real floating layer rather than a title
   attribute, so it appears immediately and matches the rest of the product. */

.mt-rail__tip {
	position: fixed;
	z-index: 2200;
	display: flex;
	align-items: center;
	gap: var(--mt-space-2);
	max-width: 260px;
	padding: 5px 9px;
	border: 1px solid var(--mt-glass-line);
	border-radius: var(--mt-radius-control);
	background: var(--mt-surface-menu);
	backdrop-filter: var(--mt-glass-menu);
	-webkit-backdrop-filter: var(--mt-glass-menu);
	box-shadow: var(--mt-elevation-3);
	color: var(--mt-text);
	font-size: var(--mt-text-compact);
	font-weight: var(--mt-weight-medium);
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transform: translateX(-4px);
	transition:
		opacity var(--mt-duration-fast) var(--mt-ease),
		transform var(--mt-duration-fast) var(--mt-ease);
}

.mt-rail__tip[data-show='true'] {
	opacity: 1;
	transform: translateX(0);
}

.mt-rail__tip-count {
	padding-inline: 5px;
	border-radius: var(--mt-radius-pill);
	background: var(--mt-danger);
	color: #fff;
	font-size: var(--mt-text-meta);
	font-variant-numeric: tabular-nums;
}

/* ================================================ overlay (narrow) ====== */
/*
 * Below 1100px the rail stops pushing the content and starts covering it. The
 * shell offset drops to zero, the rail collapses to nothing, and a trigger in
 * the header brings it back as a sheet over a scrim. This is the only place
 * the rail is allowed to float.
 */
@media (max-width: 1100px) {
	html[data-mt-layout='rail'] {
		--mt-rail-width: 0px;
	}

	html[data-mt-layout='rail'] #mt-rail {
		width: 216px;
		box-shadow: var(--mt-elevation-4);
		transform: translateX(-100%);
		transition: transform var(--mt-duration-panel) var(--mt-ease);
	}

	html[data-mt-layout='rail'][data-mt-rail-open='true'] #mt-rail {
		transform: translateX(0);
	}

	/* An overlay rail always shows its labels: there is room, and a sheet of
	   anonymous icons over the content is worse than no sheet at all. */
	html[data-mt-layout='rail'] .mt-rail__label,
	html[data-mt-layout='rail'] .mt-rail__wordmark {
		position: static;
		width: auto;
		height: auto;
		clip-path: none;
		opacity: 1;
	}

	html[data-mt-layout='rail'] .mt-rail__item {
		justify-content: flex-start;
		padding-inline: 8px;
	}

	html[data-mt-layout='rail'] .mt-rail__brand {
		justify-content: flex-start;
		padding-inline: 14px;
	}

	/* Overlay has room for the counters again — but only for rows that
	   actually have one. The blanket rule this replaces put an empty red pill
	   next to every application in the list. */
	html[data-mt-layout='rail'] .mt-rail__item[data-badge]:not([data-badge='0']) .mt-rail__badge {
		display: block !important;
	}

	.mt-rail__scrim {
		position: fixed;
		inset: 0;
		z-index: 2050;
		background: color-mix(in srgb, #000 42%, transparent);
		opacity: 0;
		visibility: hidden;
		transition:
			opacity var(--mt-duration) var(--mt-ease),
			visibility var(--mt-duration) var(--mt-ease);
	}

	html[data-mt-rail-open='true'] .mt-rail__scrim {
		opacity: 1;
		visibility: visible;
	}
}

/* The overlay trigger only exists while the rail is a sheet. */
.mt-rail-trigger { display: none; }

@media (max-width: 1100px) {
	html[data-mt-layout='rail'] .mt-rail-trigger {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: var(--mt-control-lg);
		height: var(--mt-control-lg);
		margin-inline-end: var(--mt-space-1);
		border: 0;
		border-radius: var(--mt-radius-control);
		background: transparent;
		color: var(--mt-text);
		cursor: pointer;
	}
	html[data-mt-layout='rail'] .mt-rail-trigger:hover { background: var(--mt-hover-bg-strong); }
	html[data-mt-layout='rail'] .mt-rail-trigger svg { width: 20px; height: 20px; }
}

/* On a phone the sheet takes most of the width and the header logo needs its
   space back. */
@media (max-width: 660px) {
	html[data-mt-layout='rail'] #mt-rail { width: min(280px, 82vw); }
}

@media (prefers-reduced-motion: reduce) {
	#mt-rail,
	#header,
	#content,
	#content-vue { transition: none; }
}
