/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-2017, 2025 Dan "Ducky" Little
 *
 * 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 NONINFRINGEMENT. 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 IN THE
 * SOFTWARE.
 */

@favorite-star-color: #29b2ff;

.group {
  .group {
    padding-left: @gm-control-size;
  }

  .group-label {
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;

    input[type="checkbox"] {
      /* render a fontawesome chevron instead of a checkbox */
      border: none;

      &::before {
        .fa;

        content: @fa-var-chevron-right;
        width: auto;
        height: auto;
        box-shadow: none;
        clip-path: none;
        transform: none;
      }

      transition: 120ms transform ease-in-out;
      transform: rotate(0deg);

      &:checked {
        transform: rotate(90deg);
      }
    }

    &:hover {
      background-color: #eee;
    }
  }

  .layer {
    padding-left: @gm-control-size;
  }

  &.gm-collapse {
    .children {
      max-height: 0 !important;
      overflow: hidden;
      visibility: hidden !important;
      transition:
        max-height 0.5s ease-in,
        visibility 0s linear 0.5s;
    }
  }

  &.gm-expand {
    .children {
      max-height: 3000px;
      visibility: visible;
      transition:
        max-height 0.5s ease-in,
        visibility 0s linear 0;
    }
  }
}

@checkbox-width: @gm-control-size;
@checkbox-margin: 0.125em;

.layer {
  /* unstyle the tool buttons; buttons do not inherit font by
   * default, which would detach the icons from the panel scale. */
  button {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    font: inherit;
  }

  .layer-label {
    cursor: pointer;
    /* center the toggle, favorite, and label on a common axis,
     * the same way .group-label does. */
    display: flex;
    align-items: center;

    .checkbox {
      margin: @checkbox-margin;
      width: @checkbox-width;
    }
  }

  .layer-tools,
  .catalog-legend {
    padding-left: (@checkbox-width + @checkbox-margin * 2);
  }

  /* keep all of the row's glyphs on the label's scale; the layer
   * toggle stays the visually-largest control in the row. */
  .metadata.icon,
  .favorite.icon,
  .refresh.icon,
  .checkbox.icon {
    font-size: 1em;
  }

  .favorite.icon {
    margin-right: 0.25em;
  }

  .metadata.icon,
  .refresh.icon {
    margin-right: 0.25em;
    margin-left: 0.25em;
  }

  &.out-of-resolution {
    color: #aaa;
    font-style: italic;
  }

  .layer-tools {
    .icon {
      color: #333;
      font-size: @gm-control-size;
      width: 1.75em;
      height: 1.75em;
      border-radius: 50%;

      display: inline-flex;
      justify-content: center;
      align-items: center;

      margin-right: 0.25em;
      margin-bottom: 0.25em;

      &:hover {
        box-shadow: 0 0 1px 1px #a09999;
      }

      &.active {
        box-shadow: 0 0 1px 1px #a09999;
        background-color: rgba(160, 153, 153, 0.2);
      }
    }
  }

  input[type="checkbox"].favorite {
    color: @favorite-star-color;
    border: none;

    /* the star glyphs come from .icon.favorite in icons.less */
    &::before {
      .fa;

      width: auto;
      height: auto;
      box-shadow: none;
      clip-path: none;
      transform: none;
    }
  }
}

.layer.inline-tools {
  .layer-label {
    display: inline-block;
  }

  .layer-tools {
    padding-left: 6px;
    display: inline-block;
  }
}

.catalog {
  /* dense-panel scale: the labels and, through their em sizing,
   * the controls and glyphs all step down together. */
  font-size: @gm-text-ui;

  .searchbox {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;

    text-align: center;

    input {
      padding: 4px;
      margin: 4px;
      text-align: left;
      width: 85%;
      height: 1.5em;
    }
  }

  a.metadata {
    color: black;
  }
}

.catalog.searchable {
  padding-top: 40px;
  padding-left: 4px;
}

.catalog.favorites.flat {
  padding-left: 4px;
}

.catalog.visible-layers.flat {
  padding-left: 4px;
}

/***
 ***  Flat Catalog
 ***/

.catalog.flat {
  .group {
    padding-left: 0px;

    .group-label {
      display: none;
    }

    .children {
      max-height: 2000px !important;
    }

    .layer {
      padding-left: 0px;
    }
  }
}
