/* Modul Cloud — material and depth
   ---------------------------------------------------------------------------
   Where css/tokens.css defines *what* a surface is made of, this file says
   which elements are made of it. Five elevation levels, one recipe each:

     level 0  the desk           page background, the wallpaper, the scrim
     level 1  the shell          header, navigation, the work area
     level 2  cards and panels   things resting on the work area
     level 3  menus and popovers things lifted clear of it
     level 4  dialogs            things above everything

   A surface's level decides all four of its properties together — fill,
   border, blur and shadow. That is the whole point: an element cannot pick a
   heavy shadow and a transparent fill and end up floating nowhere. The three
   material modes (Чистый / Мягкий / Стекло) move the alphas and blurs as a
   set, so the hierarchy holds at every setting.

   Readability outranks the effect. Chrome may go properly transparent; the
   surface a paragraph is printed on may not. */

/* ================================================== level 0 — the desk == */

/*
 * Nothing below depends on a class being stamped by JavaScript. The old build
 * added `.mt-has-bg` to <html> on DOMContentLoaded and hung every wallpaper
 * rule off it, which meant the first paint always showed the no-wallpaper
 * layout and then re-flowed. Here the page is painted on <html>, <body> is
 * transparent, and the two decorative layers sit behind the content with their
 * own opacity — so "has a wallpaper" is a number the server already knows and
 * writes into the generated stylesheet, and the first paint is simply correct.
 *
 * (The class is still stamped, because modultalk and modultasks read it.)
 */

html {
	background: var(--mt-page-bg);
}

body {
	background: transparent;
}

/*
 * The wallpaper.
 *
 * Two sources, one layer. Nextcloud's own Theming app already gives every
 * instance a background image, and a design system that silently threw it away
 * would look like a bug to everybody who had one. So the instance's wallpaper
 * is inherited as the default and the user's own choice from the Фон tab draws
 * over it — either way the picture ends up underneath the same scrim and the
 * same material rules, which is the whole point: the old build let a
 * photograph reach the interface unmediated, and that is what bleached it.
 */
#mt-workspace-bg {
	position: fixed;
	inset: var(--mt-bg-bleed);
	z-index: -2;
	pointer-events: none;
	background-image: var(--mt-bg-image);
	background-size: var(--mt-bg-size);
	background-position: var(--mt-bg-position);
	background-repeat: var(--mt-bg-repeat);
	background-attachment: scroll;
	filter: var(--mt-bg-filter);
	transform: scale(var(--mt-bg-scale));
	transform-origin: center center;
	opacity: var(--mt-bg-visible);
	transition:
		filter var(--mt-duration-slow) var(--mt-ease-out),
		transform var(--mt-duration-slow) var(--mt-ease-out),
		opacity var(--mt-duration-slow) var(--mt-ease-out);
}

/* The instance's own wallpaper, drawn only while the user has not chosen one
   of their own. It deliberately ignores the image adjustments: those belong to
   a picture the user picked, not to one they inherited. */
#mt-workspace-bg::before {
	content: '';
	position: absolute;
	inset: 0;
	background-image: var(--image-background, none);
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	opacity: calc((1 - var(--mt-has-own-bg)) * var(--mt-has-bg));
}

/* The dim pass sits inside the layer so the user's own filters do not apply
   to it — dimming an image should not also desaturate the dimming. */
#mt-workspace-bg::after {
	content: '';
	position: absolute;
	inset: 0;
	background: #000;
	opacity: var(--mt-bg-dim);
	transition: opacity var(--mt-duration) var(--mt-ease-out);
}

/*
 * The scrim, and it is the most important surface in the product.
 *
 * A photograph behind an interface does two damaging things: it bleaches the
 * translucent panels above it into milk, and it competes with the content for
 * attention. A scrim fixes both, but only if it is tinted in the *page*
 * colour rather than in flat black — tinted, it pulls the photograph towards
 * the theme and the whole screen reads as one designed thing; black, it just
 * fogs the picture and everything goes grey.
 *
 * Its strength is set by the material mode: heavy under Чистый, where the
 * panels are opaque and the image is pure environment; light under Стекло,
 * where the image is meant to be read through the chrome.
 *
 * It is drawn in a deep neutral, never in the page colour. Washing a
 * photograph with a light grey raises its luminance towards the white panels
 * sitting on it, so the panels stop reading as surfaces and the whole screen
 * goes flat and over-exposed. Deepening the picture does the opposite: it
 * pushes it below the interface, which is what a desk is supposed to do.
 */
body::before {
	content: '';
	position: fixed;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background: var(--mt-scrim-color);
	opacity: calc(var(--mt-scrim-alpha) * var(--mt-bg-visible) * var(--mt-has-bg));
	transition: opacity var(--mt-duration-slow) var(--mt-ease-out);
}

