/* Font imports */

@import url(https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=block);
@import url(https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20,700,1);


/* Themes */

html[theme=light] {
	color-scheme: light;

	--hue: 100deg;
	
	--surface-0: hsl(var(--hue), 5%, 99%);
	--surface-1: hsl(var(--hue), 10%, 95%);
	--surface-2: hsl(var(--hue), 10%, 90%);
	--surface-3: hsl(var(--hue), 20%, 85%);
	--surface-4: hsl(var(--hue), 20%, 70%);

	--red-background: hsl(0, 50%, 70%);
	--red-text: hsl(0, 80%, 10%);

	--text: hsl(var(--hue), 50%, 10%);
	--secondary-text: hsl(var(--hue), 10%, 30%);
	--shadow: hsla(var(--hue), 20%, 10%, 0.4);
	
	--border-radius: 0.5em;
}

html[theme=dark] {
	color-scheme: dark;

	--hue: 100deg;
	
	--surface-0: hsl(var(--hue), 5%, 1%);
	--surface-1: hsl(var(--hue), 5%, 10%);
	--surface-2: hsl(var(--hue), 5%, 15%);
	--surface-3: hsl(var(--hue), 10%, 17.5%);
	--surface-4: hsl(var(--hue), 12.5%, 20%);

	--red-background: hsl(0, 40%, 30%);
	--red-text: hsl(0, 95%, 95%);

	--text: hsl(var(--hue), 30%, 90%);
	--secondary-text: hsl(var(--hue), 10%, 65%);
	--shadow: hsl(var(--hue), 5%, 5%);
	
	--border-radius: 0.5em;
}

.watra-logo {
	filter: hue-rotate(calc(var(--hue) - 100deg));
}


/* Content layout */

body {
	font-family: Lato, sans-serif;
	background-color: var(--surface-0);
	color: var(--text);
	margin: 0;
	transition: background-color 250ms, color 250ms;
}

main {
	max-width: 60em;
	padding: 0 1em;
	margin: 0 auto;
	overflow-x: auto;
}


/* Browser customisation */

html {
	scrollbar-color: var(--secondary-text) var(--surface-2);
	-webkit-tap-highlight-color: transparent;
}

::selection {
	background-color: var(--secondary-text);
	color: var(--surface-1);
}


/* Material icons */

@font-face {
	font-family: blank;
	size-adjust: 0%;
	src: local("Arial");
}

i, button.icon {
	font-family: "Material Symbols Sharp", blank;
	font-style: normal;
	color: inherit;

	display: inline-block;
	font-size: 0.99em; /* 🤔 */
	width: 1em;
	margin-right: 0.25em;
	
	overflow: hidden;
	vertical-align: bottom;
	white-space: nowrap;

	user-select: none;
}

button i, header i {
	scale: 1.25;
}

i.spin {
	animation: spin 1s infinite linear;
	scale: 0.9;
}


/* Form layout */

form {
	display: grid;
	width: 100%;
	grid-template-columns: auto 1fr;
	column-gap: 0.5em;
	row-gap: 0.5em;
	align-items: center;
	margin: 1em 0;
}

form > button:last-child, form > h1, form > h2, form > h3 {
	margin-bottom: 0.5em;
	white-space: nowrap;
	grid-column: 1 / -1;
}

form input, form select {
	width: 100%;
	max-width: 20em;
}

form input:only-child, form select:only-child {
	grid-column: 1 / -1;
}

div.vertical-split > form {
	margin-top: 0;
}

div.vertical-split:last-child form {
	margin-bottom: 0;
}


/* Form elements */

input, button, select, textarea {
	font-family: Lato, sans-serif;
	padding: 0.5em;
	border-radius: var(--border-radius);
	transition: border-color 250ms, background-color 250ms;
	border: none;
	box-sizing: border-box;
}

textarea {
	width: 100%;
	min-height: 5em;
	field-sizing: content;
	resize: none;
}

label {
	overflow: hidden;
	vertical-align: middle;
	/* white-space: nowrap; */
}

label > * {
	margin: 0;
}

/* Input elements */

