/* Modul Cloud — the shell
   ---------------------------------------------------------------------------
   The top bar, the frame around the work area, and the two places where the
   rail layout has to reach into Nextcloud's own geometry.

   The header is a neutral working strip rather than a coloured bar: it reads
   as product chrome, it survives every accent, and it is the one surface a
   workspace background is genuinely allowed to show through. */

/* ============================================================== header == */

#header:not(.header-guest) {
	height: var(--mt-header-height);
	color: var(--mt-text);
	/* the fill, blur, border and highlight all come from .mt-level-1 in
	   css/material.css, which this selector is part of */
}

#header .header-start,
#header .header-end {
	gap: 2px;
}

/* Only the hover surface: core positions the logo absolutely inside this
   anchor and reserves the room for it with an 86px start padding, so touching
   the padding here collapses the anchor and clips the logo out of existence. */
#header #nextcloud {
	border-radius: var(--mt-radius-control);
	transition: background-color var(--mt-duration-fast) var(--mt-ease);
}
#header #nextcloud:hover { background: var(--mt-hover-bg-strong); }
#header #nextcloud .logo { transition: none; }

/*
 * The shipped logo asset is *white*, and core flips it for bright backgrounds
 * by deriving --background-image-invert-if-bright from its own plain
 * background colour — which is not the colour our header is painted in, so it
 * gets the answer wrong on a dark chrome. These rules decide from the theme
 * actually in force instead.
 *
 * The fallback keeps Theming's escape hatch working: when an admin uploads a
 * logo, that app defines --image-logoheader-custom as the string `true`, which
 * is not a valid filter, so the declaration is dropped and the custom artwork
 * is left exactly as supplied. Overriding it unconditionally would have
 * inverted every corporate logo on the instance.
 */
@media (prefers-color-scheme: dark) {
	html:not([data-mt-theme='light']) #header #nextcloud .logo {
		filter: var(--image-logoheader-custom, none);
	}
}
html[data-mt-theme='dark'] #header #nextcloud .logo {
	filter: var(--image-logoheader-custom, none);
}
html[data-mt-theme='light'] #header #nextcloud .logo {
	filter: var(--image-logoheader-custom, invert(100%));
}

/* The current application's name. 14px medium, not a banner. */
#header .header-appname,
#header .app-menu__current-app .button-vue__text,
#header .header-appname .header-shared-by {
	color: var(--mt-text) !important;
	font-size: var(--mt-text-ui);
	font-weight: var(--mt-weight-semibold);
	letter-spacing: var(--mt-tracking-tight);
}

/* Triggers and icons in the top bar follow the text colour of the chrome. */
#header .header-menu__trigger,
#header .action-item__menutoggle,
#header .app-menu__waffle,
#header .header-menu__trigger * {
	color: var(--mt-text) !important;
}

#header .header-menu__trigger:hover,
#header .app-menu__waffle:hover {
	background-color: var(--mt-hover-bg-strong) !important;
}

/* Header buttons are square-ish with a small corner, not lozenges. */
#header .header-menu__trigger,
#header .app-menu__waffle,
#header .app-menu__current-app {
	border-radius: var(--mt-radius-control) !important;
}

/* --- unified search ---------------------------------------------------
   The most visible field in the product. It is an input, so it gets input
   shape: a 6px corner and a recessed fill, not a pill. */
#unified-search .header-menu__trigger,
.unified-search-input__button {
	border-radius: var(--mt-radius-control) !important;
}

.unified-search-input__button {
	height: calc(var(--mt-control-md));
	background: var(--mt-surface-field) !important;
	border: 1px solid var(--mt-border) !important;
	color: var(--mt-text-muted) !important;
	font-size: var(--mt-text-compact);
	transition:
		background-color var(--mt-duration-fast) var(--mt-ease),
		border-color var(--mt-duration-fast) var(--mt-ease);
}

.unified-search-input__button:hover {
	border-color: var(--mt-border-strong) !important;
	color: var(--mt-text) !important;
}

.unified-search-input__button:focus-visible {
	border-color: var(--mt-primary) !important;
	box-shadow: 0 0 0 3px var(--mt-selected-bg) !important;
}

/* The notification bell is removed from the chrome by product decision — the
   start page carries what needs attention today. The mount point stays in the
   DOM (core owns core/templates/layout.user.php), so the app still runs and
   /settings/user/notifications remains reachable; only the trigger is gone. */
#header #notifications {
	display: none !important;
}

/* Avatars are the one place a full circle belongs. */
.avatardiv, .avatar {
	border-radius: var(--mt-radius-pill) !important;
}

/* ======================================================== the work area == */

#content, #app-content {
	background: var(--mt-page-bg);
}

