:root {
    /* Enable transition of height 0 to auto. See
       https://stackoverflow.com/a/3512194 */
    interpolate-size: allow-keywords;
}


/* Override water.css */

body {
    max-width: 1000px;
    &.wide {
	max-width: unset;
    }
    margin: 0 auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    /* Sticky top and middle elements to close the space between them on
       scrolling. */
    .top-sticky {
	position: sticky;
	z-index: 2;
	top: 0;
	/* --background-body from water.css */
	background-color: var(--background-body);
	flex-grow: 0;
	flex-shrink: 1;
	flex-basis: auto;
    }
    .mid-sticky {
	position: sticky;
	z-index: 1;
	top: 180px;
	/* --background-body from water.css */
	background-color: var(--background-body);
	flex-grow: 1;
	flex-shrink: 1;
	flex-basis: auto;
    }
}
table {
    input {
	border: 1px solid #c2c2c2;
	width: stretch;
	box-sizing: border-box;
    }
    textarea {
	border: 1px solid #c2c2c2;
	width: stretch;
    }
    select {
	border: 1px solid #c2c2c2;
	width: stretch;
    }
    &.flexible {
	table-layout: auto;
	td {
	    max-width: 500px;
	}
    }
    /* Many to many fields in tables */
    td > ul {
	margin: 0;
	padding-left: 20px;
    }
}
textarea {
    white-space: pre-line;
}


/* Monospace font families used for codes, tags and identifiers. */

span.code {
    font-family: "DejaVu Sans Mono", "Lucida Console", "Consolas", "Courier New", "Courier", monospace;
    font-size: 10pt;
}


/* Body with wide table */

.wide-table {
    padding-left: 10px;
    padding-right: 20px;
    max-height: 50vh;
    width: auto;
    max-with: auto;
    overflow: scroll;
    table {
	width: unset;
	th {
	    position: sticky;
	    top: 0;
	    z-index: 1;
	    background: white;
	}
    }
}


/*  */

form.table-controls {
    display: flex;
    justify-content: end;
    input {
	width: 98px;
	height: 41px;
    }
}


/* Many to many form field search */

.option-scrollable {
    overflow: auto;
    resize: vertical;
    height: 160px;
}
.option-filtered {
    display: none;
}


/* Navigation bar */

.top-navigation {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
    background-color: #092642;
    & > .titlebar {
	display: flex;
	align-items: center;
	& img {
	    display: block;
	    width: 54px;
	    margin: 5px;
	    margin-left: 13px;
	}
	& .title {
	    margin-left: 10px;
	    color: #f2f2f2;
	    font-family: Arial;
	    font-weight: bold;
	    font-size: 18pt;
	}
	#user-button {
	    display: flex;
	    justify-content: center;
	    align-items: center;
	    min-width: 40px;
	    min-height: 40px;
	    aspect-ratio: 1 / 1;
	    margin-top: 6px;
	    margin-left: auto;
	    margin-right: 6px;
	    padding: 6px;
	    border-radius: 50%;
	    line-height: 1;
	    color: #f2f2f2;
	    background-color: #0080A8;
	}
	#user-popover {
	    div {
		display: flex;
		flex-direction: column;
		align-items: stretch;
		button, p {
		    margin: 6px;
		}
	    }
	    margin: 0;
	    border-width: 1px;
	    border-radius: 6px;
	    border-color: black;
	    inset: auto;
	    z-index: 3;
	    top: calc(anchor(bottom) + 6px);
	    right: anchor(right);
	    background-color: #f2f2f2;
	    justify-self: anchor-left;
	}
    }
    & > .page-links {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	align-items: stretch;
	grid-auto-flow: column;
	grid-auto-rows: minmax(40px, auto);
	& a {
	    display: flex;
	    align-items: center;
	    justify-content: center;
	    padding-left: 15px;
	    padding-right: 15px;
	    padding-top: 10px;
	    padding-bottom: 10px;
	    color: #f2f2f2;
	    text-decoration: none;
	    font-size: 17px;
	    transition:
		background-color 0.1s,
		color 0.1s;
	}
	& a:hover {
	    background-color: #ddd;
	    color: black;
	}
	& a.active {
	    background-color: #0080A8;
	    color: white;
	}
	& form {
	    margin-left: auto;
	    & input {
		display: flex;
		align-items: center;
		justify-content: center;
		border: none;
		border-radius: 0;
		margin: 0;
		background-color: transparent;
		color: #f2f2f2;
		text-decoration: none;
		font-size: 17px;
		transition:
		    background-color 0.2s,
		    color 0.2s;
	    }
	    & input:hover {
		background-color: #ddd;
		color: black;
	    }
	}
    }
}


