:root {
    --color-background: #EEEEEE;
    --color-background-dark: #202020;

    --color-primary: #004080;
    --color-primary-focus: var(--color-primary);

    --color-text: #202020;
    --color-text-on-primary: #EEEEEE;
    --color-text-light: #505050;
    --color-text-primary: var(--color-primary-focus);
    --color-text-green: #006600;
    --color-text-orange: #FF7000;
    --color-text-red: #FF0000;

    --color-focus: #FF8000;
    --color-shadow: #00000055;
    --color-border: var(--color-text-primary);
    --color-gray-border: gray;
    --table--row-border: #D0D0D0;

    --color-svg: var(--color-text-primary);
    --color-svg-on-primary: var(--color-text-on-primary);
}

:root.theme-dark {
    --color-primary-focus: #0080FF;
    --color-background: var(--color-background-dark);

    --color-text: #CDCDCD;
    --color-text-light: #B3B3B3;
    --color-text-green: #00DD00;

    --color-shadow: #FFFFFF40;
    --color-gray-border: lightgray;
    --table--row-border: #505050;
}

:root {
    /* COLORS */
    --window--shadow: 0 0 calc(var(--window--margin) * 2) var(--window--margin) var(--color-shadow);
    --label--color-text: var(--color-text-light);
    --disabled-opacity: 0.5;

    /* SVG */
    --color-svg-black: #101010;
    --color-svg-cyan: #00ABCD;
    --color-svg-green: #00AA00;
    --color-svg-orange: #FF9933;
    --color-svg-red: #EE0000;
    --color-svg-white: #FFFFFF;

    /* TEXT */
    --font-family: Verdana;
    --font-size-base: 12px;
    --line-height-base: 1.5;

    /* SIZES */
    --border-radius: 5px;
    --button-std--margin: 5px;
    --field-max-width: 300px;
    --icon-height: 24px;
    --icon-small-height: 16px;
    --icon-table-height: 18px;
    --media-aspect-ratio: 5 / 4;
    --window--margin: 5px;

    /* Z-INDEXES */
    --zindex-loading: 1000;
}


/*****************************************/
/* BASE ELEMENTS                         */
/*****************************************/

html {
    box-sizing: border-box;
    scroll-behavior: smooth;
    text-size-adjust: 100%;
    word-break: break-word;
    word-wrap: break-word;
    -webkit-text-size-adjust: 100%;
}

*, *::before, *::after {
    box-sizing: inherit;
}

body {
    background-color: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-family), sans-serif;
    font-size: var(--font-size-base);
    height: 100dvh;
    line-height: var(--line-height-base);
    margin: 0;
    overflow: hidden;
    padding: 0;
    width: 100dvw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* A */

a {
    color: var(--color-text-primary);
    display: inline;
    text-decoration: none;
    vertical-align: middle;
}

a:hover {
    text-decoration: underline;
}

/* BUTTON */

button,
a.button {
    background: transparent;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    display: inline-block;
    font-size: inherit;
    line-height: var(--line-height-base);
    margin: 0;
    padding: 0;
    text-decoration: none;
    vertical-align: middle;
}

button:hover,
a.button:hover {
    text-decoration: none;
}

button[disabled],
a.button[disabled] {
    opacity: var(--disabled-opacity);
}

/* IMG */

img,
svg {
    border-style: none;
    display: block;
    height: auto;
    image-orientation: from-image;
    image-rendering: auto;
    max-inline-size: 100%;
    vertical-align: middle;
}

img.icon,
svg.icon {
    height: var(--icon-height);
    width: var(--icon-height);
}

img.icon-small,
svg.icon-small {
    height: var(--icon-small-height);
    width: var(--icon-small-height);
}

/* LIST */

ol,
ul {
    list-style-position: inside;
    margin: 2px auto;
    max-width: max-content;
    padding: 0;
    text-align: left;
    width: 100%;
}

/* P */

p {
    color: var(--color-text);
}

/* PROGRESS */

progress {
    display: block;
    margin: auto;
    max-width: 100%;
    width: 250px;
}

