/*
    JSPWiki - a JSP-based WikiWiki clone.

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); fyou may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
*/

/*
Style: Collapsible
    Generic support for Collapsible Lists and Boxes.
    (see behavior/Collapsible.js)
*/
//fixme: need to overrule [class^=tab-] *:first-child{margin-top:0;}


/*
Collapsible toggle button, and body scroll animation
*/
//list buttons are rendered as little triangles, which turn 90deg when clicked
.collapse-btn {
	position: relative;
    color: @gray-light;  //default color
	border: 0;
	background: transparent;
	padding:0;

    &:focus {
        outline: 0;
    }
	&:not([disabled]) {
	    color:@link-color;

    	&:hover, &:focus {
        	color: @wiki-mark;
    	}
	}
    &::before {
        content: '';
        width: 0;
        height: 0;
        border-style: solid;
        border-color: transparent currentColor;
        border-width: @collapse-btn-base/2 0 @collapse-btn-base/2 @collapse-btn-base/2;
        position: absolute;
        display: block;
        top: -@collapse-btn-base*(1 - 1/8);
        left: -@collapse-btn-base*(1 + 1/4);
        transition: transform .25s ease-in-out;
    	transform: rotate(45deg) translate(@collapse-btn-base/4);

    }
    &[disabled]::before,
	&[aria-expanded="false"]::before {
    	transform: rotate(0) translate(0);
	}
}
.collapse-body {
    //height will be toggled by javascript to make the animation work
    transition: height .4s ease-in-out;
    height: auto;
    overflow: hidden;

	&[aria-expanded="false"] {
		display:none;   //make sure nested buttons are not reachable anymore -- hidden content is not focusable
	}
}


/*
Style: Collapsible Lists
>   %%collapse

DOM structure BEFORE:
(start code)
    div.collapsible
        ul
            li
                List-item-text
                ul
                    li ...
(end)

DOM structure AFTER:
(start code)
    div.collapsible
        ul
            li
                button.collapse-btn#UID List-item-text
                ul.collapsse-body
                    li ...
*/
.collapse {
    ul, ol {
        list-style:none;
    }

	//additional bootstrap list styles
    .list-nostyle,
    .list-unstyled,
    .list-group {
    	.collapse-btn[disabled] { color:transparent; } //hide the button

    }

	//unstyled list: a lign all list-items on the left margin
    & > ul.list-unstyled, & > ol.list-unstyled {
    	padding-left: 1em;
    }
    & li > ul.list-unstyled, & li > ol.list-unstyled {
    	padding-left:1em;
    	margin-left:-1em;
    }

    //list group: draw nested boxes around groups of list items
    &.list-group {
    	.collapse-btn {
    		//margin-right: @collapse-btn-base;
    		&::before {
				//top: -@collapse-btn-base;
        		//left: 0;
	    	}
    	}
    }
}


/*
Collapsible Boxes
>   %%collapsebox
>   %%collapsebox.closed
>   %%collapsebox-closed
>   %%collapsebox.info , etc..

DOM structure BEFORE:
(start code)
    div.collapsebox
      h4 title
      ... body ...
(end)

DOM structure AFTER:
(start code)
    div.collapsebox
      button.collapse-btn#UID
      h4 title
      div.collapse-body
        ... body ...
(end)

*/
div.list-group,
div[class^=collapsebox] {
    margin-bottom: @line-height-computed;  //copied from contextual boxes from bootstrap

	//collapse boxes have animated +/- toggle buttons
	//inspired by https://codepen.io/El11/pen/gXxxYz
    .collapse-btn {
        margin-top: @line-height-computed/2;  //adopt margin from header  -- see bootstrap style.less
        margin-right: @collapse-btn-base/2;
        height: @collapse-btn-base;
        width: @collapse-btn-base;
        float: left;

        & + h2,& + h3,& + h4 {
            margin: 0;
        }
        &::before,
        &::after {
        	background: @link-color;
        	position: absolute;
        	content: '';
        	border: 0; //overwrite the triangle borders
        	height: @collapse-btn-base/4;
        	width: @collapse-btn-base;
        	left: 0;
        	top: 0;
        }
        &[disabled]::after {
        	background: @gray-light;
        }
        &::before {
        	transform: rotate(0);
        	transform-origin: center;   //vertical leg of the plus sign
        }
		&:not([disabled]) {
	    	&:hover, &:focus {
	    		&::before, &::after {
        			background: @wiki-mark;
	    		}
    		}
		}
        &[aria-expanded="false"]::before {
        	transform: rotate(-90deg);
        }
	}
}