/* The page frame never paints: it is the window onto the desk. */
#content,
#content-vue,
#body-user #content {
	background: transparent !important;
}

/* ============================================== level 1 — the shell ==== */
/*
 * Header, navigation and the work area. These are large, and a large surface
 * that casts a shadow makes the whole page feel like it is peeling up, so
 * level 1 is defined by a border and a fill — never by elevation.
 */

.mt-level-1,
#header:not(.header-guest) {
	background: var(--mt-surface-header);
	backdrop-filter: var(--mt-glass-header);
	-webkit-backdrop-filter: var(--mt-glass-header);
	border-bottom: 1px solid var(--mt-glass-line);
	box-shadow: inset 0 1px 0 var(--mt-glass-highlight);
}

/*
 * The work area. Near-opaque at every material, because this is where the
 * running text lives and no amount of blur buys back a point of contrast.
 * Under Стекло it still lets a hint of the wallpaper through, which is enough
 * to feel connected to the desk without costing legibility.
 */
/*
 * No backdrop-filter here, and none on cards below. A blur forces its element
 * onto its own compositor layer and re-samples everything behind it every
 * frame; on the work area that is a full-viewport layer re-sampled on every
 * scroll tick. The surface is 90-100% opaque at every material anyway, so the
 * blur was buying a few invisible percent for a measurable amount of jank.
 * Blur belongs to chrome and to floating layers, which are few and static.
 */
#app-content,
#app-content-vue,
.app-content {
	/* File/task tables are large scrolling surfaces. Keep the wallpaper in the
	 * shell, but give application content an opaque reading plane: a user
	 * wallpaper must never bleed through rows, labels or form fields. */
	background: var(--mt-surface) !important;
}

/* Navigation, lists and the details sidebar. */
#app-navigation,
.app-navigation,
.app-content-list,
#app-sidebar,
#app-sidebar-vue,
.app-sidebar {
	background: var(--mt-surface-raised) !important;
	backdrop-filter: var(--mt-glass-sidebar);
	-webkit-backdrop-filter: var(--mt-glass-sidebar);
}

/* The dashboard is the exception: its widgets are the cards, so the canvas
   behind them stays open to the image. */
#app-dashboard,
.dashboard {
	background: transparent !important;
}

/* Rows and table chrome inherit the work area rather than painting their own
   opaque colour on top of it. */
.files-list,
.files-list__table,
.files-list__thead,
.files-list__row,
.list-container {
	background: transparent;
}

/* ========================================== level 2 — cards and panels == */

.mt-level-2 {
	background: var(--mt-surface-card);
	border: 1px solid var(--mt-border);
	border-radius: var(--mt-radius-card);
	box-shadow: var(--mt-elevation-2);
}

/* Cards are numerous: alpha only, never a blur. See the note at level 1. */
.section,
.settings-section,
.panel,
.dashboard-panel {
	background: var(--mt-surface-card);
}

/* ========================================= level 3 — menus and popovers == */
/*
 * A menu is the surface a user reads *while* something else is on screen, so
 * it is the densest of the translucent ones and it carries a real shadow: the
 * shadow is what says "temporary, and on top", which is exactly what a context
 * menu needs to say.
 */
.mt-level-3 {
	background: var(--mt-surface-menu);
	backdrop-filter: var(--mt-glass-menu);
	-webkit-backdrop-filter: var(--mt-glass-menu);
	border: 1px solid var(--mt-glass-line);
	border-radius: var(--mt-radius-menu);
	box-shadow: var(--mt-elevation-3), inset 0 1px 0 var(--mt-glass-highlight);
}

/* ================================================ level 4 — dialogs ==== */

.mt-level-4 {
	background: var(--mt-surface-modal);
	backdrop-filter: var(--mt-glass-modal);
	-webkit-backdrop-filter: var(--mt-glass-modal);
	border: 1px solid var(--mt-glass-line);
	border-radius: var(--mt-radius-modal);
	box-shadow: var(--mt-elevation-4), inset 0 1px 0 var(--mt-glass-highlight);
}

/* ====================================================== safety floor ==== */
/*
 * The floors are computed where the facts are: lib/Service/AppearanceService
 * knows whether the user actually has a wallpaper, and emits solid surfaces
 * and zero blur when they do not — which is what makes Стекло cost nothing on
 * a plain page — and clamps the content and card alphas when they do, because
 * no fixed opacity survives a blinding-white photograph. The same arithmetic
 * lives in js/appearance-core.js so the panel previews the truth rather than
 * an approximation of it.
 */
