:root {
    --pageWidth: 50rem;

    --smallFontSize: small;
    --verySmallFontSize: 0.7em;
    --emptyListFontSize: 0.8rem;
    --listItemFontSize: 0.9rem;

    --appBackgroundColor: var(--paletteColor80);
    --appContentContainerBackgroundColor: red;
    --appContentBackgroundColor: var(--paletteColor90);

    --buttonBackgroundColor: var(--paletteColor50);
    --buttonBackgroundColorHover: var(--paletteColor60);
    --buttonBackgroundColorActive: var(--paletteColor40);
    --buttonColor: var(--paletteColor90);
    --buttonColorHover: var(--paletteColor100);
    --buttonColorActive: var(--paletteColor80);
    --buttonFontSize: 0.7rem;
    --defaultButtonBorderColor: var(--buttonBackgroundColor);

    --hoverBackgroundColor: var(--paletteColor65);
    --hoverColor: red;
    --hoverInnerBackgroundColor: var(--paletteColor45);
    --hoverInnerColor: var(--paletteColor90);
    --activeBackgroundColor: var(--paletteColor70);

    --rowHoverBackgroundColor: var(--paletteColor65);
    --rowSelectedBackgroundColor: var(--paletteColor65);

    --currentActivityColor: var(--paletteColor30);
    --currentActivityBackgroundColor: var(--paletteColor90);
    --activityNameColor: inherit;
    --activityNameFontSize: inherit;
    --activityTextColor: var(--paletteColor30);
    --activityListItem_name_fontSize: var(--listItemFontSize);
    --listItem_borderColor: #bbb;
    --notesCellColor: var(--paletteColor45);
    --notesCellFontSize: var(--verySmallFontSize);
    --breadcrumbColor: var(--paletteColor50);
    --breadcrumbSeparatorColor: var(--paletteColor20);
    --breadcrumbFontSize: var(--smallFontSize);

    --listSectionTitleBackgroundColor: var(--paletteColor82);
    --listSectionTitleColor: var(--paletteColor40);
    --listSectionFontSize: var(--smallFontSize);

    --activeActivityBorderColor: hsl(108, 51%, 50%);
    --activeActivityBackgroundColor: hsl(108, 51%, 90%);
    --activeActivityBackgroundHoverColor: hsl(108, 51%, 60%);
    --activeActivityBackgroundActiveColor: hsl(108, 51%, 40%);

    --startActivityButtonColor: var(--activeActivityBorderColor);
    --startActivityButtonBackgroundColor: var(--activeActivityBackgroundColor);
    --startActivityButtonBorderColor: var(--activeActivityBorderColor);
    --startActivityButtonBackgroundColorHover: var(--activeActivityBackgroundHoverColor);
    --startActivityButtonBackgroundColorActive: var(--activeActivityBackgroundActiveColor);

    --stopActivityButtonColor: hsl(10, 51%, 50%);
    --stopActivityButtonBackgroundColor: hsl(10, 50%, 90%);
    --stopActivityButtonBorderColor: hsl(10, 50%, 50%);
    --stopActivityButtonBackgroundColorHover: hsl(10, 50%, 60%);
    --stopActivityButtonBackgroundColorActive: hsl(10, 50%, 40%);

    --durationHoursColor: var(--paletteColor30);
    --durationHoursFontSize: 0.8rem;
    --durationMinutesColor: var(--paletteColor30);
    --durationMinutesFontSize: var(--smallFontSize);
    --durationUnitColor: var(--paletteColor70);
    --durationUnitFontSize: var(--verySmallFontSize);
    --durationLabelFontSize: var(--smallFontSize);
    --durationNameColor: var(--paletteColor30);

    --tabBackgroundColor: var(--appContentBackgroundColor);
    --tabTextColor: var(--paletteColor30);
    --tabBorderColorSelected: var(--paletteColor20);
    --tabBackgroundColorHover: var(--paletteColor70);
    --tabBorderColorHover: var(--paletteColor30);
    --tabBackgroundColorActive: var(--paletteColor60);
    --tabBorderColorActive: var(--paletteColor20);

    --instanceNameTextColor: red;
    --instanceNameFontSize: var(--verySmallFontSize);

    --errorColor: #b00020;
}

html {
    font-family: Helvetica, sans-serif;
    font-size: 120%;
    color: var(--paletteColor30);
}