/* Login and Sign Up forms. */

.registration {
    display: flex;
    flex-direction: column;
    align-items: center;
    & form {
	display: flex;
	flex-direction: column;
	align-items: center;
	& a {
	    align-self: end;
	}
	& label {
	    margin-top: 10px;
	}
	& input {
	    width: 320px;
	}
	& input[type="submit"] {
	    min-width: 160px;
	    margin-top: 20px;
	}
    }
    p {
	align-self: start;
    }
    .hidden {
	display: none;
    }
}


/* Treeview list */

.tree-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-columns: 3fr 1fr 2fr;
    align-items: center;
    gap: 6px;
}
.tree {
    margin-bottom: 20px;
}
.tree-node {
    &.tree-hidden {
	display: none;
    }
    &.tree-filtered {
	display: none;
    }
    .related-element {
	/* For systems shown in PBS. */
	color: black;
	font-style: italic;
    }
    .filtered-element {
	/* For ancestors in the list that do not meet filter criteria. */
	color: black;
    }
    .tree-branch {
	margin-left: calc(var(--depth) * 20px);
	cursor: pointer;
    }
    .tree-branch::before {
	display: inline-block;
	color: black;
	content: "\0025B6";
	font-family: sans-serif;
	rotate: 90deg;
	transition: rotate 0.2s;
    }
    .tree-branch:hover::before {
	color: #0080A8;
    }
    &.tree-closed .tree-branch::before {
	rotate: 0deg;
	transition: rotate 0.2s;
    }
    .tree-leaf {
	margin-left: calc(var(--depth) * 20px + 4px);
    }
    .tree-leaf::before {
	display: inline-block;
	/* margin-right: 6px; */
	color: black;
	content: "\0025CF";
	font-family: sans-serif;
    }
}


/* Collapse and Expand Buttons */

.tree-controls {
    display: flex;
    flex-direction: row;
    justify-content: end;
    align-items: stretch;
    margin-top: 20px;
    margin-bottom: 20px;
    label {
	flex-grow: 1;
    }
}
.search-controls {
    display: flex;
    flex-direction: column;
    justify-content: start;
    align-items: end;
    .search-fields {
	flex-grow: 1;
	display: flex;
	flex-wrap: wrap;
	justify-content: start;
	align-items: center;
	div {
	    flex-grow: 1;
	    display: flex;
	    justify-content: start;
	    align-items: center;
	    * {
		flex-grow: 1;
	    }
	    label {
		margin-right: 6px;
		flex-grow: 0;
	    }
	}
    }
}
.list-filter-controls {
    display: flex;
    justify-content: end;
    align-items: center;
    margin-top: 20px;
    input {
	flex-grow: 1;
    }
}


/* Buttons to add/remove items from the list. */

.list-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    margin-top: 20px;
}


.controls {
    display: flex;
    flex-direction: row;
    margin-top: 20px;
    gap: 5px;
    .distant {
	margin-left: auto;
    }
}

.attention {
    color: #fff;
    background-color: #ba2121;
    &:hover {
	background-color: #a41515;
    }
}

.commit {
    color: #fff;
    background-color: #2121ba;
    &:hover {
	background-color: #1515a4;
    }
}


/* Loading icon animation */

div.loading-icon {
    color: #092642;
    box-sizing: border-box;
    display: inline-block;
    position: relative;
    aspect-ratio: 1 / 1;
    width: 80px;
    div {
	box-sizing: border-box;
	position: absolute;
	top: 42%;
	width: 16%;
	height: 16%;
	border-radius: 50%;
	background: currentcolor;
	animation-timing-function: cubic-bezier(0, 1, 1, 0);
    }
    div:nth-child(1) {
	left: 10%;
	animation: loading-icon-1 0.6s infinite;
    }
    div:nth-child(2) {
	left: 10%;
	animation: loading-icon-2 0.6s infinite;
    }
    div:nth-child(3) {
	left: 42%;
	animation: loading-icon-2 0.6s infinite;
    }
    div:nth-child(4) {
	left: 74%;
	animation: loading-icon-3 0.6s infinite;
    }
}
@keyframes loading-icon-1 {
    0% {
	transform: scale(0);
    }
    100% {
	transform: scale(1);
    }
}
@keyframes loading-icon-2 {
    0% {
	transform: translate(0, 0);
    }
    100% {
	transform: translate(200%, 0);
    }
}
@keyframes loading-icon-3 {
    0% {
	transform: scale(1);
    }
    100% {
	transform: scale(0);
    }
}


/* Form errors */

.errorlist {
    color: #c62828;
}
