/*
Copyright 2022 Jason Dark <https://jkdark.com/>.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

dialog[is="basic-modal"] {
	/*
	Browsers provide a default border and padding. We need to zero them out
	and "relocate" them to the <form> so we can make our backdrop clickable.
	*/
	border: none;
	padding: 0;

	/* Cosmetic */
	box-shadow: 0.5rem 0.5rem 1rem black;

	/*
	The dialog will, by default, be centered, and automatically grow to
	accomodate its contents. Instead of capping the dimensions here, we
	also forward that responsibility to the immediate form child.
	*/
}

dialog[is="basic-modal"]::backdrop {
	/* We can customize the backdrop, though the default one is fine */
	background-color: rgba(0,0,0,0.5);
}

dialog[is="basic-modal"] > form {
	/*
	This guarantees the modal's dimensions are well-behaved, and also lets
	us set up overflow scrolling on the content.
	*/
	box-sizing: border-box;
	max-width: 80vw;
	max-height: 80vh;
	
	/* If you want borders, padding, etc, put them here instead. */
	padding: 1rem;
	border: 1px solid black;

	/* We do a flex layout to make the <main> section grow/shrink */
	display: flex;
	flex-direction: column;

	/*
	Since we set the tabindex=-1 for focusing reasons,
	we disable the focus ring.
	*/
	outline: none;
}

dialog[is="basic-modal"] > form > header {
	/* We want to keep the header's height */
	flex: 0 0 auto;

	/* We stick the titlebar and X button on the same row */
	display: flex;
	
	/* Ensure that the title doesn't run into the X button. */
	gap: 1rem;
}

dialog[is="basic-modal"] > form > header > :first-child {
	/*
	This will make the titlebar "generate" no width, but opportunistically
	stretch to be as wide as possible.
	*/
	width: 0;
	flex: 1 1 0;
	align-self: center;
	
	/* This will give any overflow the "..." ellipsis */
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	
	/* Cosmetic */
	font-weight: bold;
}

dialog[is="basic-modal"] > form > header > :last-child {
	/* Cosmetic -- move the X button partially into the padding */
	transform: translate(0.5rem, -0.5rem);

	/*
	One might also consider some sort of image-replacement technique to
	place a decorative "X" on the button.
	*/
}

dialog[is="basic-modal"] > form > main {
	/* This sets up scrolling if necessary */
	min-height: 0;
	flex: 1 1 auto;
	overflow: auto;
	overscroll-behavior: contain;

	/* Cosmetic spacing. */
	margin: 1rem 0;
}

dialog[is="basic-modal"] > form > footer {
	/* Like the header, we preserve the footer's height. */
	flex: 0 0 auto;

	/* Right align and put spacing between any footer elements. */
	display: flex;
	justify-content: end;
	gap: 1rem;
}