input, select, textarea {
	background-color: var(--surface-3);
	color: var(--text);
	accent-color: var(--secondary-text);
	outline: 1px solid transparent;
	outline-offset: -1px;
	transition: outline 250ms, background-color 250ms;
}

input:focus, select:focus, textarea:focus {
	outline: 1px solid var(--text);
}

input:disabled, select:disabled, textarea:disabled {
	background-color: var(--surface-2);
	color: var(--secondary-text);
}

input.invalid, select.invalid {
	background-color: var(--red-background) !important;
}

input[type^=date]:disabled:not([value]) {
	color: transparent;
}

input[type=checkbox], input[type=radio] {
	vertical-align: middle;
	height: 1.5em;
	width: 1.5em;
	margin: 0;
	flex-shrink: 0;
}

input[type=checkbox] + label, input[type=radio] + label {
	margin-left: 0.5em;
}

input[type=checkbox]:focus, input[type=radio]:focus {
	outline: none;
}

input[type=checkbox]:focus-visible, input[type=radio]:focus-visible {
	outline: 1px solid var(--text);
}

input[type=checkbox]:disabled + label, input[type=radio]:disabled + label {
	color: var(--secondary-text);
}

input[type=file] {
	display: block;
	max-width: 100%;
	margin: 0.5em 0;
    padding: 0.5em;
	background-color: var(--surface-3);
}

input[type=file]::file-selector-button {
	display: none;
}

input[type=file]::before {
	content: "upload_file";
	margin-right: 0.5em;
	font-family: "Material Symbols Sharp", blank;
}

h1 > input, h2 > input {
	background-color: transparent;
	padding: 0;
	width: unset;
	height: unset;
	field-sizing: content;
	font-size: inherit;
	font-weight: inherit;
	transition: padding 250ms, background-color 250ms;
}

h1 > input:focus, h2 > input:focus {
	background-color: var(--surface-2);
	padding: 0.25em;
}

h1 > input:disabled, h2 > input:disabled {
	background-color: unset;
	color: var(--text);
}

h1 > img {
	height: 1em;
	vertical-align: middle;
}

select option {
	background-color: var(--surface-1);
}

/* Buttons */

button {
	cursor: pointer;
	background-color: var(--surface-4);
	overflow: hidden;
	white-space: nowrap;
	transition: box-shadow 250ms;
}

button.dangerous {
	background-color: var(--red-background);
	color: var(--red-text);
}

button:disabled {
	background-color: var(--surface-3);
	color: var(--secondary-text);
	cursor: not-allowed;
}

button:not(:disabled):hover,
button:not(:disabled):focus-visible, 
a:focus-visible > button:only-child {
	box-shadow: 0 0 0.5em var(--shadow);
	outline: none;
}

button.icon {
	background-color: transparent;
	padding: 0;
	margin: 0;
	transition: color 250ms;
}

button.icon:hover, button.icon:focus-visible {
	background-color: transparent;
	box-shadow: none;
	color: var(--secondary-text);
}

/* Other elements */

main > h1:first-child {
	margin-top: 0.5em;
}

h1 + h2 {
	margin-top: -0.5em;
}

a {
	color: var(--text);
	outline: none;
	cursor: pointer;
	transition: color 250ms;
}

a:has(button) {
	text-decoration: none;
}

a:not(:has(button)):hover,
a:not(:has(button)):focus-visible {
	color: var(--secondary-text);
}

hr {
	border: solid 1px var(--secondary-text);
	border-bottom: 0;
	width: 100%;
	grid-column: 1 / -1;
	box-sizing: border-box;
}

details > summary {
	cursor: pointer;
	text-decoration: underline;
	transition: color 250ms;
}

details > summary:hover {
	color: var(--secondary-text);
}

details > summary > * {
	display: inline;
}

details:not([open]) > summary > .close-text { display: none }
details[open] > summary > .open-text { display: none }

dl {
	display: grid;
	grid-template-columns: max-content 1fr;

	& > dt {
		font-weight: bold;
	}

	& > dd {
		margin-left: 1em;
	}

	& > dt + dt, & > dt:last-child {
		grid-column: 1 / -1;
	}
}

