/* Fragment Mono, served from the site (SIL Open Font License, fonts/OFL.txt); regular only, bold is synthesized */
@font-face {
	font-family: 'Fragment Mono';
	src: url('../fonts/fragment-mono-latin-400-normal.woff2') format('woff2');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: 'Fragment Mono';
	src: url('../fonts/fragment-mono-latin-400-italic.woff2') format('woff2');
	font-weight: 400;
	font-style: italic;
	font-display: swap;
}

:root {
	--navy: #201E50;
	--blue: #2A5C8A;
	--teal: #3E8E9C;
	--orange: #E08A3C;
	--sky: #E3F4F6;
	--muted: #6b6a8c;
	--paper: #fff;                /* cards and buttons, and the text on a navy fill */
	--danger: #B5471B;            /* error text */
	--warn-bg: #fff3e0;
	--font: 'Fragment Mono', monospace;
	/* flat offset shadow, no blur: the retro "printed" look */
	--shadow: 4px 4px 0 var(--navy);
}

/* night mode (profile setting, applied by templates/base.html to the logged-in account's pages): the same variables with
   the roles swapped. navy is the ink (text, borders, shadows, filled buttons), sky the page, paper the cards, and the
   text on an ink fill, so ink becomes light and paper and sky dark. No colour is written twice outside this block. */
html[data-theme="dark"] {
	--navy: #E3F4F6;
	--sky: #14132E;
	--paper: #232152;
	--blue: #7DB2E0;
	--teal: #6CC4D0;
	--orange: #F0A55E;
	--muted: #A9A8C9;
	--danger: #F29B7B;
	--warn-bg: #3D3120;
}

/* always reserve the scrollbar space: in short windows the scrollbar would come and go and shift the page sideways */
html {
	scrollbar-gutter: stable;
}

body {
	background-color: var(--sky);
	color: var(--navy);
	font-family: var(--font);
	font-size: 14px;
	/* the footer stays at the bottom of the screen even on short pages: the page takes the room left
	   (min height = the screen minus body's default 8px margins; dvh follows phone address bars) */
	display: flex;
	flex-direction: column;
	min-height: calc(100vh - 16px);
	min-height: calc(100dvh - 16px);
}

div#page {
	flex: 1 0 auto;
}

footer#site-footer {
	flex: none;
	width: 1000px;
	max-width: 90%;
	margin: 0 auto;
	padding: 8px 0;
	text-align: center;
	font-size: 0.75rem;
}

footer#site-footer p {
	margin: 4px 0;
}

/* form controls don't inherit the font by default */
button, input, select, textarea {
	font: inherit;
}

/* one link style: underlined, blue and thicker on hover (menus, logo and buttons excepted) */
a, a:visited {
	color: var(--navy);
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
}

/* every :hover below is inside (hover: hover): on a touchscreen it would stay stuck after a tap. The one
   exception is the menu dropdown, which on a touch-only screen opens through that very :hover */
@media (hover: hover) {
	a:hover {
		color: var(--blue);
		text-decoration-thickness: 2px;
	}
}

/* one button for the whole site: outlined pill with a hard shadow, inverted on hover, pressed into its shadow on click */
button, input[type=submit], input[type=button], input[type=reset], a.button, a.card-button {
	display: inline-block;
	width: fit-content;
	max-width: 100%;
	box-sizing: border-box;
	padding: 8px 20px;
	border: 2px solid var(--navy);
	border-radius: 25px;
	background-color: var(--paper);
	color: var(--navy);
	letter-spacing: 1px;
	text-decoration: none;
	box-shadow: 3px 3px 0 var(--navy);
	cursor: pointer;
}

/* hover only where a pointer can hover: on a touchscreen it would stay stuck on the button after a tap.
   A press (:active) gets the inverted look everywhere, so a tap still flashes it */
@media (hover: hover) {
	button:hover, input[type=submit]:hover, input[type=button]:hover, input[type=reset]:hover, a.button:hover, a.card-button:hover {
		background-color: var(--navy);
		color: var(--sky);
	}
}

button:active, input[type=submit]:active, input[type=button]:active, input[type=reset]:active, a.button:active, a.card-button:active {
	background-color: var(--navy);
	color: var(--sky);
	transform: translate(2px, 2px);
	box-shadow: 1px 1px 0 var(--navy);
}