progress::-webkit-progress-value,
progress::-moz-progress-bar {
    background-color: var(--color-primary-focus);
}

/* FIELDSET */

fieldset {
    border: 1px solid var(--color-gray-border);
    border-radius: var(--border-radius);
    margin: 20px auto;
    padding: 10px;
    width: 100%;
}

fieldset.small {
    max-width: max-content;
}

fieldset legend {
    margin: 0 auto 0 min(5%, 16px);
}

fieldset legend.title,
fieldset legend.subtitle,
fieldset legend.ssubtitle {
    font-size: larger;
}

/* TABLE */

table {
    border: 1px solid var(--color-primary);
    border-collapse: collapse;
    border-spacing: 0;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
    display: block;
    margin: 20px auto;
    max-width: 100%;
    overflow-x: auto;
    text-align: left;
    white-space: nowrap;
    width: max-content;
}

table tr {
    margin: 0;
    padding: 0;
}

table tr:not(:has(> th)):not(:last-child) {
    border-bottom: 1px solid var(--table--row-border);
}

table tr:has(th) {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
    font-weight: bold;
}

table tr th,
table tr td {
    overflow: hidden;
    padding: 5px 15px;
}

table tr th {
    font-weight: inherit;
    padding-bottom: 8px;
    padding-top: 10px;
    text-align: center;
}

table:has(tr.selected) {
    border-collapse: collapse;
}

table tr.selected {
    border: 2px solid var(--color-focus);
    font-weight: bold;
}

table img.icon,
table svg.icon {
    display: block;
    height: var(--icon-table-height);
    width: var(--icon-table-height);
}

table td > img.icon,
table td > svg.icon {
    display: inline-block;
    margin: 0 5px;
}

table td > button,
table td > a.button {
    display: inline-block;
    margin: 0 5px;
    width: max-content;
}

table td > button:first-child,
table td > a.button:first-child {
    margin-left: 0;
}

table td > button:last-child,
table td > a.button:last-child {
    margin-right: 0;
}


/*****************************************/
/* SVG                                   */
/*****************************************/

svg {
    fill: none;
    font-family: arial, sans-serif;
    font-weight: bold;
    stroke: var(--color-svg);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 6px;
}

svg text {
    dominant-baseline: middle;
    fill: var(--color-svg);
    letter-spacing: 1px;
    stroke: none;
    text-anchor: middle;
}

svg.on-primary {
    --color-svg: var(--color-svg-on-primary);
}


/*****************************************/
/* UTILITIES                             */
/*****************************************/

span.no-wrap {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
}

*[hidden] {
    display: none !important;
}

button.offvalue,
img.offvalue,
svg.offvalue {
    opacity: 0.3;
}

button[disabled] {
    cursor: default;
}

a.back,
button.back {
    color: var(--color-text);
    display: block;
    margin: 0 auto 10px min(5dvw, 40px);
    max-width: max-content;
}

a.back:before,
button.back:before {
    content: "◀";
    margin-right: 5px;
    vertical-align: text-bottom;
}

a.back:hover,
button.back:hover {
    color: var(--color-focus);
}


/*****************************************/
/* WINDOW                                */
/*****************************************/

div.window-background {
    align-items: stretch;
    background: transparent;
    display: flex;
    height: 100dvh;
    justify-content: stretch;
    left: 0;
    position: fixed;
    top: 0;
    width: 100dvw;
    z-index: var(--zindex-loading);
}

