@use "variables";
@use "global";

.collapsible {
  border: 1px solid var(--mm-border-color, variables.$collection-border-color);
  background-color: var(--mm-surface-color, variables.$collection-bg-color);
  margin: variables.$element-top-margin 0 variables.$element-bottom-margin 0;
  overflow: hidden;

  li {
    list-style-type: none;
  }
}

// Main header (top-level header for the whole collapsible)
.collapsible-main-header {
  background-color: var(--mm-surface-color, variables.$collection-bg-color);
  border-bottom: 1px solid var(--mm-border-color, variables.$collection-border-color);
  padding: 10px 20px;
  // Don't override h4 styling - let it use default typography
  // This ensures consistent height with Collection headers
}

// Item header (collapsible item header)
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 3rem;
  line-height: 1.5rem;
  padding: 1rem;
  background-color: var(--mm-surface-color, variables.$collection-bg-color);
  border-bottom: 1px solid var(--mm-border-color, variables.$collection-border-color);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .25s;

  &:hover {
    background-color: var(--mm-row-hover, variables.$collection-hover-bg-color);
  }

  &:focus {
    outline: 0;
  }

  i.material-icons {
    width: 2rem;
    font-size: 1.6rem;
    line-height: 1.5rem;
    display: block;
    flex-shrink: 0;
    margin-right: 1rem;
  }

  // Wrapper for header content - takes remaining space
  .collapsible-header-text,
  .collapsible-header-content {
    flex: 1;
    align-items: center;
    gap: 1rem;
  }
}

.keyboard-focused .collapsible-header:focus {
  background-color: var(--mm-row-hover, variables.$collection-hover-bg-color);
}

.collapsible-body {
  display: none;
  border-bottom: 1px solid var(--mm-border-color, variables.$collection-border-color);
  background-color: var(--mm-surface-color, variables.$collection-bg-color);
  box-sizing: border-box;
  padding: 2rem;

  // Remove bottom border from last item
  li:last-child & {
    border-bottom: none;
  }
}

// Active state
li.active {
  .collapsible-body {
    display: block;
  }
}

// Collapsible with header
.collapsible.with-header {
  .collapsible-main-header:first-child {
    border-top: none;
  }
}

// Sidenav collapsible styling
.sidenav,
.sidenav.sidenav-fixed {

  .collapsible {
    border: none;
    box-shadow: none;

    li { padding: 0; }
  }

  .collapsible-header {
    background-color: transparent;
    border: none;
    line-height: inherit;
    height: inherit;
    padding: 0 variables.$sidenav-padding;

    &:hover { background-color: rgba(0,0,0,.05); }
    i { line-height: inherit; }
  }

  .collapsible-body {
    border: 0;
    background-color: var(--mm-surface-color, variables.$collapsible-header-color);
    color: var(--mm-text-primary, rgba(0, 0, 0, 0.87));

    li a {
      padding: 0 (7.5px + variables.$sidenav-padding)
               0 (15px + variables.$sidenav-padding);
    }
  }

}

// Popout Collapsible

.collapsible.popout {
  border: none;
  box-shadow: none;
  > li {
    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    // transform: scaleX(.92);
    margin: 0 24px;
    transition: margin .35s cubic-bezier(0.250, 0.460, 0.450, 0.940);
  }
  > li.active {
    box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
    margin: 16px 0;
    // transform: scaleX(1);
  }
}