pre {
	overflow-x: auto;
	background-color: var(--surface-3);
	border-radius: var(--border-radius);
	padding: 1em;
}

li {
	margin: 0.5em 0;
}

li > * {
	margin-top: 0;
	margin-bottom: 0;
}

.warning {
	background-color: var(--red-background);
	color: var(--red-text);
	border-radius: var(--border-radius);
	padding: 0.5em;
	/* width: fit-content; */
}

.warning > * {
	margin: 0;
}

.warning + .warning {
	margin-top: -0.5em;
}

.heading-link {
	display: block;
	margin-top: -1em;
	margin-bottom: 1em;
}

/* Custom layouts */

.button-row {
	display: flex;
	flex-wrap: wrap;
	margin: 0.5em 0;
	gap: 0.5em;
}

.button-row:last-child {
	margin-bottom: 0;
}

.button-row:not(:has(button)) {
	display: none;
}

.entry-grid {	
	margin: 0.5em 0;
	display: grid;
	grid-template-columns: repeat(var(--entry-grid-columns), 1fr);
	gap: 0.5em;
	
	--entry-grid-columns: 3;
	&.medium { --entry-grid-columns: 2; }
	&.full { --entry-grid-columns: 1; }

	&:last-child {
		margin-bottom: 0;
	}

	& > div, & > a {
		padding: 0.5em;

		overflow: hidden;
		border-radius: var(--border-radius);

		text-decoration: none;

		&.faded {
			color: var(--secondary-text);
			background-color: var(--surface-2);

			&:hover, &:focus-visible {
				color: var(--secondary-text);
			}			
		}

		& > .entry-header {
			display: flex;
			align-items: center;
		}

		& > .entry-header:only-child {
			height: 100%;
		}

		& .entry-image {
			width: 2em;
			height: 2em;
			margin-right: 0.5em;
			display: flex;
		}

		& .entry-image > i, & .entry-image > img {
			margin: auto;
			margin-top: -0.1em;
			font-size: 2em;
			width: 100%;
		}

		& .entry-title {
			overflow: hidden;
			display: flex;
			flex-direction: column;
			justify-content: center;
		}

		& .entry-title > *, & h3 {
			margin-top: 0;
			margin-bottom: 0;
			
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		& > .entry-content {
			& > :last-child {
				margin-bottom: 0;
			}
		}

		& > label {
			margin-left: 0.5em;
		}
	}

	& > a {
		background-color: var(--surface-4);
		transition: box-shadow 250ms;
		
		&:hover, &:focus-visible {
			color: var(--text);
			box-shadow: 0 0 0.5em var(--shadow);
		}
	}

	& > div {
		background-color: var(--surface-2);
	}

	& > .grid-break {
		display: block;
		grid-column: 1 / -1;
		visibility: hidden;
		margin: 0;
		height: 0;

		&:last-child {
			display: none;
		}
	}
}

@media (max-width: 50em) {
	.entry-grid { --entry-grid-columns: 2; }
	.entry-grid.narrow { --entry-grid-columns: 3; }
	.entry-grid.medium { --entry-grid-columns: 1; }
}

@media (max-width: 30em) {
	.entry-grid.narrow { --entry-grid-columns: 2; }
	.entry-grid { --entry-grid-columns: 1; }
}

@media (min-width: 45em) {
	div.vertical-split {
		display: flex;
		align-items: flex-start;
		gap: 2em;
	}

	div.vertical-split > * {
		height: fit-content;
		flex: 1;
	}
}

section {
	padding: 1em;
	margin: 1em 0;
	border-radius: var(--border-radius);
	background-color: var(--surface-1);

	& > :first-child {
		margin-top: 0;
	}

	& > :last-child {
		margin-bottom: 0;
	}
}

article {
	padding: 1em;
	margin: 1em 0;
	background-color: var(--surface-2);
	border-radius: var(--border-radius);
}

article > h3 {
	margin-bottom: -0.5em;
}

article :first-child {
	margin-top: 0;
}

article :last-child, article:last-child {
	margin-bottom: 0;
}


/* Dialogs and popups */

dialog, .popup {
	position: fixed;
	inset: 0;
	margin: auto !important;
	flex-direction: column;
	
	padding: 1em;
	width: 25em;
	max-width: 80vw;
	min-height: 5em;
	max-height: 90vh;

	color: var(--text);
	background-color: var(--surface-0);
	border-radius: var(--border-radius);
	border: none;

	box-shadow: 0 0 0.25em var(--shadow);
}

dialog::backdrop {
	background-color: #0006
}

dialog > h1:first-child {
	margin: 0;
	font-size: 1.5em;
}

dialog .button-row {
	margin-top: auto;
	justify-content: flex-end;
}

dialog .button-row button:first-child:not(:only-child) {
	margin-right: auto;
}

.popup {
	min-width: 10em;
	min-height: 1em;
	top: unset;
	bottom: 2em;
	flex-direction: row;
	align-items: center;
	transition: bottom 100ms;

	background-color: var(--surface-2);

	&.success {
		background-color: var(--surface-3);
	}

	&.error {
		background-color: var(--red-background);
		color: var(--red-text);
	}
}

.popup > i, .popup button.icon {
	margin-right: 1em;
}

.popup > p {
	flex: 1;
	margin: 0;
	padding-right: 1em;
	overflow: hidden;
	text-overflow: ellipsis;
}

.popup > button.icon {
	margin-left: auto;
	margin-right: 0;
}

dialog[open], .popup:popover-open  {
	animation: popup-show 250ms forwards;
}

dialog:not([open]), .popup.closing {
	animation: popup-hide 250ms forwards;
}

.popup::backdrop {
	display: none;
}

body:has(dialog[open]) .popup button {
	display: none;
}

.popup:nth-of-type(1) { bottom: 2.5em }
.popup:nth-of-type(2) { bottom: 3.0em }
.popup:nth-of-type(3) { bottom: 3.5em }
.popup:nth-of-type(4) { bottom: 4.0em }
.popup:nth-of-type(n+5) { bottom: 4.5em }

.popup.progress > i {
	animation: spin 1s infinite linear;
}

dialog iframe {
	border: none;
	height: 0;
	max-height: 90vh;
	opacity: 0;
	transition: height 250ms, opacity 250ms;
}

dialog.frame {
	width: 35em;
	padding: 0.5em;

	& > i.spin {
		margin: auto;
		scale: 1.5;
	}

	& > iframe.loaded {
		opacity: 1;
	}
}

dialog.frame:has(> iframe.loaded) i.spin {
	display: none;
}

/* Page data refresh animations */
.removing { animation: element-shrink 250ms forwards }
.adding { animation: element-grow 250ms }
.fade-out { animation: fade-out 250ms forwards linear }
.fade-in { animation: fade-in 250ms linear }

/* Animations */

@keyframes popup-show {
	from {
		opacity: 0;
		scale: 0.8;
		display: none;
	}
	to {
		opacity: 1;
		scale: 1;
		display: flex;
	}
}

@keyframes popup-hide {
	from {
		opacity: 1;
		scale: 1;
		display: flex;
	}
	to {
		opacity: 0;
		scale: 0.8;
		display: none;
	}
}

@keyframes element-grow {
	from {
		opacity: 0;
		scale: 0.8;
	}
	to {
		opacity: 1;
		scale: 1;
	}
}

@keyframes element-shrink {
	from {
		opacity: 1;
		scale: 1;
	}
	to {
		opacity: 0;
		scale: 0.8;
	}
}

@keyframes fade-in {
	from { opacity: 0 }
	to { opacity: 1 }
}

@keyframes fade-out {
	from { opacity: 1 }
	to { opacity: 0 }
}

@keyframes spin {
	from {
		rotate: 0turn;
	}
	to {
		rotate: 1turn;
	}
}

body.unload::after {
	position: fixed;
	top: 45%;
	left: 0;
	right: 0;
	text-align: center;
	font-family: "Material Symbols Sharp", blank;
	content: "progress_activity";
	font-size: 2em;
	cursor: progress;
	animation: spin 1s infinite linear, fade-in 1s 1s backwards;
}