div.window {
    --window-max-height: calc(100dvh - var(--window--margin) * 2);
    --window-max-width: calc(100dvw - var(--window--margin) * 2);
    --window-min-height: 150px;
    --window-min-width: 200px;
    --window-margin-top: 0px;

    background: var(--color-background);
    border: 2px solid var(--color-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--window--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: max(var(--window-margin-top), var(--window--margin)) auto auto auto;
    height: max-content;
    justify-content: space-around;
    max-height: var(--window-max-height);
    max-width: max-content;
    min-height: min(var(--window-min-height), var(--window-max-height));
    min-width: min(var(--window-min-width), var(--window-max-width));
    overflow: hidden auto;
    padding: 20px;
    text-align: center;
    width: var(--window-max-width);
}

div.window > *,
div.window > div.inner > * {
    padding: 0;
}

div.window > *,
div.window > div.inner > *:not(div.field, div.loader, svg) {
    margin: 0;
}

div.window > div.inner > div.field {
    margin: 0 auto;
}

div.window > span {
    display: block;
}

div.window span.title,
div.window span.subtitle,
div.window span.ssubtitle {
    font-size: large;
}

div.window > div.inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: space-around;
    overflow: hidden auto;
}

div.window > div.buttons {
    display: flex;
    flex-grow: 0;
    gap: 10px;
    justify-content: flex-end;
}

div.window span.title {
    font-size: large;
}

div.window span.subtitle,
div.window span.ssubtitle {
    font-size: larger;
}


/*****************************************/
/* TEXT                                  */
/*****************************************/

h1, h2, h3, h4, h5, h6 {
    display: block;
    margin: 10px auto;
    text-align: center;
    width: 100%;
}

.title, .subtitle, .ssubtitle {
    color: var(--color-text-primary);
    font-weight: bold;
}

.title {
    font-size: x-large;
}

.subtitle {
    font-size: large;
}

.ssubtitle {
    font-size: larger;
}


/*****************************************/
/* LAYOUT                                */
/*****************************************/

body {
    --open-close-size: min(36px, 20dvh);

    display: grid;
    grid-template-columns: max-content 1fr;
    grid-template-rows: max-content 1fr;
}

/* HEADER */

body > header {
    align-items: center;
    background-color: var(--color-primary);
    color: var(--color-text-on-primary);
    display: flex;
    flex-wrap: nowrap;
    font-size: larger;
    font-weight: bold;
    gap: min(1dvw, 20px);
    grid-column: 1 / -1;
    grid-row: 1;
    justify-content: space-between;
    overflow: hidden;
    padding: 8px min(40px, 5%);
}

body > header > span.app,
body > header > span.name,
body > header > span.user {
    flex: 1;
    max-width: max-content;
}

body > header > span > img,
body > header > span > svg,
body > header > span > button {
    display: inline-block;
}

body > header > span.app > img {
    margin-right: 10px;
}

body > header > span.user > button {
    margin-left: 10px;
}

body > header > span.user > button:hover {
    --color-svg-on-primary: var(--color-focus);
}

/* NAV */

body > nav {
    background-color: var(--color-primary);
    grid-column: 1;
    grid-row: 2;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 10px 0 20px 0;
    position: relative;
}

body > nav:not(:has(> a)) {
    display: none;
}

body > nav > a {
    align-items: center;
    color: var(--color-text-on-primary);
    cursor: pointer;
    display: flex;
    flex-wrap: nowrap;
    font-weight: bolder;
    gap: 8px;
    justify-content: flex-start;
    padding: 8px 10px;
}

body > nav > a.selected {
    text-decoration: underline;
    text-decoration-color: var(--color-focus);
}

body > nav > a > svg {
    --color-svg: var(--color-svg-on-primary);

    display: inline-block;
    height: 16px;
    width: 16px;
}

body > nav > a:hover {
    --color-svg-on-primary: var(--color-focus);

    color: var(--color-focus);
    text-decoration: none;
}

body > nav > button.open-close {
    background: var(--color-primary);
    border-bottom-right-radius: var(--border-radius);
    display: none;
    height: var(--open-close-size);
    left: 0;
    padding: 2.5%;
    position: absolute;
    top: 0;
    width: var(--open-close-size);
}

body > nav > button.open-close > svg {
    height: 100%;
    width: 100%;
}

body > nav > button.open-close > svg.close {
    display: none;
}

body > nav > button.open-close:hover {
    --color-svg: var(--color-focus);
}

/* MAIN */

body > main {
    grid-column: 2;
    grid-row: 2;
    overflow-x: hidden;
    overflow-y: auto;
    padding: calc(var(--open-close-size) + 10px) min(10px, 2%) min(80px, 20dvh) min(10px, 2%);
    text-align: center;
}