/* one field for the whole site: dotted underline, solid blue while typing (same thickness, so nothing moves);
   textareas too, growing downwards */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input:not([type]), textarea {
	color: var(--navy);
	background-color: transparent;
	border: none;
	border-bottom: 2px dotted var(--navy);
	border-radius: 0;
	padding: 3px 2px;
	outline: none;
}

/* textareas grow with their text where the browser can (field-sizing), at least 3 lines */
textarea {
	line-height: 1.5;
	resize: vertical;
	field-sizing: content;
	min-height: calc(4.5em + 8px);
}

select {
	color: var(--navy);
	background-color: transparent;
	border: 2px dotted var(--navy);
	border-radius: 0;
	padding: 3px 5px;
	outline: none;
}

input[type=text]:focus, input[type=email]:focus, input[type=password]:focus, input[type=number]:focus,
input[type=url]:focus, input:not([type]):focus, textarea:focus {
	border-bottom: 2px solid var(--blue);
}

select:focus {
	border: 2px solid var(--blue);
}

input[type=checkbox], input[type=radio] {
	accent-color: var(--navy);
	cursor: pointer;
}

/* cards: every form, the admin blocks, the Mimo settings; white, navy border, hard shadow */
.card, .admin-card {
	border: 2px solid var(--navy);
	border-radius: 10px;
	background-color: var(--paper);
	box-shadow: var(--shadow);
	padding: 10px 20px 20px;
	margin: 20px 0;
	color: var(--navy);
	display: flex;
	flex-direction: column;
	gap: 15px;
	max-width: 600px;
}

.card h3, .admin-card h3 {
	margin: 5px 0;
}

/* the site shows links as blocks with a margin; not inside the cards */
.card h3 a, .admin-card h3 a {
	display: inline;
}

.card a, .admin-card a, .card p, .admin-card p {
	margin: 0;
}

/* the card's gap spaces its rows; the button sits a bit lower, at the left */
.card .form-row, .admin-card .form-row {
	margin: 0;
}

.card input[type=submit], .admin-card input[type=submit] {
	align-self: flex-start;
	margin-top: 10px;
}

/* several buttons of one form side by side, wrapping to the next line when the card is narrow */
.card div.form-actions, .admin-card div.form-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: 10px;
	margin-top: 10px;
}

.card div.form-actions input[type=submit], .admin-card div.form-actions input[type=submit] {
	margin-top: 0;
}

/* link cards: a whole card is the link, a name and a line of description (home page apps, Mimo modes) */
.app-cards {
	display: flex;
	flex-direction: column;
	gap: 15px;
	max-width: 600px;
	margin-top: 15px;
}

a.app-card, a.app-card:visited {
	display: flex;
	flex-direction: column;
	width: auto;
	gap: 4px;
	margin: 0;
	padding: 14px 20px;
	border: 2px solid var(--navy);
	border-radius: 10px;
	background-color: var(--paper);
	box-shadow: var(--shadow);
	color: var(--navy);
	text-decoration: none;
}

@media (hover: hover) {
	a.app-card:hover {
		color: var(--navy);
		border-color: var(--blue);
		box-shadow: 4px 4px 0 var(--blue);
	}
}

a.app-card:active {
	transform: translate(2px, 2px);
	box-shadow: 2px 2px 0 var(--navy);
}

span.app-name {
	font-weight: bold;
	font-size: 1.1rem;
}

span.app-description {
	color: var(--muted);
	line-height: 1.5;
}

a.app-card.inactive {
	opacity: 0.5;
}

span.app-off {
	font-weight: normal;
	font-size: 0.8rem;
}

/* an app's tags, as small labels under its description */
span.app-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 4px;
}

span.app-dates {
	margin-top: 6px;
	font-size: 0.8rem;
	color: var(--muted);
}

span.app-tag {
	font-size: 0.7rem;
	color: var(--navy);
	background-color: var(--sky);
	border: 1px solid var(--navy);
	border-radius: 10px;
	padding: 1px 8px;
}

a.app-card[hidden] {
	display: none;
}

/* the filter chips and the order switch above the cards: one is on, "Tous" first */
div.tag-filter, div.app-sort {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	max-width: 600px;
	margin-top: 15px;
}

div.tag-filter[hidden], div.app-sort[hidden] {
	display: none;
}

div.tag-filter button, div.app-sort button {
	padding: 4px 14px;
	font-size: 0.85rem;
	border-radius: 14px;
	background-color: var(--paper);
	color: var(--navy);
	box-shadow: none;
}

