/* Modul Cloud — shared component restyle
   ---------------------------------------------------------------------------
   Targets the @nextcloud/vue class families that every first-party app uses
   (Files, Dashboard, Mail, Calendar, Contacts, Notes, Deck, Tables, Forms all
   share the component library), so one pass here is consistent everywhere.

   Two principles run through the whole file:

   * Shape carries meaning. A button, an input and a list row are 6px; a card
     is 8px; a menu is 10px; a dialog is 14px. Full pills are reserved for
     badges, tags, status chips and avatars — things that are genuinely
     lozenge-shaped rather than merely small.

   * Every interactive component gets its full set of states, and they are
     ordered by loudness: selected beats hover, focus is always visible from
     the keyboard, disabled is unmistakable. The commonest complaint about the
     old build was that nothing looked clickable and nothing looked chosen. */

body {
	font-family: var(--mt-font) !important;
}

/* =============================================================== focus == */
/*
 * One focus ring for the whole product.
 *
 * Core ships `button:not(:disabled,.primary):focus-visible { outline: 2px solid
 * var(--color-main-text) !important }` at (0,2,1). A single class of ours ties
 * that and loses on nothing but source order, which turned out to be unreliable
 * — every control in the appearance panel was drawing core's black ring instead
 * of the accent one. Naming html and body gets to (0,2,3) and settles it.
 *
 * The ring is the accent, with a two-pixel halo in the surface colour outside
 * it. The halo is what makes it safe: an accent ring alone can land on a tinted
 * or selected row where it has almost no contrast, and core's text-coloured
 * ring was chosen for exactly that reason. This keeps the guarantee and the
 * brand.
 */
html body :is(button, a, input, select, textarea, summary, [tabindex]):not(:disabled):focus-visible {
	outline: 2px solid var(--mt-primary) !important;
	outline-offset: 2px;
	box-shadow: 0 0 0 2px var(--mt-surface) !important;
}

/* Inside a dense list a 2px offset collides with the neighbouring row, so the
   ring is drawn just inside the element instead. */
html body .files-list__row:focus-visible,
html body .app-navigation-entry-link:focus-visible,
html body .mt-conv:focus-visible {
	outline-offset: -2px;
}

/* ============================================================= buttons == */

.button-vue {
	border-radius: var(--mt-radius-control) !important;
	font-size: var(--mt-text-compact) !important;
	font-weight: var(--mt-weight-medium) !important;
	letter-spacing: 0 !important;
	box-shadow: none !important;
	transition:
		background-color var(--mt-duration-fast) var(--mt-ease),
		border-color var(--mt-duration-fast) var(--mt-ease),
		color var(--mt-duration-fast) var(--mt-ease),
		transform var(--mt-duration-fast) var(--mt-ease) !important;
}

/* A flat accent fill. The old build put a 135° gradient on every primary
   button, which is the single clearest tell of a generated interface — real
   products use one colour and let elevation do the talking. */
.button-vue--vue-primary,
.button-vue[type='primary'] {
	background: var(--mt-primary) !important;
	border: 1px solid transparent !important;
	/* Anchors carrying .button-vue never get core's colour rule (those target
	   <button>), so they inherited the page text colour and vanished into the
	   accent fill. Set it here for both. */
	color: var(--mt-on-primary) !important;
}

.button-vue--vue-primary:hover,
.button-vue[type='primary']:hover {
	background: var(--mt-primary-hover) !important;
}

.button-vue--vue-secondary {
	background: var(--mt-surface-card) !important;
	border: 1px solid var(--mt-border-strong) !important;
	color: var(--mt-text) !important;
}
.button-vue--vue-secondary:hover {
	background: var(--mt-hover-bg) !important;
	border-color: var(--mt-text-faint) !important;
}

.button-vue--tertiary:hover,
.button-vue--tertiary-no-background:hover {
	background: var(--mt-hover-bg-strong) !important;
}

.button-vue:not(.button-vue--tertiary):not(.button-vue--tertiary-no-background):hover {
	transform: translateY(calc(var(--mt-hover-lift) * var(--mt-hover-strength)));
}

.button-vue:active { transform: translateY(0) !important; }

.button-vue:focus-visible {
	outline: 2px solid var(--mt-primary) !important;
	outline-offset: 2px;
}

.button-vue:disabled,
.button-vue[aria-disabled='true'] {
	opacity: var(--mt-disabled-opacity) !important;
	cursor: not-allowed;
}