body > main > .title:first-child {
    margin-top: 0;
}

@media screen and (max-width: 700px) {
    body {
        grid-template-rows: max-content max-content 1fr;
    }

    body > nav {
        grid-column: 1 / -1;
        grid-row: 2;
        padding-bottom: 10px;
    }

    body > nav:not(.opened) {
        height: 0;
        overflow: visible;
        padding: 0;
    }

    body > nav > a {
        justify-content: center;
    }

    body > nav:not(.opened) > a {
        display: none;
    }

    body > nav > button.open-close {
        display: block;
    }

    body > nav.opened > button.open-close > svg.open {
        display: none;
    }

    body > nav.opened > button.open-close > svg.close {
        display: block;
    }

    body > main {
        grid-column: 1 / -1;
        grid-row: 3;
    }
}

@media screen and (max-width: 750px) {
    body > header > span.name {
        display: none;
    }
}

@media screen and (max-width: 500px) {
    body > header:has(> span.user) > span.app > span {
        display: none;
    }
}


/*****************************************/
/* INPUTS                                */
/*****************************************/

/* FIELDS */

div.fields,
fieldset.fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: space-around;
    margin: 20px auto;
}

div.fields {
    width: var(--field-max-width);
}

div.fields.horizontal,
fieldset.fields.horizontal {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    width: auto;
}

/* FIELD */

div.field,
div.fields > div:not(.buttons),
fieldset.fields > div:not(.buttons) {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 10px auto;
    max-width: 100%;
    width: var(--field-max-width);
}

div.fields > div:not(.buttons),
fieldset.fields > div:not(.buttons) {
    margin: auto;
}

div.fields > div {
    width: 100%;
}

div.field:has(input[type="number"]),
div.fields > div:has(input[type="number"]),
fieldset.fields > div:has(input[type="number"]) {
    width: calc(var(--field-max-width) / 2);
}

div.fields.horizontal > div,
fieldset.fields.horizontal > div {
    margin: 0;
    width: max-content;
}

/* FIELD CHECKBOX */

div.field.checkbox,
div.fields > div.checkbox,
fieldset.fields > div.checkbox {
    margin: 0;
}

div.field.checkbox.vertical,
div.fields > div.checkbox.vertical,
fieldset.fields > div.checkbox.vertical {
    align-items: center;
    flex-direction: column;
    gap: 5px;
    justify-content: center;
    width: auto;
}

div.field.checkbox.horizontal,
div.fields > div.checkbox.horizontal,
fieldset.fields > div.checkbox.horizontal {
    flex-direction: row;
    gap: 10px;
    justify-content: flex-start;
    padding: 0 10%;
}

div.field.checkbox > *,
div.fields > div.checkbox > *,
fieldset.fields > div.checkbox > * {
    margin: 0;
    width: max-content;
}

/* INPUT and SELECT */

input:not([type="checkbox"]),
select {
    display: block;
    background-color: var(--color-background);
    border: 1px solid var(--color-gray-border);
    border-radius: var(--border-radius);
    color: var(--color-text);
    margin: auto;
    padding: 3px 5px;
    text-align: center;
    width: 100%;
}

input[type=checkbox] {
    accent-color: var(--color-primary);
    vertical-align: middle;
}

input[type=checkbox][inert] {
    accent-color: gray;
}

label {
    display: block;
    margin: auto;
    max-width: 100%;
    text-align: left;
    vertical-align: middle;
    width: max-content;
}

label:has(+ input:not([type="checkbox"])) {
    color: var(--label--color-text);
    font-size: smaller;
    padding-left: min(5%, 16px);
    width: 100%;
}

/* BUTTONS */

a.button.std,
button.std {
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    margin: var(--button-std--margin);
    padding: 3px 6px;
}

a.button.std:hover,
button.std:hover {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
}