/* === App Layout (single column for narrow devices without media query) ============================================ */
body.app {
    height: 100dvh;
    max-width: var(--pageWidth);
    margin: 0;
    margin-inline: auto;

    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;

    overflow: hidden;

    background-color: var(--appBackgroundColor);

    > header {
        min-width: 0;

        display: grid;
        grid-template-columns:
            auto
            minmax(0, 1fr)
            auto;
        align-items: center;
        column-gap: 0.5rem;

        padding: 0.2rem 0.2rem;

        .logo {
            grid-column: 1;

            display: flex;
            align-items: center;

            img {
                display: block;
            }
        }

        .instanceName {
            grid-column: 2;
            min-width: 0;

            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;

            color: var(--instanceNameTextColor);
            font-size: var(--instanceNameFontSize);
            opacity: 0.7;
        }

        .headerActions {
            grid-column: 3;

            display: flex;
            align-items: center;
            gap: 0.4rem;

            white-space: nowrap;

            .headerAction {
                box-sizing: border-box;

                display: flex;
                align-items: center;
                height: 100%;

                margin: 0;
                padding-inline: 0.4rem;
                border: 0;

                font-size: 0.8rem;
            }
        }
    }

    > main {
        min-height: 0;
        overflow-y: auto;
        background-color: var(--appContentBackgroundColor);
    }

    > footer {
        min-width: 0;
    }
}

.textOverflow {
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

form.actionButton {
    display: inline;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    row-gap: 0.3rem;
    column-gap: 0.2rem;
    padding: 0.2rem;

    .lhs {
        display: flex;
        flex-wrap: wrap;
        gap: 0.2rem;
    }

    .rhs {
        margin-inline-start: auto;
    }
}

/* Style duration ----------------------------------------------------------------------------------------------------*/
.durations {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(4rem, max-content);
    align-self: flex-start;
    gap: 0.2rem;

    @media (max-width: 50rem) {
        .duration.week,
        .duration.month {
            display: none;
        }
    }

    @media (max-width: 35rem) {
        .duration.day {
            display: none;
        }
    }
}

.duration {
    display: inline-grid;
    grid-template-areas:
        "lb lb lb lb"
        "hr hu mn mu";
    grid-template-columns: 2ch auto 2ch auto;
    grid-template-rows: 1fr minmax(0, auto);

    align-items: baseline;
    text-align: right;

    background-color: aliceblue;
    padding: 0.1rem 0.2rem;

    .hours { grid-area: hr }
    .hours_unit { grid-area: hu }
    .minutes { grid-area: mn }
    .minutes_unit { grid-area: mu }
    .label { grid-area: lb }

    span {
        display: inline-block;
        padding: 0;
        margin: 0;
    }

    span.unit {
        font-size: var(--durationUnitFontSize);
        color: var(--durationUnitColor);
    }

    span.hours {
        color: var(--durationHoursColor);
        font-size: var(--durationHoursFontSize);
    }

    span.minutes {
        padding-inline-start: 0.1rem;
        color: var(--durationMinutesColor);
        font-size: var(--durationMinutesFontSize);
    }

    .label {
        color: var(--durationNameColor);
        font-size: var(--durationLabelFontSize);
        opacity: 0.5;
        text-align: end;
    }

    &[href] {
         color: inherit;
         text-decoration: none;
         cursor: pointer;

        &:hover,
        &:focus-visible {
             background-color: lightblue;

            .label {
                text-decoration: underline;
            }
        }
    }
}
/* Style duration ----------------------------------------------------------------------------------------------------*/

/* ----- Forms ------------------------------------------------------------------------------------------------------ */
.webAppFormContainer {
    max-width: 48rem;
    margin-inline: auto;
    padding-inline: 0.6rem;
}

.webAppForm {
    fieldset {
        min-width: 0;
        margin: 0;
        padding: 0;
        border: 0;
    }

    div {
        margin-block-end: 1rem;
    }

    label {
        display: block;
        margin-top: 0.4rem;
        margin-bottom: 0.1rem;
    }

    input,
    textarea,
    select {
        display: block;
        width: 100%;
        box-sizing: border-box;

        padding: 0.5rem;
        border: 0.05rem solid var(--paletteColor30);
        border-radius: 0.2rem;
    }

    textarea {
        min-height: 8rem;
        resize: vertical;
    }

    button[type="submit"] {
        padding: 0.3rem 1rem;
    }

    .formHelp {
        margin: 0.1rem 0.3rem 0.1rem;
        color: var(--paletteColor45);
        font-size: 0.7rem;
        font-weight: 400;
        opacity: 0.8;
    }

    .validationError {
        margin-block: 0.4rem 0;
        color: var(--errorColor);
        font-size: 0.8rem;
        font-weight: 400;
    }

    .hidden {
        display: none;
    }

    input[aria-invalid="true"],
    textarea[aria-invalid="true"] {
        border-color: var(--errorColor);
    }

    input[aria-invalid="true"]:focus,
    textarea[aria-invalid="true"]:focus {
        outline-color: var(--errorColor);
    }
}

.formActions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;

    padding-inline: 0;

    button[data-default-submit] {
        box-shadow:
            inset 0 0 0 0.1rem currentColor,
            0 0 0 0.05rem var(--defaultButtonBorderColor);
    }

    .lhs,
    .rhs,
    .additionalActions,
    .submitActions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .rhs {
        justify-content: flex-end;
        gap: 0.5rem;

        margin-inline-start: auto;
    }

    .additionalActions,
    .submitActions {
        gap: 0.4rem;
    }

    form {
        display: flex;
        align-items: center;

        margin: 0;
    }

    a.actionButton,
    button {
        box-sizing: border-box;

        display: inline-flex;
        align-items: center;
        justify-content: center;

        height: 1.6rem;
        margin: 0;
        padding: 0.3rem 0.5rem;
        border: 0;

        line-height: 1;
        white-space: nowrap;
    }

    .cancelAction {
        &::before {
            content: "←";
            margin-inline-end: 0.2rem;

            font-size: 0.85em;
            opacity: 0.8;
        }

        &::after {
            content: none;
        }
    }

    .destructiveAction {
        background-color: red;
    }
}