.button-vue--icon-only { border-radius: var(--mt-radius-control) !important; }

/* Anchors styled as buttons get none of core's box rules (they target
   <button>), so they arrived with no padding and no height — the fill hugged
   the text and read as a selection highlight rather than a button. */
a.button-vue {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--mt-space-2);
	min-height: var(--default-clickable-area);
	padding: 0 var(--mt-space-3);
	text-decoration: none;
}

/* ============================================== inputs, selects, switches == */

.input-field {
	--input-field-border-radius: var(--mt-radius-control);
}

/*
 * Global control restyling. Apps that ship their own design system opt out:
 * `.mt-ui` marks the Modul Messenger subtree, which owns its own field
 * colours — repainting them from here produced unreadable combinations.
 */
:not(.mt-ui) > .input-field__input,
input[type='text']:not(.mt-ui *),
input[type='password']:not(.mt-ui *),
input[type='email']:not(.mt-ui *),
input[type='search']:not(.mt-ui *),
input[type='number']:not(.mt-ui *),
textarea:not(.mt-ui *) {
	border-radius: var(--mt-radius-control) !important;
	border: 1px solid var(--mt-border) !important;
	background-color: var(--mt-surface-field) !important;
	color: var(--mt-text) !important;
	font-size: var(--mt-text-compact) !important;
	transition:
		border-color var(--mt-duration-fast) var(--mt-ease),
		background-color var(--mt-duration-fast) var(--mt-ease),
		box-shadow var(--mt-duration-fast) var(--mt-ease) !important;
}

input:hover:not(.mt-ui *):not(:focus),
textarea:hover:not(.mt-ui *):not(:focus) {
	border-color: var(--mt-border-strong) !important;
}

.input-field__input:focus:not(.mt-ui *),
input:focus:not(.mt-ui *),
textarea:focus:not(.mt-ui *) {
	border-color: var(--mt-primary) !important;
	background-color: var(--mt-surface) !important;
	box-shadow: 0 0 0 3px var(--mt-selected-bg) !important;
	outline: none !important;
}

input[aria-invalid='true']:not(.mt-ui *),
.input-field--error .input-field__input {
	border-color: var(--mt-danger) !important;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--mt-danger) 14%, transparent) !important;
}

input:disabled:not(.mt-ui *),
textarea:disabled:not(.mt-ui *) {
	opacity: var(--mt-disabled-opacity) !important;
	cursor: not-allowed;
}

.select,
select {
	border-radius: var(--mt-radius-control) !important;
}

.checkbox-radio-switch {
	border-radius: var(--mt-radius-control) !important;
	transition: background-color var(--mt-duration-fast) var(--mt-ease) !important;
}

/* A checked checkbox tints its row; it does not become a filled button. Solid
   accent here made "Remember me" on the login screen read as the primary
   action, which it is not. */
.checkbox-radio-switch--checked {
	background-color: var(--mt-selected-bg) !important;
	border-color: var(--mt-selected-border) !important;
}

/* ============================================================= dialogs == */