div.field:has(+ a.button.std, + button.std),
div.fields > div:has(+ a.button.std, + button.std),
fieldset.fields > div:has(+ a.button.std, + button.std) {
    margin-bottom: 15px;
}

div.window > div.buttons > button,
div.window > div.buttons > a.button {
    margin: 0;
}

/* BUTTONS DIV */

div.buttons {
    align-items: center;
    display: flex;
    justify-content: center;
}


/*****************************************/
/* MESSAGE                               */
/*****************************************/

div.message-window svg.icon {
    display: block;
    height: 60px;
    margin: 0 auto 20px auto;
    max-width: min(50dvh, 100%);
    width: 60px;
}

div.message-window span.title,
div.message-window span.subtitle {
    display: block;
    margin: 0 auto 10px auto;
    text-align: center;
}

div.message-window span.subtitle {
    font-size: larger;
}

div.message-window:has(span.subtitle:not([hidden])) span.title {
    margin-bottom: 0;
}

div.message-window div.content {
    margin-bottom: 10px;
}

div.message-window div.content > p {
    margin: 0 auto 0 0;
}

div.message-window div.content > p + p {
    margin-top: 5px;
}

div.message-window > button.close {
    display: block;
    margin: 0 0 0 auto;
}


/*****************************************/
/* LOADING                               */
/*****************************************/

div.loading {
    --window-min-width: 150px;

    min-height: unset;
}

div.loading div.loader {
    aspect-ratio: 1 / 1;
    border: 16px solid var(--color-primary);
    border-radius: 50%;
    border-top: 16px solid var(--color-focus);
    margin: 0 auto 20px auto;
    max-width: calc(100% - 20px);
    width: 80px;

    animation: loading-spin 2s linear infinite;
    -webkit-animation: loading-spin 2s linear infinite; /* Safari */
}


/* Safari */
@-webkit-keyframes loading-spin {
    0% {
        -webkit-transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
    }
}

@keyframes loading-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

div.window-background[hidden] div.window.loading div.loader {
    animation-play-state: paused;
}

div.loading div.messages {
    display: grid;
    gap: 5px 10px;
    grid-template-columns: 1fr max-content;
}

div.loading div.messages > span {
    grid-column: 1;
    text-align: left;
}

div.loading div.messages > button {
    grid-column: 2;
}


/*****************************************/
/* PAGING                                */
/*****************************************/

div.pages-index {
    display: block;
    margin: 20px auto;
    min-width: min(100%, 100px);
    max-width: max-content;
    text-align: center;
    width: 100%;
}

div.pages-index button {
    border: none;
    color: var(--color-text);
    margin: 0;
    padding: 5px 8px;
    vertical-align: middle;
}

div.pages-index select {
    display: inline-block;
    max-width: 100%;
    vertical-align: middle;
    width: 100px;
}

div.pages-index button:hover {
    color: var(--color-focus);
}

div.pages-index button.current {
    color: var(--color-focus);
    font-weight: bold;
}


/*****************************************/
/* DROPDOWN DIV                          */
/*****************************************/

div.dropdown-div {
    display: block;
    margin: 20px auto;
    max-width: 800px;
    vertical-align: middle;
    width: 100%;
}

div.dropdown-div > button.open-close {
    display: block;
    margin: 0 auto;
}

div.dropdown-div:has(> div:not([hidden])) > button.open-close {
    border-bottom: none;
    border-bottom-left-radius: unset;
    border-bottom-right-radius: unset;
}

div.dropdown-div > div {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    margin: 0 auto;
    padding: 10px min(20px, 5dvw);
}

div.dropdown-div:has(> div.button-std[hidden]) {
    display: inline-block;
    margin: var(--button-std--margin);
    max-width: 100%;
    width: max-content;
}


/*****************************************/
/* NOT-AUTHORIZED PAGE                   */
/*****************************************/

svg.not-authorized {
    height: min(50dvh, 100px);
    margin: 50px auto;
    width: 100%;
}

span.not-authorized {
    display: block;
    margin: 10px auto;
}

a.not-authorized {
    display: block;
    margin: 30px auto !important;
    width: max-content;
}