:root {
    --paletteColor20: hsl(219, 51%, 20%);
    --paletteColor30: hsl(219, 51%, 30%);
    --paletteColor40: hsl(219, 51%, 40%);
    --paletteColor45: hsl(219, 51%, 45%);
    --paletteColor50: hsl(219, 51%, 50%);
    --paletteColor60: hsl(219, 51%, 60%);
    --paletteColor65: hsl(219, 51%, 65%);
    --paletteColor70: hsl(219, 51%, 70%);
    --paletteColor78: hsl(219, 51%, 78%);
    --paletteColor80: hsl(219, 51%, 80%);
    --paletteColor82: hsl(219, 51%, 82%);
    --paletteColor86: hsl(219, 51%, 86%);
    --paletteColor90: hsl(219, 51%, 90%);
    --paletteColor100: hsl(219, 51%, 100%);
}

/* ActivityPage ------------------------------------------------------------------------------ */
.ActivityPage {
    max-width: var(--pageWidth);
    margin-inline: auto;
    padding-inline: 0.5rem;

    header {
        padding-block: 0.5rem;

        .pageSection {
            width: 100%;
        }
    }

    .body {
        min-width: 0;
        padding-inline-start: 0.75rem;
    }

    .notes {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;

        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
}
/* ActivityPage ------------------------------------------------------------------------------ */

/* Activity ---------------------------------------------------------------------------------- */
.startStopForm {
    display: inline-block;
    margin: 0;
    padding: 0;
    align-self: center;
    justify-self: center;

    button {
        display: inline-block;
        padding: 0.3rem 0.5rem;
        margin: 0;
        line-height: 1.4;
        font-size: var(--buttonFontSize);

        color: var(--activityButtonColor);
        background-color: var(--activityButtonBackgroundColor);
        border: 1px solid var(--activityButtonBorderColor);

        &:hover {
             background-color: var(--activityButtonBackgroundColorHover);
        }

        &:active {
             background-color: var(--activityButtonBackgroundColorActive);
        }
    }

    .startActivity {
        &:after {
             content: " \25BA";
        }
    }

    .stopActivity {
        --activityButtonColor: var(--stopActivityButtonColor);
        --activityButtonBackgroundColor: var(--stopActivityButtonBackgroundColor);
        --activityButtonBorderColor: var(--stopActivityButtonBorderColor);
        --activityButtonBackgroundColorHover: var(--stopActivityButtonBackgroundColorHover);
        --activityButtonBackgroundColorActive: var(--stopActivityButtonBackgroundColorActive);

        &:after {
             content: " \25FC";
        }
    }
}

.startActivity {
    --activityButtonColor: var(--startActivityButtonColor);
    --activityButtonBackgroundColor: var(--startActivityButtonBackgroundColor);
    --activityButtonBorderColor: var(--startActivityButtonBorderColor);
    --activityButtonBackgroundColorHover: var(--startActivityButtonBackgroundColorHover);
    --activityButtonBackgroundColorActive: var(--startActivityButtonBackgroundColorActive);
}
/* Activity ---------------------------------------------------------------------------------- */

.formActions {
    .startActivity {
        color: var(--activityButtonColor);
        background-color: var(--activityButtonBackgroundColor);
        border: 1px solid var(--activityButtonBorderColor);

        &:hover {
            background-color: var(--activityButtonBackgroundColorHover);
            color: var(--buttonColorHover);
        }

        &:active {
            background-color: var(--activityButtonBackgroundColorActive);
        }

        &:after {
             content: "\25BA";
             margin-inline-start: 0.2rem;
         }
    }
}
/* Current Activity -------------------------------------------------------------------------- */
.currentActivity {
    padding: 0.2rem 0.5rem;

    background: #f8f8f8;
    border-top: 2px solid #3b5998;

    &:empty {
        display: none;
    }
}
/* Current Activity -------------------------------------------------------------------------- */

/* Activity List ----------------------------------------------------------------------------- */
.activityList {
    p.empty {
        padding-inline-start: 0.75rem;
        margin: 0.25rem 0;
        font-size: var(--emptyListFontSize);
    }

    .activityListItem {
        display: grid;
        grid-template-areas:
            "action name       duration"
            "action breadcrumb duration"
            "action notes      duration";
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: auto auto auto;
        column-gap: 0.6rem;

        padding: 0.2rem;
        border-block-end: 1px solid var(--listItem_borderColor);

        .notes {
            line-height: 1.2;
            min-height: 1.2em;
        }

        .notes:empty::before {
            content: "\00a0";
        }

        .actionButton {
            grid-area: action;
            align-self: stretch;
        }

        .name {
            grid-area: name;

            min-width: 0;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;

            text-decoration: none;
            color: var(--activityNameColor);
            font-size: var(--activityListItem_name_fontSize);
        }

        .breadcrumb {
            grid-area: breadcrumb;

            min-width: 0;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .notes {
            grid-area: notes;

            min-width: 0;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .startStopForm  {
            align-self: start;

            button {
                /* Set both start and stop to be fixed size be square and nicely line up */
                height: 1.8rem;
                width: 1.8rem;

                span:first-child {
                    /* Hide the text of the start/stop button in list view; just show icon */
                    display: none;
                }
            }
        }

        .durations {
            grid-area: duration;
            align-self: start;
        }
    }
}
/* Activity List ----------------------------------------------------------------------------- */

/* PeriodListPage ---------------------------------------------------------------------------- */
.periodListPage {
    .groupingControls {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.2rem;

        margin-block: 0.2rem 0.2rem;

        .groupingControlsLabel {
            margin-inline-end: 0.25rem;

            color: var(--listSectionTitleColor);
            font-size: 0.8rem;
        }

        .groupingButton {
            border: 2px solid transparent;

            text-decoration: none;

            &.notGroupedBy {
                opacity: 0.7;
            }

            &.groupedBy {
                border-color: currentColor;

                background-color: var(--listSectionTitleBackgroundColor);
                color: var(--listSectionTitleColor);

                box-shadow: inset 0 0 0 1px rgb(255 255 255 / 30%);

            }

            &:hover {
                opacity: 1;
            }

            &:focus-visible {
                outline: 2px solid currentColor;
                outline-offset: 2px;
            }
        }
    }
}
/* PeriodListPage ---------------------------------------------------------------------------- */

/* Period List ------------------------------------------------------------------------------- */
.periodList {
    display: grid;
    row-gap: 0;

    .periodGroup {
        display: grid;
        width: 100%;
        min-width: 0;

        .periodGroupSummary {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            align-items: center;
            column-gap: 0.4rem;

            width: 100%;
            min-width: 0;
            box-sizing: border-box;

            padding-block: 0.25rem;
            padding-inline-start: 0.4rem;
            padding-inline-end: 0;
			
			cursor: pointer;
			list-style: none;

			&::-webkit-details-marker {
				display: none;
			}

            .periodGroupTitle {
				display: flex;
				align-items: center;
				gap: 0.3rem;

				&::before {
					content: "▶";

					flex: 0 0 0.8rem;

					width: 0.8rem;

					font-size: 0.65rem;
					line-height: 1;
					text-align: center;

					transform: rotate(0deg);
					transition: transform 100ms ease-in-out;
				}
				
                min-width: 0;

                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;

                color: var(--listSectionTitleColor);

                a {
                    color: inherit;
                    text-decoration: none;

                    &:hover {
                        text-decoration: underline;
                    }
                }
            }

            .periodGroupStatistics {
                display: flex;
                align-items: stretch;
                justify-content: flex-end;
                gap: 0.25rem;

                min-width: 0;
                max-width: 100%;

                white-space: nowrap;

                .periodGroupStatistic {
                    display: grid;
                    grid-template-rows: auto auto;
                    justify-items: end;

                    min-width: 3.4rem;
                    box-sizing: border-box;

                    padding: 0.1rem 0.25rem;

                    background-color: rgb(255 255 255 / 35%);

                    .periodGroupStatisticLabel {
                        color: var(--listSectionTitleColor);
                        font-size: 0.62rem;
                        font-weight: normal;
                        line-height: 1;
                        opacity: 0.55;
                    }

                    .periodGroupStatisticValue {
                        color: var(--listSectionTitleColor);
                        font-size: 0.8rem;
                        font-weight: normal;
                        line-height: 1.1;
                    }
                }

                .periodGroupDuration {
                    min-width: 4.4rem;
                    max-width: 4.4rem;
                    box-sizing: border-box;
                }
            }
        }

		&[open] {
			> .periodGroupSummary {
				> .periodGroupTitle::before {
					transform: rotate(90deg);
				}
			}
		}
		
        .periodGroupContents {
            display: grid;
            row-gap: 0;

            min-width: 0;

            padding-block-start: 0;
            padding-inline-start: 0.35rem;
            padding-inline-end: 0;

            border-inline-start: 0;
        }

        &.monthGroup {
            > .periodGroupSummary {
                background-color: color-mix(
                    in srgb,
                    var(--listSectionTitleBackgroundColor) 100%,
                    white
                );
            }
        }

        &.weekGroup {
            > .periodGroupSummary {
                background-color: color-mix(
                    in srgb,
                    var(--listSectionTitleBackgroundColor) 90%,
                    white
                );
            }
        }

        &.dayGroup {
            > .periodGroupSummary {
                background-color: color-mix(
                    in srgb,
                    var(--listSectionTitleBackgroundColor) 80%,
                    white
                );
            }
        }

        &.activityGroup {
            border: 1px solid rgb(0 0 0 / 8%);
            border-radius: 0.2rem;

            > .periodGroupSummary {
                background-color: color-mix(
                    in srgb,
                    var(--listSectionTitleBackgroundColor) 70%,
                    white
                );
            }

            > .periodGroupContents {
                padding-inline-start: 0;
                border-inline-start: 0;
            }
        }

		.periodRows {
			display: grid;
			min-width: 0;

			/*
			 * Indent the actual rows once more beneath their activity
			 * heading, matching the visual progression of the groups.
			 */
			padding-inline-start: 0.35rem;

			.periodRow {
				position: relative;

				display: grid;
				grid-template-columns:
					auto
					auto
					minmax(0, 1fr)
					auto
					minmax(4rem, max-content);

				align-items: start;
				column-gap: 0.5rem;

				width: 100%;
				min-width: 0;
				box-sizing: border-box;

				padding: 0.2rem 0 0.2rem 0.4rem;

				border-block-end: 1px solid rgb(0 0 0 / 8%);

				/*
				 * The existing period-times link supplies the edit URL.
				 * Its pseudo-element makes the entire row selectable.
				 */
				.periodTimes {
					grid-column: 1;

					color: inherit;
					text-decoration: none;

					&::after {
						content: "";

						position: absolute;
						inset: 0;

						cursor: pointer;
					}

					&:hover,
					&:focus,
					&:active,
					&:visited {
						color: inherit;
						text-decoration: none;
					}

					/*
					 * Retain a visible keyboard-focus indication around
					 * the complete selectable row.
					 */
					&:focus-visible::after {
						outline: 2px solid currentColor;
						outline-offset: -2px;
					}
				}

				/*
				 * Keep a separately linked activity name usable above the
				 * full-row edit-link overlay.
				 */
				.periodActivity {
					position: relative;
					z-index: 1;

					grid-column: 1;

					color: inherit;
				}

				.periodNotes {
					grid-column: 2 / 5;
					min-width: 0;

					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					
					font-size: 0.8rem;
					opacity: 0.65;
				}

				.periodTimes,
				.periodNotes {
					align-self: baseline;
				}

				/*
				 * Explicitly use the final grid column. Target the
				 * period-specific class rather than relying only on the
				 * generic duration class.
				 */
				.periodDuration {
					position: relative;
					z-index: 1;

					grid-column: 5;
					grid-row: 1;

					justify-self: end;
					align-self: start;

					min-width: 4rem;
					max-width: max-content;

					--durationHoursFontSize: 0.9rem;
					--durationMinutesFontSize: 0.65rem;
					--durationUnitFontSize: 0.55rem;
				}

				&:hover {
					background-color: rgb(255 255 255 / 30%);
				}

				&:active {
					background-color: rgb(255 255 255 / 50%);
				}

				&.activePeriod {
					font-weight: normal;
				}
			}
		}
    }

    @media (max-width: 45rem) {
        .periodGroup {
            .periodGroupSummary {
                grid-template-columns: minmax(0, 1fr) auto;

                .periodGroupStatistics {
                    gap: 0.15rem;

                    .periodGroupStatistic {
                        min-width: 2.9rem;
                        padding-inline: 0.15rem;
                    }

                    .periodGroupDuration {
                        min-width: 4rem;
                        max-width: 4rem;
                    }
                }
            }

            .periodGroupContents {
                padding-inline-start: 0.25rem;
            }
        }
    }
}
/* Period List ------------------------------------------------------------------------------- */

/* Search Page ------------------------------------------------------------------------------- */
.SearchPage {
    .searchResults,
    .periodResults {
        padding: 0;
        margin: 0;
        list-style: none;
    }

    .searchResultsSection {
        margin-block-start: 0.75rem;
    }
    
    .searchResults {
        border-block-start: 1px solid var(--listItem_borderColor);
    }

    .searchResultGroup {
        border-block-end: 1px solid var(--listItem_borderColor);
    }

    .activitySearchResult {
        display: grid;
        grid-template-areas:
            "action name"
            "action breadcrumb"
            "action notes";
        grid-template-columns: 1.8rem minmax(0, 1fr);
        column-gap: 0.75rem;

        padding: 0.4rem;

        .actionButton {
            align-self: start;
            grid-area: action;
            width: 1.8rem;

            button {
                box-sizing: border-box;
                width: 1.8rem;
                height: 1.8rem;
                padding: 0;
            }

            button span:first-child {
                display: none;
            }
        }

        .name {
            grid-area: name;

            min-width: 0;
            overflow: hidden;
            color: var(--activityNameColor);
            font-size: var(--activityListItem_name_fontSize);
            text-decoration: none;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .breadcrumb {
            grid-area: breadcrumb;
        }

        .notes {
            grid-area: notes;
        }
    }

    .periodResults {
        margin-inline-start: 1rem;
        padding-inline-start: 0.15rem;
        border-inline-start: 1px solid var(--listItem_borderColor);
    }

    .periodSearchResult {
        min-width: 0;
        padding: 0.2rem 0.2rem;

        .period {
            display: grid;
            grid-template-columns:
                auto                 /* date */
                auto                 /* start */
                auto                 /* separator */
                4ch                  /* stop or Now */
                3ch                  /* additional days */
                minmax(0, 1fr);      /* notes */;
            align-items: baseline;
            column-gap: 0.4rem;

            width: 100%;
            min-width: 0;

            color: var(--activityNameColor);
            font-size: var(--activityListItem_name_fontSize);
            text-decoration: none;

            .date,
            .start,
            .stop {
                white-space: nowrap;
            }

            .separator {
                text-align: center;
            }

            .additionalDays {
                color: var(--notesColor);
                font-size: 0.7rem;
                opacity: 0.8;
                white-space: nowrap;
            }

            .notes {
                min-width: 0;
                overflow: hidden;
                color: var(--notesColor);
                font-size: 0.7rem;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
    }

    .periodSearchResult + .periodSearchResult {
        border-block-start: 1px solid var(--listItem_borderColor);
    }

    .breadcrumb,
    .activitySearchResult > .notes {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    p.empty {
        padding-inline-start: 0.75rem;
        margin: 0.25rem 0;
        font-size: var(--emptyListFontSize);
    }
}

@media (max-width: 40rem) {
    .SearchPage {
        .periodResults {
            margin-inline-start: 0.75rem;
        }

        .periodSearchResult {
            .period {
                row-gap: 0.1rem;

                .notes {
                    grid-column: 1 / -1;

                    min-width: 0;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }
            }
        }
    }
}
/* Search Page ------------------------------------------------------------------------------- */

/* SignUpPage  ------------------------------------------------------------------------------- */
.signup {
    .notices {
        padding-block-start: 1rem;

        p {
            padding-inline: 0.75rem;
            font-size: 0.8em;
        }
    }
}
/* SignUpPage  ------------------------------------------------------------------------------- */

/* App Drawer -------------------------------------------------------------------------------- */
body.app > header {
    .headerActions {
        .appDrawer {
            position: relative;
            align-self: stretch;

            .appDrawerSummary {
                display: flex;
                align-items: center;
                justify-content: center;

                box-sizing: border-box;
                min-width: 1.5rem;
                height: 100%;
                padding-inline: 0.3rem;

                cursor: pointer;
                list-style: none;

                background-color: var(--buttonBackgroundColor);
                color: var(--buttonColor);

                span {
                    font-size: 0.7rem;
                    font-weight: normal;
                    line-height: 1;
                    opacity: 0.8;
                }


                &:hover {
                    background-color: var(--buttonBackgroundColorHover);
                    color: var(--buttonColorHover);
                }

                &:active {
                    background-color: var(--buttonBackgroundColorActive);
                    color: var(--buttonColorActive);
                }

                &:focus-visible {
                    outline: 2px solid currentColor;
                    outline-offset: 2px;
                }

                &::-webkit-details-marker {
                    display: none;
                }
            }

            .appDrawerActions {
                position: absolute;
                inset-block-start: calc(100% + 0.25rem);
                inset-inline-end: 0;
                z-index: 100;

                display: grid;
                gap: 0.25rem;

                box-sizing: border-box;
                min-width: 8rem;
                padding: 0.3rem;

                background-color: var(--appContentBackgroundColor);
                border: 1px solid var(--paletteColor70);
                box-shadow: 0 0.2rem 0.5rem rgb(0 0 0 / 25%);

                .appDrawerAction {
                    box-sizing: border-box;
                    width: 100%;
                    margin: 0;
                    text-align: left;
                    white-space: nowrap;
                }

                .signOutForm {
                    width: 100%;
                    margin: 0;
                }
            }
        }
    }
}
/* App Drawer -------------------------------------------------------------------------------- */