.modal-mask {
	background-color: color-mix(in srgb, #05070d 46%, transparent) !important;
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
	transition: opacity var(--mt-duration-panel) var(--mt-ease) !important;
}

.modal-container,
.dialog__modal .modal-container,
.dialog {
	border-radius: var(--mt-radius-modal) !important;
	background-color: var(--mt-surface-modal) !important;
	backdrop-filter: var(--mt-glass-modal);
	-webkit-backdrop-filter: var(--mt-glass-modal);
	border: 1px solid var(--mt-glass-line);
	box-shadow: var(--mt-elevation-4), inset 0 1px 0 var(--mt-glass-highlight) !important;
	animation: mt-modal-in var(--mt-duration-panel) var(--mt-ease);
}

.dialog__actions .button-vue { border-radius: var(--mt-radius-control) !important; }

@keyframes mt-modal-in {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ================================= menus, popovers and contextual actions == */

.action-item__popper,
.v-popper__popper .v-popper__inner,
.contextmenu,
.header-menu__content {
	border-radius: var(--mt-radius-menu) !important;
	background-color: var(--mt-surface-menu) !important;
	backdrop-filter: var(--mt-glass-menu);
	-webkit-backdrop-filter: var(--mt-glass-menu);
	border: 1px solid var(--mt-glass-line) !important;
	box-shadow: var(--mt-elevation-3), inset 0 1px 0 var(--mt-glass-highlight) !important;
	overflow: hidden;
}

/*
 * Меню открывалось в левом верхнем углу экрана и через десятую секунды
 * прыгало на место. Причина была не в библиотеке позиционирования, а в этом
 * файле, и ошибок оказалось две подряд.
 *
 * Первая: .action-item__popper — это и есть обёртка, которой floating-ui
 * ставит координаты инлайновым `transform: translate(x, y)`. Анимация сильнее
 * инлайнового стиля: пока играет keyframe со своим `transform`, значение из
 * атрибута style не действует вовсе. Все 120 мс меню рисовалось в нулевой
 * точке содержащего блока, а по окончании анимации инлайновый transform
 * вступал в силу — отсюда скачок.
 *
 * Вторая: заменить keyframe на «только прозрачность» мало. Библиотека сама
 * держит попап невидимым классом .v-popper__popper--hidden до тех пор, пока не
 * посчитает координаты. Анимация по opacity перебивает и это, поэтому пару
 * кадров окно было видно в нуле — уже без прыжка, но всё равно заметно.
 *
 * Отсюда правило, которое стоит помнить: элемент, чьим показом и положением
 * управляет скрипт, тема не анимирует вообще. Обёртке оставлено оформление,
 * а движение перенесено на .v-popper__inner — внутреннюю коробку, которую
 * никто не позиционирует и не прячет.
 */
.v-popper__popper .v-popper__inner {
	animation: mt-pop-in var(--mt-duration-fast) var(--mt-ease);
}

/* Эти два не из v-popper: их показывает и располагает CSS, поэтому мягкое
   проявление им не мешает. */
.contextmenu,
.header-menu__content {
	animation: mt-pop-fade var(--mt-duration-fast) var(--mt-ease);
}

@keyframes mt-pop-fade {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes mt-pop-in {
	from { opacity: 0; transform: translateY(-3px); }
	to { opacity: 1; transform: translateY(0); }
}

.action-item .action-button,
.action-item button {
	border-radius: var(--mt-radius-xs) !important;
	font-size: var(--mt-text-compact);
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}
.action-item .action-button:hover { background: var(--mt-hover-bg-strong) !important; }

.header-menu__trigger {
	border-radius: var(--mt-radius-control) !important;
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}
.header-menu__trigger:hover { background-color: var(--mt-hover-bg-strong) !important; }

/* ================================================ app navigation sidebar == */

.app-navigation {
	background: var(--mt-surface-panel) !important;
	border-right: 1px solid var(--mt-border) !important;
	border-radius: var(--mt-radius-card) 0 0 var(--mt-radius-card);
}

/* Only a navigation nested *inside* .app-navigation may go transparent — it is
   then just the inner scroller of a panel that is already painted. Apps differ
   here: Deck renders .app-navigation > #app-navigation-vue, but Files and
   Calendar put both on the same element, and clearing that one's background
   left the sidebar see-through with the wallpaper straight behind its text. */
.app-navigation #app-navigation-vue,
.app-navigation .app-navigation__content {
	background: transparent !important;
	border-right: none !important;
	border-radius: inherit;
}

/* A navigation that is its own root still needs the panel surface. */
#app-navigation-vue.app-navigation {
	background: var(--mt-surface-panel) !important;
}

.app-navigation-entry {
	border-radius: var(--mt-radius-control) !important;
	margin: 1px var(--mt-space-15);
	font-size: var(--mt-text-compact);
	transition:
		background-color var(--mt-duration-fast) var(--mt-ease),
		color var(--mt-duration-fast) var(--mt-ease);
}

.app-navigation-entry-link:hover,
.app-navigation-entry:hover {
	background-color: var(--mt-hover-bg-strong) !important;
}

/* Selected is a tint plus a weight change plus an edge marker — three signals,
   because one tint at 8% is invisible against a hover at 5%. */
.app-navigation-entry--active,
.app-navigation-entry.active {
	position: relative;
	background: var(--mt-selected-bg-strong) !important;
	color: var(--mt-primary) !important;
	font-weight: var(--mt-weight-semibold);
}

.app-navigation-entry--active::before,
.app-navigation-entry.active::before {
	content: '';
	position: absolute;
	inset-inline-start: 0;
	inset-block: 6px;
	width: 3px;
	border-radius: var(--mt-radius-pill);
	background: var(--mt-primary);
}

.app-navigation-entry--active .app-navigation-entry-icon,
.app-navigation-entry.active .app-navigation-entry-icon {
	filter: none;
}

/* ============================================= app switcher (waffle grid) == */

.app-menu__waffle,
.app-menu__current-app {
	border-radius: var(--mt-radius-control) !important;
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}
.app-menu__waffle:hover,
.app-menu__current-app:hover { background-color: var(--mt-hover-bg-strong) !important; }

.app-menu__popover-base .v-popper__inner,
.app-menu__popover {
	border-radius: var(--mt-radius-menu) !important;
	background-color: var(--mt-surface-menu) !important;
	backdrop-filter: var(--mt-glass-menu);
	-webkit-backdrop-filter: var(--mt-glass-menu);
	border: 1px solid var(--mt-glass-line) !important;
	box-shadow: var(--mt-elevation-3), inset 0 1px 0 var(--mt-glass-highlight) !important;
	padding: var(--mt-space-2) !important;
}

/* Та же причина, что и выше: движение только на внутренней коробке. */
.app-menu__popover-base .v-popper__inner {
	animation: mt-pop-in var(--mt-duration-fast) var(--mt-ease);
}

.app-menu__grid { gap: 2px !important; }

.app-item {
	border-radius: var(--mt-radius-card) !important;
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}
.app-item:hover { background-color: var(--mt-hover-bg-strong) !important; }

.app-item__circle {
	border-radius: var(--mt-radius-card) !important;
	box-shadow: none;
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}

.app-item--active .app-item__circle {
	background: var(--mt-primary) !important;
}

.app-item__label {
	font-weight: var(--mt-weight-medium);
	font-size: var(--mt-text-label);
}

/*
 * Значки в сетке приложений — одним цветом.
 *
 * Разнобой был не в теме, а в самих приложениях: files, mail, deck и офис
 * рисуют свой значок белым, а наши — через currentColor, который внутри <img>
 * означает чёрный. Ядро выравнивает это единственным фильтром `invert` и
 * только для светлой фирменной поверхности, так что на тёмно-зелёной половина
 * значков оставалась чёрной. Плитка с рамкой (у администратора это «Ещё
 * приложения») исключена: она прозрачная, и белый значок на ней пропал бы.
 */
.app-menu__grid .app-item:not(.app-item--outlined) .app-item__icon {
	filter: var(--mt-appicon-filter) !important;
}

/*
 * Последней плиткой ядро подставляет ссылку в публичный магазин приложений
 * Nextcloud — всем, кроме администратора (тому вместо неё показывают «Ещё
 * приложения»). В корпоративном облаке этой ссылке не место: поставить оттуда
 * человек ничего не может, а уводит она на сторонний сайт.
 */
.app-menu__grid .app-item[href^="https://apps.nextcloud.com"] {
	display: none !important;
}

/* ================================================== toasts and progress == */

.toastify {
	border-radius: var(--mt-radius-card) !important;
	border: 1px solid var(--mt-glass-line);
	box-shadow: var(--mt-elevation-3) !important;
	backdrop-filter: var(--mt-glass-menu);
	-webkit-backdrop-filter: var(--mt-glass-menu);
	font-size: var(--mt-text-compact);
	animation: mt-toast-in var(--mt-duration-slow) var(--mt-ease);
}

@keyframes mt-toast-in {
	from { opacity: 0; transform: translateX(12px); }
	to { opacity: 1; transform: translateX(0); }
}

/* ===================================================== generic surfaces == */

.card, .app-content-list-item, .list-item {
	border-radius: var(--mt-radius-control) !important;
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}

.app-content-list-item:hover,
.list-item:hover { background-color: var(--mt-hover-bg) !important; }

.app-content-list-item.active,
.app-content-list-item--active,
.list-item.active { background-color: var(--mt-selected-bg) !important; }

/* Pills, and only pills: the shapes that genuinely are lozenges. */
.badge,
.counter-bubble__counter,
.app-navigation-entry__counter,
.chip,
.tag,
.status-chip {
	border-radius: var(--mt-radius-pill) !important;
	font-size: var(--mt-text-meta);
	font-weight: var(--mt-weight-semibold);
	font-variant-numeric: tabular-nums;
}

/* An unread count is the accent's job, not a grey bubble's. */
.app-navigation-entry__counter--highlighted,
.counter-bubble__counter--highlighted {
	background: var(--mt-primary) !important;
	color: var(--mt-on-primary) !important;
}
