////
/// Copyright (c) 2016-2018 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////

// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------

// Scoped in typesetted content to match specificity of regular content
.md-typeset {

  // Details extension
  details {
    @extend .admonition;

    display: block;
    padding-top: 0;

    // Rotate title icon
    &[open] > summary::after {
      transform: rotate(180deg);
    }

    // Remove bottom spacing
    &:not([open]) {
      padding-bottom: 0;

      // Remove bottom border if block is closed
      > summary {
        border-bottom: none;
      }
    }

    // Increase spacing to the right - scoped here for higher specificity
    summary {
      padding-right: 4rem;

      // Adjust for RTL languages
      [dir="rtl"] & {
        padding-left: 4rem;
      }
    }

    // Manually hide and show, if browser doesn't support details
    .no-details &:not([open]) {

      // Hide all nested tags ...
      > * {
        display: none;
      }

      // ... but show title
      summary {
        display: block;
      }
    }
  }

  // Title
  summary {
    @extend .admonition-title;

    // Hack: set to block, so Firefox doesn't render marker
    display: block;
    outline: none;
    cursor: pointer;

    // Remove default details marker
    &::-webkit-details-marker {
      display: none;
    }

    // Icon
    &::after {
      @extend %md-icon;

      position: absolute;
      top: 0.8rem;
      right: 1.2rem;
      color: $md-color-black--lighter;
      font-size: 2rem;
      content: "\E313"; // keyboard_arrow_down

      // Adjust for RTL languages
      [dir="rtl"] & {
        right: initial;
        left: 1.2rem;
      }
    }
  }
}