div.tag-filter button.on, div.app-sort button.on {
	background-color: var(--navy);
	color: var(--paper);
}

/* form rows (templates/_form.html): label and field on one line, the fields lined up after a label column;
   on phones the label goes above its field (media query below) */
.form-row {
	display: grid;
	grid-template-columns: 11rem minmax(0, 1fr);
	align-items: baseline;
	gap: 4px 12px;
	margin: 14px 0;
	max-width: 36rem;
}

.form-row > label {
	color: var(--navy);
}

/* a textarea's baseline moves as it scrolls: its row aligns to the top, the label on the first line */
.form-row:has(textarea) {
	align-items: start;
}

.form-row:has(textarea) > label {
	padding-top: 3px;
}

.form-input {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

.form-input input[type=text], .form-input input[type=email], .form-input input[type=password],
.form-input input:not([type]), .form-input textarea {
	width: 100%;
	box-sizing: border-box;
}

.form-input select {
	width: fit-content;
	max-width: 100%;
}

/* checkboxes sit in the field column, their text beside them; at the left in a form that has only checkboxes */
.form-row.check > * {
	grid-column: 2;
}

form:not(:has(.form-row:not(.check))) .form-row.check > * {
	grid-column: 1 / -1;
}

.form-row.check > label {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
}

span.field-hint {
	font-size: 0.7rem;
	color: var(--muted);
}

span.field-error {
	font-size: 0.8rem;
	color: var(--danger);
}

@media (max-width: 600px) {
	.form-row {
		grid-template-columns: minmax(0, 1fr);
	}

	.form-row.check > * {
		grid-column: 1;
	}
}

/* keyboard navigation: a dotted blue outline on whatever has the focus */
:focus-visible {
	outline: 2px dotted var(--blue);
	outline-offset: 3px;
}

header {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	width: 1000px;
	margin: auto;
	max-width: 90%;
}

div.branding {
	text-align: left;
	width: 50%;
	padding-bottom: 25px;
}

span#dot {
	color: var(--blue);
	/* pulses every 3 seconds (20 bpm), and turns orange for about a second once a minute */
	animation: dot-pulse 3s ease-in-out infinite, dot-orange 60s linear infinite;
}

@keyframes dot-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.35; }
}

@keyframes dot-orange {
	0%, 97% { color: var(--blue); }
	98%, 99.5% { color: var(--orange); }
	100% { color: var(--blue); }
}

@media (prefers-reduced-motion: reduce) {
	span#dot {
		animation: none;
	}
}

span#domain {
	color: var(--teal);
}

h1, h2 {
	font-family: var(--font);
	color: var(--navy);
	text-decoration: none;
}

h1#site-title {
	font-size: 45px;
	margin: 20px 0 0;
	display: block;
	width: fit-content;
}

span#version-number {
	font-size: 1em;
	font-family: var(--font);
	color: var(--navy);
	text-decoration: none;
	text-align: center;
	display: inline-block;
	font-weight: bold;
}

h2 {
	font-size: 2em;
}

nav#main-nav {
	max-width: calc(100% - 425px);
}

ul#nav-mainlist {
	width: 100%;
	height: 100%;
	display: flex;
	list-style-type: none;
	padding: 0;
	margin: 0;
	flex-direction: row;
	justify-content: center;
	align-items: flex-end;
}


ul#nav-mainlist > li {
	padding: 20px 25px;
	text-align: center;
	font-family: var(--font);
	position: relative;
}


ul#nav-mainlist li:hover ul.nav-sublist {
	display: flex;
	width: max-content;
	min-width: 100%;
	list-style-type: none;
	padding: 10px 20px;
	flex-direction: column;
	justify-content: center;
	position: absolute;
	left: 0;
	right: 0;
	margin: 15px auto;
	border: 2px solid var(--navy);
	background-color: var(--sky);
	box-shadow: 2px 2px 0 var(--navy);
}

ul#nav-mainlist li ul.nav-sublist {
	display: none;
}

nav#main-nav ul#nav-mainlist li ul.nav-sublist > li {
	margin: 10px 0;
	padding: 3px;
	white-space: nowrap;
	font-size: 0.85em;
}

nav a {
	display: block;
	width: fit-content;
}

nav#main-nav ul li a {
	color: var(--navy);
	text-decoration: none;
	text-transform: uppercase;
	font-family: var(--font);
}