/*
 * Core leaves a margin on three sides of the work area (--body-container-margin)
 * and replaces the fourth with the height of the header, so the application is
 * glued to the bar above it: its top edge simply disappears and the panels read
 * as a continuation of the chrome. The frame is given its fourth side here.
 *
 * The gap is taken back out of the height so the bottom edge does not move.
 * #content-vue is fixed inside #content, so it inherits the new top from the
 * static position on its own — only its height has to be corrected as well.
 */
#content {
	margin-block-start: calc(var(--header-height) + var(--body-container-margin));
}

#content,
#content-vue {
	height: calc(var(--body-height) - var(--body-container-margin));
}

/* Navigation and content are two panels, not one slab split by a seam. Core
   rounds only the outer frame and then gives #app-content-vue a left-side
   radius, which left the navigation's facing edge square against a rounded
   content edge — visibly lopsided. */
#app-content-vue,
#app-content {
	border-radius: var(--mt-radius-card) !important;
	border: 1px solid var(--mt-border);
}

#app-content > .app-content-wrapper,
.app-content-list {
	padding: var(--mt-space-1);
}

/* Settings and generic section cards sit at level 2. */
.section, .settings-section {
	background: var(--mt-surface-card);
	border: 1px solid var(--mt-border);
	border-radius: var(--mt-radius-card) !important;
	box-shadow: none;
}

/* ============================================== rail layout geometry ==== */
/*
 * Two elements know about the rail, and both are handled by insetting rather
 * than by margins. #header is absolutely positioned and #content-vue is fixed,
 * so giving each a start inset, an end inset of zero and `width: auto` makes
 * them fill exactly the space the rail leaves — and, crucially, leaves core's
 * own gutters and margins untouched, whatever they happen to be in this
 * release. A hard-coded `calc(100% - 8px - rail)` would have to be revisited
 * every time Nextcloud changes its frame.
 */
#header:not(.header-guest),
#content-vue,
#content {
	inset-inline-start: var(--mt-rail-width);
	inset-inline-end: 0;
	width: auto;
}

/*
 * The ONLYOFFICE editor does not stay inside #content. Its own stylesheet pins
 * the frame to the viewport — `#app > iframe { position: fixed; left: 0 }` —
 * so insetting the container above moves nothing and the editor slides under
 * the rail: the first ~78px of the toolbar, the ONLYOFFICE mark and the cell
 * reference box end up behind it.
 *
 * Insetting the frame itself is the only place left to do it. Scoped to the
 * variable rather than to a layout class on purpose: with the rail off the
 * width is 0px, so this computes to `left: 0; width: 100%` and is a no-op for
 * everyone not in rail mode. `html` is here for weight — the connector's own
 * rule is `#content.app-onlyoffice #app > iframe` and has to be outranked.
 */
html #content.app-onlyoffice #app > iframe {
	inset-inline-start: var(--mt-rail-width);
	width: calc(100% - var(--mt-rail-width));
}

/*
 * There is deliberately no margin-based fallback here. An earlier version added
 * `body > #content:not([style*="position"]) { margin-inline-start: … }` for the
 * case of a statically positioned #content — but that selector tests the inline
 * *attribute*, not the computed position, so a fixed #content matched it too and
 * got the offset twice. Apps that render straight into #content (the messenger,
 * the wiki, contacts) ended up 120px from the edge with a strip of wallpaper
 * between the rail and the app. Every Nextcloud layout positions #content, so
 * the inset above is enough on its own.
 */

/* In rail mode the brand lives in the rail, so the header drops it and starts
   with the name of the application you are actually in. */
html[data-mt-layout='rail'] #header #nextcloud {
	display: none !important;
}

html[data-mt-layout='rail'] #header .header-start {
	padding-inline-start: var(--mt-space-2);
}

/* ============================================================ typography == */

h1, h2, h3, h4 {
	letter-spacing: var(--mt-tracking-tight);
	color: var(--mt-text);
}

/*
 * Nextcloud's settings pages ship 25–32px headings, several to a screen. In a
 * working product a section title is 16px semibold — the hierarchy comes from
 * weight, colour and the space around it, not from scale. Anything genuinely
 * at the top of a page keeps 20px, and that is the ceiling for ordinary UI.
 */
#app-content h2,
#app-content h3,
.settings-section__name,
.app-settings-section__name,
.headerbar__heading,
.section > h2,
.section > h3 {
	font-size: var(--mt-text-section) !important;
	font-weight: var(--mt-weight-semibold) !important;
	line-height: 1.3;
	letter-spacing: var(--mt-tracking-tight);
	margin-bottom: var(--mt-space-2) !important;
}

#app-content > h1,
.app-content > h1 {
	font-size: var(--mt-text-display) !important;
	font-weight: var(--mt-weight-semibold) !important;
}

.settings-section__desc,
.app-settings-section__desc {
	font-size: var(--mt-text-compact);
	color: var(--mt-text-muted);
}