a.actionButton,
button.actionButton {
    display: inline-block;

    background: var(--buttonBackgroundColor);
    color: var(--buttonColor);
    text-decoration: none;

    font-size: var(--buttonFontSize);
    line-height: 1.4;
}

a.actionButton::after,
button.actionButton::after {
    content: "→";
    margin-inline-start: 0.2rem;
    opacity: 0.8;
    font-size: 0.85em;
}

a.actionButton:hover {
    background: var(--buttonBackgroundColorHover);
    color: var(--buttonColorHover);
    text-decoration: underline;
}

a.actionButton:active {
    background: var(--buttonBackgroundColorActive);
    color: var(--buttonColorActive);
}

a.actionButton,
button {
    padding: 0.2rem 0.2rem;

    background-color: var(--buttonBackgroundColor);
    color: var(--buttonColor);
    border: none;

    font-size: var(--buttonFontSize);
    text-decoration: none;
}

button:hover {
    background-color: var(--buttonBackgroundColorHover);
    color: var(--buttonColorHover);
}

button:active {
    background-color: var(--buttonBackgroundColorActive);
    color: var(--buttonColorActive);
}


ul.gridList {
    margin-block: 0;
    list-style: none;
    padding: 0;
}

.cell,
.cell:hover,
.cell:active,
.cell:visited {
    color: var(--activityTextColor);
}

.nameCell {
    color: var(--activityNameColor);
    font-size: var(--activityNameFontSize);
}

.notes {
    min-width: 0;
    color: var(--notesCellColor);
    font-size: var(--notesCellFontSize);
    text-align: left;
}

/* Ensure empty cells have the height according to grid */
.cell.empty::before {
    content: "\00a0";
}

.listSection > div {
    padding: 0.1rem 0.2rem;

    font-size: var(--listSectionFontSize);
    font-variant: small-caps;
    letter-spacing: 0.08rem;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;

    background-color: var(--listSectionTitleBackgroundColor);
    color: var(--listSectionTitleColor);
}

/* Page Section ------------------------------------------------------------------------------ */
section.pageSection {
    h2 {
        margin: 0.02rem 0 0rem 0;
        padding: 0.2rem 0.35rem;
        font-size: 1rem;
        font-weight: 600;
        background: rgba(255, 255, 255, 0.4);
    }
}
/* Page Section ------------------------------------------------------------------------------ */


/* Selectable Row ---------------------------------------------------------------------------- */
.selectableRow {
    transition: background-color 200ms ease;
}

.selectableRow:hover,
.selectableRow:focus-within {
    background: var(--rowHoverBackgroundColor);
}

.selectableRow.selected,
.selectableRow[aria-selected="true"] {
    background: var(--rowSelectedBackgroundColor);
}
/* Selectable Row ---------------------------------------------------------------------------- */

/* Dashboard Durations ----------------------------------------------------------------------- */
.dashboardDurations {
    box-sizing: border-box;
    margin-inline-start: auto;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    padding: 0.2rem;
}
/* Dashboard Durations ----------------------------------------------------------------------- */

nav.breadcrumb {
    margin: 0;
    padding: 0;
    font-size: var(--breadcrumbFontSize);

    ul {
        display: inline-flex;
        align-items: baseline;

        margin: 0;
        padding: 0;
        list-style: none;

        li {
            display: inline-flex;
            align-items: baseline;
        }

        li + li::before {
            content: "/";
            margin-inline: 0.3rem;
            opacity: 0.6;
            color: var(--breadcrumbSeparatorColor);
        }

        a {
            display: inline-block;

            /* Comfortable horizontal target and slight vertical overspill */
            padding: 0.15rem 0.3rem;
            margin-inline: -0.3rem;

            color: var(--breadcrumbColor);
            line-height: 1;
            text-decoration: none;
        }

        a:hover,
        a:focus-visible {
            color: var(--hoverInnerColor);
            background-color: var(--hoverInnerBackgroundColor);
        }
    }
}

.document {
    .markdown {
        padding-inline: 0.3rem;
        font-size: 0.8rem;
        }

        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
            font-weight: 500;
        }
    }
}