@media (hover: hover) {
	nav#main-nav ul li a:hover {
		text-decoration: underline;
		text-decoration-thickness: 2px;
	}
}

nav#main-nav ul li a.current span {
	font-weight: bold;
}

p, h3, li, a {
	color: var(--navy);
	font-family: var(--font);
}

p, h3 {
	margin: 10px 0;
}

section li, section a {
	color: var(--navy);
	font-family: var(--font);
	margin: 10px 0;
}

a {
	display: block;
}

p > a {
	display: inline-block;
}

section ul {
	list-style-type: none;
	padding: 0;
}

section ul.users-list {
	padding-left: 10px;
}

section ul.users-list > li.user {
	margin: 20px 0;
}

section ul li h3 {
	display: inline-block;
	margin: 0;
	font-weight: bold;
}

section ul li h3 + span {
	font-weight: bold;
}

section ul li span {
	font-size: 16px;
}


header div.branding a {
	text-decoration: none;
}

section {
	width: 1000px;
	margin: 40px auto;
	max-width: 90%;
}

/* messages: white, with a colored edge and a small label (info / ok / erreur) */
div.alert {
	box-sizing: border-box;
	color: var(--navy);
	background-color: var(--paper);
	border-left: 4px solid var(--blue);
	border-radius: 6px;
	padding: 10px 16px;
	line-height: 1.5;
	overflow-wrap: anywhere;
}

div.alert::before {
	content: 'info';
	display: block;
	font-size: 0.7rem;
	letter-spacing: 1px;
	color: var(--blue);
}

div.alert-success {
	border-left-color: var(--teal);
}

div.alert-success::before {
	content: 'ok';
	color: var(--teal);
}

div.alert-danger {
	border-left-color: var(--orange);
}

div.alert-danger::before {
	content: 'erreur';
	color: var(--danger);
}

/* the page messages sit between the header and the page, aligned with it */
div#page > div.alert {
	width: 1000px;
	max-width: 90%;
	margin: 30px auto 0;
}

section div.alert {
	margin: 0 0 20px;
	max-width: 600px;
}

body.busy, body.busy * {
	cursor: progress;
}

/* confirmations of the actions sent in the background (static/js/ajax_forms.js): fixed, so they show wherever you are */
div#toasts {
	position: fixed;
	top: 12px;
	left: 50%;
	transform: translateX(-50%);
	width: 600px;
	max-width: calc(100vw - 32px);
	z-index: 50;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

div#toasts div.alert {
	margin: 0;
	max-width: none;
	cursor: pointer;
	box-shadow: 3px 3px 0 var(--navy);
	border: 2px solid var(--navy);
	border-left-width: 4px;
}


@media (max-width: 950px) {
	body header {
		flex-direction: column;
		align-items: center;
	}
	
	header div.branding {
		width: auto;
		max-width: 95%;
	}

	header nav#main-nav {
		width: auto;
		max-width: 95%;
	}
	
	header span#version-number {
		margin: auto;
		display: block;
	}
}

@media (max-width: 500px) {
	html body header {
		align-items: center;
	}
	
	div.branding h1#site-title {
		font-size: 30px;
	}
	nav#main-nav ul#nav-mainlist {
		justify-content: space-between;
	}

	/* the items are spread over the width anyway: small side padding so four fit on a phone,
	   and the padding is on the link so the whole block can be tapped */
	nav#main-nav ul#nav-mainlist > li {
		padding: 0;
	}

	nav#main-nav ul#nav-mainlist > li > a {
		padding: 15px 5px;
	}
	
	body header nav#main-nav {
		width: 100%;
		max-width: 100%;
	}
	
	nav#main-nav ul#nav-mainlist li:hover ul.nav-sublist {
		display: none;
	}
}

/* phones: taller buttons and links, easy to tap (about 44px) */
@media (max-width: 600px) {
	button, input[type=submit], input[type=button], input[type=reset], a.button, a.card-button {
		padding: 12px 22px;
	}

	/* links alone on their line: the tap area grows, not the text */
	section a {
		padding: 8px 0;
		margin: 2px 0;
	}

	/* links inside a sentence: inline, so the taller tap area doesn't move the lines */
	p a, p > a, span a {
		display: inline;
		padding: 8px 0;
	}
}

/* switched-off apps, only listed for admins */
nav#main-nav span.app-item.inactive, section a.inactive {
	opacity: 0.45;
}
